UNPKG

@sentry/nextjs

Version:
27 lines (24 loc) • 957 B
import { MIDDLEWARE } from '@sentry/conventions/op'; import { SENTRY_SEGMENT_NAME_SOURCE } from '@sentry/conventions/attributes'; import { stripUrlQueryAndFragment } from '@sentry/core'; import { ATTR_NEXT_SPAN_TYPE, ATTR_NEXT_SPAN_NAME } from './nextSpanAttributes.js'; function enhanceMiddlewareRootSpan(span) { const { attributes } = span; if (attributes[ATTR_NEXT_SPAN_TYPE] !== "Middleware.execute") { return; } span.setOp(MIDDLEWARE); const spanName = attributes[ATTR_NEXT_SPAN_NAME]; if (typeof spanName !== "string" || !spanName || !span.getName()) { return; } const match = spanName.match(/^middleware (GET|POST|PUT|DELETE|PATCH|HEAD|OPTIONS)/); if (match) { span.setName(`middleware ${match[1]}`); attributes[SENTRY_SEGMENT_NAME_SOURCE] = "route"; } else { span.setName(stripUrlQueryAndFragment(spanName)); } } export { enhanceMiddlewareRootSpan }; //# sourceMappingURL=enhanceMiddlewareRootSpan.js.map