-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
fix(metrics): Update handling metrics when user-agent unavailable #16244
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+223
−110
Conversation
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
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
3c17ee8 to
3b1cf86
Compare
5803e85 to
45a2779
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>
- Use Next.js userAgent() for improved bot detection at middleware level - Track "unknown" traffic explicitly (previously silently skipped) - Add device type to metrics for richer segmentation - Fix critical bug: set classification on request headers (not response) so tracesSampler can actually read them - Extract shared patterns/types to src/lib/trafficClassification.ts - Add header validation to prevent injection of invalid traffic types - Remove speculative markdown client patterns (vscode, intellij, sublime, got) - Add emitSamplingMetric helper to reduce repetition in tracesSampler Co-Authored-By: Claude <noreply@anthropic.com>
0349959 to
35ab210
Compare
Merge MARKDOWN_CLIENT_PATTERNS and AI_AGENT_PATTERN into a single shared pattern in trafficClassification.ts. Both markdown serving and traffic classification now use the same pattern. Co-Authored-By: Claude <noreply@anthropic.com>
1bbf4b2 to
2e98985
Compare
Remove unnecessary abstraction - the helper was only wrapping a single Sentry.metrics.count() call across 5 call sites. Co-Authored-By: Claude <noreply@anthropic.com>
cd700dc to
7edfa70
Compare
sergical
approved these changes
Feb 9, 2026
Member
sergical
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤖
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.
Enhance traffic classification for docs site metrics with better bot detection and visibility into unknown traffic.
Summary
userAgent()for improved bot detection at middleware levelsrc/lib/trafficClassification.tsChanges
Middleware (
src/middleware.ts)userAgent()which has comprehensive bot detection (Google, Bing, social crawlers, etc.)text/markdown,text/plain)Traces Sampler (
src/tracesSampler.ts)x-traffic-typeandx-device-typerequest headersemitSamplingMetric()helper to reduce code repetitionShared Module (
src/lib/trafficClassification.ts)TrafficType- shared type definitionAI_AGENT_PATTERN- single source of truth for AI agent detectionBOT_PATTERN- single source of truth for bot detectionSAMPLE_RATES- lookup object for sample rates by traffic typematchPattern()- shared utility functionMetrics Attributes
The
docs.trace.sampledmetric now includes:traffic_typeai_agent,bot,user,unknowndevice_typedesktop,mobile,tablet,crawler,unknownsample_rate0,0.3,1agent_matchclaudebot,cursorbot_matchgooglebot,slackbotIS YOUR CHANGE URGENT?
SLA
PRE-MERGE CHECKLIST