fix(metrics): Skip traffic metrics when user-agent unavailable#16244
Draft
jaffrepaul wants to merge 1 commit intomasterfrom
Draft
fix(metrics): Skip traffic metrics when user-agent unavailable#16244jaffrepaul wants to merge 1 commit intomasterfrom
jaffrepaul wants to merge 1 commit intomasterfrom
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
cf3750c to
3c17ee8
Compare
Middleware traces (Edge runtime) don't receive normalizedRequest from Sentry SDK, causing all middleware traffic to be classified as "unknown". Since each request generates both a middleware trace and a handler trace, this was inflating the "unknown" count significantly. Instead of emitting "unknown" when we can't classify traffic, skip the metric entirely. The handler trace (Node.js) will emit the properly classified metric. Also adds case-insensitive header lookup since HTTP headers are case-insensitive but JS objects are case-sensitive. Co-Authored-By: Claude <noreply@anthropic.com>
3c17ee8 to
3b1cf86
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Add traffic type metrics to trace sampling and fix inflated "unknown" counts.
Changes
This PR adds Sentry metrics to track traffic patterns hitting the docs site, emitting a
docs.trace.sampledcounter with attributes for traffic type (ai_agent, bot, user), the specific bot/agent matched, and the sample rate applied.Key fix: Middleware traces (Edge runtime) don't receive
normalizedRequestfrom the Sentry SDK, so user-agent is unavailable. Previously this caused all middleware traffic to be classified as "unknown", significantly inflating that bucket since each request generates both a middleware trace and a handler trace.Now we skip the metric entirely when user-agent is unavailable. The handler trace (Node.js) emits the properly classified metric.
Also adds case-insensitive header lookup since HTTP headers are case-insensitive but JS objects are case-sensitive.
Metrics visibility
This enables querying in Sentry to understand: