Skip to content

docs: recommend trace sampling in production - #85

Merged
lesnik512 merged 1 commit into
mainfrom
docs/tracing-sampler
Oct 16, 2026
Merged

lesnik512 merged 1 commit into
mainfrom
docs/tracing-sampler

Conversation

@lesnik512

Copy link
Copy Markdown
Member

Adds a short README section on sampling traces in production. It's docs only, because the sampler can already be set without code: lite-bootstrap passes sampler=None to TracerProvider, and the SDK then reads OTEL_TRACES_SAMPLER and OTEL_TRACES_SAMPLER_ARG (lite-bootstrap ADR-0008).

Measurements

I ran GET /api/decks/1/ through the full app: lite-bootstrap tracing, the ASGI server span and the SQLAlchemy spans, 6 spans per request. The OTLP exporter was patched to encode each batch to protobuf and then drop it, so there was no network export. Each run was inside the template's compose container with SERVICE_DEBUG=false, and each number is the median of 5 runs, averaged over two interleaved rounds. Results are in req/s, with the change against no tracing:

sampler litestar, 1 client litestar, 100 clients fastapi, 1 client fastapi, 100 clients
no tracing 1,567 1,502 1,366 1,352
parentbased_always_on (default) 872 (-44%) 940 (-37%) 810 (-41%) 852 (-37%)
parentbased_traceidratio, 0.1 1,209 (-23%) 1,173 (-22%) 1,116 (-18%) 1,052 (-22%)
parentbased_traceidratio, 0.01 1,265 (-19%) 1,213 (-19%) 1,139 (-17%) 1,083 (-20%)
parentbased_always_off 1,265 (-19%) 1,215 (-19%) 1,137 (-17%) 1,051 (-22%)

Going below 10% gains little. About 20% stays even with always_off, because the ASGI middleware and the SQLAlchemy hooks still run when a span is not recorded. The fastapi no-tracing baseline varied by about 11% between rounds, so treat those percentages as approximate.

The trade-off is that head sampling drops 90% of traces, failed requests included. Sentry still gets every error.

@lesnik512
lesnik512 merged commit 13e6083 into main Oct 16, 2026
2 checks passed
@lesnik512
lesnik512 deleted the docs/tracing-sampler branch October 16, 2026 09:38
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