-
Notifications
You must be signed in to change notification settings - Fork 656
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing a proof of concept of a few changes to the propagation API
Adding a UnifiedContext, composing DistributedContext and SpanContext. This will enable propagators to extract and inject values from either system, enabling more sophisticated schemes and standards to propagate data. This also removes the need for generics and propagators that only consume one or the other, requiring integrators to do extra work to wire propagators appropriately. Modifying the API of the propagators to consume the context as a mutable argument. By passing in the context rather than returning, this enables the chained use of propagators, allowing for situations such as supporting multiple trace propagation standards simulatenously.
- Loading branch information
1 parent
b7b38a5
commit 81f4c57
Showing
17 changed files
with
186 additions
and
298 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
opentelemetry-api/src/opentelemetry/context/unified_context.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
# Copyright 2019, OpenTelemetry Authors | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
from opentelemetry.distributedcontext import DistributedContext | ||
from opentelemetry.trace import SpanContext | ||
|
||
|
||
class UnifiedContext: | ||
"""A unified context object that contains all context relevant to | ||
telemetry. | ||
The UnifiedContext is a single object that composes all contexts that | ||
are needed by the various forms of telemetry. It is intended to be an | ||
object that can be passed as the argument to any component that needs | ||
to read or modify content values (such as propagators). By unifying | ||
all context in a composed data structure, it expands the flexibility | ||
of the APIs that modify it. | ||
As it is designed to carry context specific to all telemetry use | ||
cases, it's schema is explicit. Note that this is not intended to | ||
be an object that acts as a singleton that returns different results | ||
based on the thread or coroutine of execution. For that, see `Context`. | ||
Args: | ||
distributed: The DistributedContext for this instance. | ||
span: The SpanContext for this instance. | ||
""" | ||
__slots__ = ["distributed", "span"] | ||
|
||
def __init__(self, distributed: DistributedContext, span: SpanContext): | ||
self.distributed = distributed | ||
self.span = span | ||
|
||
@staticmethod | ||
def create(span: SpanContext) -> "UnifiedContext": | ||
"""Create an unpopulated UnifiedContext object. | ||
Example: | ||
from opentelemetry.trace import tracer | ||
span = tracer.create_span("") | ||
context = UnifiedContext.create(span) | ||
Args: | ||
parent_span: the parent SpanContext that will be the | ||
parent of the span in the UnifiedContext. | ||
""" | ||
return UnifiedContext(DistributedContext(), span) | ||
|
||
def __repr__(self) -> str: | ||
return "{}(distributed={}, span={})".format( | ||
type(self).__name__, repr(self.distributed), repr(self.span)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.