@sentry/core 10.48.0 → 10.49.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/fetch.js +36 -17
- 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/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/requestdata.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/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 +32 -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/weakRef.js +62 -0
- package/build/cjs/utils/weakRef.js.map +1 -0
- package/build/esm/fetch.js +36 -17
- 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/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/requestdata.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/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 +29 -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/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/fetch.d.ts +12 -8
- package/build/types/fetch.d.ts.map +1 -1
- package/build/types/index.d.ts +4 -1
- package/build/types/index.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/integrations/requestdata.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 +11 -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/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/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/fetch.d.ts +14 -10
- package/build/types-ts3.8/index.d.ts +4 -1
- 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 +11 -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/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/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
CHANGED
|
@@ -75,7 +75,7 @@ function instrumentFetchRequest(
|
|
|
75
75
|
// Examples: users re-using same options object for multiple fetch calls, frozen objects
|
|
76
76
|
const options = { ...(handlerData.args[1] || {}) };
|
|
77
77
|
|
|
78
|
-
const headers =
|
|
78
|
+
const headers = _INTERNAL_getTracingHeadersForFetchRequest(
|
|
79
79
|
request,
|
|
80
80
|
options,
|
|
81
81
|
// If performance is disabled (TWP) or there's no active root span (pageload/navigation/interaction),
|
|
@@ -127,16 +127,20 @@ function _callOnRequestSpanEnd(
|
|
|
127
127
|
}
|
|
128
128
|
|
|
129
129
|
/**
|
|
130
|
-
*
|
|
131
|
-
*
|
|
130
|
+
* Builds merged fetch headers that include `sentry-trace` and `baggage` (and optionally `traceparent`)
|
|
131
|
+
* for the given request and init, without mutating the original request or options.
|
|
132
|
+
* Returns `undefined` when there is no `sentry-trace` value to attach.
|
|
132
133
|
*
|
|
133
|
-
*
|
|
134
|
-
*
|
|
135
|
-
*
|
|
136
|
-
*
|
|
134
|
+
* @internal Exported for cross-package instrumentation (for example Cloudflare Workers fetcher bindings)
|
|
135
|
+
* and unit tests
|
|
136
|
+
*
|
|
137
|
+
* Baggage handling:
|
|
138
|
+
* 1. No previous baggage header → include Sentry baggage
|
|
139
|
+
* 2. Previous baggage has no Sentry entries → merge Sentry baggage in
|
|
140
|
+
* 3. Previous baggage already has Sentry entries → leave as-is (may be user-defined)
|
|
137
141
|
*/
|
|
138
142
|
// eslint-disable-next-line complexity -- yup it's this complicated :(
|
|
139
|
-
function
|
|
143
|
+
function _INTERNAL_getTracingHeadersForFetchRequest(
|
|
140
144
|
request,
|
|
141
145
|
fetchOptionsObj
|
|
142
146
|
|
|
@@ -181,19 +185,20 @@ function _addTracingHeadersToFetchRequest(
|
|
|
181
185
|
}
|
|
182
186
|
|
|
183
187
|
return newHeaders;
|
|
184
|
-
} else if (
|
|
188
|
+
} else if (isHeadersInitTupleArray(originalHeaders)) {
|
|
185
189
|
const newHeaders = [...originalHeaders];
|
|
186
190
|
|
|
187
|
-
if (!
|
|
191
|
+
if (!newHeaders.find(header => header[0] === 'sentry-trace')) {
|
|
188
192
|
newHeaders.push(['sentry-trace', sentryTrace]);
|
|
189
193
|
}
|
|
190
194
|
|
|
191
|
-
if (propagateTraceparent && traceparent && !
|
|
195
|
+
if (propagateTraceparent && traceparent && !newHeaders.find(header => header[0] === 'traceparent')) {
|
|
192
196
|
newHeaders.push(['traceparent', traceparent]);
|
|
193
197
|
}
|
|
194
198
|
|
|
195
199
|
const prevBaggageHeaderWithSentryValues = originalHeaders.find(
|
|
196
|
-
header =>
|
|
200
|
+
header =>
|
|
201
|
+
header[0] === 'baggage' && typeof header[1] === 'string' && baggageHeaderHasSentryBaggageValues(header[1]),
|
|
197
202
|
);
|
|
198
203
|
|
|
199
204
|
if (baggage && !prevBaggageHeaderWithSentryValues) {
|
|
@@ -202,7 +207,7 @@ function _addTracingHeadersToFetchRequest(
|
|
|
202
207
|
newHeaders.push(['baggage', baggage]);
|
|
203
208
|
}
|
|
204
209
|
|
|
205
|
-
return newHeaders
|
|
210
|
+
return newHeaders;
|
|
206
211
|
} else {
|
|
207
212
|
const existingSentryTraceHeader = 'sentry-trace' in originalHeaders ? originalHeaders['sentry-trace'] : undefined;
|
|
208
213
|
const existingTraceparentHeader = 'traceparent' in originalHeaders ? originalHeaders.traceparent : undefined;
|
|
@@ -226,11 +231,10 @@ function _addTracingHeadersToFetchRequest(
|
|
|
226
231
|
|
|
227
232
|
const newHeaders
|
|
228
233
|
|
|
229
|
-
= {
|
|
230
|
-
...originalHeaders,
|
|
234
|
+
= Object.assign({}, originalHeaders, {
|
|
231
235
|
'sentry-trace': (existingSentryTraceHeader ) ?? sentryTrace,
|
|
232
236
|
baggage: newBaggageHeaders.length > 0 ? newBaggageHeaders.join(',') : undefined,
|
|
233
|
-
};
|
|
237
|
+
});
|
|
234
238
|
|
|
235
239
|
if (propagateTraceparent && traceparent && !existingTraceparentHeader) {
|
|
236
240
|
newHeaders.traceparent = traceparent;
|
|
@@ -259,6 +263,10 @@ function endSpan(span, handlerData) {
|
|
|
259
263
|
}
|
|
260
264
|
|
|
261
265
|
function baggageHeaderHasSentryBaggageValues(baggageHeader) {
|
|
266
|
+
if (typeof baggageHeader !== 'string') {
|
|
267
|
+
return false;
|
|
268
|
+
}
|
|
269
|
+
|
|
262
270
|
return baggageHeader.split(',').some(baggageEntry => baggageEntry.trim().startsWith(baggage.SENTRY_BAGGAGE_KEY_PREFIX));
|
|
263
271
|
}
|
|
264
272
|
|
|
@@ -266,6 +274,17 @@ function isHeaders(headers) {
|
|
|
266
274
|
return typeof Headers !== 'undefined' && is.isInstanceOf(headers, Headers);
|
|
267
275
|
}
|
|
268
276
|
|
|
277
|
+
/** `HeadersInit` array form: each entry is a [name, value] pair of strings. */
|
|
278
|
+
function isHeadersInitTupleArray(headers) {
|
|
279
|
+
if (!Array.isArray(headers)) {
|
|
280
|
+
return false;
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
return headers.every(
|
|
284
|
+
(item) => Array.isArray(item) && item.length === 2 && typeof item[0] === 'string',
|
|
285
|
+
);
|
|
286
|
+
}
|
|
287
|
+
|
|
269
288
|
function getSpanStartOptions(
|
|
270
289
|
url$1,
|
|
271
290
|
method,
|
|
@@ -319,7 +338,7 @@ function getFetchSpanAttributes(
|
|
|
319
338
|
return attributes;
|
|
320
339
|
}
|
|
321
340
|
|
|
322
|
-
exports.
|
|
341
|
+
exports._INTERNAL_getTracingHeadersForFetchRequest = _INTERNAL_getTracingHeadersForFetchRequest;
|
|
323
342
|
exports._callOnRequestSpanEnd = _callOnRequestSpanEnd;
|
|
324
343
|
exports.instrumentFetchRequest = instrumentFetchRequest;
|
|
325
344
|
//# sourceMappingURL=fetch.js.map
|
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;;AAE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SAAA,GAAAE,0BAAA,CAAAF,KAAA,CAAA;AACA,EAAA,MAAA,YAAA,GAAA,SAAA,GAAAG,sCAAA,CAAA,SAAA,CAAA,GAAAH,KAAA;AACA,EAAA,OAAA;AACA,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;;;;;;"}
|
|
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 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 = _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 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 * 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","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":";;;;;;;;;;;;;;AAgEA;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,MAAM,OAAO,KAAK,CAAC,MAAM,CAAC;AAC1B,IAAI;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ANGED
|
@@ -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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -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,O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AsB;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;;;;;;"}
|
|
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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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,IAAI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A,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
|
+
{"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;A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