Skip to content

fix(metrics): Skip traffic metrics when user-agent unavailable#16244

Draft
jaffrepaul wants to merge 1 commit intomasterfrom
fix/trace-sampler-unknown-metrics
Draft

fix(metrics): Skip traffic metrics when user-agent unavailable#16244
jaffrepaul wants to merge 1 commit intomasterfrom
fix/trace-sampler-unknown-metrics

Conversation

@jaffrepaul
Copy link
Contributor

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.sampled counter 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 normalizedRequest from 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:

  • Volume breakdown by traffic type (user vs bot vs AI agent)
  • Which bots are hitting the site most frequently
  • Which AI agents are consuming docs content
  • How much traffic is being filtered vs sampled

@vercel
Copy link

vercel bot commented Feb 2, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
develop-docs Ready Ready Preview, Comment Feb 2, 2026 8:52pm
sentry-docs Ready Ready Preview, Comment Feb 2, 2026 8:52pm

Request Review

@jaffrepaul jaffrepaul force-pushed the fix/trace-sampler-unknown-metrics branch from cf3750c to 3c17ee8 Compare February 2, 2026 20:39
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>
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