Skip to content

feat: make the ASGI receive/send spans opt-out on Litestar - #288

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

lesnik512 merged 1 commit into
mainfrom
feat/litestar-exclude-spans

Conversation

@lesnik512

Copy link
Copy Markdown
Member

Closes #287.

Adds opentelemetry_exclude_spans to LitestarConfig and passes it to LitestarOpenTelemetryConfig(exclude_spans=...). FastAPI has had this since #225.

Same shape as FastAPI

The field stays on each framework config, not the shared OpenTelemetryConfig, because the FastStream and FastMCP bootstrappers have nothing to pass it to. The FastAPI comment said Litestar's instrumentor lacked the parameter. That was wrong, and the comment now names both frameworks.

The default is an empty list, so existing services keep all their spans. The value is passed unconditionally, as on FastAPI: the ASGI middleware treats [] and Litestar's default None the same way.

No dependency change

Litestar's OpenTelemetryConfig has had exclude_spans since 2.22, and litestar-otl already requires litestar>=2.22. I checked the 2.22.0 wheel directly.

Tests

The tests run a real request through the bootstrapped app with an in-memory exporter. The default test asserts that an INTERNAL span (an ASGI event span) is recorded. The new test asserts that with ["receive", "send"] only the SERVER span remains. Before the change it failed with unexpected keyword argument 'opentelemetry_exclude_spans'.

The configuration and performance docs no longer say "FastAPI only".

LitestarConfig gets the same opentelemetry_exclude_spans field as
FastAPIConfig and passes it to Litestar's OpenTelemetryConfig, which has
taken exclude_spans since 2.22, the litestar-otl floor.
@lesnik512
lesnik512 merged commit afdaa03 into main Oct 16, 2026
30 checks passed
@lesnik512
lesnik512 deleted the feat/litestar-exclude-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.

Litestar: expose opentelemetry_exclude_spans like FastAPI does

1 participant