Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork1.7k
feat(nextjs): remove tracing from pages router API routes#18394
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
base:develop
Are you sure you want to change the base?
Changes fromall commits
e2fef716fce173ec986a831fac7aeb4c84d596150fea4d841bdb4be3ceaa14403e76279c04b47ecfe19bFile filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -22,7 +22,11 @@ import { | ||
| import { getScopesFromContext } from '@sentry/opentelemetry'; | ||
| import type { VercelEdgeOptions } from '@sentry/vercel-edge'; | ||
| import { getDefaultIntegrations, init as vercelEdgeInit } from '@sentry/vercel-edge'; | ||
| import { ATTR_NEXT_SPAN_NAME, ATTR_NEXT_SPAN_TYPE } from '../common/nextSpanAttributes'; | ||
| import { | ||
| ATTR_NEXT_PAGES_API_ROUTE_TYPE, | ||
| TRANSACTION_ATTR_SHOULD_DROP_TRANSACTION, | ||
| } from '../common/span-attributes-with-logic-attached'; | ||
| import { addHeadersAsAttributes } from '../common/utils/addHeadersAsAttributes'; | ||
| import { dropMiddlewareTunnelRequests } from '../common/utils/dropMiddlewareTunnelRequests'; | ||
| import { isBuild } from '../common/utils/isBuild'; | ||
| @@ -82,12 +86,21 @@ export function init(options: VercelEdgeOptions = {}): void { | ||
| dropMiddlewareTunnelRequests(span, spanAttributes); | ||
| // Mark all spans generated by Next.js as 'auto' | ||
| if (spanAttributes?.[ATTR_NEXT_SPAN_TYPE] !== undefined) { | ||
| span.setAttribute(SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, 'auto'); | ||
| } | ||
| // Backfill span attributes for api route pages because we removed it from the wrapper | ||
| if ( | ||
| spanAttributes?.[ATTR_NEXT_SPAN_TYPE] === 'Node.runHandler' && | ||
| String(spanAttributes?.['next.span_name']).startsWith(ATTR_NEXT_PAGES_API_ROUTE_TYPE) | ||
| ) { | ||
| span.setAttribute(SEMANTIC_ATTRIBUTE_SENTRY_OP, 'http.server'); | ||
| span.setAttribute(SEMANTIC_ATTRIBUTE_SENTRY_SOURCE, 'route'); | ||
| } | ||
| // Make sure middleware spans get the right op | ||
| if (spanAttributes?.[ATTR_NEXT_SPAN_TYPE] === 'Middleware.execute') { | ||
| span.setAttribute(SEMANTIC_ATTRIBUTE_SENTRY_OP, 'http.server.middleware'); | ||
| span.setAttribute(SEMANTIC_ATTRIBUTE_SENTRY_SOURCE, 'url'); | ||
| @@ -119,8 +132,8 @@ export function init(options: VercelEdgeOptions = {}): void { | ||
| // The otel auto inference will clobber the transaction name because the span has an http.target | ||
| if ( | ||
| event.type === 'transaction' && | ||
| event.contexts?.trace?.data?.[ATTR_NEXT_SPAN_TYPE] === 'Middleware.execute' && | ||
| event.contexts?.trace?.data?.[ATTR_NEXT_SPAN_NAME] !== undefined | ||
| ) { | ||
| if (event.transaction) { | ||
| // Older nextjs versions pass the full url appended to the middleware name, which results in high cardinality transaction names. | ||
| @@ -139,6 +152,20 @@ export function init(options: VercelEdgeOptions = {}): void { | ||
| } | ||
| } | ||
| // Backfill the transaction name for api route pages because we removed it from the wrapper | ||
| if ( | ||
| event.type === 'transaction' && | ||
| event.contexts?.trace?.data?.[ATTR_NEXT_SPAN_TYPE] === 'Node.runHandler' && | ||
| String(event.contexts.trace.data['next.span_name']).startsWith(ATTR_NEXT_PAGES_API_ROUTE_TYPE) | ||
| ) { | ||
| let path = String(event.contexts.trace.data['next.span_name']).replace(ATTR_NEXT_PAGES_API_ROUTE_TYPE, '').trim(); | ||
| // Set transaction name on isolation scope to ensure parameterized routes are used | ||
| // The HTTP server integration sets it on isolation scope, so we need to match that | ||
| const method = event.request?.method || 'GET'; | ||
| path = path ?? event.request?.url ?? '/'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. Bug: Nullish coalescing won't handle empty path stringThe | ||
| event.transaction = `${method} ${path}`; | ||
| } | ||
| setUrlProcessingMetadata(event); | ||
| }); | ||
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.