-
Notifications
You must be signed in to change notification settings - Fork 18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: implement transaction context #315
base: main
Are you sure you want to change the base?
feat: implement transaction context #315
Conversation
7f2da6b
to
b622d21
Compare
b622d21
to
11d580d
Compare
] | ||
|
||
_evaluation_context = EvaluationContext() | ||
|
||
_hooks: typing.List[Hook] = [] | ||
|
||
_transaction_context_propagator: TransactionContextPropagator = ( | ||
NoopTransactionContextPropagator() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should the SDK initialize a functional transaction context propagator by default?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We do something similar to this in JS. What would the alternative be?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Having a default implementation that is not a no-op. But it could introduce a performance penalty if you are not using it, so probably better to default to no-op. We might want to put out a warning if you call set_transaction_context
with a NoopTransactionContextPropagator though.
|
||
|
||
def get_transaction_context() -> EvaluationContext: | ||
return _transaction_context_propagator.get_transaction_context() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this the right API or do we want something based on decorators/context managers?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you elaborate on this? The main use case for accessing transaction context would be within the SDK when it merges context prior to flag evaluation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, the comment should have been in the set_transaction_context
. I was wondering if we should do something like this instead:
with start_transaction_context(context):
continue_transaction() # context will be cleaned up after the block completes
Similar to the way it works in JS by taking a callback.
11d580d
to
1c72782
Compare
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #315 +/- ##
==========================================
- Coverage 97.32% 97.18% -0.15%
==========================================
Files 26 28 +2
Lines 1198 1244 +46
==========================================
+ Hits 1166 1209 +43
- Misses 32 35 +3
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
Signed-off-by: Federico Bond <[email protected]>
1c72782
to
c31a2fa
Compare
This is a draft implementation of transaction context propagation via contextvars.