Skip to content

Consistently return ScopeShim and SpanShim objects in the OT shim #242

Closed

Description

@johananl

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:

  1. The instrumentation creates and activates a span using start_active_span(), which results in a ScopeShim object containing a SpanShim object.
  2. The instrumentation then obtains the currently-active span using the shim's active_span property.
  3. 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)

Activity

  1. self-assigned this
    on Jul 11, 2020
  2. added 11 commits that reference this issue on Jul 17, 2020
    03c6aa7
    c1595ed
    bd5efd0
    d661552
    3a89ac9
    97947a5
    795e11d
    6de59d4
    3a3ca89
    7de3b03
    4df8da2
  3. 10 remaining items

  4. added 13 commits that reference this issue on Aug 5, 2020
    e93e135
    48cb3a5
    384c303
    40015cc
    251730c
    a06c808
    36dd87c
    8f3cdb5
    d688851
    0aabe24
    d975527
    9205f1f
    63d0224
  5. added 2 commits that reference this issue on Nov 1, 2020
    ea28887
    7189c1a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

release:required-for-gaTo be resolved before GA releaseshimOpenTracing or OpenCensus compatibilitytracing

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions