-
Notifications
You must be signed in to change notification settings - Fork 624
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 initial DistributedContext implementation. #92
Conversation
opentelemetry-api/src/opentelemetry/distributedcontext/__init__.py
Outdated
Show resolved
Hide resolved
opentelemetry-api/src/opentelemetry/distributedcontext/__init__.py
Outdated
Show resolved
Hide resolved
opentelemetry-sdk/src/opentelemetry/sdk/distributedcontext/__init__.py
Outdated
Show resolved
Hide resolved
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've left comments on the parsing logic.
We might want to refer to the draft CorrelationContext spec.
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.
IMO the one change needed is to adhere to ABCs for unimplemented APIs.
As an aside, I think #89 and this PR are going to conflict a bit around the context singleton specifically. I think options are:
- we merge this PR in and unifying propagator formatters #89 might refactor this context var depending on how that turns out.
- we remove the distributedcontext singleton specifically (keep the classes which all look awesome) and have unifying propagator formatters #89 handle adding the appropriate context var.
I'm okay with either. looks great!
|
||
from opentelemetry import distributedcontext as dctx_api | ||
|
||
_CURRENT_DISTRIBUTEDCONTEXT_CV = contextvars.ContextVar( |
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 think we should use the existing context object that exists in the API: https://github.com/open-telemetry/opentelemetry-python/blob/master/opentelemetry-api/src/opentelemetry/context/__init__.py
There will be a need to supplement raw contextvars with other mechanisms to support python 3.4 up to 3.7
def get_current_context(self) -> typing.Optional[DistributedContext]: | ||
return self._cv.get(default=None) | ||
|
||
@contextmanager |
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.
nice!
opentelemetry-api/src/opentelemetry/distributedcontext/__init__.py
Outdated
Show resolved
Hide resolved
opentelemetry-api/src/opentelemetry/distributedcontext/__init__.py
Outdated
Show resolved
Hide resolved
036d8ac
to
701fccd
Compare
opentelemetry-api/src/opentelemetry/distributedcontext/__init__.py
Outdated
Show resolved
Hide resolved
I'm wondering if we could keep |
@carlosalberto That's basically what's happening 😄
The benefit of the current approach is that the type checker can ensure that only validated strings are passed into the API while maintaining the optimizations provided by using raw |
374a771
to
8f7c530
Compare
8e4d93f
to
634e7db
Compare
|
||
PROPAGATOR = HTTPTextFormat() | ||
|
||
|
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.
minor: remove extra line
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.
LGTM.
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.
There are a few small things I noticed that should be fixed before merging this.
opentelemetry-api/src/opentelemetry/distributedcontext/__init__.py
Outdated
Show resolved
Hide resolved
opentelemetry-api/src/opentelemetry/distributedcontext/__init__.py
Outdated
Show resolved
Hide resolved
-- @toumorokoshi in #92 (review) I'm still not so sure about that policy (did we officially decide on it?). But I'm sure we decided that the API package must be usable as no-op implementation without loading any implementation from elsewhere. |
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.
Just some details I found when reading this PR.
opentelemetry-api/src/opentelemetry/distributedcontext/__init__.py
Outdated
Show resolved
Hide resolved
UNLIMITED_PROPAGATION = -1 | ||
|
||
def __init__(self, entry_ttl: int) -> None: | ||
self.entry_ttl = entry_ttl |
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.
Given that currently only NO_PROPAGATION
and UNLIMITED_PROPAGATION
are allowed should be a check for that?
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'm not sure there's much value in doing a runtime check for these values, especially considering the intended purpose is to actually support positive integers in the future.
Co-Authored-By: Reiley Yang <reyang@microsoft.com>
…_.py Co-Authored-By: Christian Neumüller <christian+github@neumueller.me>
289066c
to
7eab1e8
Compare
7239e4f
to
ae4f570
Compare
@toumorokoshi Your review is pending with requested changes. I'm thinking that option 1 mentioned in the review comment (merge this PR and revisit #89 ) may be the easiest path forward. Thoughts? |
Discussed in the community meeting, we can follow up in another PR / issue.
@GeorgeJoy FYI. |
This PR fixes issue #91 by attempting to implement the distributed context api specification.
The work is based somewhat on the opentelemetry-ruby implementation.
This PR hasn't yet implemented the propagator APIs for DistributedContext. The intent is that when this PR is ready for review a stub will have been implemented for propagators in distributed context.