Repository navigation
Regression test: W3C traceparent upstream context in FastAPI (issue #879) - #919
Open
CagriYonca wants to merge 1 commit into
Open
CagriYonca wants to merge 1 commit into
CagriYonca wants to merge 1 commit into
Conversation
CagriYonca
force-pushed
the
test/fastapi-traceparent-regression
branch
from
October 15, 2026 07:58
4d0c21d to
c3e0c1a
Compare
CagriYonca
marked this pull request as ready for review
October 15, 2026 09:02
This branch has not been deployed
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What & Why
FastAPI >= 0.142.0 introduced its own telemetry middleware (
fastapi/middleware/asyncexitstack.py→
fastapi/telemetry/_asgi.py). When an incoming request carries a W3Ctraceparentheader,this middleware builds a native OpenTelemetry
Contextand passes it directly totracer.start_span(name, context=parent, ...).Before the fix merged in PR #904,
InstanaTracer.start_span()enforced a strict type check:This caused every request carrying an upstream
traceparentheader to return HTTP 500,silently breaking distributed trace continuity for any FastAPI service sitting behind another
instrumented service.
What this PR adds
A regression test —
test_w3c_traceparent_upstream_contextintests/frameworks/test_fastapi.py— that guards against this regression coming back.The test:
traceparentheader with a 128-bit trace ID and 64-bit span ID.GET /request viaTestClientwith that header.HTTP 200— a500here means theTypeErroris still present.X-INSTANA-T,X-INSTANA-S, andServer-Timingresponse headers areset, confirming Instana's trace context is still propagated downstream.
trace_id(lower 64 bits) matches the upstreamtrace ID, preserving cross-service trace continuity.
parent_idmatches the upstream span ID, so the UI rendersthe correct parent–child relationship.
Test result evidence
tracer.pystate1f34ca7c(before fix)raise TypeError(...)main(after fix,a449cebb+)SpanContextconversionScope
fix(tracer): support converting OpenTelemetry parent span context).Related