Skip to content

[Bug]: Silently fails OTEL trace propagation #812

@HonakerM

Description

@HonakerM

Problem Description

The standard open telemetry documentation includes the following snippet for trace propagation:

from opentelemetry import context as opentelemetry_context
from opentelemetry.trace.propagation.tracecontext import TraceContextTextMapPropagator

carrier = {}
TraceContextTextMapPropagator().inject(carrier)

# Send to different process ...

ctx = TraceContextTextMapPropagator().extract(carrier=carrier)
opentelemetry_context.attach(ctx)

However, this silently fails with Instana. The traces are not connected and there is no warning emitted.


I tried using the Instana TextPropagator like the following:

from instana.propagators.text_propagator import TextPropagator
carrier = {}
TextPropagator().inject(current_span.get_span_context(), carrier)

# Send to different processs

ctx = TextPropagator().extract(carrier=carrier)
opentelemetry_context.attach(ctx)

But ran into errors around ctx being a SpanContext and not a normal Context.


The only way I was able to resolve this issue was to do something like the following where I use thread local variables to ensure I call start_span with the SpanContext

import threading
from instana.propagators.text_propagator import TextPropagator

CURRENT_INSTANA_SPAN_CONTEXT = threading.local()

carrier = {}
TextPropagator().inject(current_span.get_span_context(), carrier)

# Send to different processs

ctx = TextPropagator().extract(carrier=carrier)
CURRENT_INSTANA_SPAN_CONTEXT.context = ctx

# Later in code:
with tracer.start_span("span_name", span_context=CURRENT_INSTANA_SPAN_CONTEXT.context

I would like to be able to use standard OTEL trace propagation methods with Instana or have similar functionality

Minimal, Complete, Verifiable, Example

No response

Python Version

3.11

Python Modules

N/A

Python Environment

N/A

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions