@sentry/core 10.48.0 → 10.50.0-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/cjs/client.js +9 -0
- package/build/cjs/client.js.map +1 -1
- package/build/cjs/fetch.js +41 -19
- package/build/cjs/fetch.js.map +1 -1
- package/build/cjs/index.js +9 -5
- package/build/cjs/index.js.map +1 -1
- package/build/cjs/integration.js +9 -0
- package/build/cjs/integration.js.map +1 -1
- package/build/cjs/integrations/conversationId.js +11 -0
- package/build/cjs/integrations/conversationId.js.map +1 -1
- package/build/cjs/integrations/express/index.js +44 -7
- package/build/cjs/integrations/express/index.js.map +1 -1
- package/build/cjs/integrations/express/patch-layer.js +7 -1
- package/build/cjs/integrations/express/patch-layer.js.map +1 -1
- package/build/cjs/integrations/express/types.js.map +1 -1
- package/build/cjs/integrations/mcp-server/transport.js +9 -9
- package/build/cjs/integrations/mcp-server/transport.js.map +1 -1
- package/build/cjs/tracing/ai/gen-ai-attributes.js +0 -30
- package/build/cjs/tracing/ai/gen-ai-attributes.js.map +1 -1
- package/build/cjs/tracing/ai/utils.js +24 -0
- package/build/cjs/tracing/ai/utils.js.map +1 -1
- package/build/cjs/tracing/anthropic-ai/index.js +5 -5
- package/build/cjs/tracing/anthropic-ai/index.js.map +1 -1
- package/build/cjs/tracing/anthropic-ai/utils.js +4 -2
- package/build/cjs/tracing/anthropic-ai/utils.js.map +1 -1
- package/build/cjs/tracing/google-genai/index.js +16 -5
- package/build/cjs/tracing/google-genai/index.js.map +1 -1
- package/build/cjs/tracing/langchain/index.js +3 -0
- package/build/cjs/tracing/langchain/index.js.map +1 -1
- package/build/cjs/tracing/langchain/utils.js +12 -4
- package/build/cjs/tracing/langchain/utils.js.map +1 -1
- package/build/cjs/tracing/langgraph/index.js +4 -3
- package/build/cjs/tracing/langgraph/index.js.map +1 -1
- package/build/cjs/tracing/openai/index.js +12 -5
- package/build/cjs/tracing/openai/index.js.map +1 -1
- package/build/cjs/tracing/sentrySpan.js +5 -0
- package/build/cjs/tracing/sentrySpan.js.map +1 -1
- package/build/cjs/tracing/spans/captureSpan.js +3 -1
- package/build/cjs/tracing/spans/captureSpan.js.map +1 -1
- package/build/cjs/tracing/spans/extractGenAiSpans.js +50 -0
- package/build/cjs/tracing/spans/extractGenAiSpans.js.map +1 -0
- package/build/cjs/tracing/spans/spanJsonToStreamedSpan.js +26 -0
- package/build/cjs/tracing/spans/spanJsonToStreamedSpan.js.map +1 -0
- package/build/cjs/tracing/trace.js +17 -6
- package/build/cjs/tracing/trace.js.map +1 -1
- package/build/cjs/tracing/utils.js +3 -37
- package/build/cjs/tracing/utils.js.map +1 -1
- package/build/cjs/tracing/vercel-ai/constants.js +15 -23
- package/build/cjs/tracing/vercel-ai/constants.js.map +1 -1
- package/build/cjs/tracing/vercel-ai/index.js +41 -45
- package/build/cjs/tracing/vercel-ai/index.js.map +1 -1
- package/build/cjs/tracing/vercel-ai/utils.js +11 -39
- package/build/cjs/tracing/vercel-ai/utils.js.map +1 -1
- package/build/cjs/tracing/vercel-ai/vercel-ai-attributes.js +4 -1
- package/build/cjs/tracing/vercel-ai/vercel-ai-attributes.js.map +1 -1
- package/build/cjs/utils/browser.js +2 -3
- package/build/cjs/utils/browser.js.map +1 -1
- package/build/cjs/utils/version.js +1 -1
- package/build/cjs/utils/version.js.map +1 -1
- package/build/cjs/utils/weakRef.js +62 -0
- package/build/cjs/utils/weakRef.js.map +1 -0
- package/build/esm/client.js +9 -0
- package/build/esm/client.js.map +1 -1
- package/build/esm/fetch.js +41 -19
- package/build/esm/fetch.js.map +1 -1
- package/build/esm/index.js +2 -1
- package/build/esm/index.js.map +1 -1
- package/build/esm/integration.js +9 -0
- package/build/esm/integration.js.map +1 -1
- package/build/esm/integrations/conversationId.js +11 -0
- package/build/esm/integrations/conversationId.js.map +1 -1
- package/build/esm/integrations/express/index.js +44 -7
- package/build/esm/integrations/express/index.js.map +1 -1
- package/build/esm/integrations/express/patch-layer.js +7 -1
- package/build/esm/integrations/express/patch-layer.js.map +1 -1
- package/build/esm/integrations/express/types.js.map +1 -1
- package/build/esm/integrations/mcp-server/transport.js +9 -9
- package/build/esm/integrations/mcp-server/transport.js.map +1 -1
- package/build/esm/package.json +1 -1
- package/build/esm/tracing/ai/gen-ai-attributes.js +1 -26
- package/build/esm/tracing/ai/gen-ai-attributes.js.map +1 -1
- package/build/esm/tracing/ai/utils.js +23 -1
- package/build/esm/tracing/ai/utils.js.map +1 -1
- package/build/esm/tracing/anthropic-ai/index.js +6 -6
- package/build/esm/tracing/anthropic-ai/index.js.map +1 -1
- package/build/esm/tracing/anthropic-ai/utils.js +5 -3
- package/build/esm/tracing/anthropic-ai/utils.js.map +1 -1
- package/build/esm/tracing/google-genai/index.js +17 -6
- package/build/esm/tracing/google-genai/index.js.map +1 -1
- package/build/esm/tracing/langchain/index.js +4 -1
- package/build/esm/tracing/langchain/index.js.map +1 -1
- package/build/esm/tracing/langchain/utils.js +13 -5
- package/build/esm/tracing/langchain/utils.js.map +1 -1
- package/build/esm/tracing/langgraph/index.js +5 -4
- package/build/esm/tracing/langgraph/index.js.map +1 -1
- package/build/esm/tracing/openai/index.js +13 -6
- package/build/esm/tracing/openai/index.js.map +1 -1
- package/build/esm/tracing/sentrySpan.js +5 -0
- package/build/esm/tracing/sentrySpan.js.map +1 -1
- package/build/esm/tracing/spans/captureSpan.js +3 -1
- package/build/esm/tracing/spans/captureSpan.js.map +1 -1
- package/build/esm/tracing/spans/extractGenAiSpans.js +48 -0
- package/build/esm/tracing/spans/extractGenAiSpans.js.map +1 -0
- package/build/esm/tracing/spans/spanJsonToStreamedSpan.js +24 -0
- package/build/esm/tracing/spans/spanJsonToStreamedSpan.js.map +1 -0
- package/build/esm/tracing/trace.js +17 -6
- package/build/esm/tracing/trace.js.map +1 -1
- package/build/esm/tracing/utils.js +3 -37
- package/build/esm/tracing/utils.js.map +1 -1
- package/build/esm/tracing/vercel-ai/constants.js +15 -19
- package/build/esm/tracing/vercel-ai/constants.js.map +1 -1
- package/build/esm/tracing/vercel-ai/index.js +38 -42
- package/build/esm/tracing/vercel-ai/index.js.map +1 -1
- package/build/esm/tracing/vercel-ai/utils.js +14 -41
- package/build/esm/tracing/vercel-ai/utils.js.map +1 -1
- package/build/esm/tracing/vercel-ai/vercel-ai-attributes.js +4 -1
- package/build/esm/tracing/vercel-ai/vercel-ai-attributes.js.map +1 -1
- package/build/esm/utils/browser.js +2 -3
- package/build/esm/utils/browser.js.map +1 -1
- package/build/esm/utils/version.js +1 -1
- package/build/esm/utils/version.js.map +1 -1
- package/build/esm/utils/weakRef.js +59 -0
- package/build/esm/utils/weakRef.js.map +1 -0
- package/build/types/build-time-plugins/buildTimeOptionsBase.d.ts +13 -0
- package/build/types/build-time-plugins/buildTimeOptionsBase.d.ts.map +1 -1
- package/build/types/client.d.ts +20 -0
- package/build/types/client.d.ts.map +1 -1
- package/build/types/fetch.d.ts +12 -8
- package/build/types/fetch.d.ts.map +1 -1
- package/build/types/index.d.ts +5 -2
- package/build/types/index.d.ts.map +1 -1
- package/build/types/integration.d.ts.map +1 -1
- package/build/types/integrations/conversationId.d.ts.map +1 -1
- package/build/types/integrations/express/index.d.ts +10 -3
- package/build/types/integrations/express/index.d.ts.map +1 -1
- package/build/types/integrations/express/patch-layer.d.ts +1 -1
- package/build/types/integrations/express/patch-layer.d.ts.map +1 -1
- package/build/types/integrations/express/types.d.ts +5 -1
- package/build/types/integrations/express/types.d.ts.map +1 -1
- package/build/types/tracing/ai/gen-ai-attributes.d.ts +0 -8
- package/build/types/tracing/ai/gen-ai-attributes.d.ts.map +1 -1
- package/build/types/tracing/ai/utils.d.ts +13 -0
- package/build/types/tracing/ai/utils.d.ts.map +1 -1
- package/build/types/tracing/anthropic-ai/index.d.ts.map +1 -1
- package/build/types/tracing/anthropic-ai/types.d.ts +5 -0
- package/build/types/tracing/anthropic-ai/types.d.ts.map +1 -1
- package/build/types/tracing/anthropic-ai/utils.d.ts +1 -1
- package/build/types/tracing/anthropic-ai/utils.d.ts.map +1 -1
- package/build/types/tracing/google-genai/index.d.ts.map +1 -1
- package/build/types/tracing/google-genai/types.d.ts +5 -0
- package/build/types/tracing/google-genai/types.d.ts.map +1 -1
- package/build/types/tracing/langchain/index.d.ts.map +1 -1
- package/build/types/tracing/langchain/types.d.ts +5 -0
- package/build/types/tracing/langchain/types.d.ts.map +1 -1
- package/build/types/tracing/langchain/utils.d.ts +2 -2
- package/build/types/tracing/langchain/utils.d.ts.map +1 -1
- package/build/types/tracing/langgraph/index.d.ts.map +1 -1
- package/build/types/tracing/langgraph/types.d.ts +5 -0
- package/build/types/tracing/langgraph/types.d.ts.map +1 -1
- package/build/types/tracing/openai/index.d.ts.map +1 -1
- package/build/types/tracing/openai/types.d.ts +5 -0
- package/build/types/tracing/openai/types.d.ts.map +1 -1
- package/build/types/tracing/sentrySpan.d.ts.map +1 -1
- package/build/types/tracing/spans/captureSpan.d.ts.map +1 -1
- package/build/types/tracing/spans/extractGenAiSpans.d.ts +15 -0
- package/build/types/tracing/spans/extractGenAiSpans.d.ts.map +1 -0
- package/build/types/tracing/spans/spanJsonToStreamedSpan.d.ts +6 -0
- package/build/types/tracing/spans/spanJsonToStreamedSpan.d.ts.map +1 -0
- package/build/types/tracing/trace.d.ts.map +1 -1
- package/build/types/tracing/utils.d.ts.map +1 -1
- package/build/types/tracing/vercel-ai/constants.d.ts +2 -5
- package/build/types/tracing/vercel-ai/constants.d.ts.map +1 -1
- package/build/types/tracing/vercel-ai/index.d.ts.map +1 -1
- package/build/types/tracing/vercel-ai/utils.d.ts +1 -5
- package/build/types/tracing/vercel-ai/utils.d.ts.map +1 -1
- package/build/types/tracing/vercel-ai/vercel-ai-attributes.d.ts +0 -480
- package/build/types/tracing/vercel-ai/vercel-ai-attributes.d.ts.map +1 -1
- package/build/types/types-hoist/clientreport.d.ts +1 -1
- package/build/types/types-hoist/clientreport.d.ts.map +1 -1
- package/build/types/types-hoist/envelope.d.ts +1 -1
- package/build/types/types-hoist/envelope.d.ts.map +1 -1
- package/build/types/types-hoist/integration.d.ts +13 -0
- package/build/types/types-hoist/integration.d.ts.map +1 -1
- package/build/types/types-hoist/replay.d.ts +25 -0
- package/build/types/types-hoist/replay.d.ts.map +1 -1
- package/build/types/types-hoist/view-hierarchy.d.ts +1 -0
- package/build/types/types-hoist/view-hierarchy.d.ts.map +1 -1
- package/build/types/utils/browser.d.ts +1 -1
- package/build/types/utils/browser.d.ts.map +1 -1
- package/build/types/utils/weakRef.d.ts +34 -0
- package/build/types/utils/weakRef.d.ts.map +1 -0
- package/build/types-ts3.8/build-time-plugins/buildTimeOptionsBase.d.ts +13 -0
- package/build/types-ts3.8/client.d.ts +20 -0
- package/build/types-ts3.8/fetch.d.ts +14 -10
- package/build/types-ts3.8/index.d.ts +5 -2
- package/build/types-ts3.8/integrations/express/index.d.ts +10 -3
- package/build/types-ts3.8/integrations/express/patch-layer.d.ts +1 -1
- package/build/types-ts3.8/integrations/express/types.d.ts +5 -1
- package/build/types-ts3.8/tracing/ai/gen-ai-attributes.d.ts +0 -8
- package/build/types-ts3.8/tracing/ai/utils.d.ts +13 -0
- package/build/types-ts3.8/tracing/anthropic-ai/types.d.ts +5 -0
- package/build/types-ts3.8/tracing/anthropic-ai/utils.d.ts +1 -1
- package/build/types-ts3.8/tracing/google-genai/types.d.ts +5 -0
- package/build/types-ts3.8/tracing/langchain/types.d.ts +5 -0
- package/build/types-ts3.8/tracing/langchain/utils.d.ts +2 -2
- package/build/types-ts3.8/tracing/langgraph/types.d.ts +5 -0
- package/build/types-ts3.8/tracing/openai/types.d.ts +5 -0
- package/build/types-ts3.8/tracing/spans/extractGenAiSpans.d.ts +15 -0
- package/build/types-ts3.8/tracing/spans/spanJsonToStreamedSpan.d.ts +6 -0
- package/build/types-ts3.8/tracing/vercel-ai/constants.d.ts +2 -5
- package/build/types-ts3.8/tracing/vercel-ai/utils.d.ts +1 -5
- package/build/types-ts3.8/tracing/vercel-ai/vercel-ai-attributes.d.ts +0 -480
- package/build/types-ts3.8/types-hoist/clientreport.d.ts +1 -1
- package/build/types-ts3.8/types-hoist/envelope.d.ts +1 -1
- package/build/types-ts3.8/types-hoist/integration.d.ts +13 -0
- package/build/types-ts3.8/types-hoist/replay.d.ts +25 -0
- package/build/types-ts3.8/types-hoist/view-hierarchy.d.ts +1 -0
- package/build/types-ts3.8/utils/browser.d.ts +1 -1
- package/build/types-ts3.8/utils/weakRef.d.ts +34 -0
- package/package.json +1 -1
package/build/cjs/fetch.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fetch.js","sources":["../../src/fetch.ts"],"sourcesContent":["import { getClient } from './currentScopes';\nimport { SEMANTIC_ATTRIBUTE_SENTRY_OP, SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN } from './semanticAttributes';\nimport { setHttpStatus, SPAN_STATUS_ERROR, startInactiveSpan } from './tracing';\nimport { SentryNonRecordingSpan } from './tracing/sentryNonRecordingSpan';\nimport type { FetchBreadcrumbHint } from './types-hoist/breadcrumb';\nimport type { HandlerDataFetch } from './types-hoist/instrument';\nimport type { ResponseHookInfo } from './types-hoist/request';\nimport type { Span, SpanAttributes, SpanOrigin } from './types-hoist/span';\nimport { SENTRY_BAGGAGE_KEY_PREFIX } from './utils/baggage';\nimport { hasSpansEnabled } from './utils/hasSpansEnabled';\nimport { isInstanceOf, isRequest } from './utils/is';\nimport { getActiveSpan } from './utils/spanUtils';\nimport { getTraceData } from './utils/traceData';\nimport {\n getSanitizedUrlStringFromUrlObject,\n isURLObjectRelative,\n parseStringToURLObject,\n stripDataUrlContent,\n} from './utils/url';\n\ntype PolymorphicRequestHeaders =\n | Record<string, string | undefined>\n | Array<[string, string]>\n // the below is not precisely the Header type used in Request, but it'll pass duck-typing\n | {\n append: (key: string, value: string) => void;\n get: (key: string) => string | null | undefined;\n };\n\ninterface InstrumentFetchRequestOptions {\n spanOrigin?: SpanOrigin;\n propagateTraceparent?: boolean;\n onRequestSpanEnd?: (span: Span, responseInformation: ResponseHookInfo) => void;\n}\n\n/**\n * Create and track fetch request spans for usage in combination with `addFetchInstrumentationHandler`.\n *\n * @deprecated pass an options object instead of the spanOrigin parameter\n *\n * @returns Span if a span was created, otherwise void.\n */\nexport function instrumentFetchRequest(\n handlerData: HandlerDataFetch,\n shouldCreateSpan: (url: string) => boolean,\n shouldAttachHeaders: (url: string) => boolean,\n spans: Record<string, Span>,\n spanOrigin: SpanOrigin,\n): Span | undefined;\n/**\n * Create and track fetch request spans for usage in combination with `addFetchInstrumentationHandler`.\n *\n * @returns Span if a span was created, otherwise void.\n */\nexport function instrumentFetchRequest(\n handlerData: HandlerDataFetch,\n shouldCreateSpan: (url: string) => boolean,\n shouldAttachHeaders: (url: string) => boolean,\n spans: Record<string, Span>,\n // eslint-disable-next-line @typescript-eslint/unified-signatures -- needed because the other overload is deprecated\n instrumentFetchRequestOptions: InstrumentFetchRequestOptions,\n): Span | undefined;\n\n/**\n * Create and track fetch request spans for usage in combination with `addFetchInstrumentationHandler`.\n *\n * @returns Span if a span was created, otherwise void.\n */\nexport function instrumentFetchRequest(\n handlerData: HandlerDataFetch,\n shouldCreateSpan: (url: string) => boolean,\n shouldAttachHeaders: (url: string) => boolean,\n spans: Record<string, Span>,\n spanOriginOrOptions?: SpanOrigin | InstrumentFetchRequestOptions,\n): Span | undefined {\n if (!handlerData.fetchData) {\n return undefined;\n }\n\n const { method, url } = handlerData.fetchData;\n\n const shouldCreateSpanResult = hasSpansEnabled() && shouldCreateSpan(url);\n\n if (handlerData.endTimestamp) {\n const spanId = handlerData.fetchData.__span;\n if (!spanId) return;\n\n const span = spans[spanId];\n\n if (span) {\n // Only end the span and call hooks if we're actually recording\n if (shouldCreateSpanResult) {\n endSpan(span, handlerData);\n _callOnRequestSpanEnd(span, handlerData, spanOriginOrOptions);\n }\n\n // eslint-disable-next-line @typescript-eslint/no-dynamic-delete\n delete spans[spanId];\n }\n\n return undefined;\n }\n\n // Backwards-compatible with the old signature. Needed to introduce the combined optional parameter\n // to avoid API breakage for anyone calling this function with the optional spanOrigin parameter\n // TODO (v11): remove this backwards-compatible code and only accept the options parameter\n const { spanOrigin = 'auto.http.browser', propagateTraceparent = false } =\n typeof spanOriginOrOptions === 'object' ? spanOriginOrOptions : { spanOrigin: spanOriginOrOptions };\n\n const hasParent = !!getActiveSpan();\n\n const span =\n shouldCreateSpanResult && hasParent\n ? startInactiveSpan(getSpanStartOptions(url, method, spanOrigin))\n : new SentryNonRecordingSpan();\n\n handlerData.fetchData.__span = span.spanContext().spanId;\n spans[span.spanContext().spanId] = span;\n\n if (shouldAttachHeaders(handlerData.fetchData.url)) {\n const request: string | Request = handlerData.args[0];\n\n // Shallow clone the options object to avoid mutating the original user-provided object\n // Examples: users re-using same options object for multiple fetch calls, frozen objects\n const options: { [key: string]: unknown } = { ...(handlerData.args[1] || {}) };\n\n const headers = _addTracingHeadersToFetchRequest(\n request,\n options,\n // If performance is disabled (TWP) or there's no active root span (pageload/navigation/interaction),\n // we do not want to use the span as base for the trace headers,\n // which means that the headers will be generated from the scope and the sampling decision is deferred\n hasSpansEnabled() && hasParent ? span : undefined,\n propagateTraceparent,\n );\n if (headers) {\n // Ensure this is actually set, if no options have been passed previously\n handlerData.args[1] = options;\n options.headers = headers;\n }\n }\n\n const client = getClient();\n\n if (client) {\n const fetchHint = {\n input: handlerData.args,\n response: handlerData.response,\n startTimestamp: handlerData.startTimestamp,\n endTimestamp: handlerData.endTimestamp,\n } satisfies FetchBreadcrumbHint;\n\n client.emit('beforeOutgoingRequestSpan', span, fetchHint);\n }\n\n return span;\n}\n\n/**\n * Calls the onRequestSpanEnd callback if it is defined.\n */\nexport function _callOnRequestSpanEnd(\n span: Span,\n handlerData: HandlerDataFetch,\n spanOriginOrOptions?: SpanOrigin | InstrumentFetchRequestOptions,\n): void {\n const onRequestSpanEnd =\n typeof spanOriginOrOptions === 'object' && spanOriginOrOptions !== null\n ? spanOriginOrOptions.onRequestSpanEnd\n : undefined;\n\n onRequestSpanEnd?.(span, {\n headers: handlerData.response?.headers,\n error: handlerData.error,\n });\n}\n\n/**\n * Adds sentry-trace and baggage headers to the various forms of fetch headers.\n * exported only for testing purposes\n *\n * When we determine if we should add a baggage header, there are 3 cases:\n * 1. No previous baggage header -> add baggage\n * 2. Previous baggage header has no sentry baggage values -> add our baggage\n * 3. Previous baggage header has sentry baggage values -> do nothing (might have been added manually by users)\n */\n// eslint-disable-next-line complexity -- yup it's this complicated :(\nexport function _addTracingHeadersToFetchRequest(\n request: string | Request,\n fetchOptionsObj: {\n headers?:\n | {\n [key: string]: string[] | string | undefined;\n }\n | PolymorphicRequestHeaders;\n },\n span?: Span,\n propagateTraceparent?: boolean,\n): PolymorphicRequestHeaders | undefined {\n const traceHeaders = getTraceData({ span, propagateTraceparent });\n const sentryTrace = traceHeaders['sentry-trace'];\n const baggage = traceHeaders.baggage;\n const traceparent = traceHeaders.traceparent;\n\n // Nothing to do, when we return undefined here, the original headers will be used\n if (!sentryTrace) {\n return undefined;\n }\n\n const originalHeaders = fetchOptionsObj.headers || (isRequest(request) ? request.headers : undefined);\n\n if (!originalHeaders) {\n return { ...traceHeaders };\n } else if (isHeaders(originalHeaders)) {\n const newHeaders = new Headers(originalHeaders);\n\n // We don't want to override manually added sentry headers\n if (!newHeaders.get('sentry-trace')) {\n newHeaders.set('sentry-trace', sentryTrace);\n }\n\n if (propagateTraceparent && traceparent && !newHeaders.get('traceparent')) {\n newHeaders.set('traceparent', traceparent);\n }\n\n if (baggage) {\n const prevBaggageHeader = newHeaders.get('baggage');\n\n if (!prevBaggageHeader) {\n newHeaders.set('baggage', baggage);\n } else if (!baggageHeaderHasSentryBaggageValues(prevBaggageHeader)) {\n newHeaders.set('baggage', `${prevBaggageHeader},${baggage}`);\n }\n }\n\n return newHeaders;\n } else if (Array.isArray(originalHeaders)) {\n const newHeaders = [...originalHeaders];\n\n if (!originalHeaders.find(header => header[0] === 'sentry-trace')) {\n newHeaders.push(['sentry-trace', sentryTrace]);\n }\n\n if (propagateTraceparent && traceparent && !originalHeaders.find(header => header[0] === 'traceparent')) {\n newHeaders.push(['traceparent', traceparent]);\n }\n\n const prevBaggageHeaderWithSentryValues = originalHeaders.find(\n header => header[0] === 'baggage' && baggageHeaderHasSentryBaggageValues(header[1]),\n );\n\n if (baggage && !prevBaggageHeaderWithSentryValues) {\n // If there are multiple entries with the same key, the browser will merge the values into a single request header.\n // Its therefore safe to simply push a \"baggage\" entry, even though there might already be another baggage header.\n newHeaders.push(['baggage', baggage]);\n }\n\n return newHeaders as PolymorphicRequestHeaders;\n } else {\n const existingSentryTraceHeader = 'sentry-trace' in originalHeaders ? originalHeaders['sentry-trace'] : undefined;\n const existingTraceparentHeader = 'traceparent' in originalHeaders ? originalHeaders.traceparent : undefined;\n const existingBaggageHeader = 'baggage' in originalHeaders ? originalHeaders.baggage : undefined;\n\n const newBaggageHeaders: string[] = existingBaggageHeader\n ? Array.isArray(existingBaggageHeader)\n ? [...existingBaggageHeader]\n : [existingBaggageHeader]\n : [];\n\n const prevBaggageHeaderWithSentryValues =\n existingBaggageHeader &&\n (Array.isArray(existingBaggageHeader)\n ? existingBaggageHeader.find(headerItem => baggageHeaderHasSentryBaggageValues(headerItem))\n : baggageHeaderHasSentryBaggageValues(existingBaggageHeader));\n\n if (baggage && !prevBaggageHeaderWithSentryValues) {\n newBaggageHeaders.push(baggage);\n }\n\n const newHeaders: {\n 'sentry-trace': string;\n baggage: string | undefined;\n traceparent?: string;\n } = {\n ...originalHeaders,\n 'sentry-trace': (existingSentryTraceHeader as string | undefined) ?? sentryTrace,\n baggage: newBaggageHeaders.length > 0 ? newBaggageHeaders.join(',') : undefined,\n };\n\n if (propagateTraceparent && traceparent && !existingTraceparentHeader) {\n newHeaders.traceparent = traceparent;\n }\n\n return newHeaders;\n }\n}\n\nfunction endSpan(span: Span, handlerData: HandlerDataFetch): void {\n if (handlerData.response) {\n setHttpStatus(span, handlerData.response.status);\n\n const contentLength = handlerData.response?.headers?.get('content-length');\n\n if (contentLength) {\n const contentLengthNum = parseInt(contentLength);\n if (contentLengthNum > 0) {\n span.setAttribute('http.response_content_length', contentLengthNum);\n }\n }\n } else if (handlerData.error) {\n span.setStatus({ code: SPAN_STATUS_ERROR, message: 'internal_error' });\n }\n span.end();\n}\n\nfunction baggageHeaderHasSentryBaggageValues(baggageHeader: string): boolean {\n return baggageHeader.split(',').some(baggageEntry => baggageEntry.trim().startsWith(SENTRY_BAGGAGE_KEY_PREFIX));\n}\n\nfunction isHeaders(headers: unknown): headers is Headers {\n return typeof Headers !== 'undefined' && isInstanceOf(headers, Headers);\n}\n\nfunction getSpanStartOptions(\n url: string,\n method: string,\n spanOrigin: SpanOrigin,\n): Parameters<typeof startInactiveSpan>[0] {\n // Data URLs need special handling because parseStringToURLObject treats them as \"relative\"\n // (no \"://\"), causing getSanitizedUrlStringFromUrlObject to return just the pathname\n // without the \"data:\" prefix, making later stripDataUrlContent calls ineffective.\n // So for data URLs, we strip the content first and use that directly.\n if (url.startsWith('data:')) {\n const sanitizedUrl = stripDataUrlContent(url);\n return {\n name: `${method} ${sanitizedUrl}`,\n attributes: getFetchSpanAttributes(url, undefined, method, spanOrigin),\n };\n }\n\n const parsedUrl = parseStringToURLObject(url);\n const sanitizedUrl = parsedUrl ? getSanitizedUrlStringFromUrlObject(parsedUrl) : url;\n return {\n name: `${method} ${sanitizedUrl}`,\n attributes: getFetchSpanAttributes(url, parsedUrl, method, spanOrigin),\n };\n}\n\nfunction getFetchSpanAttributes(\n url: string,\n parsedUrl: ReturnType<typeof parseStringToURLObject>,\n method: string,\n spanOrigin: SpanOrigin,\n): SpanAttributes {\n const attributes: SpanAttributes = {\n url: stripDataUrlContent(url),\n type: 'fetch',\n 'http.method': method,\n [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: spanOrigin,\n [SEMANTIC_ATTRIBUTE_SENTRY_OP]: 'http.client',\n };\n if (parsedUrl) {\n if (!isURLObjectRelative(parsedUrl)) {\n attributes['http.url'] = stripDataUrlContent(parsedUrl.href);\n attributes['server.address'] = parsedUrl.host;\n }\n if (parsedUrl.search) {\n attributes['http.query'] = parsedUrl.search;\n }\n if (parsedUrl.hash) {\n attributes['http.fragment'] = parsedUrl.hash;\n }\n }\n return attributes;\n}\n"],"names":["hasSpansEnabled","getActiveSpan","startInactiveSpan","SentryNonRecordingSpan","getClient","getTraceData","isRequest","setHttpStatus","SPAN_STATUS_ERROR","SENTRY_BAGGAGE_KEY_PREFIX","isInstanceOf","url","stripDataUrlContent","parseStringToURLObject","getSanitizedUrlStringFromUrlObject","SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN","SEMANTIC_ATTRIBUTE_SENTRY_OP","isURLObjectRelative"],"mappings":";;;;;;;;;;;;;;AA+DA;AACA;AACA;AACA;AACA;AACO,SAAS,sBAAsB;AACtC,EAAE,WAAW;AACb,EAAE,gBAAgB;AAClB,EAAE,mBAAmB;AACrB,EAAE,KAAK;AACP,EAAE,mBAAmB;AACrB,EAAoB;AACpB,EAAE,IAAI,CAAC,WAAW,CAAC,SAAS,EAAE;AAC9B,IAAI,OAAO,SAAS;AACpB,EAAE;;AAEF,EAAE,MAAM,EAAE,MAAM,EAAE,KAAI,GAAI,WAAW,CAAC,SAAS;;AAE/C,EAAE,MAAM,sBAAA,GAAyBA,+BAAe,MAAM,gBAAgB,CAAC,GAAG,CAAC;;AAE3E,EAAE,IAAI,WAAW,CAAC,YAAY,EAAE;AAChC,IAAI,MAAM,MAAA,GAAS,WAAW,CAAC,SAAS,CAAC,MAAM;AAC/C,IAAI,IAAI,CAAC,MAAM,EAAE;;AAEjB,IAAI,MAAM,IAAA,GAAO,KAAK,CAAC,MAAM,CAAC;;AAE9B,IAAI,IAAI,IAAI,EAAE;AACd;AACA,MAAM,IAAI,sBAAsB,EAAE;AAClC,QAAQ,OAAO,CAAC,IAAI,EAAE,WAAW,CAAC;AAClC,QAAQ,qBAAqB,CAAC,IAAI,EAAE,WAAW,EAAE,mBAAmB,CAAC;AACrE,MAAM;;AAEN;AACA,MAA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ACA,EAAA;AACA,EAAA,MAAA,UAAA,GAAA;AACA,IAAA,GAAA,EAAAC,uBAAA,CAAAD,KAAA,CAAA;AACA,IAAA,IAAA,EAAA,OAAA;AACA,IAAA,aAAA,EAAA,MAAA;AACA,IAAA,CAAAI,mDAAA,GAAA,UAAA;AACA,IAAA,CAAAC,+CAAA,GAAA,aAAA;AACA,GAAA;AACA,EAAA,IAAA,SAAA,EAAA;AACA,IAAA,IAAA,CAAAC,uBAAA,CAAA,SAAA,CAAA,EAAA;AACA,MAAA,UAAA,CAAA,UAAA,CAAA,GAAAL,uBAAA,CAAA,SAAA,CAAA,IAAA,CAAA;AACA,MAAA,UAAA,CAAA,gBAAA,CAAA,GAAA,SAAA,CAAA,IAAA;AACA,IAAA;AACA,IAAA,IAAA,SAAA,CAAA,MAAA,EAAA;AACA,MAAA,UAAA,CAAA,YAAA,CAAA,GAAA,SAAA,CAAA,MAAA;AACA,IAAA;AACA,IAAA,IAAA,SAAA,CAAA,IAAA,EAAA;AACA,MAAA,UAAA,CAAA,eAAA,CAAA,GAAA,SAAA,CAAA,IAAA;AACA,IAAA;AACA,EAAA;AACA,EAAA,OAAA,UAAA;AACA;;;;;;"}
|
|
1
|
+
{"version":3,"file":"fetch.js","sources":["../../src/fetch.ts"],"sourcesContent":["import { getClient } from './currentScopes';\nimport { SEMANTIC_ATTRIBUTE_SENTRY_OP, SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN } from './semanticAttributes';\nimport { setHttpStatus, SPAN_STATUS_ERROR, startInactiveSpan } from './tracing';\nimport { SentryNonRecordingSpan } from './tracing/sentryNonRecordingSpan';\nimport type { FetchBreadcrumbHint } from './types-hoist/breadcrumb';\nimport type { HandlerDataFetch } from './types-hoist/instrument';\nimport type { ResponseHookInfo } from './types-hoist/request';\nimport type { Span, SpanAttributes, SpanOrigin } from './types-hoist/span';\nimport { SENTRY_BAGGAGE_KEY_PREFIX } from './utils/baggage';\nimport { hasSpansEnabled } from './utils/hasSpansEnabled';\nimport { isInstanceOf, isRequest } from './utils/is';\nimport { getActiveSpan } from './utils/spanUtils';\nimport { getTraceData } from './utils/traceData';\nimport {\n getSanitizedUrlStringFromUrlObject,\n isURLObjectRelative,\n parseStringToURLObject,\n stripDataUrlContent,\n} from './utils/url';\n\ntype PolymorphicRequestHeaders =\n | Record<string, unknown>\n | Array<[string, unknown]>\n | Iterable<Iterable<unknown>>\n // the below is not precisely the Header type used in Request, but it'll pass duck-typing\n | {\n append: (key: string, value: string) => void;\n get: (key: string) => string | null | undefined;\n };\n\ninterface InstrumentFetchRequestOptions {\n spanOrigin?: SpanOrigin;\n propagateTraceparent?: boolean;\n onRequestSpanEnd?: (span: Span, responseInformation: ResponseHookInfo) => void;\n}\n\n/**\n * Create and track fetch request spans for usage in combination with `addFetchInstrumentationHandler`.\n *\n * @deprecated pass an options object instead of the spanOrigin parameter\n *\n * @returns Span if a span was created, otherwise void.\n */\nexport function instrumentFetchRequest(\n handlerData: HandlerDataFetch,\n shouldCreateSpan: (url: string) => boolean,\n shouldAttachHeaders: (url: string) => boolean,\n spans: Record<string, Span>,\n spanOrigin: SpanOrigin,\n): Span | undefined;\n/**\n * Create and track fetch request spans for usage in combination with `addFetchInstrumentationHandler`.\n *\n * @returns Span if a span was created, otherwise void.\n */\nexport function instrumentFetchRequest(\n handlerData: HandlerDataFetch,\n shouldCreateSpan: (url: string) => boolean,\n shouldAttachHeaders: (url: string) => boolean,\n spans: Record<string, Span>,\n // eslint-disable-next-line @typescript-eslint/unified-signatures -- needed because the other overload is deprecated\n instrumentFetchRequestOptions: InstrumentFetchRequestOptions,\n): Span | undefined;\n\n/**\n * Create and track fetch request spans for usage in combination with `addFetchInstrumentationHandler`.\n *\n * @returns Span if a span was created, otherwise void.\n */\nexport function instrumentFetchRequest(\n handlerData: HandlerDataFetch,\n shouldCreateSpan: (url: string) => boolean,\n shouldAttachHeaders: (url: string) => boolean,\n spans: Record<string, Span>,\n spanOriginOrOptions?: SpanOrigin | InstrumentFetchRequestOptions,\n): Span | undefined {\n if (!handlerData.fetchData) {\n return undefined;\n }\n\n const { method, url } = handlerData.fetchData;\n\n const shouldCreateSpanResult = hasSpansEnabled() && shouldCreateSpan(url);\n\n if (handlerData.endTimestamp) {\n const spanId = handlerData.fetchData.__span;\n if (!spanId) return;\n\n const span = spans[spanId];\n\n if (span) {\n // Only end the span and call hooks if we're actually recording\n if (shouldCreateSpanResult) {\n endSpan(span, handlerData);\n _callOnRequestSpanEnd(span, handlerData, spanOriginOrOptions);\n }\n\n // eslint-disable-next-line @typescript-eslint/no-dynamic-delete\n delete spans[spanId];\n }\n\n return undefined;\n }\n\n // Backwards-compatible with the old signature. Needed to introduce the combined optional parameter\n // to avoid API breakage for anyone calling this function with the optional spanOrigin parameter\n // TODO (v11): remove this backwards-compatible code and only accept the options parameter\n const { spanOrigin = 'auto.http.browser', propagateTraceparent = false } =\n typeof spanOriginOrOptions === 'object' ? spanOriginOrOptions : { spanOrigin: spanOriginOrOptions };\n\n const client = getClient();\n const hasParent = !!getActiveSpan();\n\n const span =\n shouldCreateSpanResult && hasParent\n ? startInactiveSpan(getSpanStartOptions(url, method, spanOrigin))\n : new SentryNonRecordingSpan();\n\n if (shouldCreateSpanResult && !hasParent) {\n client?.recordDroppedEvent('no_parent_span', 'span');\n }\n\n handlerData.fetchData.__span = span.spanContext().spanId;\n spans[span.spanContext().spanId] = span;\n\n if (shouldAttachHeaders(handlerData.fetchData.url)) {\n const request: string | Request = handlerData.args[0];\n\n // Shallow clone the options object to avoid mutating the original user-provided object\n // Examples: users re-using same options object for multiple fetch calls, frozen objects\n const options: { [key: string]: unknown } = { ...(handlerData.args[1] || {}) };\n\n const headers = _INTERNAL_getTracingHeadersForFetchRequest(\n request,\n options,\n // If performance is disabled (TWP) or there's no active root span (pageload/navigation/interaction),\n // we do not want to use the span as base for the trace headers,\n // which means that the headers will be generated from the scope and the sampling decision is deferred\n hasSpansEnabled() && hasParent ? span : undefined,\n propagateTraceparent,\n );\n if (headers) {\n // Ensure this is actually set, if no options have been passed previously\n handlerData.args[1] = options;\n options.headers = headers;\n }\n }\n\n if (client) {\n const fetchHint = {\n input: handlerData.args,\n response: handlerData.response,\n startTimestamp: handlerData.startTimestamp,\n endTimestamp: handlerData.endTimestamp,\n } satisfies FetchBreadcrumbHint;\n\n client.emit('beforeOutgoingRequestSpan', span, fetchHint);\n }\n\n return span;\n}\n\n/**\n * Calls the onRequestSpanEnd callback if it is defined.\n */\nexport function _callOnRequestSpanEnd(\n span: Span,\n handlerData: HandlerDataFetch,\n spanOriginOrOptions?: SpanOrigin | InstrumentFetchRequestOptions,\n): void {\n const onRequestSpanEnd =\n typeof spanOriginOrOptions === 'object' && spanOriginOrOptions !== null\n ? spanOriginOrOptions.onRequestSpanEnd\n : undefined;\n\n onRequestSpanEnd?.(span, {\n headers: handlerData.response?.headers,\n error: handlerData.error,\n });\n}\n\n/**\n * Builds merged fetch headers that include `sentry-trace` and `baggage` (and optionally `traceparent`)\n * for the given request and init, without mutating the original request or options.\n * Returns `undefined` when there is no `sentry-trace` value to attach.\n *\n * @internal Exported for cross-package instrumentation (for example Cloudflare Workers fetcher bindings)\n * and unit tests\n *\n * Baggage handling:\n * 1. No previous baggage header → include Sentry baggage\n * 2. Previous baggage has no Sentry entries → merge Sentry baggage in\n * 3. Previous baggage already has Sentry entries → leave as-is (may be user-defined)\n */\n// eslint-disable-next-line complexity -- yup it's this complicated :(\nexport function _INTERNAL_getTracingHeadersForFetchRequest(\n request: string | URL | Request,\n fetchOptionsObj: {\n headers?:\n | {\n [key: string]: string[] | string | undefined;\n }\n | PolymorphicRequestHeaders;\n },\n span?: Span,\n propagateTraceparent?: boolean,\n): PolymorphicRequestHeaders | undefined {\n const traceHeaders = getTraceData({ span, propagateTraceparent });\n const sentryTrace = traceHeaders['sentry-trace'];\n const baggage = traceHeaders.baggage;\n const traceparent = traceHeaders.traceparent;\n\n // Nothing to do, when we return undefined here, the original headers will be used\n if (!sentryTrace) {\n return undefined;\n }\n\n const originalHeaders = fetchOptionsObj.headers || (isRequest(request) ? request.headers : undefined);\n\n if (!originalHeaders) {\n return { ...traceHeaders };\n } else if (isHeaders(originalHeaders)) {\n const newHeaders = new Headers(originalHeaders);\n\n // We don't want to override manually added sentry headers\n if (!newHeaders.get('sentry-trace')) {\n newHeaders.set('sentry-trace', sentryTrace);\n }\n\n if (propagateTraceparent && traceparent && !newHeaders.get('traceparent')) {\n newHeaders.set('traceparent', traceparent);\n }\n\n if (baggage) {\n const prevBaggageHeader = newHeaders.get('baggage');\n\n if (!prevBaggageHeader) {\n newHeaders.set('baggage', baggage);\n } else if (!baggageHeaderHasSentryBaggageValues(prevBaggageHeader)) {\n newHeaders.set('baggage', `${prevBaggageHeader},${baggage}`);\n }\n }\n\n return newHeaders;\n } else if (isHeadersInitTupleArray(originalHeaders)) {\n const newHeaders = [...originalHeaders];\n\n if (!newHeaders.find(header => header[0] === 'sentry-trace')) {\n newHeaders.push(['sentry-trace', sentryTrace]);\n }\n\n if (propagateTraceparent && traceparent && !newHeaders.find(header => header[0] === 'traceparent')) {\n newHeaders.push(['traceparent', traceparent]);\n }\n\n const prevBaggageHeaderWithSentryValues = originalHeaders.find(\n header =>\n header[0] === 'baggage' && typeof header[1] === 'string' && baggageHeaderHasSentryBaggageValues(header[1]),\n );\n\n if (baggage && !prevBaggageHeaderWithSentryValues) {\n // If there are multiple entries with the same key, the browser will merge the values into a single request header.\n // Its therefore safe to simply push a \"baggage\" entry, even though there might already be another baggage header.\n newHeaders.push(['baggage', baggage]);\n }\n\n return newHeaders;\n } else {\n const existingSentryTraceHeader = 'sentry-trace' in originalHeaders ? originalHeaders['sentry-trace'] : undefined;\n const existingTraceparentHeader = 'traceparent' in originalHeaders ? originalHeaders.traceparent : undefined;\n const existingBaggageHeader = 'baggage' in originalHeaders ? originalHeaders.baggage : undefined;\n\n const newBaggageHeaders: string[] = existingBaggageHeader\n ? Array.isArray(existingBaggageHeader)\n ? [...existingBaggageHeader]\n : [existingBaggageHeader]\n : [];\n\n const prevBaggageHeaderWithSentryValues =\n existingBaggageHeader &&\n (Array.isArray(existingBaggageHeader)\n ? existingBaggageHeader.find(headerItem => baggageHeaderHasSentryBaggageValues(headerItem))\n : baggageHeaderHasSentryBaggageValues(existingBaggageHeader));\n\n if (baggage && !prevBaggageHeaderWithSentryValues) {\n newBaggageHeaders.push(baggage);\n }\n\n const newHeaders: {\n 'sentry-trace': string;\n baggage: string | undefined;\n traceparent?: string;\n } = Object.assign({}, originalHeaders, {\n 'sentry-trace': (existingSentryTraceHeader as string | undefined) ?? sentryTrace,\n baggage: newBaggageHeaders.length > 0 ? newBaggageHeaders.join(',') : undefined,\n });\n\n if (propagateTraceparent && traceparent && !existingTraceparentHeader) {\n newHeaders.traceparent = traceparent;\n }\n\n return newHeaders;\n }\n}\n\nfunction endSpan(span: Span, handlerData: HandlerDataFetch): void {\n if (handlerData.response) {\n setHttpStatus(span, handlerData.response.status);\n\n const contentLength = handlerData.response?.headers?.get('content-length');\n\n if (contentLength) {\n const contentLengthNum = parseInt(contentLength);\n if (contentLengthNum > 0) {\n span.setAttribute('http.response_content_length', contentLengthNum);\n }\n }\n } else if (handlerData.error) {\n span.setStatus({ code: SPAN_STATUS_ERROR, message: 'internal_error' });\n }\n span.end();\n}\n\nfunction baggageHeaderHasSentryBaggageValues(baggageHeader: unknown): boolean {\n if (typeof baggageHeader !== 'string') {\n return false;\n }\n\n return baggageHeader.split(',').some(baggageEntry => baggageEntry.trim().startsWith(SENTRY_BAGGAGE_KEY_PREFIX));\n}\n\nfunction isHeaders(headers: unknown): headers is Headers {\n return typeof Headers !== 'undefined' && isInstanceOf(headers, Headers);\n}\n\n/** `HeadersInit` array form: each entry is a [name, value] pair of strings. */\nfunction isHeadersInitTupleArray(headers: unknown): headers is [string, unknown][] {\n if (!Array.isArray(headers)) {\n return false;\n }\n\n return headers.every(\n (item): item is [string, unknown] => Array.isArray(item) && item.length === 2 && typeof item[0] === 'string',\n );\n}\n\nfunction getSpanStartOptions(\n url: string,\n method: string,\n spanOrigin: SpanOrigin,\n): Parameters<typeof startInactiveSpan>[0] {\n // Data URLs need special handling because parseStringToURLObject treats them as \"relative\"\n // (no \"://\"), causing getSanitizedUrlStringFromUrlObject to return just the pathname\n // without the \"data:\" prefix, making later stripDataUrlContent calls ineffective.\n // So for data URLs, we strip the content first and use that directly.\n if (url.startsWith('data:')) {\n const sanitizedUrl = stripDataUrlContent(url);\n return {\n name: `${method} ${sanitizedUrl}`,\n attributes: getFetchSpanAttributes(url, undefined, method, spanOrigin),\n };\n }\n\n const parsedUrl = parseStringToURLObject(url);\n const sanitizedUrl = parsedUrl ? getSanitizedUrlStringFromUrlObject(parsedUrl) : url;\n return {\n name: `${method} ${sanitizedUrl}`,\n attributes: getFetchSpanAttributes(url, parsedUrl, method, spanOrigin),\n };\n}\n\nfunction getFetchSpanAttributes(\n url: string,\n parsedUrl: ReturnType<typeof parseStringToURLObject>,\n method: string,\n spanOrigin: SpanOrigin,\n): SpanAttributes {\n const attributes: SpanAttributes = {\n url: stripDataUrlContent(url),\n type: 'fetch',\n 'http.method': method,\n [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: spanOrigin,\n [SEMANTIC_ATTRIBUTE_SENTRY_OP]: 'http.client',\n };\n if (parsedUrl) {\n if (!isURLObjectRelative(parsedUrl)) {\n attributes['http.url'] = stripDataUrlContent(parsedUrl.href);\n attributes['server.address'] = parsedUrl.host;\n }\n if (parsedUrl.search) {\n attributes['http.query'] = parsedUrl.search;\n }\n if (parsedUrl.hash) {\n attributes['http.fragment'] = parsedUrl.hash;\n }\n }\n return attributes;\n}\n"],"names":["hasSpansEnabled","getClient","getActiveSpan","startInactiveSpan","SentryNonRecordingSpan","getTraceData","isRequest","setHttpStatus","SPAN_STATUS_ERROR","SENTRY_BAGGAGE_KEY_PREFIX","isInstanceOf","url","stripDataUrlContent","parseStringToURLObject","getSanitizedUrlStringFromUrlObject","SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN","SEMANTIC_ATTRIBU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IAAA,IAAA,EAAA,CAAA,EAAA,MAAA,CAAA,CAAA,EAAA,YAAA,CAAA,CAAA;AACA,IAAA,UAAA,EAAA,sBAAA,CAAAA,KAAA,EAAA,SAAA,EAAA,MAAA,EAAA,UAAA,CAAA;AACA,GAAA;AACA;;AAEA,SAAA,sBAAA;AACA,EAAAA,KAAA;AACA,EAAA,SAAA;AACA,EAAA,MAAA;AACA,EAAA,UAAA;AACA,EAAA;AACA,EAAA,MAAA,UAAA,GAAA;AACA,IAAA,GAAA,EAAAC,uBAAA,CAAAD,KAAA,CAAA;AACA,IAAA,IAAA,EAAA,OAAA;AACA,IAAA,aAAA,EAAA,MAAA;AACA,IAAA,CAAAI,mDAAA,GAAA,UAAA;AACA,IAAA,CAAAC,+CAAA,GAAA,aAAA;AACA,GAAA;AACA,EAAA,IAAA,SAAA,EAAA;AACA,IAAA,IAAA,CAAAC,uBAAA,CAAA,SAAA,CAAA,EAAA;AACA,MAAA,UAAA,CAAA,UAAA,CAAA,GAAAL,uBAAA,CAAA,SAAA,CAAA,IAAA,CAAA;AACA,MAAA,UAAA,CAAA,gBAAA,CAAA,GAAA,SAAA,CAAA,IAAA;AACA,IAAA;AACA,IAAA,IAAA,SAAA,CAAA,MAAA,EAAA;AACA,MAAA,UAAA,CAAA,YAAA,CAAA,GAAA,SAAA,CAAA,MAAA;AACA,IAAA;AACA,IAAA,IAAA,SAAA,CAAA,IAAA,EAAA;AACA,MAAA,UAAA,CAAA,eAAA,CAAA,GAAA,SAAA,CAAA,IAAA;AACA,IAAA;AACA,EAAA;AACA,EAAA,OAAA,UAAA;AACA;;;;;;"}
|
package/build/cjs/index.js
CHANGED
|
@@ -50,6 +50,7 @@ const traceData = require('./utils/traceData.js');
|
|
|
50
50
|
const tracePropagationTargets = require('./utils/tracePropagationTargets.js');
|
|
51
51
|
const meta = require('./utils/meta.js');
|
|
52
52
|
const debounce = require('./utils/debounce.js');
|
|
53
|
+
const weakRef = require('./utils/weakRef.js');
|
|
53
54
|
const shouldIgnoreSpan = require('./utils/should-ignore-span.js');
|
|
54
55
|
const request = require('./utils/request.js');
|
|
55
56
|
const constants$1 = require('./constants.js');
|
|
@@ -73,7 +74,7 @@ const featureFlagsIntegration = require('./integrations/featureFlags/featureFlag
|
|
|
73
74
|
const growthbook = require('./integrations/featureFlags/growthbook.js');
|
|
74
75
|
const conversationId = require('./integrations/conversationId.js');
|
|
75
76
|
const profiling = require('./profiling.js');
|
|
76
|
-
const fetch
|
|
77
|
+
const fetch = require('./fetch.js');
|
|
77
78
|
const trpc = require('./trpc.js');
|
|
78
79
|
const index$8 = require('./integrations/mcp-server/index.js');
|
|
79
80
|
const feedback = require('./feedback.js');
|
|
@@ -107,7 +108,7 @@ const dsn = require('./utils/dsn.js');
|
|
|
107
108
|
const error = require('./utils/error.js');
|
|
108
109
|
const worldwide = require('./utils/worldwide.js');
|
|
109
110
|
const console = require('./instrument/console.js');
|
|
110
|
-
const fetch = require('./instrument/fetch.js');
|
|
111
|
+
const fetch$1 = require('./instrument/fetch.js');
|
|
111
112
|
const globalError = require('./instrument/globalError.js');
|
|
112
113
|
const globalUnhandledRejection = require('./instrument/globalUnhandledRejection.js');
|
|
113
114
|
const handlers = require('./instrument/handlers.js');
|
|
@@ -307,6 +308,8 @@ exports.getTraceData = traceData.getTraceData;
|
|
|
307
308
|
exports.shouldPropagateTraceForUrl = tracePropagationTargets.shouldPropagateTraceForUrl;
|
|
308
309
|
exports.getTraceMetaTags = meta.getTraceMetaTags;
|
|
309
310
|
exports.debounce = debounce.debounce;
|
|
311
|
+
exports.derefWeakRef = weakRef.derefWeakRef;
|
|
312
|
+
exports.makeWeakRef = weakRef.makeWeakRef;
|
|
310
313
|
exports.shouldIgnoreSpan = shouldIgnoreSpan.shouldIgnoreSpan;
|
|
311
314
|
exports.extractQueryParamsFromUrl = request.extractQueryParamsFromUrl;
|
|
312
315
|
exports.headersToDict = request.headersToDict;
|
|
@@ -340,7 +343,8 @@ exports.featureFlagsIntegration = featureFlagsIntegration.featureFlagsIntegratio
|
|
|
340
343
|
exports.growthbookIntegration = growthbook.growthbookIntegration;
|
|
341
344
|
exports.conversationIdIntegration = conversationId.conversationIdIntegration;
|
|
342
345
|
exports.profiler = profiling.profiler;
|
|
343
|
-
exports.
|
|
346
|
+
exports._INTERNAL_getTracingHeadersForFetchRequest = fetch._INTERNAL_getTracingHeadersForFetchRequest;
|
|
347
|
+
exports.instrumentFetchRequest = fetch.instrumentFetchRequest;
|
|
344
348
|
exports.trpcMiddleware = trpc.trpcMiddleware;
|
|
345
349
|
exports.wrapMcpServerWithSentry = index$8.wrapMcpServerWithSentry;
|
|
346
350
|
exports.captureFeedback = feedback.captureFeedback;
|
|
@@ -388,8 +392,8 @@ exports.makeDsn = dsn.makeDsn;
|
|
|
388
392
|
exports.SentryError = error.SentryError;
|
|
389
393
|
exports.GLOBAL_OBJ = worldwide.GLOBAL_OBJ;
|
|
390
394
|
exports.addConsoleInstrumentationHandler = console.addConsoleInstrumentationHandler;
|
|
391
|
-
exports.addFetchEndInstrumentationHandler = fetch.addFetchEndInstrumentationHandler;
|
|
392
|
-
exports.addFetchInstrumentationHandler = fetch.addFetchInstrumentationHandler;
|
|
395
|
+
exports.addFetchEndInstrumentationHandler = fetch$1.addFetchEndInstrumentationHandler;
|
|
396
|
+
exports.addFetchInstrumentationHandler = fetch$1.addFetchInstrumentationHandler;
|
|
393
397
|
exports.addGlobalErrorInstrumentationHandler = globalError.addGlobalErrorInstrumentationHandler;
|
|
394
398
|
exports.addGlobalUnhandledRejectionInstrumentationHandler = globalUnhandledRejection.addGlobalUnhandledRejectionInstrumentationHandler;
|
|
395
399
|
exports.addHandler = handlers.addHandler;
|
package/build/cjs/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
package/build/cjs/integration.js
CHANGED
|
@@ -131,6 +131,15 @@ function setupIntegration(client, integration, integrationIndex) {
|
|
|
131
131
|
client.addEventProcessor(processor);
|
|
132
132
|
}
|
|
133
133
|
|
|
134
|
+
(['processSpan', 'processSegmentSpan'] ).forEach(hook => {
|
|
135
|
+
const callback = integration[hook];
|
|
136
|
+
if (typeof callback === 'function') {
|
|
137
|
+
// The cast is needed because TS can't resolve overloads when the discriminant is a union type.
|
|
138
|
+
// Both overloads have the same callback signature so this is safe.
|
|
139
|
+
client.on(hook , (span) => callback.call(integration, span, client));
|
|
140
|
+
}
|
|
141
|
+
});
|
|
142
|
+
|
|
134
143
|
debugBuild.DEBUG_BUILD && debugLogger.debug.log(`Integration installed: ${integration.name}`);
|
|
135
144
|
}
|
|
136
145
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"integration.js","sources":["../../src/integration.ts"],"sourcesContent":["import type { Client } from './client';\nimport { getClient } from './currentScopes';\nimport { DEBUG_BUILD } from './debug-build';\nimport type { Event, EventHint } from './types-hoist/event';\nimport type { Integration, IntegrationFn } from './types-hoist/integration';\nimport type { CoreOptions } from './types-hoist/options';\nimport { debug } from './utils/debug-logger';\n\nexport const installedIntegrations: string[] = [];\n\n/** Map of integrations assigned to a client */\nexport type IntegrationIndex = {\n [key: string]: Integration;\n};\n\ntype IntegrationWithDefaultInstance = Integration & { isDefaultInstance?: true };\n\n/**\n * Remove duplicates from the given array, preferring the last instance of any duplicate. Not guaranteed to\n * preserve the order of integrations in the array.\n *\n * @private\n */\nfunction filterDuplicates(integrations: Integration[]): Integration[] {\n const integrationsByName: { [key: string]: Integration } = {};\n\n integrations.forEach((currentInstance: IntegrationWithDefaultInstance) => {\n const { name } = currentInstance;\n\n const existingInstance: IntegrationWithDefaultInstance | undefined = integrationsByName[name];\n\n // We want integrations later in the array to overwrite earlier ones of the same type, except that we never want a\n // default instance to overwrite an existing user instance\n if (existingInstance && !existingInstance.isDefaultInstance && currentInstance.isDefaultInstance) {\n return;\n }\n\n integrationsByName[name] = currentInstance;\n });\n\n return Object.values(integrationsByName);\n}\n\n/** Gets integrations to install */\nexport function getIntegrationsToSetup(\n options: Pick<CoreOptions, 'defaultIntegrations' | 'integrations'>,\n): Integration[] {\n const defaultIntegrations = options.defaultIntegrations || [];\n const userIntegrations = options.integrations;\n\n // We flag default instances, so that later we can tell them apart from any user-created instances of the same class\n defaultIntegrations.forEach((integration: IntegrationWithDefaultInstance) => {\n integration.isDefaultInstance = true;\n });\n\n let integrations: Integration[];\n\n if (Array.isArray(userIntegrations)) {\n integrations = [...defaultIntegrations, ...userIntegrations];\n } else if (typeof userIntegrations === 'function') {\n const resolvedUserIntegrations = userIntegrations(defaultIntegrations);\n integrations = Array.isArray(resolvedUserIntegrations) ? resolvedUserIntegrations : [resolvedUserIntegrations];\n } else {\n integrations = defaultIntegrations;\n }\n\n return filterDuplicates(integrations);\n}\n\n/**\n * Given a list of integration instances this installs them all. When `withDefaults` is set to `true` then all default\n * integrations are added unless they were already provided before.\n * @param integrations array of integration instances\n * @param withDefault should enable default integrations\n */\nexport function setupIntegrations(client: Client, integrations: Integration[]): IntegrationIndex {\n const integrationIndex: IntegrationIndex = {};\n\n integrations.forEach((integration: Integration | undefined) => {\n if (integration?.beforeSetup) {\n integration.beforeSetup(client);\n }\n });\n\n integrations.forEach((integration: Integration | undefined) => {\n // guard against empty provided integrations\n if (integration) {\n setupIntegration(client, integration, integrationIndex);\n }\n });\n\n return integrationIndex;\n}\n\n/**\n * Execute the `afterAllSetup` hooks of the given integrations.\n */\nexport function afterSetupIntegrations(client: Client, integrations: Integration[]): void {\n for (const integration of integrations) {\n // guard against empty provided integrations\n if (integration?.afterAllSetup) {\n integration.afterAllSetup(client);\n }\n }\n}\n\n/** Setup a single integration. */\nexport function setupIntegration(client: Client, integration: Integration, integrationIndex: IntegrationIndex): void {\n if (integrationIndex[integration.name]) {\n DEBUG_BUILD && debug.log(`Integration skipped because it was already installed: ${integration.name}`);\n return;\n }\n integrationIndex[integration.name] = integration;\n\n // `setupOnce` is only called the first time\n if (!installedIntegrations.includes(integration.name) && typeof integration.setupOnce === 'function') {\n integration.setupOnce();\n installedIntegrations.push(integration.name);\n }\n\n // `setup` is run for each client\n if (integration.setup && typeof integration.setup === 'function') {\n integration.setup(client);\n }\n\n if (typeof integration.preprocessEvent === 'function') {\n const callback = integration.preprocessEvent.bind(integration) as typeof integration.preprocessEvent;\n client.on('preprocessEvent', (event, hint) => callback(event, hint, client));\n }\n\n if (typeof integration.processEvent === 'function') {\n const callback = integration.processEvent.bind(integration) as typeof integration.processEvent;\n\n const processor = Object.assign((event: Event, hint: EventHint) => callback(event, hint, client), {\n id: integration.name,\n });\n\n client.addEventProcessor(processor);\n }\n\n DEBUG_BUILD && debug.log(`Integration installed: ${integration.name}`);\n}\n\n/** Add an integration to the current scope's client. */\nexport function addIntegration(integration: Integration): void {\n const client = getClient();\n\n if (!client) {\n DEBUG_BUILD && debug.warn(`Cannot add integration \"${integration.name}\" because no SDK Client is available.`);\n return;\n }\n\n client.addIntegration(integration);\n}\n\n/**\n * Define an integration function that can be used to create an integration instance.\n * Note that this by design hides the implementation details of the integration, as they are considered internal.\n */\nexport function defineIntegration<Fn extends IntegrationFn>(fn: Fn): (...args: Parameters<Fn>) => Integration {\n return fn;\n}\n"],"names":["DEBUG_BUILD","debug","getClient"],"mappings":";;;;;;AAQO,MAAM,qBAAqB,GAAa;;AAE/C;;AAOA;AACA;AACA;AACA;AACA;AACA;AACA,SAAS,gBAAgB,CAAC,YAAY,EAAgC;AACtE,EAAE,MAAM,kBAAkB,GAAmC,EAAE;;AAE/D,EAAE,YAAY,CAAC,OAAO,CAAC,CAAC,eAAe,KAAqC;AAC5E,IAAI,MAAM,EAAE,IAAA,EAAK,GAAI,eAAe;;AAEpC,IAAI,MAAM,gBAAgB,GAA+C,kBAAkB,CAAC,IAAI,CAAC;;AAEjG;AACA;AACA,IAAI,IAAI,gBAAA,IAAoB,CAAC,gBAAgB,CAAC,iBAAA,IAAqB,eAAe,CAAC,iBAAiB,EAAE;AACtG,MAAM;AACN,IAAI;;AAEJ,IAAI,kBAAkB,CAAC,IAAI,CAAA,GAAI,eAAe;AAC9C,EAAE,CAAC,CAAC;;AAEJ,EAAE,OAAO,MAAM,CAAC,MAAM,CAAC,kBAAkB,CAAC;AAC1C;;AAEA;AACO,SAAS,sBAAsB;AACtC,EAAE,OAAO;AACT,EAAiB;AACjB,EAAE,MAAM,sBAAsB,OAAO,CAAC,mBAAA,IAAuB,EAAE;AAC/D,EAAE,MAAM,gBAAA,GAAmB,OAAO,CAAC,YAAY;;AAE/C;AACA,EAAE,mBAAmB,CAAC,OAAO,CAAC,CAAC,WAAW,KAAqC;AAC/E,IAAI,WAAW,CAAC,iBAAA,GAAoB,IAAI;AACxC,EAAE,CAAC,CAAC;;AAEJ,EAAE,IAAI,YAAY;;AAElB,EAAE,IAAI,KAAK,CAAC,OAAO,CAAC,gBAAgB,CAAC,EAAE;AAC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A,EAAA,EAAA,WAAA,CAAA,IAAA;AACA,KAAA,CAAA;;AAEA,IAAA,MAAA,CAAA,iBAAA,CAAA,SAAA,CAAA;AACA,EAAA;;AAEA,EAAAD,sBAAA,IAAAC,iBAAA,CAAA,GAAA,CAAA,CAAA,uBAAA,EAAA,WAAA,CAAA,IAAA,CAAA,CAAA,CAAA;AACA;;AAEA;AACA,SAAA,cAAA,CAAA,WAAA,EAAA;AACA,EAAA,MAAA,MAAA,GAAAC,uBAAA,EAAA;;AAEA,EAAA,IAAA,CAAA,MAAA,EAAA;AACA,IAAAF,sBAAA,IAAAC,iBAAA,CAAA,IAAA,CAAA,CAAA,wBAAA,EAAA,WAAA,CAAA,IAAA,CAAA,qCAAA,CAAA,CAAA;AACA,IAAA;AACA,EAAA;;AAEA,EAAA,MAAA,CAAA,cAAA,CAAA,WAAA,CAAA;AACA;;AAEA;AACA;AACA;AACA;AACA,SAAA,iBAAA,CAAA,EAAA,EAAA;AACA,EAAA,OAAA,EAAA;AACA;;;;;;;;;;"}
|
|
1
|
+
{"version":3,"file":"integration.js","sources":["../../src/integration.ts"],"sourcesContent":["import type { Client } from './client';\nimport { getClient } from './currentScopes';\nimport { DEBUG_BUILD } from './debug-build';\nimport type { Event, EventHint } from './types-hoist/event';\nimport type { Integration, IntegrationFn } from './types-hoist/integration';\nimport type { CoreOptions } from './types-hoist/options';\nimport type { StreamedSpanJSON } from './types-hoist/span';\nimport { debug } from './utils/debug-logger';\n\nexport const installedIntegrations: string[] = [];\n\n/** Map of integrations assigned to a client */\nexport type IntegrationIndex = {\n [key: string]: Integration;\n};\n\ntype IntegrationWithDefaultInstance = Integration & { isDefaultInstance?: true };\n\n/**\n * Remove duplicates from the given array, preferring the last instance of any duplicate. Not guaranteed to\n * preserve the order of integrations in the array.\n *\n * @private\n */\nfunction filterDuplicates(integrations: Integration[]): Integration[] {\n const integrationsByName: { [key: string]: Integration } = {};\n\n integrations.forEach((currentInstance: IntegrationWithDefaultInstance) => {\n const { name } = currentInstance;\n\n const existingInstance: IntegrationWithDefaultInstance | undefined = integrationsByName[name];\n\n // We want integrations later in the array to overwrite earlier ones of the same type, except that we never want a\n // default instance to overwrite an existing user instance\n if (existingInstance && !existingInstance.isDefaultInstance && currentInstance.isDefaultInstance) {\n return;\n }\n\n integrationsByName[name] = currentInstance;\n });\n\n return Object.values(integrationsByName);\n}\n\n/** Gets integrations to install */\nexport function getIntegrationsToSetup(\n options: Pick<CoreOptions, 'defaultIntegrations' | 'integrations'>,\n): Integration[] {\n const defaultIntegrations = options.defaultIntegrations || [];\n const userIntegrations = options.integrations;\n\n // We flag default instances, so that later we can tell them apart from any user-created instances of the same class\n defaultIntegrations.forEach((integration: IntegrationWithDefaultInstance) => {\n integration.isDefaultInstance = true;\n });\n\n let integrations: Integration[];\n\n if (Array.isArray(userIntegrations)) {\n integrations = [...defaultIntegrations, ...userIntegrations];\n } else if (typeof userIntegrations === 'function') {\n const resolvedUserIntegrations = userIntegrations(defaultIntegrations);\n integrations = Array.isArray(resolvedUserIntegrations) ? resolvedUserIntegrations : [resolvedUserIntegrations];\n } else {\n integrations = defaultIntegrations;\n }\n\n return filterDuplicates(integrations);\n}\n\n/**\n * Given a list of integration instances this installs them all. When `withDefaults` is set to `true` then all default\n * integrations are added unless they were already provided before.\n * @param integrations array of integration instances\n * @param withDefault should enable default integrations\n */\nexport function setupIntegrations(client: Client, integrations: Integration[]): IntegrationIndex {\n const integrationIndex: IntegrationIndex = {};\n\n integrations.forEach((integration: Integration | undefined) => {\n if (integration?.beforeSetup) {\n integration.beforeSetup(client);\n }\n });\n\n integrations.forEach((integration: Integration | undefined) => {\n // guard against empty provided integrations\n if (integration) {\n setupIntegration(client, integration, integrationIndex);\n }\n });\n\n return integrationIndex;\n}\n\n/**\n * Execute the `afterAllSetup` hooks of the given integrations.\n */\nexport function afterSetupIntegrations(client: Client, integrations: Integration[]): void {\n for (const integration of integrations) {\n // guard against empty provided integrations\n if (integration?.afterAllSetup) {\n integration.afterAllSetup(client);\n }\n }\n}\n\n/** Setup a single integration. */\nexport function setupIntegration(client: Client, integration: Integration, integrationIndex: IntegrationIndex): void {\n if (integrationIndex[integration.name]) {\n DEBUG_BUILD && debug.log(`Integration skipped because it was already installed: ${integration.name}`);\n return;\n }\n integrationIndex[integration.name] = integration;\n\n // `setupOnce` is only called the first time\n if (!installedIntegrations.includes(integration.name) && typeof integration.setupOnce === 'function') {\n integration.setupOnce();\n installedIntegrations.push(integration.name);\n }\n\n // `setup` is run for each client\n if (integration.setup && typeof integration.setup === 'function') {\n integration.setup(client);\n }\n\n if (typeof integration.preprocessEvent === 'function') {\n const callback = integration.preprocessEvent.bind(integration) as typeof integration.preprocessEvent;\n client.on('preprocessEvent', (event, hint) => callback(event, hint, client));\n }\n\n if (typeof integration.processEvent === 'function') {\n const callback = integration.processEvent.bind(integration) as typeof integration.processEvent;\n\n const processor = Object.assign((event: Event, hint: EventHint) => callback(event, hint, client), {\n id: integration.name,\n });\n\n client.addEventProcessor(processor);\n }\n\n (['processSpan', 'processSegmentSpan'] as const).forEach(hook => {\n const callback = integration[hook];\n if (typeof callback === 'function') {\n // The cast is needed because TS can't resolve overloads when the discriminant is a union type.\n // Both overloads have the same callback signature so this is safe.\n client.on(hook as 'processSpan', (span: StreamedSpanJSON) => callback.call(integration, span, client));\n }\n });\n\n DEBUG_BUILD && debug.log(`Integration installed: ${integration.name}`);\n}\n\n/** Add an integration to the current scope's client. */\nexport function addIntegration(integration: Integration): void {\n const client = getClient();\n\n if (!client) {\n DEBUG_BUILD && debug.warn(`Cannot add integration \"${integration.name}\" because no SDK Client is available.`);\n return;\n }\n\n client.addIntegration(integration);\n}\n\n/**\n * Define an integration function that can be used to create an integration instance.\n * Note that this by design hides the implementation details of the integration, as they are considered internal.\n */\nexport function defineIntegration<Fn extends IntegrationFn>(fn: Fn): (...args: Parameters<Fn>) => Integration {\n return fn;\n}\n"],"names":["DEBUG_BUILD","debug","getClient"],"mappings":";;;;;;AASO,MAAM,qBAAqB,GAA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AAA,UAAA,EAAA;AACA;AACA;AACA,MAAA,MAAA,CAAA,EAAA,CAAA,IAAA,GAAA,CAAA,IAAA,KAAA,QAAA,CAAA,IAAA,CAAA,WAAA,EAAA,IAAA,EAAA,MAAA,CAAA,CAAA;AACA,IAAA;AACA,EAAA,CAAA,CAAA;;AAEA,EAAAD,sBAAA,IAAAC,iBAAA,CAAA,GAAA,CAAA,CAAA,uBAAA,EAAA,WAAA,CAAA,IAAA,CAAA,CAAA,CAAA;AACA;;AAEA;AACA,SAAA,cAAA,CAAA,WAAA,EAAA;AACA,EAAA,MAAA,MAAA,GAAAC,uBAAA,EAAA;;AAEA,EAAA,IAAA,CAAA,MAAA,EAAA;AACA,IAAAF,sBAAA,IAAAC,iBAAA,CAAA,IAAA,CAAA,CAAA,wBAAA,EAAA,WAAA,CAAA,IAAA,CAAA,qCAAA,CAAA,CAAA;AACA,IAAA;AACA,EAAA;;AAEA,EAAA,MAAA,CAAA,cAAA,CAAA,WAAA,CAAA;AACA;;AAEA;AACA;AACA;AACA;AACA,SAAA,iBAAA,CAAA,EAAA,EAAA;AACA,EAAA,OAAA,EAAA;AACA;;;;;;;;;;"}
|
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
3
3
|
const currentScopes = require('../currentScopes.js');
|
|
4
4
|
const integration = require('../integration.js');
|
|
5
5
|
const semanticAttributes = require('../semanticAttributes.js');
|
|
6
|
+
const spanUtils = require('../utils/spanUtils.js');
|
|
6
7
|
|
|
7
8
|
const INTEGRATION_NAME = 'ConversationId';
|
|
8
9
|
|
|
@@ -17,6 +18,16 @@ const _conversationIdIntegration = (() => {
|
|
|
17
18
|
const conversationId = scopeData.conversationId || isolationScopeData.conversationId;
|
|
18
19
|
|
|
19
20
|
if (conversationId) {
|
|
21
|
+
const { op, data: attributes, description: name } = spanUtils.spanToJSON(span);
|
|
22
|
+
|
|
23
|
+
// Only apply conversation ID to gen_ai spans.
|
|
24
|
+
// We also check for Vercel AI spans (ai.operationId attribute or ai.* span name)
|
|
25
|
+
// because the Vercel AI integration sets the gen_ai.* op in its own spanStart handler
|
|
26
|
+
// which fires after this, so the op is not yet available at this point.
|
|
27
|
+
if (!op?.startsWith('gen_ai.') && !attributes['ai.operationId'] && !name?.startsWith('ai.')) {
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
|
|
20
31
|
span.setAttribute(semanticAttributes.GEN_AI_CONVERSATION_ID_ATTRIBUTE, conversationId);
|
|
21
32
|
}
|
|
22
33
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"conversationId.js","sources":["../../../src/integrations/conversationId.ts"],"sourcesContent":["import type { Client } from '../client';\nimport { getCurrentScope, getIsolationScope } from '../currentScopes';\nimport { defineIntegration } from '../integration';\nimport { GEN_AI_CONVERSATION_ID_ATTRIBUTE } from '../semanticAttributes';\nimport type { IntegrationFn } from '../types-hoist/integration';\nimport type { Span } from '../types-hoist/span';\n\nconst INTEGRATION_NAME = 'ConversationId';\n\nconst _conversationIdIntegration = (() => {\n return {\n name: INTEGRATION_NAME,\n setup(client: Client) {\n client.on('spanStart', (span: Span) => {\n const scopeData = getCurrentScope().getScopeData();\n const isolationScopeData = getIsolationScope().getScopeData();\n\n const conversationId = scopeData.conversationId || isolationScopeData.conversationId;\n\n if (conversationId) {\n span.setAttribute(GEN_AI_CONVERSATION_ID_ATTRIBUTE, conversationId);\n }\n });\n },\n };\n}) satisfies IntegrationFn;\n\n/**\n * Automatically applies conversation ID from scope to spans.\n *\n * This integration reads the conversation ID from the current or isolation scope\n * and applies it to spans when they start. This ensures the conversation ID is\n * available for all AI-related operations.\n */\nexport const conversationIdIntegration = defineIntegration(_conversationIdIntegration);\n"],"names":["getCurrentScope","getIsolationScope","GEN_AI_CONVERSATION_ID_ATTRIBUTE","defineIntegration"],"mappings":"
|
|
1
|
+
{"version":3,"file":"conversationId.js","sources":["../../../src/integrations/conversationId.ts"],"sourcesContent":["import type { Client } from '../client';\nimport { getCurrentScope, getIsolationScope } from '../currentScopes';\nimport { defineIntegration } from '../integration';\nimport { GEN_AI_CONVERSATION_ID_ATTRIBUTE } from '../semanticAttributes';\nimport type { IntegrationFn } from '../types-hoist/integration';\nimport type { Span } from '../types-hoist/span';\nimport { spanToJSON } from '../utils/spanUtils';\n\nconst INTEGRATION_NAME = 'ConversationId';\n\nconst _conversationIdIntegration = (() => {\n return {\n name: INTEGRATION_NAME,\n setup(client: Client) {\n client.on('spanStart', (span: Span) => {\n const scopeData = getCurrentScope().getScopeData();\n const isolationScopeData = getIsolationScope().getScopeData();\n\n const conversationId = scopeData.conversationId || isolationScopeData.conversationId;\n\n if (conversationId) {\n const { op, data: attributes, description: name } = spanToJSON(span);\n\n // Only apply conversation ID to gen_ai spans.\n // We also check for Vercel AI spans (ai.operationId attribute or ai.* span name)\n // because the Vercel AI integration sets the gen_ai.* op in its own spanStart handler\n // which fires after this, so the op is not yet available at this point.\n if (!op?.startsWith('gen_ai.') && !attributes['ai.operationId'] && !name?.startsWith('ai.')) {\n return;\n }\n\n span.setAttribute(GEN_AI_CONVERSATION_ID_ATTRIBUTE, conversationId);\n }\n });\n },\n };\n}) satisfies IntegrationFn;\n\n/**\n * Automatically applies conversation ID from scope to spans.\n *\n * This integration reads the conversation ID from the current or isolation scope\n * and applies it to spans when they start. This ensures the conversation ID is\n * available for all AI-related operations.\n */\nexport const conversationIdIntegration = defineIntegration(_conversationIdIntegration);\n"],"names":["getCurrentScope","getIsolationScope","spanToJSON","GEN_AI_CONVERSATION_ID_ATTRIBUTE","defineIntegration"],"mappings":";;;;;;;AAQA,MAAM,gBAAA,GAAmB,gBAAgB;;AAEzC,MAAM,0BAAA,IAA8B,MAAM;AAC1C,EAAE,OAAO;AACT,IAAI,IAAI,EAAE,gBAAgB;AAC1B,IAAI,KAAK,CAAC,MAAM,EAAU;AAC1B,MAAM,MAAM,CAAC,EAAE,CAAC,WAAW,EAAE,CAAC,IAAI,KAAW;AAC7C,QAAQ,MAAM,YAAYA,6BAAe,EAAE,CAAC,YAAY,EAAE;AAC1D,QAAQ,MAAM,qBAAqBC,+BAAiB,EAAE,CAAC,YAAY,EAAE;;AAErE,QAAQ,MAAM,iBAAiB,SAAS,CAAC,cAAA,IAAkB,kBAAkB,CAAC,cAAc;;AAE5F,QAAQ,IAAI,cAAc,EAAE;AAC5B,UAAU,MAAM,EAAE,EAAE,EAAE,IAAI,EAAE,UAAU,EAAE,WAAW,EAAE,MAAK,GAAIC,oBAAU,CAAC,IAAI,CAAC;;AAE9E;AACA;AACA;AACA;AACA,UAAU,IAAI,CAAC,EAAE,EAAE,UAAU,CAAC,SAAS,CAAA,IAAK,CAAC,UAAU,CAAC,gBAAgB,CAAA,IAAK,CAAC,IAAI,EAAE,UAAU,CAAC,KAAK,CAAC,EAAE;AACvG,YAAY;AACZ,UAAU;;AAEV,UAAU,IAAI,CAAC,YAAY,CAACC,mDAAgC,EAAE,cAAc,CAAC;AAC7E,QAAQ;AACR,MAAM,CAAC,CAAC;AACR,IAAI,CAAC;AACL,GAAG;AACH,CAAC,CAAA;;AAED;AACA;AACA;AACA;AACA;AACA;AACA;MACa,yBAAA,GAA4BC,6BAAiB,CAAC,0BAA0B;;;;"}
|
|
@@ -41,6 +41,24 @@ const setSdkProcessingMetadata = require('./set-sdk-processing-metadata.js');
|
|
|
41
41
|
const getExpressExport = (express) =>
|
|
42
42
|
utils.hasDefaultProp(express) ? express.default : (express );
|
|
43
43
|
|
|
44
|
+
function isLegacyOptions(
|
|
45
|
+
options,
|
|
46
|
+
) {
|
|
47
|
+
return !!(options ).express;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// TODO: remove this deprecation handling in v11
|
|
51
|
+
let didLegacyDeprecationWarning = false;
|
|
52
|
+
function deprecationWarning() {
|
|
53
|
+
if (!didLegacyDeprecationWarning) {
|
|
54
|
+
didLegacyDeprecationWarning = true;
|
|
55
|
+
debugBuild.DEBUG_BUILD &&
|
|
56
|
+
debugLogger.debug.warn(
|
|
57
|
+
'[Express] `patchExpressModule(options)` is deprecated. Use `patchExpressModule(moduleExports, getOptions)` instead.',
|
|
58
|
+
);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
44
62
|
/**
|
|
45
63
|
* This is a portable instrumentatiton function that works in any environment
|
|
46
64
|
* where Express can be loaded, without depending on OpenTelemetry.
|
|
@@ -50,11 +68,30 @@ const getExpressExport = (express) =>
|
|
|
50
68
|
* import express from 'express';
|
|
51
69
|
* import * as Sentry from '@sentry/deno'; // or any SDK that extends core
|
|
52
70
|
*
|
|
53
|
-
* Sentry.patchExpressModule(
|
|
71
|
+
* Sentry.patchExpressModule(express, () => ({}));
|
|
72
|
+
* ```
|
|
54
73
|
*/
|
|
55
|
-
|
|
74
|
+
|
|
75
|
+
function patchExpressModule(
|
|
76
|
+
optionsOrExports,
|
|
77
|
+
maybeGetOptions,
|
|
78
|
+
) {
|
|
79
|
+
let getOptions;
|
|
80
|
+
let moduleExports;
|
|
81
|
+
if (!maybeGetOptions && isLegacyOptions(optionsOrExports)) {
|
|
82
|
+
const { express, ...options } = optionsOrExports;
|
|
83
|
+
moduleExports = express;
|
|
84
|
+
getOptions = () => options;
|
|
85
|
+
deprecationWarning();
|
|
86
|
+
} else if (typeof maybeGetOptions !== 'function') {
|
|
87
|
+
throw new TypeError('`patchExpressModule(moduleExports, getOptions)` requires a `getOptions` callback');
|
|
88
|
+
} else {
|
|
89
|
+
getOptions = maybeGetOptions;
|
|
90
|
+
moduleExports = optionsOrExports ;
|
|
91
|
+
}
|
|
92
|
+
|
|
56
93
|
// pass in the require() or import() result of express
|
|
57
|
-
const express = getExpressExport(
|
|
94
|
+
const express = getExpressExport(moduleExports);
|
|
58
95
|
const routerProto = utils.isExpressWithRouterPrototype(express)
|
|
59
96
|
? express.Router.prototype // Express v5
|
|
60
97
|
: utils.isExpressWithoutRouterPrototype(express)
|
|
@@ -74,7 +111,7 @@ const patchExpressModule = (options) => {
|
|
|
74
111
|
function routeTrace( ...args) {
|
|
75
112
|
const route = originalRouteMethod.apply(this, args);
|
|
76
113
|
const layer = this.stack[this.stack.length - 1] ;
|
|
77
|
-
patchLayer.patchLayer(
|
|
114
|
+
patchLayer.patchLayer(getOptions, layer, utils.getLayerPath(args));
|
|
78
115
|
return route;
|
|
79
116
|
},
|
|
80
117
|
);
|
|
@@ -94,7 +131,7 @@ const patchExpressModule = (options) => {
|
|
|
94
131
|
if (!layer) {
|
|
95
132
|
return route;
|
|
96
133
|
}
|
|
97
|
-
patchLayer.patchLayer(
|
|
134
|
+
patchLayer.patchLayer(getOptions, layer, utils.getLayerPath(args));
|
|
98
135
|
return route;
|
|
99
136
|
},
|
|
100
137
|
);
|
|
@@ -119,7 +156,7 @@ const patchExpressModule = (options) => {
|
|
|
119
156
|
if (router) {
|
|
120
157
|
const layer = router.stack[router.stack.length - 1];
|
|
121
158
|
if (layer) {
|
|
122
|
-
patchLayer.patchLayer(
|
|
159
|
+
patchLayer.patchLayer(getOptions, layer, utils.getLayerPath(args));
|
|
123
160
|
}
|
|
124
161
|
}
|
|
125
162
|
return route;
|
|
@@ -130,7 +167,7 @@ const patchExpressModule = (options) => {
|
|
|
130
167
|
}
|
|
131
168
|
|
|
132
169
|
return express;
|
|
133
|
-
}
|
|
170
|
+
}
|
|
134
171
|
|
|
135
172
|
/**
|
|
136
173
|
* An Express-compatible error handler, used by setupExpressErrorHandler
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../../../src/integrations/express/index.ts"],"sourcesContent":["/**\n * Platform-portable Express tracing integration.\n *\n * @module\n *\n * This Sentry integration is a derivative work based on the OpenTelemetry\n * Express instrumentation.\n *\n * <https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/packages/instrumentation-express>\n *\n * Extended under the terms of the Apache 2.0 license linked below:\n *\n * ----\n *\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { debug } from '../../utils/debug-logger';\nimport { captureException } from '../../exports';\nimport { DEBUG_BUILD } from '../../debug-build';\nimport type {\n ExpressApplication,\n ExpressErrorMiddleware,\n ExpressExport,\n ExpressHandlerOptions,\n ExpressIntegrationOptions,\n ExpressLayer,\n ExpressMiddleware,\n ExpressModuleExport,\n ExpressRequest,\n ExpressResponse,\n ExpressRouter,\n ExpressRouterv4,\n ExpressRouterv5,\n MiddlewareError,\n} from './types';\nimport {\n defaultShouldHandleError,\n getLayerPath,\n hasDefaultProp,\n isExpressWithoutRouterPrototype,\n isExpressWithRouterPrototype,\n} from './utils';\nimport { wrapMethod } from '../../utils/object';\nimport { patchLayer } from './patch-layer';\nimport { setSDKProcessingMetadata } from './set-sdk-processing-metadata';\n\nconst getExpressExport = (express: ExpressModuleExport): ExpressExport =>\n hasDefaultProp(express) ? express.default : (express as ExpressExport);\n\n/**\n * This is a portable instrumentatiton function that works in any environment\n * where Express can be loaded, without depending on OpenTelemetry.\n *\n * @example\n * ```javascript\n * import express from 'express';\n * import * as Sentry from '@sentry/deno'; // or any SDK that extends core\n *\n * Sentry.patchExpressModule({ express })\n */\nexport const patchExpressModule = (options: ExpressIntegrationOptions) => {\n // pass in the require() or import() result of express\n const express = getExpressExport(options.express);\n const routerProto: ExpressRouterv4 | ExpressRouterv5 | undefined = isExpressWithRouterPrototype(express)\n ? express.Router.prototype // Express v5\n : isExpressWithoutRouterPrototype(express)\n ? express.Router // Express v4\n : undefined;\n\n if (!routerProto) {\n throw new TypeError('no valid Express route function to instrument');\n }\n\n // oxlint-disable-next-line @typescript-eslint/unbound-method\n const originalRouteMethod = routerProto.route;\n try {\n wrapMethod(\n routerProto,\n 'route',\n function routeTrace(this: ExpressRouter, ...args: Parameters<typeof originalRouteMethod>[]) {\n const route = originalRouteMethod.apply(this, args);\n const layer = this.stack[this.stack.length - 1] as ExpressLayer;\n patchLayer(options, layer, getLayerPath(args));\n return route;\n },\n );\n } catch (e) {\n DEBUG_BUILD && debug.error('Failed to patch express route method:', e);\n }\n\n // oxlint-disable-next-line @typescript-eslint/unbound-method\n const originalRouterUse = routerProto.use;\n try {\n wrapMethod(\n routerProto,\n 'use',\n function useTrace(this: ExpressApplication, ...args: Parameters<typeof originalRouterUse>) {\n const route = originalRouterUse.apply(this, args);\n const layer = this.stack[this.stack.length - 1];\n if (!layer) {\n return route;\n }\n patchLayer(options, layer, getLayerPath(args));\n return route;\n },\n );\n } catch (e) {\n DEBUG_BUILD && debug.error('Failed to patch express use method:', e);\n }\n\n const { application } = express;\n const originalApplicationUse = application.use;\n try {\n wrapMethod(\n application,\n 'use',\n function appUseTrace(\n this: ExpressApplication & {\n _router?: ExpressRouter;\n router?: ExpressRouter;\n },\n ...args: Parameters<ExpressApplication['use']>\n ) {\n // If we access app.router in express 4.x we trigger an assertion error.\n // This property existed in v3, was removed in v4 and then re-added in v5.\n const route = originalApplicationUse.apply(this, args);\n const router = isExpressWithRouterPrototype(express) ? this.router : this._router;\n if (router) {\n const layer = router.stack[router.stack.length - 1];\n if (layer) {\n patchLayer(options, layer, getLayerPath(args));\n }\n }\n return route;\n },\n );\n } catch (e) {\n DEBUG_BUILD && debug.error('Failed to patch express application.use method:', e);\n }\n\n return express;\n};\n\n/**\n * An Express-compatible error handler, used by setupExpressErrorHandler\n */\nexport function expressErrorHandler(options?: ExpressHandlerOptions): ExpressErrorMiddleware {\n return function sentryErrorMiddleware(\n error: MiddlewareError,\n request: ExpressRequest,\n res: ExpressResponse,\n next: (error: MiddlewareError) => void,\n ): void {\n // When an error happens, the `expressRequestHandler` middleware does not run, so we set it here too\n setSDKProcessingMetadata(request);\n const shouldHandleError = options?.shouldHandleError || defaultShouldHandleError;\n\n if (shouldHandleError(error)) {\n const eventId = captureException(error, {\n mechanism: { type: 'auto.middleware.express', handled: false },\n });\n (res as { sentry?: string }).sentry = eventId;\n }\n\n next(error);\n };\n}\n\n/**\n * Add an Express error handler to capture errors to Sentry.\n *\n * The error handler must be before any other middleware and after all controllers.\n *\n * @param app The Express instances\n * @param options {ExpressHandlerOptions} Configuration options for the handler\n *\n * @example\n * ```javascript\n * import * as Sentry from 'sentry/deno'; // or any other @sentry/<platform>\n * import * as express from 'express';\n *\n * Sentry.instrumentExpress(express);\n *\n * const app = express();\n *\n * // Add your routes, etc.\n *\n * // Add this after all routes,\n * // but before any and other error-handling middlewares are defined\n * Sentry.setupExpressErrorHandler(app);\n *\n * app.listen(3000);\n * ```\n */\nexport function setupExpressErrorHandler(\n app: {\n //oxlint-disable-next-line no-explicit-any\n use: (middleware: any) => unknown;\n },\n options?: ExpressHandlerOptions,\n): void {\n app.use(expressRequestHandler());\n app.use(expressErrorHandler(options));\n}\n\nfunction expressRequestHandler(): ExpressMiddleware {\n return function sentryRequestMiddleware(request: ExpressRequest, _res: ExpressResponse, next: () => void): void {\n setSDKProcessingMetadata(request);\n next();\n };\n}\n"],"names":["hasDefaultProp","isExpressWithRouterPrototype","isExpressWithoutRouterPrototype","wrapMethod","patchLayer","getLayerPath","DEBUG_BUILD","debug","setSDKProcessingMetadata","defaultShouldHandleError","captureException"],"mappings":";;;;;;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AAgCA,MAAM,gBAAA,GAAmB,CAAC,OAAO;AACjC,EAAEA,oBAAc,CAAC,OAAO,CAAA,GAAI,OAAO,CAAC,OAAA,IAAW,OAAA,EAAyB;;AAExE;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;MACa,kBAAA,GAAqB,CAAC,OAAO,KAAgC;A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AC;AACrC,IAAI,IAAI,EAAE;AACV,EAAE,CAAC;AACH;;;;;;"}
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../../../src/integrations/express/index.ts"],"sourcesContent":["/**\n * Platform-portable Express tracing integration.\n *\n * @module\n *\n * This Sentry integration is a derivative work based on the OpenTelemetry\n * Express instrumentation.\n *\n * <https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/packages/instrumentation-express>\n *\n * Extended under the terms of the Apache 2.0 license linked below:\n *\n * ----\n *\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { debug } from '../../utils/debug-logger';\nimport { captureException } from '../../exports';\nimport { DEBUG_BUILD } from '../../debug-build';\nimport type {\n ExpressApplication,\n ExpressErrorMiddleware,\n ExpressExport,\n ExpressHandlerOptions,\n ExpressIntegrationOptions,\n ExpressLayer,\n ExpressMiddleware,\n ExpressModuleExport,\n ExpressRequest,\n ExpressResponse,\n ExpressRouter,\n ExpressRouterv4,\n ExpressRouterv5,\n MiddlewareError,\n} from './types';\nimport {\n defaultShouldHandleError,\n getLayerPath,\n hasDefaultProp,\n isExpressWithoutRouterPrototype,\n isExpressWithRouterPrototype,\n} from './utils';\nimport { wrapMethod } from '../../utils/object';\nimport { patchLayer } from './patch-layer';\nimport { setSDKProcessingMetadata } from './set-sdk-processing-metadata';\n\nconst getExpressExport = (express: ExpressModuleExport): ExpressExport =>\n hasDefaultProp(express) ? express.default : (express as ExpressExport);\n\nfunction isLegacyOptions(\n options: ExpressModuleExport | (ExpressIntegrationOptions & { express: ExpressModuleExport }),\n): options is ExpressIntegrationOptions & { express: ExpressModuleExport } {\n return !!(options as { express: ExpressModuleExport }).express;\n}\n\n// TODO: remove this deprecation handling in v11\nlet didLegacyDeprecationWarning = false;\nfunction deprecationWarning() {\n if (!didLegacyDeprecationWarning) {\n didLegacyDeprecationWarning = true;\n DEBUG_BUILD &&\n debug.warn(\n '[Express] `patchExpressModule(options)` is deprecated. Use `patchExpressModule(moduleExports, getOptions)` instead.',\n );\n }\n}\n\n/**\n * This is a portable instrumentatiton function that works in any environment\n * where Express can be loaded, without depending on OpenTelemetry.\n *\n * @example\n * ```javascript\n * import express from 'express';\n * import * as Sentry from '@sentry/deno'; // or any SDK that extends core\n *\n * Sentry.patchExpressModule(express, () => ({}));\n * ```\n */\nexport function patchExpressModule(\n moduleExports: ExpressModuleExport,\n getOptions: () => ExpressIntegrationOptions,\n): ExpressModuleExport;\n/**\n * @deprecated Pass the Express module export as the first argument and options getter as the second argument.\n */\nexport function patchExpressModule(\n options: ExpressIntegrationOptions & { express: ExpressModuleExport },\n): ExpressModuleExport;\nexport function patchExpressModule(\n optionsOrExports: ExpressModuleExport | (ExpressIntegrationOptions & { express: ExpressModuleExport }),\n maybeGetOptions?: () => ExpressIntegrationOptions,\n): ExpressModuleExport {\n let getOptions: () => ExpressIntegrationOptions;\n let moduleExports: ExpressModuleExport;\n if (!maybeGetOptions && isLegacyOptions(optionsOrExports)) {\n const { express, ...options } = optionsOrExports;\n moduleExports = express;\n getOptions = () => options;\n deprecationWarning();\n } else if (typeof maybeGetOptions !== 'function') {\n throw new TypeError('`patchExpressModule(moduleExports, getOptions)` requires a `getOptions` callback');\n } else {\n getOptions = maybeGetOptions;\n moduleExports = optionsOrExports as ExpressModuleExport;\n }\n\n // pass in the require() or import() result of express\n const express = getExpressExport(moduleExports);\n const routerProto: ExpressRouterv4 | ExpressRouterv5 | undefined = isExpressWithRouterPrototype(express)\n ? express.Router.prototype // Express v5\n : isExpressWithoutRouterPrototype(express)\n ? express.Router // Express v4\n : undefined;\n\n if (!routerProto) {\n throw new TypeError('no valid Express route function to instrument');\n }\n\n // oxlint-disable-next-line @typescript-eslint/unbound-method\n const originalRouteMethod = routerProto.route;\n try {\n wrapMethod(\n routerProto,\n 'route',\n function routeTrace(this: ExpressRouter, ...args: Parameters<typeof originalRouteMethod>[]) {\n const route = originalRouteMethod.apply(this, args);\n const layer = this.stack[this.stack.length - 1] as ExpressLayer;\n patchLayer(getOptions, layer, getLayerPath(args));\n return route;\n },\n );\n } catch (e) {\n DEBUG_BUILD && debug.error('Failed to patch express route method:', e);\n }\n\n // oxlint-disable-next-line @typescript-eslint/unbound-method\n const originalRouterUse = routerProto.use;\n try {\n wrapMethod(\n routerProto,\n 'use',\n function useTrace(this: ExpressApplication, ...args: Parameters<typeof originalRouterUse>) {\n const route = originalRouterUse.apply(this, args);\n const layer = this.stack[this.stack.length - 1];\n if (!layer) {\n return route;\n }\n patchLayer(getOptions, layer, getLayerPath(args));\n return route;\n },\n );\n } catch (e) {\n DEBUG_BUILD && debug.error('Failed to patch express use method:', e);\n }\n\n const { application } = express;\n const originalApplicationUse = application.use;\n try {\n wrapMethod(\n application,\n 'use',\n function appUseTrace(\n this: ExpressApplication & {\n _router?: ExpressRouter;\n router?: ExpressRouter;\n },\n ...args: Parameters<ExpressApplication['use']>\n ) {\n // If we access app.router in express 4.x we trigger an assertion error.\n // This property existed in v3, was removed in v4 and then re-added in v5.\n const route = originalApplicationUse.apply(this, args);\n const router = isExpressWithRouterPrototype(express) ? this.router : this._router;\n if (router) {\n const layer = router.stack[router.stack.length - 1];\n if (layer) {\n patchLayer(getOptions, layer, getLayerPath(args));\n }\n }\n return route;\n },\n );\n } catch (e) {\n DEBUG_BUILD && debug.error('Failed to patch express application.use method:', e);\n }\n\n return express;\n}\n\n/**\n * An Express-compatible error handler, used by setupExpressErrorHandler\n */\nexport function expressErrorHandler(options?: ExpressHandlerOptions): ExpressErrorMiddleware {\n return function sentryErrorMiddleware(\n error: MiddlewareError,\n request: ExpressRequest,\n res: ExpressResponse,\n next: (error: MiddlewareError) => void,\n ): void {\n // When an error happens, the `expressRequestHandler` middleware does not run, so we set it here too\n setSDKProcessingMetadata(request);\n const shouldHandleError = options?.shouldHandleError || defaultShouldHandleError;\n\n if (shouldHandleError(error)) {\n const eventId = captureException(error, {\n mechanism: { type: 'auto.middleware.express', handled: false },\n });\n (res as { sentry?: string }).sentry = eventId;\n }\n\n next(error);\n };\n}\n\n/**\n * Add an Express error handler to capture errors to Sentry.\n *\n * The error handler must be before any other middleware and after all controllers.\n *\n * @param app The Express instances\n * @param options {ExpressHandlerOptions} Configuration options for the handler\n *\n * @example\n * ```javascript\n * import * as Sentry from 'sentry/deno'; // or any other @sentry/<platform>\n * import * as express from 'express';\n *\n * Sentry.instrumentExpress(express);\n *\n * const app = express();\n *\n * // Add your routes, etc.\n *\n * // Add this after all routes,\n * // but before any and other error-handling middlewares are defined\n * Sentry.setupExpressErrorHandler(app);\n *\n * app.listen(3000);\n * ```\n */\nexport function setupExpressErrorHandler(\n app: {\n //oxlint-disable-next-line no-explicit-any\n use: (middleware: any) => unknown;\n },\n options?: ExpressHandlerOptions,\n): void {\n app.use(expressRequestHandler());\n app.use(expressErrorHandler(options));\n}\n\nfunction expressRequestHandler(): ExpressMiddleware {\n return function sentryRequestMiddleware(request: ExpressRequest, _res: ExpressResponse, next: () => void): void {\n setSDKProcessingMetadata(request);\n next();\n };\n}\n"],"names":["hasDefaultProp","DEBUG_BUILD","debug","isExpressWithRouterPrototype","isExpressWithoutRouterPrototype","wrapMethod","patchLayer","getLayerPath","setSDKProcessingMetadata","defaultShouldHandleError","captureException"],"mappings":";;;;;;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AAgCA,MAAM,gBAAA,GAAmB,CAAC,OAAO;AACjC,EAAEA,oBAAc,CAAC,OAAO,CAAA,GAAI,OAAO,CAAC,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B;AACvC,IAAI,KAAK;AACT,IAAI,OAAO;AACX,IAAI,GAAG;AACP,IAAI,IAAI;AACR,IAAU;AACV;AACA,IAAIM,iDAAwB,CAAC,OAAO,CAAC;AACrC,IAAI,MAAM,iBAAA,GAAoB,OAAO,EAAE,iBAAA,IAAqBC,8BAAwB;;AAEpF,IAAI,IAAI,iBAAiB,CAAC,KAAK,CAAC,EAAE;AAClC,MAAM,MAAM,OAAA,GAAUC,yBAAgB,CAAC,KAAK,EAAE;AAC9C,QAAQ,SAAS,EAAE,EAAE,IAAI,EAAE,yBAAyB,EAAE,OAAO,EAAE,KAAA,EAAO;AACtE,OAAO,CAAC;AACR,MAAM,CAAC,GAAA,GAA4B,MAAA,GAAS,OAAO;AACnD,IAAI;;AAEJ,IAAI,IAAI,CAAC,KAAK,CAAC;AACf,EAAE,CAAC;AACH;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAAS,wBAAwB;AACxC,EAAE;;AAGA;AACF,EAAE,OAAO;AACT,EAAQ;AACR,EAAE,GAAG,CAAC,GAAG,CAAC,qBAAqB,EAAE,CAAC;AAClC,EAAE,GAAG,CAAC,GAAG,CAAC,mBAAmB,CAAC,OAAO,CAAC,CAAC;AACvC;;AAEA,SAAS,qBAAqB,GAAsB;AACpD,EAAE,OAAO,SAAS,uBAAuB,CAAC,OAAO,EAAkB,IAAI,EAAmB,IAAI,EAAoB;AAClH,IAAIF,iDAAwB,CAAC,OAAO,CAAC;AACrC,IAAI,IAAI,EAAE;AACV,EAAE,CAAC;AACH;;;;;;"}
|
|
@@ -44,7 +44,11 @@ const setSdkProcessingMetadata = require('./set-sdk-processing-metadata.js');
|
|
|
44
44
|
*/
|
|
45
45
|
|
|
46
46
|
|
|
47
|
-
function patchLayer(
|
|
47
|
+
function patchLayer(
|
|
48
|
+
getOptions,
|
|
49
|
+
maybeLayer,
|
|
50
|
+
layerPath,
|
|
51
|
+
) {
|
|
48
52
|
if (!maybeLayer?.handle) {
|
|
49
53
|
return;
|
|
50
54
|
}
|
|
@@ -69,6 +73,8 @@ function patchLayer(options, maybeLayer, layerPath) {
|
|
|
69
73
|
//oxlint-disable-next-line no-explicit-any
|
|
70
74
|
...otherArgs
|
|
71
75
|
) {
|
|
76
|
+
const options = getOptions();
|
|
77
|
+
|
|
72
78
|
// Set normalizedRequest here because expressRequestHandler middleware
|
|
73
79
|
// (registered via setupExpressErrorHandler) is added after routes and
|
|
74
80
|
// therefore never runs for successful requests — route handlers typically
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"patch-layer.js","sources":["../../../../src/integrations/express/patch-layer.ts"],"sourcesContent":["/**\n * Platform-portable Express tracing integration.\n *\n * @module\n *\n * This Sentry integration is a derivative work based on the OpenTelemetry\n * Express instrumentation.\n *\n * <https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/packages/instrumentation-express>\n *\n * Extended under the terms of the Apache 2.0 license linked below:\n *\n * ----\n *\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { DEBUG_BUILD } from '../../debug-build';\nimport { SEMANTIC_ATTRIBUTE_SENTRY_OP, SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN } from '../../semanticAttributes';\nimport { SPAN_STATUS_ERROR, startSpanManual, withActiveSpan } from '../../tracing';\nimport { debug } from '../../utils/debug-logger';\nimport type { SpanAttributes } from '../../types-hoist/span';\nimport { getActiveSpan } from '../../utils/spanUtils';\nimport { getStoredLayers, storeLayer } from './request-layer-store';\nimport {\n type ExpressRequest,\n type ExpressResponse,\n type ExpressIntegrationOptions,\n type ExpressLayer,\n ATTR_HTTP_ROUTE,\n ATTR_EXPRESS_TYPE,\n ATTR_EXPRESS_NAME,\n ExpressLayerType_ROUTER,\n} from './types';\nimport {\n asErrorAndMessage,\n getActualMatchedRoute,\n getConstructedRoute,\n getLayerMetadata,\n isLayerIgnored,\n} from './utils';\nimport { getIsolationScope } from '../../currentScopes';\nimport { getDefaultIsolationScope } from '../../defaultScopes';\nimport { getOriginalFunction, markFunctionWrapped } from '../../utils/object';\nimport { setSDKProcessingMetadata } from './set-sdk-processing-metadata';\n\nexport type ExpressPatchLayerOptions = Pick<\n ExpressIntegrationOptions,\n 'onRouteResolved' | 'ignoreLayers' | 'ignoreLayersType'\n>;\n\nexport function patchLayer(options: ExpressPatchLayerOptions, maybeLayer?: ExpressLayer, layerPath?: string): void {\n if (!maybeLayer?.handle) {\n return;\n }\n const layer = maybeLayer;\n\n const layerHandleOriginal = layer.handle;\n\n // avoid patching multiple times the same layer\n if (getOriginalFunction(layerHandleOriginal)) {\n return;\n }\n\n if (layerHandleOriginal.length === 4) {\n // todo: instrument error handlers\n return;\n }\n\n function layerHandlePatched(\n this: ExpressLayer,\n req: ExpressRequest,\n res: ExpressResponse,\n //oxlint-disable-next-line no-explicit-any\n ...otherArgs: any[]\n ) {\n // Set normalizedRequest here because expressRequestHandler middleware\n // (registered via setupExpressErrorHandler) is added after routes and\n // therefore never runs for successful requests — route handlers typically\n // send a response without calling next(). It would be safe to set this\n // multiple times, since the data is identical, but more performant not to.\n setSDKProcessingMetadata(req);\n\n // Only create spans when there's an active parent span\n // Without a parent span, this request is being ignored, so skip it\n const parentSpan = getActiveSpan();\n if (!parentSpan) {\n return layerHandleOriginal.apply(this, [req, res, ...otherArgs]);\n }\n\n if (layerPath) {\n storeLayer(req, layerPath);\n }\n const storedLayers = getStoredLayers(req);\n const isLayerPathStored = !!layerPath;\n\n const constructedRoute = getConstructedRoute(req);\n const actualMatchedRoute = getActualMatchedRoute(req, constructedRoute);\n\n options.onRouteResolved?.(actualMatchedRoute);\n\n const metadata = getLayerMetadata(constructedRoute, layer, layerPath);\n const name = metadata.attributes[ATTR_EXPRESS_NAME];\n const type = metadata.attributes[ATTR_EXPRESS_TYPE];\n const attributes: SpanAttributes = Object.assign(metadata.attributes, {\n [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.http.express',\n [SEMANTIC_ATTRIBUTE_SENTRY_OP]: `${type}.express`,\n });\n if (actualMatchedRoute) {\n attributes[ATTR_HTTP_ROUTE] = actualMatchedRoute;\n }\n\n // verify against the config if the layer should be ignored\n if (isLayerIgnored(metadata.attributes[ATTR_EXPRESS_NAME], type, options)) {\n // XXX: the isLayerPathStored guard here is *not* present in the\n // original @opentelemetry/instrumentation-express impl, but was\n // suggested by the Sentry code review bot. It appears to correctly\n // prevent improper layer calculation in the case where there's a\n // middleware without a layerPath argument. It's unclear whether\n // that's possible, or if any existing code depends on that \"bug\".\n if (isLayerPathStored) {\n storedLayers.pop();\n }\n return layerHandleOriginal.apply(this, [req, res, ...otherArgs]);\n }\n\n const currentScope = getIsolationScope();\n if (currentScope !== getDefaultIsolationScope()) {\n if (type === 'request_handler') {\n // type cast b/c Otel unfortunately types info.request as any :(\n const method = req.method ? req.method.toUpperCase() : 'GET';\n currentScope.setTransactionName(`${method} ${constructedRoute}`);\n }\n } else {\n DEBUG_BUILD && debug.warn('Isolation scope is still default isolation scope - skipping setting transactionName');\n }\n\n return startSpanManual({ name, attributes }, span => {\n let spanHasEnded = false;\n // TODO: Fix router spans (getRouterPath does not work properly) to\n // have useful names before removing this branch\n if (metadata.attributes[ATTR_EXPRESS_TYPE] === ExpressLayerType_ROUTER) {\n span.end();\n spanHasEnded = true;\n }\n // listener for response.on('finish')\n const onResponseFinish = () => {\n if (!spanHasEnded) {\n spanHasEnded = true;\n span.end();\n }\n };\n\n // verify we have a callback\n for (let i = 0; i < otherArgs.length; i++) {\n const callback = otherArgs[i] as Function;\n if (typeof callback !== 'function') {\n continue;\n }\n\n //oxlint-disable-next-line no-explicit-any\n otherArgs[i] = function (...args: any[]) {\n // express considers anything but an empty value, \"route\" or \"router\"\n // passed to its callback to be an error\n const maybeError = args[0];\n const isError = !!maybeError && maybeError !== 'route' && maybeError !== 'router';\n if (!spanHasEnded && isError) {\n const [_, message] = asErrorAndMessage(maybeError);\n // intentionally do not record the exception here, because\n // the error handler we assign does that, provided the user\n // correctly calls setupExpressErrorHandler.\n // TODO: A future enhancement can automatically attach\n // the error handler if we detect that it has not been added.\n span.setStatus({\n code: SPAN_STATUS_ERROR,\n message,\n });\n }\n\n if (!spanHasEnded) {\n spanHasEnded = true;\n res.removeListener('finish', onResponseFinish);\n span.end();\n }\n if (!(req.route && isError) && isLayerPathStored) {\n storedLayers.pop();\n }\n // execute the callback back in the parent's scope, so that\n // we bubble up each level as next() is called.\n return withActiveSpan(parentSpan, () => callback.apply(this, args));\n };\n break;\n }\n\n try {\n return layerHandleOriginal.apply(this, [req, res, ...otherArgs]);\n } catch (anyError) {\n const [_, message] = asErrorAndMessage(anyError);\n // intentionally do not record the exception here, because\n // the error handler we assign does that, provided the user\n // correctly calls setupExpressErrorHandler.\n // TODO: A future enhancement can automatically attach\n // the error handler if we detect that it has not been added.\n span.setStatus({\n code: SPAN_STATUS_ERROR,\n message,\n });\n throw anyError;\n /* v8 ignore next - it sees the block end at the throw */\n } finally {\n // At this point if the callback wasn't called, that means\n // either the layer is asynchronous (so it will call the\n // callback later on) or that the layer directly ends the\n // http response, so we'll hook into the \"finish\" event to\n // handle the later case.\n if (!spanHasEnded) {\n res.once('finish', onResponseFinish);\n }\n }\n });\n }\n\n // `handle` isn't just a regular function in some cases. It also contains\n // some properties holding metadata and state so we need to proxy them\n // through through patched function. Use a for-in to also pick up properties\n // that other libraries might add to the prototype before we instrument.\n // ref: https://github.com/open-telemetry/opentelemetry-js-contrib/issues/1950\n // ref: https://github.com/open-telemetry/opentelemetry-js-contrib/issues/2271\n // oxlint-disable-next-line guard-for-in\n for (const key in layerHandleOriginal as Function & Record<string, unknown>) {\n // skip standard function prototype fields that both have\n if (key in layerHandlePatched) {\n continue;\n }\n Object.defineProperty(layerHandlePatched, key, {\n get() {\n return layerHandleOriginal[key];\n },\n set(value) {\n layerHandleOriginal[key] = value;\n },\n });\n }\n\n markFunctionWrapped(layerHandlePatched, layerHandleOriginal);\n\n Object.defineProperty(layer, 'handle', {\n enumerable: true,\n configurable: true,\n writable: true,\n value: layerHandlePatched,\n });\n}\n"],"names":["getOriginalFunction","setSDKProcessingMetadata","getActiveSpan","storeLayer","getStoredLayers","getConstructedRoute","getActualMatchedRoute","getLayerMetadata","ATTR_EXPRESS_NAME","ATTR_EXPRESS_TYPE","SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN","SEMANTIC_ATTRIBUTE_SENTRY_OP","ATTR_HTTP_ROUTE","isLayerIgnored","getIsolationScope","getDefaultIsolationScope","DEBUG_BUILD","debug","startSpanManual","ExpressLayerType_ROUTER","asErrorAndMessage","SPAN_STATUS_ERROR","withActiveSpan","markFunctionWrapped"],"mappings":";;;;;;;;;;;;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AAoCO,SAAS,UAAU,CAAC,OAAO,EAA4B,UAAU,EAAiB,SAAS,EAAiB;AACnH,EAAE,IAAI,CAAC,UAAU,EAAE,MAAM,EAAE;AAC3B,IAAI;AACJ,EAAE;AACF,EAAE,MAAM,KAAA,GAAQ,UAAU;;AAE1B,EAAE,MAAM,mBAAA,GAAsB,KAAK,CAAC,MAAM;;AAE1C;AACA,EAAE,IAAIA,0BAAmB,CAAC,mBAAmB,CAAC,EAAE;AAChD,IAAI;AACJ,EAAE;;AAEF,EAAE,IAAI,mBAAmB,CAAC,MAAA,KAAW,CAAC,EAAE;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AACA,IAAA,KAAA,EAAA,kBAAA;AACA,GAAA,CAAA;AACA;;;;"}
|
|
1
|
+
{"version":3,"file":"patch-layer.js","sources":["../../../../src/integrations/express/patch-layer.ts"],"sourcesContent":["/**\n * Platform-portable Express tracing integration.\n *\n * @module\n *\n * This Sentry integration is a derivative work based on the OpenTelemetry\n * Express instrumentation.\n *\n * <https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/packages/instrumentation-express>\n *\n * Extended under the terms of the Apache 2.0 license linked below:\n *\n * ----\n *\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { DEBUG_BUILD } from '../../debug-build';\nimport { SEMANTIC_ATTRIBUTE_SENTRY_OP, SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN } from '../../semanticAttributes';\nimport { SPAN_STATUS_ERROR, startSpanManual, withActiveSpan } from '../../tracing';\nimport { debug } from '../../utils/debug-logger';\nimport type { SpanAttributes } from '../../types-hoist/span';\nimport { getActiveSpan } from '../../utils/spanUtils';\nimport { getStoredLayers, storeLayer } from './request-layer-store';\nimport {\n type ExpressRequest,\n type ExpressResponse,\n type ExpressIntegrationOptions,\n type ExpressLayer,\n ATTR_HTTP_ROUTE,\n ATTR_EXPRESS_TYPE,\n ATTR_EXPRESS_NAME,\n ExpressLayerType_ROUTER,\n} from './types';\nimport {\n asErrorAndMessage,\n getActualMatchedRoute,\n getConstructedRoute,\n getLayerMetadata,\n isLayerIgnored,\n} from './utils';\nimport { getIsolationScope } from '../../currentScopes';\nimport { getDefaultIsolationScope } from '../../defaultScopes';\nimport { getOriginalFunction, markFunctionWrapped } from '../../utils/object';\nimport { setSDKProcessingMetadata } from './set-sdk-processing-metadata';\n\nexport type ExpressPatchLayerOptions = Pick<\n ExpressIntegrationOptions,\n 'onRouteResolved' | 'ignoreLayers' | 'ignoreLayersType'\n>;\n\nexport function patchLayer(\n getOptions: () => ExpressPatchLayerOptions,\n maybeLayer?: ExpressLayer,\n layerPath?: string,\n): void {\n if (!maybeLayer?.handle) {\n return;\n }\n const layer = maybeLayer;\n\n const layerHandleOriginal = layer.handle;\n\n // avoid patching multiple times the same layer\n if (getOriginalFunction(layerHandleOriginal)) {\n return;\n }\n\n if (layerHandleOriginal.length === 4) {\n // todo: instrument error handlers\n return;\n }\n\n function layerHandlePatched(\n this: ExpressLayer,\n req: ExpressRequest,\n res: ExpressResponse,\n //oxlint-disable-next-line no-explicit-any\n ...otherArgs: any[]\n ) {\n const options = getOptions();\n\n // Set normalizedRequest here because expressRequestHandler middleware\n // (registered via setupExpressErrorHandler) is added after routes and\n // therefore never runs for successful requests — route handlers typically\n // send a response without calling next(). It would be safe to set this\n // multiple times, since the data is identical, but more performant not to.\n setSDKProcessingMetadata(req);\n\n // Only create spans when there's an active parent span\n // Without a parent span, this request is being ignored, so skip it\n const parentSpan = getActiveSpan();\n if (!parentSpan) {\n return layerHandleOriginal.apply(this, [req, res, ...otherArgs]);\n }\n\n if (layerPath) {\n storeLayer(req, layerPath);\n }\n const storedLayers = getStoredLayers(req);\n const isLayerPathStored = !!layerPath;\n\n const constructedRoute = getConstructedRoute(req);\n const actualMatchedRoute = getActualMatchedRoute(req, constructedRoute);\n\n options.onRouteResolved?.(actualMatchedRoute);\n\n const metadata = getLayerMetadata(constructedRoute, layer, layerPath);\n const name = metadata.attributes[ATTR_EXPRESS_NAME];\n const type = metadata.attributes[ATTR_EXPRESS_TYPE];\n const attributes: SpanAttributes = Object.assign(metadata.attributes, {\n [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.http.express',\n [SEMANTIC_ATTRIBUTE_SENTRY_OP]: `${type}.express`,\n });\n if (actualMatchedRoute) {\n attributes[ATTR_HTTP_ROUTE] = actualMatchedRoute;\n }\n\n // verify against the config if the layer should be ignored\n if (isLayerIgnored(metadata.attributes[ATTR_EXPRESS_NAME], type, options)) {\n // XXX: the isLayerPathStored guard here is *not* present in the\n // original @opentelemetry/instrumentation-express impl, but was\n // suggested by the Sentry code review bot. It appears to correctly\n // prevent improper layer calculation in the case where there's a\n // middleware without a layerPath argument. It's unclear whether\n // that's possible, or if any existing code depends on that \"bug\".\n if (isLayerPathStored) {\n storedLayers.pop();\n }\n return layerHandleOriginal.apply(this, [req, res, ...otherArgs]);\n }\n\n const currentScope = getIsolationScope();\n if (currentScope !== getDefaultIsolationScope()) {\n if (type === 'request_handler') {\n // type cast b/c Otel unfortunately types info.request as any :(\n const method = req.method ? req.method.toUpperCase() : 'GET';\n currentScope.setTransactionName(`${method} ${constructedRoute}`);\n }\n } else {\n DEBUG_BUILD && debug.warn('Isolation scope is still default isolation scope - skipping setting transactionName');\n }\n\n return startSpanManual({ name, attributes }, span => {\n let spanHasEnded = false;\n // TODO: Fix router spans (getRouterPath does not work properly) to\n // have useful names before removing this branch\n if (metadata.attributes[ATTR_EXPRESS_TYPE] === ExpressLayerType_ROUTER) {\n span.end();\n spanHasEnded = true;\n }\n // listener for response.on('finish')\n const onResponseFinish = () => {\n if (!spanHasEnded) {\n spanHasEnded = true;\n span.end();\n }\n };\n\n // verify we have a callback\n for (let i = 0; i < otherArgs.length; i++) {\n const callback = otherArgs[i] as Function;\n if (typeof callback !== 'function') {\n continue;\n }\n\n //oxlint-disable-next-line no-explicit-any\n otherArgs[i] = function (...args: any[]) {\n // express considers anything but an empty value, \"route\" or \"router\"\n // passed to its callback to be an error\n const maybeError = args[0];\n const isError = !!maybeError && maybeError !== 'route' && maybeError !== 'router';\n if (!spanHasEnded && isError) {\n const [_, message] = asErrorAndMessage(maybeError);\n // intentionally do not record the exception here, because\n // the error handler we assign does that, provided the user\n // correctly calls setupExpressErrorHandler.\n // TODO: A future enhancement can automatically attach\n // the error handler if we detect that it has not been added.\n span.setStatus({\n code: SPAN_STATUS_ERROR,\n message,\n });\n }\n\n if (!spanHasEnded) {\n spanHasEnded = true;\n res.removeListener('finish', onResponseFinish);\n span.end();\n }\n if (!(req.route && isError) && isLayerPathStored) {\n storedLayers.pop();\n }\n // execute the callback back in the parent's scope, so that\n // we bubble up each level as next() is called.\n return withActiveSpan(parentSpan, () => callback.apply(this, args));\n };\n break;\n }\n\n try {\n return layerHandleOriginal.apply(this, [req, res, ...otherArgs]);\n } catch (anyError) {\n const [_, message] = asErrorAndMessage(anyError);\n // intentionally do not record the exception here, because\n // the error handler we assign does that, provided the user\n // correctly calls setupExpressErrorHandler.\n // TODO: A future enhancement can automatically attach\n // the error handler if we detect that it has not been added.\n span.setStatus({\n code: SPAN_STATUS_ERROR,\n message,\n });\n throw anyError;\n /* v8 ignore next - it sees the block end at the throw */\n } finally {\n // At this point if the callback wasn't called, that means\n // either the layer is asynchronous (so it will call the\n // callback later on) or that the layer directly ends the\n // http response, so we'll hook into the \"finish\" event to\n // handle the later case.\n if (!spanHasEnded) {\n res.once('finish', onResponseFinish);\n }\n }\n });\n }\n\n // `handle` isn't just a regular function in some cases. It also contains\n // some properties holding metadata and state so we need to proxy them\n // through through patched function. Use a for-in to also pick up properties\n // that other libraries might add to the prototype before we instrument.\n // ref: https://github.com/open-telemetry/opentelemetry-js-contrib/issues/1950\n // ref: https://github.com/open-telemetry/opentelemetry-js-contrib/issues/2271\n // oxlint-disable-next-line guard-for-in\n for (const key in layerHandleOriginal as Function & Record<string, unknown>) {\n // skip standard function prototype fields that both have\n if (key in layerHandlePatched) {\n continue;\n }\n Object.defineProperty(layerHandlePatched, key, {\n get() {\n return layerHandleOriginal[key];\n },\n set(value) {\n layerHandleOriginal[key] = value;\n },\n });\n }\n\n markFunctionWrapped(layerHandlePatched, layerHandleOriginal);\n\n Object.defineProperty(layer, 'handle', {\n enumerable: true,\n configurable: true,\n writable: true,\n value: layerHandlePatched,\n });\n}\n"],"names":["getOriginalFunction","setSDKProcessingMetadata","getActiveSpan","storeLayer","getStoredLayers","getConstructedRoute","getActualMatchedRoute","getLayerMetadata","ATTR_EXPRESS_NAME","ATTR_EXPRESS_TYPE","SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN","SEMANTIC_ATTRIBUTE_SENTRY_OP","ATTR_HTTP_ROUTE","isLayerIgnored","getIsolationScope","getDefaultIsolationScope","DEBUG_BUILD","debug","startSpanManual","ExpressLayerType_ROUTER","asErrorAndMessage","SPAN_STATUS_ERROR","withActiveSpan","markFunctionWrapped"],"mappings":";;;;;;;;;;;;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AAoCO,SAAS,UAAU;AAC1B,EAAE,UAAU;AACZ,EAAE,UAAU;AACZ,EAAE,SAAS;AACX,EAAQ;AACR,EAAE,IAAI,CAAC,UAAU,EAAE,MAAM,EAAE;AAC3B,IAAI;AACJ,EAAE;AACF,EAAE,MAAM,KAAA,GAAQ,UAAU;;AAE1B,EAAE,MAAM,mBAAA,GAAsB,KAAK,CAAC,MAAM;;AAE1C;AACA,EAAE,IAAIA,0BAAmB,CAAC,mBAAmB,CAAC,EAAE;AAChD,IAAI;AACJ,EAAE;;AAEF,EAAE,IAAI,mBAAmB,CAAC,MAAA,KAAW,CAAC,EAAE;AACxC;AACA,IAAI;AACJ,EAAE;;AAEF,EAAE,SAAS,kBAAkB;;AAE7B,IAAI,GAAG;AACP,IAAI,GAAG;AACP;AACA,IAAI,GAAG;AACP,IAAI;AACJ,IAAI,MAAM,OAAA,GAAU,UAAU,EAAE;;AAEhC;AACA;AACA;AACA;AACA;AACA,IAAIC,iDAAwB,CAAC,GAAG,CAAC;;AAEjC;AACA;AACA,IAAI,MAAM,UAAA,GAAaC,uBAAa,EAAE;AACtC,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CAAA;AACA;AACA;AACA;AACA;AACA;AACA,QAAA,IAAA,CAAA,SAAA,CAAA;AACA,UAAA,IAAA,EAAAC,4BAAA;AACA,UAAA,OAAA;AACA,SAAA,CAAA;AACA,QAAA,MAAA,QAAA;AACA;AACA,MAAA,CAAA,SAAA;AACA;AACA;AACA;AACA;AACA;AACA,QAAA,IAAA,CAAA,YAAA,EAAA;AACA,UAAA,GAAA,CAAA,IAAA,CAAA,QAAA,EAAA,gBAAA,CAAA;AACA,QAAA;AACA,MAAA;AACA,IAAA,CAAA,CAAA;AACA,EAAA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,EAAA,KAAA,MAAA,GAAA,IAAA,mBAAA,GAAA;AACA;AACA,IAAA,IAAA,GAAA,IAAA,kBAAA,EAAA;AACA,MAAA;AACA,IAAA;AACA,IAAA,MAAA,CAAA,cAAA,CAAA,kBAAA,EAAA,GAAA,EAAA;AACA,MAAA,GAAA,GAAA;AACA,QAAA,OAAA,mBAAA,CAAA,GAAA,CAAA;AACA,MAAA,CAAA;AACA,MAAA,GAAA,CAAA,KAAA,EAAA;AACA,QAAA,mBAAA,CAAA,GAAA,CAAA,GAAA,KAAA;AACA,MAAA,CAAA;AACA,KAAA,CAAA;AACA,EAAA;;AAEA,EAAAE,0BAAA,CAAA,kBAAA,EAAA,mBAAA,CAAA;;AAEA,EAAA,MAAA,CAAA,cAAA,CAAA,KAAA,EAAA,QAAA,EAAA;AACA,IAAA,UAAA,EAAA,IAAA;AACA,IAAA,YAAA,EAAA,IAAA;AACA,IAAA,QAAA,EAAA,IAAA;AACA,IAAA,KAAA,EAAA,kBAAA;AACA,GAAA,CAAA;AACA;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sources":["../../../../src/integrations/express/types.ts"],"sourcesContent":["/**\n * Platform-portable Express tracing integration.\n *\n * @module\n *\n * This Sentry integration is a derivative work based on the OpenTelemetry\n * Express instrumentation.\n *\n * <https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/packages/instrumentation-express>\n *\n * Extended under the terms of the Apache 2.0 license linked below:\n *\n * ----\n *\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport type { RequestEventData } from '../../types-hoist/request';\nimport type { SpanAttributes } from '../../types-hoist/span';\n\nexport const ATTR_EXPRESS_NAME = 'express.name';\nexport const ATTR_HTTP_ROUTE = 'http.route';\nexport const ATTR_EXPRESS_TYPE = 'express.type';\n\nexport type ExpressExport = {\n Router: ExpressRouterv5 | ExpressRouterv4;\n application: ExpressApplication;\n};\n\nexport type ExpressExportv5 = ExpressExport & {\n Router: ExpressRouterv5;\n};\n\nexport type ExpressExportv4 = ExpressExport & {\n Router: ExpressRouterv4;\n};\n\nexport type ExpressModuleExport = ExpressExport | { default: ExpressExport };\n\nexport interface ExpressRequest extends RequestEventData {\n originalUrl: string;\n route: unknown;\n // Note: req.res is typed as optional (only present after middleware init).\n // mark optional to preserve compat with express v4 types.\n res?: ExpressResponse;\n}\n\n// just a minimum type def for what we need, since this also needs to\n// work in environments lacking node:http\nexport interface ExpressResponse {\n once(ev: string, listener: Function): this;\n removeListener(ev: string, listener?: Function): this;\n emit(ev: string, ...data: unknown[]): this;\n}\n\nexport interface NextFunction {\n (err?: unknown): void;\n /**\n * \"Break-out\" of a router by calling {next('router')};\n * @see {https://expressjs.com/en/guide/using-middleware.html#middleware.router}\n */\n (deferToNext: 'router'): void;\n /**\n * \"Break-out\" of a route by calling {next('route')};\n * @see {https://expressjs.com/en/guide/using-middleware.html#middleware.application}\n */\n (deferToNext: 'route'): void;\n}\n\n// Need to mark this as `any` so they don't conflict with the actual express\n//oxlint-disable-next-line no-explicit-any\nexport type ExpressApplicationRequestHandler = (...handlers: any[]) => any;\n\nexport type ExpressRequestInfo<T = unknown> = {\n /** An express request object */\n request: T;\n route: string;\n layerType: ExpressLayerType;\n};\n\nexport type ExpressLayerType = 'router' | 'middleware' | 'request_handler';\nexport const ExpressLayerType_ROUTER = 'router';\nexport const ExpressLayerType_MIDDLEWARE = 'middleware';\nexport const ExpressLayerType_REQUEST_HANDLER = 'request_handler';\n\nexport type PathParams = string | RegExp | Array<string | RegExp>;\nexport type LayerPathSegment = string | RegExp | number;\n\nexport interface ExpressRoute {\n path: string;\n stack: ExpressLayer[];\n}\n\nexport type ExpressRouterv4 = ExpressRouter;\n\nexport interface ExpressRouterv5 {\n prototype: ExpressRouter;\n}\n\n// https://github.com/expressjs/express/blob/main/lib/router/layer.js#L33\nexport type ExpressLayer = {\n handle: Function &\n Record<string, unknown> & {\n stack?: ExpressLayer[];\n };\n name: string;\n params: { [key: string]: string };\n path?: string;\n regexp: RegExp;\n route?: ExpressLayer;\n};\n\nexport type ExpressRouter = {\n params: { [key: string]: string };\n _params: string[];\n caseSensitive: boolean;\n mergeParams: boolean;\n strict: boolean;\n stack: ExpressLayer[];\n route(prefix: PathParams): ExpressRoute;\n use(...handlers: unknown[]): unknown;\n};\n\nexport type IgnoreMatcher = string | RegExp | ((name: string) => boolean);\n\nexport type ExpressIntegrationOptions = {\n express
|
|
1
|
+
{"version":3,"file":"types.js","sources":["../../../../src/integrations/express/types.ts"],"sourcesContent":["/**\n * Platform-portable Express tracing integration.\n *\n * @module\n *\n * This Sentry integration is a derivative work based on the OpenTelemetry\n * Express instrumentation.\n *\n * <https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/packages/instrumentation-express>\n *\n * Extended under the terms of the Apache 2.0 license linked below:\n *\n * ----\n *\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport type { RequestEventData } from '../../types-hoist/request';\nimport type { SpanAttributes } from '../../types-hoist/span';\n\nexport const ATTR_EXPRESS_NAME = 'express.name';\nexport const ATTR_HTTP_ROUTE = 'http.route';\nexport const ATTR_EXPRESS_TYPE = 'express.type';\n\nexport type ExpressExport = {\n Router: ExpressRouterv5 | ExpressRouterv4;\n application: ExpressApplication;\n};\n\nexport type ExpressExportv5 = ExpressExport & {\n Router: ExpressRouterv5;\n};\n\nexport type ExpressExportv4 = ExpressExport & {\n Router: ExpressRouterv4;\n};\n\nexport type ExpressModuleExport = ExpressExport | { default: ExpressExport };\n\nexport interface ExpressRequest extends RequestEventData {\n originalUrl: string;\n route: unknown;\n // Note: req.res is typed as optional (only present after middleware init).\n // mark optional to preserve compat with express v4 types.\n res?: ExpressResponse;\n}\n\n// just a minimum type def for what we need, since this also needs to\n// work in environments lacking node:http\nexport interface ExpressResponse {\n once(ev: string, listener: Function): this;\n removeListener(ev: string, listener?: Function): this;\n emit(ev: string, ...data: unknown[]): this;\n}\n\nexport interface NextFunction {\n (err?: unknown): void;\n /**\n * \"Break-out\" of a router by calling {next('router')};\n * @see {https://expressjs.com/en/guide/using-middleware.html#middleware.router}\n */\n (deferToNext: 'router'): void;\n /**\n * \"Break-out\" of a route by calling {next('route')};\n * @see {https://expressjs.com/en/guide/using-middleware.html#middleware.application}\n */\n (deferToNext: 'route'): void;\n}\n\n// Need to mark this as `any` so they don't conflict with the actual express\n//oxlint-disable-next-line no-explicit-any\nexport type ExpressApplicationRequestHandler = (...handlers: any[]) => any;\n\nexport type ExpressRequestInfo<T = unknown> = {\n /** An express request object */\n request: T;\n route: string;\n layerType: ExpressLayerType;\n};\n\nexport type ExpressLayerType = 'router' | 'middleware' | 'request_handler';\nexport const ExpressLayerType_ROUTER = 'router';\nexport const ExpressLayerType_MIDDLEWARE = 'middleware';\nexport const ExpressLayerType_REQUEST_HANDLER = 'request_handler';\n\nexport type PathParams = string | RegExp | Array<string | RegExp>;\nexport type LayerPathSegment = string | RegExp | number;\n\nexport interface ExpressRoute {\n path: string;\n stack: ExpressLayer[];\n}\n\nexport type ExpressRouterv4 = ExpressRouter;\n\nexport interface ExpressRouterv5 {\n prototype: ExpressRouter;\n}\n\n// https://github.com/expressjs/express/blob/main/lib/router/layer.js#L33\nexport type ExpressLayer = {\n handle: Function &\n Record<string, unknown> & {\n stack?: ExpressLayer[];\n };\n name: string;\n params: { [key: string]: string };\n path?: string;\n regexp: RegExp;\n route?: ExpressLayer;\n};\n\nexport type ExpressRouter = {\n params: { [key: string]: string };\n _params: string[];\n caseSensitive: boolean;\n mergeParams: boolean;\n strict: boolean;\n stack: ExpressLayer[];\n route(prefix: PathParams): ExpressRoute;\n use(...handlers: unknown[]): unknown;\n};\n\nexport type IgnoreMatcher = string | RegExp | ((name: string) => boolean);\n\nexport type ExpressIntegrationOptions = {\n /**\n * @deprecated Pass the express module as the first argument, and an\n * options getter as the second argument to patchExpressModule.\n */\n express?: ExpressModuleExport;\n\n /** Ignore specific based on their name */\n ignoreLayers?: IgnoreMatcher[];\n /** Ignore specific layers based on their type */\n ignoreLayersType?: ExpressLayerType[];\n /**\n * Optional callback invoked each time a layer resolves the matched HTTP route.\n * Platform-specific integrations (e.g. Node.js) use this to propagate the\n * resolved route to the underlying transport layer (e.g. OTel RPCMetadata).\n */\n onRouteResolved?: (route: string | undefined) => void;\n};\n\nexport type LayerMetadata = {\n attributes: SpanAttributes;\n name: string;\n};\n\nexport interface ExpressApplication {\n stack: ExpressLayer[];\n use: ExpressApplicationRequestHandler;\n}\n\nexport interface MiddlewareError extends Error {\n status?: number | string;\n statusCode?: number | string;\n status_code?: number | string;\n output?: {\n statusCode?: number | string;\n };\n}\n\nexport type ExpressMiddleware = (req: ExpressRequest, res: ExpressResponse, next: () => void) => void;\n\nexport type ExpressErrorMiddleware = (\n error: MiddlewareError,\n req: ExpressRequest,\n res: ExpressResponse,\n next: (error: MiddlewareError) => void,\n) => void;\n\nexport interface ExpressHandlerOptions {\n /**\n * Callback method deciding whether error should be captured and sent to Sentry\n * @param error Captured middleware error\n */\n shouldHandleError?(this: void, error: MiddlewareError): boolean;\n}\n"],"names":[],"mappings":";;AAgCO,MAAM,iBAAA,GAAoB;AAC1B,MAAM,eAAA,GAAkB;AACxB,MAAM,iBAAA,GAAoB;;AA2D1B,MAAM,uBAAA,GAA0B;AAChC,MAAM,2BAAA,GAA8B;AACpC,MAAM,gCAAA,GAAmC;;;;;;;;;"}
|