Skip to content

Litestar: expose opentelemetry_exclude_spans like FastAPI does #287

Closed

Description

@lesnik512

FastAPIConfig.opentelemetry_exclude_spans (#185, #225) drops the ASGI receive and send spans. LitestarConfig has no equivalent. The comment above the FastAPI field says Litestar's instrumentor has no such parameter, but Litestar's OpenTelemetryConfig has had exclude_spans: list[Literal["receive", "send"]] | None since 2.22, and litestar-otl already requires litestar>=2.22. Since #279, LitestarOpenTelemetryInstrument builds that config itself, so the value only needs passing through.

What it saves

I measured this on litestar-sqlalchemy-template, GET /api/decks/{id}/. The test runs the full app with one ORM read and drives it through raw ASGI. The OTLP exporter is patched to encode spans and then drop them. Each request emits 6 spans: the server span, 2 http send spans, connect and 2 SELECT. Excluding the send and receive spans removes the 2 http send spans. Medians of 3 runs, in req/s:

1 client 100 clients
no tracing 1585 1558
always on 896 953
always on, exclude_spans=["receive", "send"] 963 1006
10% ratio sampler 1211 1162
10% ratio sampler, exclude_spans=["receive", "send"] 1255 1208

That is about 75 µs per request with every request traced. The FastAPI template showed about 55 µs per request on the same endpoint.

Proposal

Add the same opentelemetry_exclude_spans field to LitestarConfig and pass it to LitestarOpenTelemetryConfig(exclude_spans=...). Keep the default empty, as on FastAPI, so existing trace views don't change. Update the FastAPI comment, and remove "FastAPI only" from the configuration and performance docs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions