Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Add the Context notion. #424
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
Add the Context notion. #424
Changes from 54 commits
fb10415
8451596
5275f32
7c01d61
dd834a7
7f9c6b8
f43b7db
548e3d0
4942040
dda30bb
59cf5f3
278839b
71f51e5
a3502c1
9be19e2
ae1c052
0a4f08d
a491a5b
a36759c
58c6248
ecdd80d
95f7bd2
656fe58
9e8a3bd
086facb
63c40a6
551a255
bf398e1
5a9a679
0f26bc7
6b962ba
60e22c0
505c2f7
e06c9b0
af9287a
d38b6fc
0e76724
c697fef
a4d588c
fdd79e1
48d98c2
07398c1
051f36f
e307486
073a526
9745124
4649574
c4b3423
0b5c1f1
3b58a29
3fe6238
732f4e9
01e0925
a3e5134
13b1c02
75ae4bc
5f0b166
7393c0c
42adf76
eeb9afc
0794250
190da25
c8bbf39
f28568c
74d1084
dc92999
93a0cf7
e91a898
2db3f2e
4e02075
8bc320e
96c26b9
85cbb5b
f1431c8
965f365
a289dff
27e701a
980af1b
c9c3cf1
31af4d9
a3567d9
cbd3b71
54735b8
349af35
6ce4054
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
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.
s/maybe/may be/
Is "finished" accurate? I wish we kept OT naming here, "span ended" sounds weird.
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.
:) I will update this line in another (tiny) PR.
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 should encourage to have this return a Token that is used to restore the Context. See Java (grpc) and https://docs.python.org/3/library/contextvars.html#contextvars.ContextVar.set which does the same at a value level because set makes that value current.
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.
Added another minor note as well.
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 probably need a restore where we use the handle to restore to the previous Context.
PS: attach/detach are probably better names for these 2 methods.
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.
I'd leave Restore out for now as well (for simplicity purposes - lets add it when we add "Remove" from
Context
to have a more complete set of operations).And you mean:
Set current Context -> Attach Context
Restore Context -> Detach Context
?
To me that sounds great, but probably too Java-ish ;)
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.
Restore/Detach is not equivalent to Remove. You need to have code like this:
So detach is very important compared with Remove, I don't see how a Context would work without detach, because you will set a new Context and that will stay active even after you are out of scope. Another option is to have
Context.attach(newContext)
returning a Scope that when it goes out of scope restores the previous Context. See example: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.
By the way, added a small section on the
Detach Context
part. Please review.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.
My question around this change is that since the Context API already provides a mechanism to explicitly set and get a Context, how will using a token to restore a previous Context differ from getting a previous Context then setting it again when wanting to restore?
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.
@codeboten this is a very interesting point about why not just simply having one
set
is not enough, because as you said it can be used to restore the previous Context.There are few reasons:
set
as push to a stack andrestore
as pop where you check that the element you intend to pop is the expected one. This is critical and I've seen cases where auth tokens were leaked because of this issue (I don't think I can share too many things about this issue, but the root cause were people calling set without a paired restore).It can still happen if a Set is not followed by a Restore, but by having the Restore users can identify very soon this wrong behavior because the next Restore call will give a signal to the users (log, crash, based on a config).
So this API helps users use the Context API in an expected way.
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.
Can this reasoning be added to the spec? It became a topic for discussion without any sort of information in the merged spec itself to help substantiate: open-telemetry/opentelemetry-python#429 (comment)
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.
Added #490