In its current implementation, the OT shim doesn't preserve ScopeShim and SpanShim objects after creating them. This results in situations such as the following:
- The instrumentation creates and activates a span using
start_active_span(), which results in a ScopeShim object containing a SpanShim object.
- The instrumentation then obtains the currently-active span using the shim's
active_span property.
- The
ScopeShim returned by active_span isn't the same object as the one returned from start_active_span().
The reason for the behavior described above is that we only keep state in the OpenTelemetry tracer. We don't really have an OpenTracing tracer or scope manager which keep track of spans. When the user queries the shim's API for the currently-active span for example, we construct a new object from the existing OpenTelemetry object. So the returned object contains the same OpenTelemetry span, but the wrapper objects themselves aren't the same OpenTracing objects as the ones returned to the user during span creation and activation.
There doesn't seem to be an easy way to address this issue. @Oberon00 has some ideas on how this can be implemented.
|
@property |
|
def active(self): |
|
span = self._tracer.unwrap().get_current_span() |
|
if span is None: |
|
return None |
|
|
|
span_context = SpanContextShim(span.get_context()) |
|
wrapped_span = SpanShim(self._tracer, span_context, span) |
|
return ScopeShim(self, span=wrapped_span) |
|
# TODO: The returned `ScopeShim` instance here always ends the |
|
# corresponding span, regardless of the `finish_on_close` value used |
|
# when activating the span. This is because here we return a *new* |
|
# `ScopeShim` rather than returning a saved instance of `ScopeShim`. |
|
# https://github.com/open-telemetry/opentelemetry-python/pull/211/files#r335398792 |
|
# TODO: We can't check for equality of self.shim.active_span and |
|
# scope.span because the same OpenTelemetry span is returned inside |
|
# different SpanShim objects. A possible solution is described |
|
# here: |
|
# https://github.com/open-telemetry/opentelemetry-python/issues/161#issuecomment-534136274 |
|
# TODO: Check equality of the spans themselves rather than |
|
# their context once the SpanShim reconstruction problem has |
|
# been addressed (see previous TODO). |
Relevant discussions:
#211 (comment)
#161 (comment)
In its current implementation, the OT shim doesn't preserve
ScopeShimandSpanShimobjects after creating them. This results in situations such as the following:start_active_span(), which results in aScopeShimobject containing aSpanShimobject.active_spanproperty.ScopeShimreturned byactive_spanisn't the same object as the one returned fromstart_active_span().The reason for the behavior described above is that we only keep state in the OpenTelemetry tracer. We don't really have an OpenTracing tracer or scope manager which keep track of spans. When the user queries the shim's API for the currently-active span for example, we construct a new object from the existing OpenTelemetry object. So the returned object contains the same OpenTelemetry span, but the wrapper objects themselves aren't the same OpenTracing objects as the ones returned to the user during span creation and activation.
There doesn't seem to be an easy way to address this issue. @Oberon00 has some ideas on how this can be implemented.
opentelemetry-python/ext/opentelemetry-ext-opentracing-shim/src/opentelemetry/ext/opentracing_shim/__init__.py
Lines 158 to 171 in 26d56c0
opentelemetry-python/ext/opentelemetry-ext-opentracing-shim/tests/test_shim.py
Lines 63 to 67 in 26d56c0
opentelemetry-python/ext/opentelemetry-ext-opentracing-shim/tests/test_shim.py
Lines 283 to 285 in 26d56c0
Relevant discussions:
#211 (comment)
#161 (comment)