rittenhop-dev/versions/5.94.2/node_modules/@sentry/node/esm/handlers.js.map

1 line
46 KiB
Plaintext
Raw Normal View History

2024-09-23 19:40:12 -04:00
{"version":3,"file":"handlers.js","sources":["../../src/handlers.ts"],"sourcesContent":["import type * as http from 'http';\n/* eslint-disable @typescript-eslint/no-explicit-any */\nimport {\n SEMANTIC_ATTRIBUTE_SENTRY_SOURCE,\n captureException,\n continueTrace,\n flush,\n getActiveSpan,\n getClient,\n getCurrentScope,\n hasTracingEnabled,\n runWithAsyncContext,\n setHttpStatus,\n startTransaction,\n withScope,\n} from '@sentry/core';\nimport type { Span } from '@sentry/types';\nimport type { AddRequestDataToEventOptions } from '@sentry/utils';\nimport {\n addRequestDataToTransaction,\n dropUndefinedKeys,\n extractPathForTransaction,\n extractRequestData,\n isString,\n logger,\n} from '@sentry/utils';\n\nimport type { NodeClient } from './client';\nimport { DEBUG_BUILD } from './debug-build';\n// TODO (v8 / XXX) Remove this import\nimport type { ParseRequestOptions } from './requestDataDeprecated';\nimport { isAutoSessionTrackingEnabled } from './sdk';\nimport { trpcMiddleware as newTrpcMiddleware } from './trpc';\n\n/**\n * Express-compatible tracing handler.\n * @see Exposed as `Handlers.tracingHandler`\n */\nexport function tracingHandler(): (\n req: http.IncomingMessage,\n res: http.ServerResponse,\n next: (error?: any) => void,\n) => void {\n return function sentryTracingMiddleware(\n req: http.IncomingMessage,\n res: http.ServerResponse,\n next: (error?: any) => void,\n ): void {\n const options = getClient()?.getOptions();\n\n if (\n !options ||\n options.instrumenter !== 'sentry' ||\n req.method?.toUpperCase() === 'OPTIONS' ||\n req.method?.toUpperCase() === 'HEAD'\n ) {\n return next();\n }\n\n const sentryTrace = req.headers && isString(req.headers['sentry-trace']) ? req.headers['sentry-trace'] : undefined;\n const baggage = req.headers?.baggage;\n if (!hasTracingEnabled(options)) {\n return next();\n }\n\n const [name, source] = extractPathForTransaction(req, { path: true, method: true });\n const transaction = continueTrace({ sentryTrace, baggage }, ctx =>\n // TODO: Refactor this to use `startSpan()`\n // eslint-disable-next-line deprecation/deprecation\n startTransaction(\n {\n name,\n op: 'http.server',\n origin: 'auto.http.node.tracingHandler',\n ...ctx,\n data: {\n [SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: source,\n },\n metadata: {\n // eslint-disable-next-line deprecation/deprecation\n ...ctx.metadata,\n // The request should already have been stored in `scope.sdkProcessingMetadata` (which will become\n // `event.sdkProcessingMetadata` the same way the metadata here will) by `sentryRequestMiddleware`, but on the\n // off chance someone is using `sentryTracingMiddleware` without `sentryRequestMiddleware`, it doesn't hurt to\n // be sure\n request: req,\n },\n },\n // extra context passed to the tracesSampler\n { request: extractRequestData(req) },\n ),\n );\n\n // We put the transaction on the scope so users can attach children to it\n // eslint-disable-next-line deprecation/deprecation\n getCurrentScope().setSpan(transaction);\n\n // We also set __sentry_transaction on the response so people can grab the transaction there to add\n // spans to it later.\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n (res as any).__sentry_transaction = transaction;\n\n res.once('finish', () => {\n // Push `transaction.finish` to the next event loop so open spans have a chance to finish before the transaction\n // closes\n setImmediate(() => {\n // eslint-disable-next-line deprecation/deprecation\n addRequestDataToTransaction(transaction, req);\n setHttpStatus(transaction, res.statusCode);\n transaction.end();\n });\n });\n\n next();\n };\n}\n\nexport type RequestHandlerOptions =\n // TODO (v8 / XXX) Remove ParseRequestOpt