Repository navigation
test: adapt FastAPI tests for native OTel spans - #912
Open
CagriYonca wants to merge 2 commits into
Open
CagriYonca wants to merge 2 commits into
CagriYonca wants to merge 2 commits into
Conversation
CagriYonca
force-pushed
the
update-fastapi-tests
branch
from
October 7, 2026 12:15
b69cabc to
a256fe1
Compare
pvital
requested changes
Oct 7, 2026
CagriYonca
force-pushed
the
update-fastapi-tests
branch
from
October 7, 2026 12:36
a256fe1 to
1f27e81
Compare
Signed-off-by: Cagri Yonca <cagri@ibm.com>
Signed-off-by: Cagri Yonca <cagri@ibm.com>
CagriYonca
force-pushed
the
update-fastapi-tests
branch
from
October 7, 2026 12:57
0b4418f to
78e05f4
Compare
pvital
requested changes
Oct 7, 2026
| def assert_fastapi_otel_spans( | ||
| spans: list, | ||
| http_route: str, | ||
| *, |
Contributor
Author
There was a problem hiding this comment.
It forces you to give argument keys for cleaner function calls:
assert_fastapi_otel_spans(spans, "/400", False, 400) # not valid
assert_fastapi_otel_spans(spans, "/400", expect_serialization=False, http_status_code=400) # valid
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.
FastAPI
0.115.0addedopentelemetry-apias a dependency and now emits its own spans automatically. Since Instana registers itself as the global OTelTracerProvider, these spans land in Instana's recorder and were breaking all FastAPI tests with unexpected span counts.Per request, FastAPI now adds:
fastapi.dependencies,fastapi.endpoint,fastapi.serialization— parented under theasgispanGET /path— orphan (separate trace,p == 0); FastAPI opens it before Instana's middleware runs so it never inherits the Instana trace contextChanges:
yieldto the_resourcefixture (teardown was silently not running)assert_fastapi_otel_spans()helper intests/helpers.pyto avoid repeating the same OTel span assertions across all testsNo production code is changed. The question of whether to suppress FastAPI's native spans at the instrumentation level is tracked separately.
Note: Removed unused variable from sqlalchemy tests based on ruff report.