UNPKG

@sentry/nextjs

Version:
47 lines (43 loc) 2.41 kB
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); const attributes = require('@sentry/conventions/attributes'); const core = require('@sentry/core'); const nextSpanAttributes = require('../common/nextSpanAttributes.js'); const spanAttributesWithLogicAttached = require('../common/span-attributes-with-logic-attached.js'); function enhanceHandleRequestRootSpan(span) { const { attributes: attributes$1 } = span; if (attributes$1[nextSpanAttributes.ATTR_NEXT_SPAN_TYPE] !== "BaseServer.handleRequest") { return; } attributes$1[core.SEMANTIC_ATTRIBUTE_SENTRY_OP] = "http.server"; span.setOp("http.server"); const currentName = span.getName(); if (currentName) { span.setName(core.stripUrlQueryAndFragment(currentName)); } const method = attributes$1[attributes.HTTP_METHOD] ?? attributes$1[attributes.HTTP_REQUEST_METHOD]; const target = attributes$1[attributes.HTTP_TARGET]; const route = attributes$1[attributes.HTTP_ROUTE] || attributes$1[nextSpanAttributes.ATTR_NEXT_ROUTE]; const spanName = attributes$1[nextSpanAttributes.ATTR_NEXT_SPAN_NAME]; if (typeof method === "string" && typeof route === "string" && !route.startsWith("middleware")) { const cleanRoute = route.replace(/\/route$/, ""); span.setName(`${method} ${cleanRoute}`); attributes$1[core.SEMANTIC_ATTRIBUTE_SENTRY_SOURCE] = "route"; attributes$1[attributes.HTTP_ROUTE] = cleanRoute; attributes$1[nextSpanAttributes.ATTR_NEXT_ROUTE] = cleanRoute; } const routeBackfill = attributes$1[spanAttributesWithLogicAttached.TRANSACTION_ATTR_SENTRY_ROUTE_BACKFILL]; if (typeof routeBackfill === "string" && span.getName() !== "GET /_app") { span.setName(`${typeof method === "string" ? method : "GET"} ${routeBackfill}`); attributes$1[attributes.HTTP_ROUTE] = attributes$1[attributes.HTTP_ROUTE] ?? routeBackfill; } const middlewareMatch = typeof spanName === "string" && spanName.match(/^middleware (GET|POST|PUT|DELETE|PATCH|HEAD|OPTIONS)/); if (middlewareMatch) { span.setName(`middleware ${middlewareMatch[1]}`); span.setOp("http.server.middleware"); } if (span.getName() === "GET /_error" && typeof target === "string") { span.setName(`${typeof method === "string" ? `${method} ` : ""}${target}`); } } exports.enhanceHandleRequestRootSpan = enhanceHandleRequestRootSpan; //# sourceMappingURL=enhanceHandleRequestRootSpan.js.map