Object.defineProperty(exports, '__esModule', { value: true }); const core = require('@sentry/core'); const utils = require('@sentry/utils'); const responseEnd = require('./responseEnd.js'); /** * Wraps a function on the edge runtime with error and performance monitoring. */ function withEdgeWrapping( handler, options, ) { return async function ( ...args) { core.addTracingExtensions(); const req = args[0]; let sentryTrace; let baggage; if (req instanceof Request) { sentryTrace = req.headers.get('sentry-trace') || ''; baggage = req.headers.get('baggage'); } return core.continueTrace( { sentryTrace, baggage, }, () => { return core.startSpan( { name: options.spanDescription, op: options.spanOp, attributes: { [core.SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: 'route', [core.SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.function.nextjs.withEdgeWrapping', }, metadata: { request: req instanceof Request ? utils.winterCGRequestToRequestData(req) : undefined, }, }, async span => { const handlerResult = await core.handleCallbackErrors( () => handler.apply(this, args), error => { core.captureException(error, { mechanism: { type: 'instrument', handled: false, data: { function: options.mechanismFunctionName, }, }, }); }, ); if (span) { if (handlerResult instanceof Response) { core.setHttpStatus(span, handlerResult.status); } else { span.setStatus('ok'); } } return handlerResult; }, ).finally(() => responseEnd.flushQueue()); }, ); }; } exports.withEdgeWrapping = withEdgeWrapping; //# sourceMappingURL=edgeWrapperUtils.js.map