Skip to content

chore(sentry): disable Django middleware span auto-instrumentation#155

Merged
thomasrockhu-codecov merged 1 commit into
masterfrom
thomas-hu/sentry-disable-django-middleware-spans
May 20, 2026
Merged

chore(sentry): disable Django middleware span auto-instrumentation#155
thomasrockhu-codecov merged 1 commit into
masterfrom
thomas-hu/sentry-disable-django-middleware-spans

Conversation

@thomasrockhu-codecov

@thomasrockhu-codecov thomasrockhu-codecov commented May 20, 2026

Copy link
Copy Markdown
Contributor

Summary

Adds middleware_spans=False to DjangoIntegration in codecov_slack_app/settings.py so per-middleware spans stop being auto-emitted.

Why

Auto-instrumented middleware.django spans don't carry useful debugging information. A middleware.django span carries only span.description (the FQN of the middleware method) and span.duration — no middleware-specific attributes, no headers, no auth context. Because Django middleware wraps get_response, the __call__ duration is bounded by the chain below it and clusters at the request-envelope value, so individual middleware spans rarely identify a real bottleneck.

Everything debuggable (the request envelope, ORM queries, outbound HTTP via HttpxIntegration, view rendering) is on its own span and is not affected by this change.

If a specific custom middleware ever needs targeted timing, we can manually wrap it with sentry_sdk.start_span(op="middleware.codecov", description="…").

Test plan

  • CI green
  • After deploy, confirm span.op:middleware.django count drops to ~0 for the slack-app project
  • Confirm transaction throughput and p95 latency are unchanged on the parent (http.server) span

Refs

Sets `middleware_spans=False` on the `DjangoIntegration` passed to
`sentry_sdk.init`.

Per-middleware spans (`span.op:middleware.django`) don't carry
middleware-specific debugging information — only the middleware FQN
and a duration that is bounded by the chain below it rather than
reflecting the middleware's own cost. No headers, no auth context, no
signal that isn't already on the request envelope or on the ORM /
HTTP child spans. Dropping them reduces SDK overhead with no
observability regression.
@thomasrockhu-codecov thomasrockhu-codecov force-pushed the thomas-hu/sentry-disable-django-middleware-spans branch from c2ca99f to c00a27e Compare May 20, 2026 16:25
@thomasrockhu-codecov thomasrockhu-codecov merged commit 1405d28 into master May 20, 2026
4 checks passed
@thomasrockhu-codecov thomasrockhu-codecov deleted the thomas-hu/sentry-disable-django-middleware-spans branch May 20, 2026 16:49
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.

3 participants