fix(metrics): Skip sampling middleware spans that lack request context#16312
fix(metrics): Skip sampling middleware spans that lack request context#16312jaffrepaul wants to merge 1 commit intomasterfrom
Conversation
Middleware spans in Sentry's Edge runtime instrumentation don't receive normalizedRequest, making traffic classification impossible. These spans were being classified as "unknown", inflating that metric. Since every middleware span has a corresponding page span (e.g., "middleware GET /path" → "GET /path") that does receive full request context, we can safely skip middleware spans without losing data. Co-Authored-By: Claude <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
Bugbot Autofix is OFF. To automatically fix reported issues with Cloud Agents, enable Autofix in the Cursor dashboard.
| // (e.g., "GET /path") will capture the same request with full classification data. | ||
| if (spanName.startsWith('middleware ')) { | ||
| return 0; | ||
| } |
There was a problem hiding this comment.
Skipped middleware spans miss metric counter emission
Low Severity
Every other return path in tracesSampler emits a Sentry.metrics.count('docs.trace.sampled', ...) call before returning — including the bot path that also returns 0. The new middleware early-return skips this metric entirely. Since the PR notes middleware spans account for ~50% of all spans, this creates a significant observability gap in docs.trace.sampled volume tracking with no way to distinguish "we intentionally dropped these" from "something broke."


DESCRIBE YOUR PR
Middleware spans in Sentry's Edge runtime instrumentation don't receive
normalizedRequest, making traffic classification impossible. These spans were being classified as "unknown", inflating that metric significantly (~50% of all spans).Since every middleware span has a corresponding page span (e.g., "middleware GET /path" → "GET /path") that does receive full request context, we can safely skip sampling middleware spans without losing any classification data.
Root cause: Discovered via local debugging that
samplingContext.normalizedRequestis alwaysundefinedfor spans namedmiddleware GET /..., while the correspondingGET /...spans have full headers including user-agent.IS YOUR CHANGE URGENT?
SLA
PRE-MERGE CHECKLIST