Skip to content

Commit f367d2c

Browse files
committed
fix(tracer): use isinstance guard when extracting span context from OTel context
Signed-off-by: Michael Ramos <ramosm@us.ibm.com>
1 parent fea2e0a commit f367d2c

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

src/instana/tracer.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,10 @@ def start_span(
121121
) -> InstanaSpan:
122122
# Extract span_context from context if needed (OpenTelemetry API compliance)
123123
if context is not None and span_context is None:
124-
span_context = otel_get_current_span(context).get_span_context() # type: ignore[assignment]
124+
otel_ctx = otel_get_current_span(context).get_span_context()
125+
if isinstance(otel_ctx, SpanContext):
126+
span_context = otel_ctx
127+
125128

126129
parent_context = (
127130
span_context if span_context else instana_get_current_span().get_span_context()
@@ -159,7 +162,9 @@ def start_as_current_span(
159162
) -> Iterator[InstanaSpan]:
160163
# Extract span_context from context if needed (OpenTelemetry API compliance)
161164
if context is not None and span_context is None:
162-
span_context = otel_get_current_span(context).get_span_context() # type: ignore[assignment]
165+
otel_ctx = otel_get_current_span(context).get_span_context()
166+
if isinstance(otel_ctx, SpanContext):
167+
span_context = otel_ctx
163168

164169
# Pass both context and span_context - the guard in start_span prevents redundant extraction
165170
span = self.start_span(

0 commit comments

Comments
 (0)