Skip to content

feat: drop the ASGI send/receive spans from traces - #86

Merged
lesnik512 merged 1 commit into
mainfrom
feat/exclude-asgi-event-spans
Oct 16, 2026
Merged

lesnik512 merged 1 commit into
mainfrom
feat/exclude-asgi-event-spans

Conversation

@lesnik512

Copy link
Copy Markdown
Member

Sets opentelemetry_exclude_spans=["receive", "send"] in api_bootstrapper_config. lite-bootstrap passes it to FastAPIInstrumentor.instrument_app (lite-bootstrap #225, available since 1.8.0; the template is on 1.9.3).

Why

A traced GET /api/decks/{id}/ records 6 spans: the server span, 2 http send spans, connect and 2 SELECT. The two send spans mark when the response start and body went out, which is rarely worth looking at for a JSON API. Dropping them is cheap. The benchmark below is the same harness as #85: the full app driven through raw ASGI, with the OTLP exporter encoding spans and then dropping them. Medians of 3 runs, in req/s:

1 client 100 clients
no tracing 1450 1411
always on 836 858
always on, send/receive excluded 876 923
10% ratio sampler 1116 1058
10% ratio sampler, send/receive excluded 1142 1093

The README notes the setting and says to remove it if those spans are needed.

Tests

test_request_has_no_asgi_event_spans sends a real GET /api/decks/ and asserts that, apart from SQLAlchemy spans, the only span recorded is the SERVER span. It failed before the settings change, when INTERNAL event spans were present.

litestar-sqlalchemy-template will get the same change once lite-bootstrap releases modern-python/lite-bootstrap#288.

Sets opentelemetry_exclude_spans=["receive", "send"], so a traced request
records its server span and database spans only.
@lesnik512
lesnik512 merged commit e702bc7 into main Oct 16, 2026
2 checks passed
@lesnik512
lesnik512 deleted the feat/exclude-asgi-event-spans branch October 16, 2026 11:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant