Repository navigation
Conversation
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.
Closes #309.
On FastAPI, Litestar and FastMCP,
opentelemetry_exclude_spansnow defaults to["receive", "send"], so each request records only its server span. Before this change, the OpenTelemetry ASGI middleware also opened one span perreceiveand persendevent. It opened them withstart_as_current_spaneven when the trace was unsampled.FastMcpConfiggains the field, and it is passed toOpenTelemetryMiddleware.Changes
OpenTelemetryAsgiConfiginopentelemetry_instrument.pysubclassesOpenTelemetryConfigand declaresopentelemetry_exclude_spansonce.FastAPIConfig,LitestarConfigandFastMcpConfiginherit it in place ofOpenTelemetryConfig, the same waySentryLeanCaptureConfigis shared. Free and FastStream keepOpenTelemetryConfigand get no field. The issue left this mixin optional.FastMcpOpenTelemetryInstrument._instrument_http_apppassesexclude_spans. The middleware has accepted it since the 0.49b0 floor (opentelemetry/instrumentation/asgi/__init__.py:551at contrib tag v0.49b0, which I checked).exclude_spans" comment is gone along with the per-config fields.Tests
Written first. These failed on main:
test_fastapi_opentelemetry_exclude_spans_defaults_to_dropping_the_event_spans(the flipped default test)test_litestar_otel_exclude_spans_defaults_to_only_the_server_span: one request now gives exactly one span, of kind SERVER. This covers the issue's "one server span" check.test_fastmcp_otel_exclude_spans_defaults_to_only_the_server_spanandtest_fastmcp_otel_exclude_spans_emptied_records_the_event_spans, which send a health-check request throughhttp_app().The existing explicit-value tests on FastAPI and Litestar now set
[]and check that the event spans come back.The full suite passes, 554 tests at 100% coverage.
just lint(includingty),just adr-checkandjust docs-buildpass too. I didn't run the floors locally. The only new call isexclude_spansonOpenTelemetryMiddleware, which has been in the floor's signature since 0.49b0, so I left the floors to CI.Measurement
In-process on an M2 Mac at 100% sampling (CPython 3.14.7, opentelemetry-sdk 1.45.1, instrumentation-asgi 0.66b1, fastapi 0.162.0, litestar 2.25.0, fastmcp 4.1.4). Figures are µs over the bare app:
otel)opentelemetry_exclude_spans=[](otel_all_spans)tools/callFastMCP's rounds differed by up to 9%, and FastAPI's
otelrow by 17%. These agree with the issue's Linux numbers: 46 µs on FastAPI, 41 to 53 µs on Litestar and 91 µs for the FastMCP prototype.otel_all_spansis a new scenario in the three suites, withALL_SPANSincommon.py. The existing*_exclscenarios now have the same config as the default, so I left them alone.Docs
configuration.md: the paragraph now covers FastAPI, Litestar and FastMCP and gives the new default, its cost and how to get the spans back.performance.md: the table row is marked as the default since 2.0. The "savings applied for you" paragraph now has six savings, and the unsampled-floor note says the spans are excluded by default.benchmarks/README.md:Departure from the issue
The issue suggests shipping the field on FastMCP with an empty default in a 1.x minor, which would make this PR only the flip. I did both here because main is on 2.0. If you want the field in a 1.x release too, it would need a separate backport.
Breaking changes
Traces from FastAPI, Litestar and FastMCP services no longer have the per-message
receiveandsendspans. Setopentelemetry_exclude_spans=[]to get them back.