|
1 | 1 | import { |
2 | 2 | SEMANTIC_ATTRIBUTE_SENTRY_OP, |
3 | 3 | SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, |
| 4 | + SEMANTIC_ATTRIBUTE_SENTRY_SOURCE, |
4 | 5 | applySdkMetadata, |
5 | 6 | getClient, |
6 | 7 | getGlobalScope, |
@@ -284,32 +285,21 @@ export function init(options: NodeOptions): NodeClient | undefined { |
284 | 285 | getGlobalScope().addEventProcessor( |
285 | 286 | Object.assign( |
286 | 287 | (event => { |
287 | | - // Sometimes, the HTTP integration will not work, causing us not to properly set an op for spans generated by |
288 | | - // Next.js that are actually more or less correct server HTTP spans, so we are backfilling the op here. |
289 | | - |
290 | | - // if ( |
291 | | - // event.type === 'transaction' && |
292 | | - // event.transaction?.match(/^(RSC )?GET /) && |
293 | | - // event.contexts?.trace?.data?.['sentry.rsc'] === true && |
294 | | - // !event.contexts.trace.op |
295 | | - // ) { |
296 | | - // event.contexts.trace.data = event.contexts.trace.data || {}; |
297 | | - // event.contexts.trace.data[SEMANTIC_ATTRIBUTE_SENTRY_OP] = 'http.server'; |
298 | | - // event.contexts.trace.op = 'http.server'; |
299 | | - // } |
300 | | - |
301 | | - // TODO: Add logic here to backfill things like, parameterized transaction name, op, request interface, etc. |
302 | | - |
303 | 288 | // Enhance route handler transactions |
304 | | - if (event.type === 'transaction' && event.contexts?.trace?.data?.['sentry.route_handler'] === true) { |
| 289 | + if ( |
| 290 | + event.type === 'transaction' && |
| 291 | + event.contexts?.trace?.data?.['next.span_type'] === 'BaseServer.handleRequest' |
| 292 | + ) { |
305 | 293 | event.contexts.trace.data = event.contexts.trace.data || {}; |
306 | 294 | event.contexts.trace.data[SEMANTIC_ATTRIBUTE_SENTRY_OP] = 'http.server'; |
307 | 295 | event.contexts.trace.op = 'http.server'; |
308 | | - if (typeof event.contexts.trace.data[ATTR_HTTP_ROUTE] === 'string') { |
309 | | - // eslint-disable-next-line deprecation/deprecation |
310 | | - event.transaction = `${event.contexts.trace.data[SEMATTRS_HTTP_METHOD]} ${event.contexts.trace.data[ |
311 | | - ATTR_HTTP_ROUTE |
312 | | - ].replace(/\/route$/, '')}`; |
| 296 | + |
| 297 | + // eslint-disable-next-line deprecation/deprecation |
| 298 | + const method = event.contexts.trace.data[SEMATTRS_HTTP_METHOD]; |
| 299 | + const route = event.contexts.trace.data[ATTR_HTTP_ROUTE]; |
| 300 | + if (typeof method === 'string' && typeof route === 'string') { |
| 301 | + event.transaction = `${method} ${route.replace(/\/route$/, '')}`; |
| 302 | + event.contexts.trace.data[SEMANTIC_ATTRIBUTE_SENTRY_SOURCE] = 'route'; |
313 | 303 | } |
314 | 304 | } |
315 | 305 |
|
|
0 commit comments