@sentry/node 10.49.0 → 10.50.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/index.js +7 -7
- package/build/cjs/integrations/{node-fetch.js → node-fetch/index.js} +3 -3
- package/build/cjs/integrations/node-fetch/index.js.map +1 -0
- package/build/cjs/integrations/node-fetch/vendored/undici.js +484 -0
- package/build/cjs/integrations/node-fetch/vendored/undici.js.map +1 -0
- package/build/cjs/sdk/index.js +2 -2
- package/build/cjs/sdk/index.js.map +1 -1
- package/build/esm/index.js +3 -3
- package/build/esm/integrations/{node-fetch.js → node-fetch/index.js} +2 -2
- package/build/esm/integrations/node-fetch/index.js.map +1 -0
- package/build/esm/integrations/node-fetch/vendored/undici.js +482 -0
- package/build/esm/integrations/node-fetch/vendored/undici.js.map +1 -0
- package/build/esm/package.json +1 -1
- package/build/esm/sdk/index.js +1 -1
- package/build/types/index.d.ts +2 -2
- package/build/types/index.d.ts.map +1 -1
- package/build/types/integrations/{node-fetch.d.ts → node-fetch/index.d.ts} +2 -2
- package/build/types/integrations/node-fetch/index.d.ts.map +1 -0
- package/build/types/integrations/node-fetch/vendored/internal-types.d.ts +25 -0
- package/build/types/integrations/node-fetch/vendored/internal-types.d.ts.map +1 -0
- package/build/types/integrations/node-fetch/vendored/types.d.ts +62 -0
- package/build/types/integrations/node-fetch/vendored/types.d.ts.map +1 -0
- package/build/types/integrations/node-fetch/vendored/undici.d.ts +22 -0
- package/build/types/integrations/node-fetch/vendored/undici.d.ts.map +1 -0
- package/build/types-ts3.8/index.d.ts +2 -2
- package/build/types-ts3.8/integrations/{node-fetch.d.ts → node-fetch/index.d.ts} +2 -2
- package/build/types-ts3.8/integrations/node-fetch/vendored/internal-types.d.ts +25 -0
- package/build/types-ts3.8/integrations/node-fetch/vendored/types.d.ts +62 -0
- package/build/types-ts3.8/integrations/node-fetch/vendored/undici.d.ts +22 -0
- package/package.json +4 -5
- package/build/cjs/integrations/node-fetch.js.map +0 -1
- package/build/esm/integrations/node-fetch.js.map +0 -1
- package/build/types/integrations/node-fetch.d.ts.map +0 -1
package/build/cjs/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
2
|
|
|
3
3
|
const http = require('./integrations/http.js');
|
|
4
|
-
const
|
|
4
|
+
const index$9 = require('./integrations/node-fetch/index.js');
|
|
5
5
|
const fs = require('./integrations/fs.js');
|
|
6
6
|
const express = require('./integrations/tracing/express.js');
|
|
7
7
|
const index$1 = require('./integrations/tracing/fastify/index.js');
|
|
@@ -25,8 +25,8 @@ const tedious = require('./integrations/tracing/tedious.js');
|
|
|
25
25
|
const genericPool = require('./integrations/tracing/genericPool.js');
|
|
26
26
|
const dataloader = require('./integrations/tracing/dataloader.js');
|
|
27
27
|
const amqplib = require('./integrations/tracing/amqplib.js');
|
|
28
|
-
const index$
|
|
29
|
-
const index$
|
|
28
|
+
const index$b = require('./integrations/tracing/vercelai/index.js');
|
|
29
|
+
const index$a = require('./integrations/tracing/openai/index.js');
|
|
30
30
|
const index = require('./integrations/tracing/anthropic-ai/index.js');
|
|
31
31
|
const index$4 = require('./integrations/tracing/google-genai/index.js');
|
|
32
32
|
const index$7 = require('./integrations/tracing/langchain/index.js');
|
|
@@ -47,7 +47,7 @@ const nodeCore = require('@sentry/node-core');
|
|
|
47
47
|
|
|
48
48
|
|
|
49
49
|
exports.httpIntegration = http.httpIntegration;
|
|
50
|
-
exports.nativeNodeFetchIntegration =
|
|
50
|
+
exports.nativeNodeFetchIntegration = index$9.nativeNodeFetchIntegration;
|
|
51
51
|
exports.fsIntegration = fs.fsIntegration;
|
|
52
52
|
exports.expressIntegration = express.expressIntegration;
|
|
53
53
|
exports.setupExpressErrorHandler = express.setupExpressErrorHandler;
|
|
@@ -77,8 +77,8 @@ exports.tediousIntegration = tedious.tediousIntegration;
|
|
|
77
77
|
exports.genericPoolIntegration = genericPool.genericPoolIntegration;
|
|
78
78
|
exports.dataloaderIntegration = dataloader.dataloaderIntegration;
|
|
79
79
|
exports.amqplibIntegration = amqplib.amqplibIntegration;
|
|
80
|
-
exports.vercelAIIntegration = index$
|
|
81
|
-
exports.openAIIntegration = index$
|
|
80
|
+
exports.vercelAIIntegration = index$b.vercelAIIntegration;
|
|
81
|
+
exports.openAIIntegration = index$a.openAIIntegration;
|
|
82
82
|
exports.anthropicAIIntegration = index.anthropicAIIntegration;
|
|
83
83
|
exports.googleGenAIIntegration = index$4.googleGenAIIntegration;
|
|
84
84
|
exports.langChainIntegration = index$7.langChainIntegration;
|
|
@@ -116,7 +116,6 @@ exports.captureFeedback = core.captureFeedback;
|
|
|
116
116
|
exports.captureMessage = core.captureMessage;
|
|
117
117
|
exports.captureSession = core.captureSession;
|
|
118
118
|
exports.close = core.close;
|
|
119
|
-
exports.consoleIntegration = core.consoleIntegration;
|
|
120
119
|
exports.consoleLoggingIntegration = core.consoleLoggingIntegration;
|
|
121
120
|
exports.continueTrace = core.continueTrace;
|
|
122
121
|
exports.createConsolaReporter = core.createConsolaReporter;
|
|
@@ -193,6 +192,7 @@ exports.SentryContextManager = nodeCore.SentryContextManager;
|
|
|
193
192
|
exports._INTERNAL_normalizeCollectionInterval = nodeCore._INTERNAL_normalizeCollectionInterval;
|
|
194
193
|
exports.anrIntegration = nodeCore.anrIntegration;
|
|
195
194
|
exports.childProcessIntegration = nodeCore.childProcessIntegration;
|
|
195
|
+
exports.consoleIntegration = nodeCore.consoleIntegration;
|
|
196
196
|
exports.contextLinesIntegration = nodeCore.contextLinesIntegration;
|
|
197
197
|
exports.createGetModuleFromFilename = nodeCore.createGetModuleFromFilename;
|
|
198
198
|
exports.createSentryWinstonTransport = nodeCore.createSentryWinstonTransport;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
2
|
|
|
3
|
-
const
|
|
3
|
+
const undici = require('./vendored/undici.js');
|
|
4
4
|
const core = require('@sentry/core');
|
|
5
5
|
const nodeCore = require('@sentry/node-core');
|
|
6
6
|
|
|
@@ -8,7 +8,7 @@ const INTEGRATION_NAME = 'NodeFetch';
|
|
|
8
8
|
|
|
9
9
|
const instrumentOtelNodeFetch = nodeCore.generateInstrumentOnce(
|
|
10
10
|
INTEGRATION_NAME,
|
|
11
|
-
|
|
11
|
+
undici.UndiciInstrumentation,
|
|
12
12
|
(options) => {
|
|
13
13
|
return _getConfigWithDefaults(options);
|
|
14
14
|
},
|
|
@@ -105,4 +105,4 @@ function _getConfigWithDefaults(options = {}) {
|
|
|
105
105
|
|
|
106
106
|
exports._getConfigWithDefaults = _getConfigWithDefaults;
|
|
107
107
|
exports.nativeNodeFetchIntegration = nativeNodeFetchIntegration;
|
|
108
|
-
//# sourceMappingURL=
|
|
108
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../../../src/integrations/node-fetch/index.ts"],"sourcesContent":["import type { UndiciInstrumentationConfig } from './vendored/types';\nimport { UndiciInstrumentation } from './vendored/undici';\nimport type { IntegrationFn } from '@sentry/core';\nimport {\n defineIntegration,\n getClient,\n hasSpansEnabled,\n SEMANTIC_ATTRIBUTE_SENTRY_CUSTOM_SPAN_NAME,\n SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN,\n SEMANTIC_ATTRIBUTE_URL_FULL,\n stripDataUrlContent,\n} from '@sentry/core';\nimport type { NodeClient } from '@sentry/node-core';\nimport { generateInstrumentOnce, SentryNodeFetchInstrumentation } from '@sentry/node-core';\nimport type { NodeClientOptions } from '../../types';\n\nconst INTEGRATION_NAME = 'NodeFetch';\n\ninterface NodeFetchOptions extends Pick<\n UndiciInstrumentationConfig,\n 'requestHook' | 'responseHook' | 'headersToSpanAttributes'\n> {\n /**\n * Whether breadcrumbs should be recorded for requests.\n * Defaults to true\n */\n breadcrumbs?: boolean;\n\n /**\n * If set to false, do not emit any spans.\n * This will ensure that the default UndiciInstrumentation from OpenTelemetry is not setup,\n * only the Sentry-specific instrumentation for breadcrumbs & trace propagation is applied.\n *\n * If `skipOpenTelemetrySetup: true` is configured, this defaults to `false`, otherwise it defaults to `true`.\n */\n spans?: boolean;\n\n /**\n * Whether to inject trace propagation headers (sentry-trace, baggage, traceparent) into outgoing fetch requests.\n *\n * When set to `false`, Sentry will not inject any trace propagation headers, but will still create breadcrumbs\n * (if `breadcrumbs` is enabled). This is useful when `skipOpenTelemetrySetup: true` is configured and you want\n * to avoid duplicate trace headers being injected by both Sentry and OpenTelemetry's UndiciInstrumentation.\n *\n * @default `true`\n */\n tracePropagation?: boolean;\n\n /**\n * Do not capture spans or breadcrumbs for outgoing fetch requests to URLs where the given callback returns `true`.\n * This controls both span & breadcrumb creation - spans will be non recording if tracing is disabled.\n */\n ignoreOutgoingRequests?: (url: string) => boolean;\n}\n\nconst instrumentOtelNodeFetch = generateInstrumentOnce(\n INTEGRATION_NAME,\n UndiciInstrumentation,\n (options: NodeFetchOptions) => {\n return _getConfigWithDefaults(options);\n },\n);\n\nconst instrumentSentryNodeFetch = generateInstrumentOnce(\n `${INTEGRATION_NAME}.sentry`,\n SentryNodeFetchInstrumentation,\n (options: NodeFetchOptions) => {\n return options;\n },\n);\n\nconst _nativeNodeFetchIntegration = ((options: NodeFetchOptions = {}) => {\n return {\n name: 'NodeFetch',\n setupOnce() {\n const instrumentSpans = _shouldInstrumentSpans(options, getClient<NodeClient>()?.getOptions());\n\n // This is the \"regular\" OTEL instrumentation that emits spans\n if (instrumentSpans) {\n instrumentOtelNodeFetch(options);\n }\n\n // This is the Sentry-specific instrumentation that creates breadcrumbs & propagates traces\n // This must be registered after the OTEL one, to ensure that the core trace propagation logic takes presedence\n // Otherwise, the sentry-trace header may be set multiple times\n instrumentSentryNodeFetch(options);\n },\n };\n}) satisfies IntegrationFn;\n\nexport const nativeNodeFetchIntegration = defineIntegration(_nativeNodeFetchIntegration);\n\n// Matching the behavior of the base instrumentation\nfunction getAbsoluteUrl(origin: string, path: string = '/'): string {\n const url = `${origin}`;\n\n if (url.endsWith('/') && path.startsWith('/')) {\n return `${url}${path.slice(1)}`;\n }\n\n if (!url.endsWith('/') && !path.startsWith('/')) {\n return `${url}/${path}`;\n }\n\n return `${url}${path}`;\n}\n\nfunction _shouldInstrumentSpans(options: NodeFetchOptions, clientOptions: Partial<NodeClientOptions> = {}): boolean {\n // If `spans` is passed in, it takes precedence\n // Else, we by default emit spans, unless `skipOpenTelemetrySetup` is set to `true` or spans are not enabled\n return typeof options.spans === 'boolean'\n ? options.spans\n : !clientOptions.skipOpenTelemetrySetup && hasSpansEnabled(clientOptions);\n}\n\n/** Exported only for tests. */\nexport function _getConfigWithDefaults(options: Partial<NodeFetchOptions> = {}): UndiciInstrumentationConfig {\n const instrumentationConfig = {\n requireParentforSpans: false,\n ignoreRequestHook: request => {\n const url = getAbsoluteUrl(request.origin, request.path);\n const _ignoreOutgoingRequests = options.ignoreOutgoingRequests;\n const shouldIgnore = _ignoreOutgoingRequests && url && _ignoreOutgoingRequests(url);\n\n return !!shouldIgnore;\n },\n startSpanHook: request => {\n const url = getAbsoluteUrl(request.origin, request.path);\n\n // Sanitize data URLs to prevent long base64 strings in span attributes\n if (url.startsWith('data:')) {\n const sanitizedUrl = stripDataUrlContent(url);\n return {\n [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.http.otel.node_fetch',\n 'http.url': sanitizedUrl,\n [SEMANTIC_ATTRIBUTE_URL_FULL]: sanitizedUrl,\n [SEMANTIC_ATTRIBUTE_SENTRY_CUSTOM_SPAN_NAME]: `${request.method || 'GET'} ${sanitizedUrl}`,\n };\n }\n\n return {\n [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.http.otel.node_fetch',\n };\n },\n requestHook: options.requestHook,\n responseHook: options.responseHook,\n headersToSpanAttributes: options.headersToSpanAttributes,\n } satisfies UndiciInstrumentationConfig;\n\n return instrumentationConfig;\n}\n"],"names":["generateInstrumentOnce","UndiciInstrumentation","SentryNodeFetchInstrumentation","getClient","defineIntegration","hasSpansEnabled","stripDataUrlContent","SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN","SEMANTIC_ATTRIBUTE_URL_FULL","SEMANTIC_ATTRIBUTE_SENTRY_CUSTOM_SPAN_NAME"],"mappings":";;;;;;AAgBA,MAAM,gBAAA,GAAmB,WAAW;;AAuCpC,MAAM,uBAAA,GAA0BA,+BAAsB;AACtD,EAAE,gBAAgB;AAClB,EAAEC,4BAAqB;AACvB,EAAE,CAAC,OAAO,KAAuB;AACjC,IAAI,OAAO,sBAAsB,CAAC,OAAO,CAAC;AAC1C,EAAE,CAAC;AACH,CAAC;;AAED,MAAM,yBAAA,GAA4BD,+BAAsB;AACxD,EAAE,CAAC,EAAA,gBAAA,CAAA,OAAA,CAAA;AACA,EAAAE,uCAAA;AACA,EAAA,CAAA,OAAA,KAAA;AACA,IAAA,OAAA,OAAA;AACA,EAAA,CAAA;AACA,CAAA;;AAEA,MAAA,2BAAA,IAAA,CAAA,OAAA,GAAA,EAAA,KAAA;AACA,EAAA,OAAA;AACA,IAAA,IAAA,EAAA,WAAA;AACA,IAAA,SAAA,GAAA;AACA,MAAA,MAAA,eAAA,GAAA,sBAAA,CAAA,OAAA,EAAAC,cAAA,EAAA,EAAA,UAAA,EAAA,CAAA;;AAEA;AACA,MAAA,IAAA,eAAA,EAAA;AACA,QAAA,uBAAA,CAAA,OAAA,CAAA;AACA,MAAA;;AAEA;AACA;AACA;AACA,MAAA,yBAAA,CAAA,OAAA,CAAA;AACA,IAAA,CAAA;AACA,GAAA;AACA,CAAA,CAAA;;AAEA,MAAA,0BAAA,GAAAC,sBAAA,CAAA,2BAAA;;AAEA;AACA,SAAA,cAAA,CAAA,MAAA,EAAA,IAAA,GAAA,GAAA,EAAA;AACA,EAAA,MAAA,GAAA,GAAA,CAAA,EAAA,MAAA,CAAA,CAAA;;AAEA,EAAA,IAAA,GAAA,CAAA,QAAA,CAAA,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A,UAAA,CAAA,OAAA,CAAA,EAAA;AACA,QAAA,MAAA,YAAA,GAAAC,wBAAA,CAAA,GAAA,CAAA;AACA,QAAA,OAAA;AACA,UAAA,CAAAC,qCAAA,GAAA,2BAAA;AACA,UAAA,UAAA,EAAA,YAAA;AACA,UAAA,CAAAC,gCAAA,GAAA,YAAA;AACA,UAAA,CAAAC,+CAAA,GAAA,CAAA,EAAA,OAAA,CAAA,MAAA,IAAA,KAAA,CAAA,CAAA,EAAA,YAAA,CAAA,CAAA;AACA,SAAA;AACA,MAAA;;AAEA,MAAA,OAAA;AACA,QAAA,CAAAF,qCAAA,GAAA,2BAAA;AACA,OAAA;AACA,IAAA,CAAA;AACA,IAAA,WAAA,EAAA,OAAA,CAAA,WAAA;AACA,IAAA,YAAA,EAAA,OAAA,CAAA,YAAA;AACA,IAAA,uBAAA,EAAA,OAAA,CAAA,uBAAA;AACA,GAAA;;AAEA,EAAA,OAAA,qBAAA;AACA;;;;;"}
|
|
@@ -0,0 +1,484 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
|
|
3
|
+
const diagch = require('diagnostics_channel');
|
|
4
|
+
const url = require('url');
|
|
5
|
+
const instrumentation = require('@opentelemetry/instrumentation');
|
|
6
|
+
const api = require('@opentelemetry/api');
|
|
7
|
+
const core$1 = require('@opentelemetry/core');
|
|
8
|
+
const semanticConventions = require('@opentelemetry/semantic-conventions');
|
|
9
|
+
const core = require('@sentry/core');
|
|
10
|
+
|
|
11
|
+
/*
|
|
12
|
+
* Copyright The OpenTelemetry Authors
|
|
13
|
+
*
|
|
14
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
15
|
+
* you may not use this file except in compliance with the License.
|
|
16
|
+
* You may obtain a copy of the License at
|
|
17
|
+
*
|
|
18
|
+
* https://www.apache.org/licenses/LICENSE-2.0
|
|
19
|
+
*
|
|
20
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
21
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
22
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
23
|
+
* See the License for the specific language governing permissions and
|
|
24
|
+
* limitations under the License.
|
|
25
|
+
*
|
|
26
|
+
* NOTICE from the Sentry authors:
|
|
27
|
+
* - Vendored from: https://github.com/open-telemetry/opentelemetry-js-contrib/tree/ed97091c9890dd18e52759f2ea98e9d7593b3ae4/packages/instrumentation-undici
|
|
28
|
+
* - Upstream version: @opentelemetry/instrumentation-undici@0.24.0
|
|
29
|
+
* - Tracking issue: https://github.com/getsentry/sentry-javascript/issues/20165
|
|
30
|
+
* - Minor TypeScript strictness adjustments for this repository's compiler settings
|
|
31
|
+
*/
|
|
32
|
+
/* eslint-disable -- vendored @opentelemetry/instrumentation-undici (#20165) */
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
const PACKAGE_NAME = '@sentry/instrumentation-undici';
|
|
36
|
+
|
|
37
|
+
// A combination of https://github.com/elastic/apm-agent-nodejs and
|
|
38
|
+
// https://github.com/gadget-inc/opentelemetry-instrumentations/blob/main/packages/opentelemetry-instrumentation-undici/src/index.ts
|
|
39
|
+
class UndiciInstrumentation extends instrumentation.InstrumentationBase {
|
|
40
|
+
// Keep ref to avoid https://github.com/nodejs/node/issues/42170 bug and for
|
|
41
|
+
// unsubscribing.
|
|
42
|
+
|
|
43
|
+
__init() {this._recordFromReq = new WeakMap();}
|
|
44
|
+
|
|
45
|
+
constructor(config = {}) {
|
|
46
|
+
super(PACKAGE_NAME, core.SDK_VERSION, config);UndiciInstrumentation.prototype.__init.call(this); }
|
|
47
|
+
|
|
48
|
+
// No need to instrument files/modules
|
|
49
|
+
init() {
|
|
50
|
+
return undefined;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
disable() {
|
|
54
|
+
super.disable();
|
|
55
|
+
this._channelSubs.forEach(sub => sub.unsubscribe());
|
|
56
|
+
this._channelSubs.length = 0;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
enable() {
|
|
60
|
+
// "enabled" handling is currently a bit messy with InstrumentationBase.
|
|
61
|
+
// If constructed with `{enabled: false}`, this `.enable()` is still called,
|
|
62
|
+
// and `this.getConfig().enabled !== this.isEnabled()`, creating confusion.
|
|
63
|
+
//
|
|
64
|
+
// For now, this class will setup for instrumenting if `.enable()` is
|
|
65
|
+
// called, but use `this.getConfig().enabled` to determine if
|
|
66
|
+
// instrumentation should be generated. This covers the more likely common
|
|
67
|
+
// case of config being given a construction time, rather than later via
|
|
68
|
+
// `instance.enable()`, `.disable()`, or `.setConfig()` calls.
|
|
69
|
+
super.enable();
|
|
70
|
+
|
|
71
|
+
// This method is called by the super-class constructor before ours is
|
|
72
|
+
// called. So we need to ensure the property is initalized.
|
|
73
|
+
this._channelSubs = this._channelSubs || [];
|
|
74
|
+
|
|
75
|
+
// Avoid to duplicate subscriptions
|
|
76
|
+
if (this._channelSubs.length > 0) {
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
this.subscribeToChannel('undici:request:create', this.onRequestCreated.bind(this));
|
|
81
|
+
this.subscribeToChannel('undici:client:sendHeaders', this.onRequestHeaders.bind(this));
|
|
82
|
+
this.subscribeToChannel('undici:request:headers', this.onResponseHeaders.bind(this));
|
|
83
|
+
this.subscribeToChannel('undici:request:trailers', this.onDone.bind(this));
|
|
84
|
+
this.subscribeToChannel('undici:request:error', this.onError.bind(this));
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
_updateMetricInstruments() {
|
|
88
|
+
this._httpClientDurationHistogram = this.meter.createHistogram(semanticConventions.METRIC_HTTP_CLIENT_REQUEST_DURATION, {
|
|
89
|
+
description: 'Measures the duration of outbound HTTP requests.',
|
|
90
|
+
unit: 's',
|
|
91
|
+
valueType: api.ValueType.DOUBLE,
|
|
92
|
+
advice: {
|
|
93
|
+
explicitBucketBoundaries: [0.005, 0.01, 0.025, 0.05, 0.075, 0.1, 0.25, 0.5, 0.75, 1, 2.5, 5, 7.5, 10],
|
|
94
|
+
},
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
subscribeToChannel(diagnosticChannel, onMessage) {
|
|
99
|
+
// `diagnostics_channel` had a ref counting bug until v18.19.0.
|
|
100
|
+
// https://github.com/nodejs/node/pull/47520
|
|
101
|
+
const [major = 0, minor = 0] = process.version
|
|
102
|
+
.replace('v', '')
|
|
103
|
+
.split('.')
|
|
104
|
+
.map(n => Number(n));
|
|
105
|
+
const useNewSubscribe = major > 18 || (major === 18 && minor >= 19);
|
|
106
|
+
|
|
107
|
+
let unsubscribe;
|
|
108
|
+
if (useNewSubscribe) {
|
|
109
|
+
diagch.subscribe?.(diagnosticChannel, onMessage);
|
|
110
|
+
unsubscribe = () => diagch.unsubscribe?.(diagnosticChannel, onMessage);
|
|
111
|
+
} else {
|
|
112
|
+
const channel = diagch.channel(diagnosticChannel);
|
|
113
|
+
channel.subscribe(onMessage);
|
|
114
|
+
unsubscribe = () => channel.unsubscribe(onMessage);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
this._channelSubs.push({
|
|
118
|
+
name: diagnosticChannel,
|
|
119
|
+
unsubscribe,
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
parseRequestHeaders(request) {
|
|
124
|
+
const result = new Map();
|
|
125
|
+
|
|
126
|
+
if (Array.isArray(request.headers)) {
|
|
127
|
+
// headers are an array [k1, v2, k2, v2] (undici v6+)
|
|
128
|
+
// values could be string or a string[] for multiple values
|
|
129
|
+
for (let i = 0; i < request.headers.length; i += 2) {
|
|
130
|
+
const key = request.headers[i];
|
|
131
|
+
const value = request.headers[i + 1];
|
|
132
|
+
|
|
133
|
+
// Key should always be a string, but the types don't know that, and let's be safe
|
|
134
|
+
if (typeof key === 'string' && value !== undefined) {
|
|
135
|
+
result.set(key.toLowerCase(), value);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
} else if (typeof request.headers === 'string') {
|
|
139
|
+
// headers are a raw string (undici v5)
|
|
140
|
+
// headers could be repeated in several lines for multiple values
|
|
141
|
+
const headers = request.headers.split('\r\n');
|
|
142
|
+
for (const line of headers) {
|
|
143
|
+
if (!line) {
|
|
144
|
+
continue;
|
|
145
|
+
}
|
|
146
|
+
const colonIndex = line.indexOf(':');
|
|
147
|
+
if (colonIndex === -1) {
|
|
148
|
+
// Invalid header? Probably this can't happen, but again let's be safe.
|
|
149
|
+
continue;
|
|
150
|
+
}
|
|
151
|
+
const key = line.substring(0, colonIndex).toLowerCase();
|
|
152
|
+
const value = line.substring(colonIndex + 1).trim();
|
|
153
|
+
const allValues = result.get(key);
|
|
154
|
+
|
|
155
|
+
if (allValues && Array.isArray(allValues)) {
|
|
156
|
+
allValues.push(value);
|
|
157
|
+
} else if (allValues) {
|
|
158
|
+
result.set(key, [allValues, value]);
|
|
159
|
+
} else {
|
|
160
|
+
result.set(key, value);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
return result;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
// This is the 1st message we receive for each request (fired after request creation). Here we will
|
|
168
|
+
// create the span and populate some atttributes, then link the span to the request for further
|
|
169
|
+
// span processing
|
|
170
|
+
onRequestCreated({ request }) {
|
|
171
|
+
// Ignore if:
|
|
172
|
+
// - instrumentation is disabled
|
|
173
|
+
// - ignored by config
|
|
174
|
+
// - method is 'CONNECT'
|
|
175
|
+
const config = this.getConfig();
|
|
176
|
+
const enabled = config.enabled !== false;
|
|
177
|
+
const shouldIgnoreReq = instrumentation.safeExecuteInTheMiddle(
|
|
178
|
+
() => !enabled || request.method === 'CONNECT' || config.ignoreRequestHook?.(request),
|
|
179
|
+
e => e && this._diag.error('caught ignoreRequestHook error: ', e),
|
|
180
|
+
true,
|
|
181
|
+
);
|
|
182
|
+
|
|
183
|
+
if (shouldIgnoreReq) {
|
|
184
|
+
return;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
const startTime = core$1.hrTime();
|
|
188
|
+
let requestUrl;
|
|
189
|
+
try {
|
|
190
|
+
requestUrl = new url.URL(request.path, request.origin);
|
|
191
|
+
} catch (err) {
|
|
192
|
+
this._diag.warn('could not determine url.full:', err);
|
|
193
|
+
// Skip instrumenting this request.
|
|
194
|
+
return;
|
|
195
|
+
}
|
|
196
|
+
const urlScheme = requestUrl.protocol.replace(':', '');
|
|
197
|
+
const requestMethod = this.getRequestMethod(request.method);
|
|
198
|
+
const attributes = {
|
|
199
|
+
[semanticConventions.ATTR_HTTP_REQUEST_METHOD]: requestMethod,
|
|
200
|
+
[semanticConventions.ATTR_HTTP_REQUEST_METHOD_ORIGINAL]: request.method,
|
|
201
|
+
[semanticConventions.ATTR_URL_FULL]: requestUrl.toString(),
|
|
202
|
+
[semanticConventions.ATTR_URL_PATH]: requestUrl.pathname,
|
|
203
|
+
[semanticConventions.ATTR_URL_QUERY]: requestUrl.search,
|
|
204
|
+
[semanticConventions.ATTR_URL_SCHEME]: urlScheme,
|
|
205
|
+
};
|
|
206
|
+
|
|
207
|
+
const schemePorts = { https: '443', http: '80' };
|
|
208
|
+
const serverAddress = requestUrl.hostname;
|
|
209
|
+
const serverPort = requestUrl.port || schemePorts[urlScheme];
|
|
210
|
+
|
|
211
|
+
attributes[semanticConventions.ATTR_SERVER_ADDRESS] = serverAddress;
|
|
212
|
+
if (serverPort && !isNaN(Number(serverPort))) {
|
|
213
|
+
attributes[semanticConventions.ATTR_SERVER_PORT] = Number(serverPort);
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
// Get user agent from headers
|
|
217
|
+
const headersMap = this.parseRequestHeaders(request);
|
|
218
|
+
const userAgentValues = headersMap.get('user-agent');
|
|
219
|
+
|
|
220
|
+
if (userAgentValues) {
|
|
221
|
+
// NOTE: having multiple user agents is not expected so
|
|
222
|
+
// we're going to take last one like `curl` does
|
|
223
|
+
// ref: https://curl.se/docs/manpage.html#-A
|
|
224
|
+
const userAgent = Array.isArray(userAgentValues) ? userAgentValues[userAgentValues.length - 1] : userAgentValues;
|
|
225
|
+
attributes[semanticConventions.ATTR_USER_AGENT_ORIGINAL] = userAgent;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
// Get attributes from the hook if present
|
|
229
|
+
const hookAttributes = instrumentation.safeExecuteInTheMiddle(
|
|
230
|
+
() => config.startSpanHook?.(request),
|
|
231
|
+
e => e && this._diag.error('caught startSpanHook error: ', e),
|
|
232
|
+
true,
|
|
233
|
+
);
|
|
234
|
+
if (hookAttributes) {
|
|
235
|
+
Object.entries(hookAttributes).forEach(([key, val]) => {
|
|
236
|
+
attributes[key] = val;
|
|
237
|
+
});
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
// Check if parent span is required via config and:
|
|
241
|
+
// - if a parent is required but not present, we use a `NoopSpan` to still
|
|
242
|
+
// propagate context without recording it.
|
|
243
|
+
// - create a span otherwise
|
|
244
|
+
const activeCtx = api.context.active();
|
|
245
|
+
const currentSpan = api.trace.getSpan(activeCtx);
|
|
246
|
+
let span;
|
|
247
|
+
|
|
248
|
+
if (config.requireParentforSpans && (!currentSpan || !api.trace.isSpanContextValid(currentSpan.spanContext()))) {
|
|
249
|
+
span = api.trace.wrapSpanContext(api.INVALID_SPAN_CONTEXT);
|
|
250
|
+
} else {
|
|
251
|
+
span = this.tracer.startSpan(
|
|
252
|
+
requestMethod === '_OTHER' ? 'HTTP' : requestMethod,
|
|
253
|
+
{
|
|
254
|
+
kind: api.SpanKind.CLIENT,
|
|
255
|
+
attributes: attributes,
|
|
256
|
+
},
|
|
257
|
+
activeCtx,
|
|
258
|
+
);
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
// Execute the request hook if defined
|
|
262
|
+
instrumentation.safeExecuteInTheMiddle(
|
|
263
|
+
() => config.requestHook?.(span, request),
|
|
264
|
+
e => e && this._diag.error('caught requestHook error: ', e),
|
|
265
|
+
true,
|
|
266
|
+
);
|
|
267
|
+
|
|
268
|
+
// Context propagation goes last so no hook can tamper
|
|
269
|
+
// the propagation headers
|
|
270
|
+
const requestContext = api.trace.setSpan(api.context.active(), span);
|
|
271
|
+
const addedHeaders = {};
|
|
272
|
+
api.propagation.inject(requestContext, addedHeaders);
|
|
273
|
+
|
|
274
|
+
const headerEntries = Object.entries(addedHeaders);
|
|
275
|
+
|
|
276
|
+
for (let i = 0; i < headerEntries.length; i++) {
|
|
277
|
+
const pair = headerEntries[i];
|
|
278
|
+
if (!pair) {
|
|
279
|
+
continue;
|
|
280
|
+
}
|
|
281
|
+
const [k, v] = pair;
|
|
282
|
+
|
|
283
|
+
if (typeof request.addHeader === 'function') {
|
|
284
|
+
request.addHeader(k, v);
|
|
285
|
+
} else if (typeof request.headers === 'string') {
|
|
286
|
+
request.headers += `${k}: ${v}\r\n`;
|
|
287
|
+
} else if (Array.isArray(request.headers)) {
|
|
288
|
+
// undici@6.11.0 accidentally, briefly removed `request.addHeader()`.
|
|
289
|
+
request.headers.push(k, v);
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
this._recordFromReq.set(request, { span, attributes, startTime });
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
// This is the 2nd message we receive for each request. It is fired when connection with
|
|
296
|
+
// the remote is established and about to send the first byte. Here we do have info about the
|
|
297
|
+
// remote address and port so we can populate some `network.*` attributes into the span
|
|
298
|
+
onRequestHeaders({ request, socket }) {
|
|
299
|
+
const record = this._recordFromReq.get(request);
|
|
300
|
+
|
|
301
|
+
if (!record) {
|
|
302
|
+
return;
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
const config = this.getConfig();
|
|
306
|
+
const { span } = record;
|
|
307
|
+
const { remoteAddress, remotePort } = socket;
|
|
308
|
+
const spanAttributes = {
|
|
309
|
+
[semanticConventions.ATTR_NETWORK_PEER_ADDRESS]: remoteAddress,
|
|
310
|
+
[semanticConventions.ATTR_NETWORK_PEER_PORT]: remotePort,
|
|
311
|
+
};
|
|
312
|
+
|
|
313
|
+
// After hooks have been processed (which may modify request headers)
|
|
314
|
+
// we can collect the headers based on the configuration
|
|
315
|
+
if (config.headersToSpanAttributes?.requestHeaders) {
|
|
316
|
+
const headersToAttribs = new Set(config.headersToSpanAttributes.requestHeaders.map(n => n.toLowerCase()));
|
|
317
|
+
const headersMap = this.parseRequestHeaders(request);
|
|
318
|
+
|
|
319
|
+
for (const [name, value] of headersMap.entries()) {
|
|
320
|
+
if (headersToAttribs.has(name)) {
|
|
321
|
+
const attrValue = Array.isArray(value) ? value : [value];
|
|
322
|
+
spanAttributes[`http.request.header.${name}`] = attrValue;
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
span.setAttributes(spanAttributes);
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
// This is the 3rd message we get for each request and it's fired when the server
|
|
331
|
+
// headers are received, body may not be accessible yet.
|
|
332
|
+
// From the response headers we can set the status and content length
|
|
333
|
+
onResponseHeaders({ request, response }) {
|
|
334
|
+
const record = this._recordFromReq.get(request);
|
|
335
|
+
|
|
336
|
+
if (!record) {
|
|
337
|
+
return;
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
const { span, attributes } = record;
|
|
341
|
+
const spanAttributes = {
|
|
342
|
+
[semanticConventions.ATTR_HTTP_RESPONSE_STATUS_CODE]: response.statusCode,
|
|
343
|
+
};
|
|
344
|
+
|
|
345
|
+
const config = this.getConfig();
|
|
346
|
+
|
|
347
|
+
// Execute the response hook if defined
|
|
348
|
+
instrumentation.safeExecuteInTheMiddle(
|
|
349
|
+
() => config.responseHook?.(span, { request, response }),
|
|
350
|
+
e => e && this._diag.error('caught responseHook error: ', e),
|
|
351
|
+
true,
|
|
352
|
+
);
|
|
353
|
+
|
|
354
|
+
if (config.headersToSpanAttributes?.responseHeaders) {
|
|
355
|
+
const headersToAttribs = new Set();
|
|
356
|
+
config.headersToSpanAttributes?.responseHeaders.forEach(name => headersToAttribs.add(name.toLowerCase()));
|
|
357
|
+
|
|
358
|
+
for (let idx = 0; idx < response.headers.length; idx = idx + 2) {
|
|
359
|
+
const nameBuf = response.headers[idx];
|
|
360
|
+
const valueBuf = response.headers[idx + 1];
|
|
361
|
+
if (nameBuf === undefined || valueBuf === undefined) {
|
|
362
|
+
continue;
|
|
363
|
+
}
|
|
364
|
+
const name = nameBuf.toString().toLowerCase();
|
|
365
|
+
const value = valueBuf;
|
|
366
|
+
|
|
367
|
+
if (headersToAttribs.has(name)) {
|
|
368
|
+
const attrName = `http.response.header.${name}`;
|
|
369
|
+
if (!Object.prototype.hasOwnProperty.call(spanAttributes, attrName)) {
|
|
370
|
+
spanAttributes[attrName] = [value.toString()];
|
|
371
|
+
} else {
|
|
372
|
+
(spanAttributes[attrName] ).push(value.toString());
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
span.setAttributes(spanAttributes);
|
|
379
|
+
span.setStatus({
|
|
380
|
+
code: response.statusCode >= 400 ? api.SpanStatusCode.ERROR : api.SpanStatusCode.UNSET,
|
|
381
|
+
});
|
|
382
|
+
record.attributes = Object.assign(attributes, spanAttributes);
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
// This is the last event we receive if the request went without any errors
|
|
386
|
+
onDone({ request }) {
|
|
387
|
+
const record = this._recordFromReq.get(request);
|
|
388
|
+
|
|
389
|
+
if (!record) {
|
|
390
|
+
return;
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
const { span, attributes, startTime } = record;
|
|
394
|
+
|
|
395
|
+
// End the span
|
|
396
|
+
span.end();
|
|
397
|
+
this._recordFromReq.delete(request);
|
|
398
|
+
|
|
399
|
+
// Record metrics
|
|
400
|
+
this.recordRequestDuration(attributes, startTime);
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
// This is the event we get when something is wrong in the request like
|
|
404
|
+
// - invalid options when calling `fetch` global API or any undici method for request
|
|
405
|
+
// - connectivity errors such as unreachable host
|
|
406
|
+
// - requests aborted through an `AbortController.signal`
|
|
407
|
+
// NOTE: server errors are considered valid responses and it's the lib consumer
|
|
408
|
+
// who should deal with that.
|
|
409
|
+
onError({ request, error }) {
|
|
410
|
+
const record = this._recordFromReq.get(request);
|
|
411
|
+
|
|
412
|
+
if (!record) {
|
|
413
|
+
return;
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
const { span, attributes, startTime } = record;
|
|
417
|
+
|
|
418
|
+
// NOTE: in `undici@6.3.0` when request aborted the error type changes from
|
|
419
|
+
// a custom error (`RequestAbortedError`) to a built-in `DOMException` carrying
|
|
420
|
+
// some differences:
|
|
421
|
+
// - `code` is from DOMEXception (ABORT_ERR: 20)
|
|
422
|
+
// - `message` changes
|
|
423
|
+
// - stacktrace is smaller and contains node internal frames
|
|
424
|
+
span.recordException(error);
|
|
425
|
+
span.setStatus({
|
|
426
|
+
code: api.SpanStatusCode.ERROR,
|
|
427
|
+
message: error.message,
|
|
428
|
+
});
|
|
429
|
+
span.end();
|
|
430
|
+
this._recordFromReq.delete(request);
|
|
431
|
+
|
|
432
|
+
// Record metrics (with the error)
|
|
433
|
+
attributes[semanticConventions.ATTR_ERROR_TYPE] = error.message;
|
|
434
|
+
this.recordRequestDuration(attributes, startTime);
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
recordRequestDuration(attributes, startTime) {
|
|
438
|
+
// Time to record metrics
|
|
439
|
+
const metricsAttributes = {};
|
|
440
|
+
// Get the attribs already in span attributes
|
|
441
|
+
const keysToCopy = [
|
|
442
|
+
semanticConventions.ATTR_HTTP_RESPONSE_STATUS_CODE,
|
|
443
|
+
semanticConventions.ATTR_HTTP_REQUEST_METHOD,
|
|
444
|
+
semanticConventions.ATTR_SERVER_ADDRESS,
|
|
445
|
+
semanticConventions.ATTR_SERVER_PORT,
|
|
446
|
+
semanticConventions.ATTR_URL_SCHEME,
|
|
447
|
+
semanticConventions.ATTR_ERROR_TYPE,
|
|
448
|
+
];
|
|
449
|
+
keysToCopy.forEach(key => {
|
|
450
|
+
if (key in attributes) {
|
|
451
|
+
metricsAttributes[key] = attributes[key];
|
|
452
|
+
}
|
|
453
|
+
});
|
|
454
|
+
|
|
455
|
+
// Take the duration and record it
|
|
456
|
+
const durationSeconds = core$1.hrTimeToMilliseconds(core$1.hrTimeDuration(startTime, core$1.hrTime())) / 1000;
|
|
457
|
+
this._httpClientDurationHistogram.record(durationSeconds, metricsAttributes);
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
getRequestMethod(original) {
|
|
461
|
+
const knownMethods = {
|
|
462
|
+
CONNECT: true,
|
|
463
|
+
OPTIONS: true,
|
|
464
|
+
HEAD: true,
|
|
465
|
+
GET: true,
|
|
466
|
+
POST: true,
|
|
467
|
+
PUT: true,
|
|
468
|
+
PATCH: true,
|
|
469
|
+
DELETE: true,
|
|
470
|
+
TRACE: true,
|
|
471
|
+
// QUERY from https://datatracker.ietf.org/doc/draft-ietf-httpbis-safe-method-w-body/
|
|
472
|
+
QUERY: true,
|
|
473
|
+
};
|
|
474
|
+
|
|
475
|
+
if (original.toUpperCase() in knownMethods) {
|
|
476
|
+
return original.toUpperCase();
|
|
477
|
+
}
|
|
478
|
+
|
|
479
|
+
return '_OTHER';
|
|
480
|
+
}
|
|
481
|
+
}
|
|
482
|
+
|
|
483
|
+
exports.UndiciInstrumentation = UndiciInstrumentation;
|
|
484
|
+
//# sourceMappingURL=undici.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"undici.js","sources":["../../../../../src/integrations/node-fetch/vendored/undici.ts"],"sourcesContent":["/*\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 * NOTICE from the Sentry authors:\n * - Vendored from: https://github.com/open-telemetry/opentelemetry-js-contrib/tree/ed97091c9890dd18e52759f2ea98e9d7593b3ae4/packages/instrumentation-undici\n * - Upstream version: @opentelemetry/instrumentation-undici@0.24.0\n * - Tracking issue: https://github.com/getsentry/sentry-javascript/issues/20165\n * - Minor TypeScript strictness adjustments for this repository's compiler settings\n */\n/* eslint-disable -- vendored @opentelemetry/instrumentation-undici (#20165) */\n\nimport * as diagch from 'diagnostics_channel';\nimport { URL } from 'url';\n\nimport { InstrumentationBase, safeExecuteInTheMiddle } from '@opentelemetry/instrumentation';\nimport type { Attributes, Histogram, HrTime, Span } from '@opentelemetry/api';\nimport {\n context,\n INVALID_SPAN_CONTEXT,\n propagation,\n SpanKind,\n SpanStatusCode,\n trace,\n ValueType,\n} from '@opentelemetry/api';\nimport { hrTime, hrTimeDuration, hrTimeToMilliseconds } from '@opentelemetry/core';\nimport {\n ATTR_ERROR_TYPE,\n ATTR_HTTP_REQUEST_METHOD,\n ATTR_HTTP_REQUEST_METHOD_ORIGINAL,\n ATTR_HTTP_RESPONSE_STATUS_CODE,\n ATTR_NETWORK_PEER_ADDRESS,\n ATTR_NETWORK_PEER_PORT,\n ATTR_SERVER_ADDRESS,\n ATTR_SERVER_PORT,\n ATTR_URL_FULL,\n ATTR_URL_PATH,\n ATTR_URL_QUERY,\n ATTR_URL_SCHEME,\n ATTR_USER_AGENT_ORIGINAL,\n METRIC_HTTP_CLIENT_REQUEST_DURATION,\n} from '@opentelemetry/semantic-conventions';\n\nimport type {\n ListenerRecord,\n RequestHeadersMessage,\n RequestMessage,\n RequestTrailersMessage,\n ResponseHeadersMessage,\n} from './internal-types';\nimport type { UndiciInstrumentationConfig, UndiciRequest } from './types';\n\nimport { SDK_VERSION } from '@sentry/core';\n\ninterface InstrumentationRecord {\n span: Span;\n attributes: Attributes;\n startTime: HrTime;\n}\n\nconst PACKAGE_NAME = '@sentry/instrumentation-undici';\n\n// A combination of https://github.com/elastic/apm-agent-nodejs and\n// https://github.com/gadget-inc/opentelemetry-instrumentations/blob/main/packages/opentelemetry-instrumentation-undici/src/index.ts\nexport class UndiciInstrumentation extends InstrumentationBase<UndiciInstrumentationConfig> {\n // Keep ref to avoid https://github.com/nodejs/node/issues/42170 bug and for\n // unsubscribing.\n declare private _channelSubs: Array<ListenerRecord>;\n private _recordFromReq = new WeakMap<UndiciRequest, InstrumentationRecord>();\n\n declare private _httpClientDurationHistogram: Histogram;\n\n constructor(config: UndiciInstrumentationConfig = {}) {\n super(PACKAGE_NAME, SDK_VERSION, config);\n }\n\n // No need to instrument files/modules\n protected override init() {\n return undefined;\n }\n\n override disable(): void {\n super.disable();\n this._channelSubs.forEach(sub => sub.unsubscribe());\n this._channelSubs.length = 0;\n }\n\n override enable(): void {\n // \"enabled\" handling is currently a bit messy with InstrumentationBase.\n // If constructed with `{enabled: false}`, this `.enable()` is still called,\n // and `this.getConfig().enabled !== this.isEnabled()`, creating confusion.\n //\n // For now, this class will setup for instrumenting if `.enable()` is\n // called, but use `this.getConfig().enabled` to determine if\n // instrumentation should be generated. This covers the more likely common\n // case of config being given a construction time, rather than later via\n // `instance.enable()`, `.disable()`, or `.setConfig()` calls.\n super.enable();\n\n // This method is called by the super-class constructor before ours is\n // called. So we need to ensure the property is initalized.\n this._channelSubs = this._channelSubs || [];\n\n // Avoid to duplicate subscriptions\n if (this._channelSubs.length > 0) {\n return;\n }\n\n this.subscribeToChannel('undici:request:create', this.onRequestCreated.bind(this));\n this.subscribeToChannel('undici:client:sendHeaders', this.onRequestHeaders.bind(this));\n this.subscribeToChannel('undici:request:headers', this.onResponseHeaders.bind(this));\n this.subscribeToChannel('undici:request:trailers', this.onDone.bind(this));\n this.subscribeToChannel('undici:request:error', this.onError.bind(this));\n }\n\n protected override _updateMetricInstruments() {\n this._httpClientDurationHistogram = this.meter.createHistogram(METRIC_HTTP_CLIENT_REQUEST_DURATION, {\n description: 'Measures the duration of outbound HTTP requests.',\n unit: 's',\n valueType: ValueType.DOUBLE,\n advice: {\n explicitBucketBoundaries: [0.005, 0.01, 0.025, 0.05, 0.075, 0.1, 0.25, 0.5, 0.75, 1, 2.5, 5, 7.5, 10],\n },\n });\n }\n\n private subscribeToChannel(diagnosticChannel: string, onMessage: (message: any, name: string | symbol) => void) {\n // `diagnostics_channel` had a ref counting bug until v18.19.0.\n // https://github.com/nodejs/node/pull/47520\n const [major = 0, minor = 0] = process.version\n .replace('v', '')\n .split('.')\n .map(n => Number(n));\n const useNewSubscribe = major > 18 || (major === 18 && minor >= 19);\n\n let unsubscribe: () => void;\n if (useNewSubscribe) {\n diagch.subscribe?.(diagnosticChannel, onMessage);\n unsubscribe = () => diagch.unsubscribe?.(diagnosticChannel, onMessage);\n } else {\n const channel = diagch.channel(diagnosticChannel);\n channel.subscribe(onMessage);\n unsubscribe = () => channel.unsubscribe(onMessage);\n }\n\n this._channelSubs.push({\n name: diagnosticChannel,\n unsubscribe,\n });\n }\n\n private parseRequestHeaders(request: UndiciRequest) {\n const result = new Map<string, string | string[]>();\n\n if (Array.isArray(request.headers)) {\n // headers are an array [k1, v2, k2, v2] (undici v6+)\n // values could be string or a string[] for multiple values\n for (let i = 0; i < request.headers.length; i += 2) {\n const key = request.headers[i];\n const value = request.headers[i + 1];\n\n // Key should always be a string, but the types don't know that, and let's be safe\n if (typeof key === 'string' && value !== undefined) {\n result.set(key.toLowerCase(), value);\n }\n }\n } else if (typeof request.headers === 'string') {\n // headers are a raw string (undici v5)\n // headers could be repeated in several lines for multiple values\n const headers = request.headers.split('\\r\\n');\n for (const line of headers) {\n if (!line) {\n continue;\n }\n const colonIndex = line.indexOf(':');\n if (colonIndex === -1) {\n // Invalid header? Probably this can't happen, but again let's be safe.\n continue;\n }\n const key = line.substring(0, colonIndex).toLowerCase();\n const value = line.substring(colonIndex + 1).trim();\n const allValues = result.get(key);\n\n if (allValues && Array.isArray(allValues)) {\n allValues.push(value);\n } else if (allValues) {\n result.set(key, [allValues, value]);\n } else {\n result.set(key, value);\n }\n }\n }\n return result;\n }\n\n // This is the 1st message we receive for each request (fired after request creation). Here we will\n // create the span and populate some atttributes, then link the span to the request for further\n // span processing\n private onRequestCreated({ request }: RequestMessage): void {\n // Ignore if:\n // - instrumentation is disabled\n // - ignored by config\n // - method is 'CONNECT'\n const config = this.getConfig();\n const enabled = config.enabled !== false;\n const shouldIgnoreReq = safeExecuteInTheMiddle(\n () => !enabled || request.method === 'CONNECT' || config.ignoreRequestHook?.(request),\n e => e && this._diag.error('caught ignoreRequestHook error: ', e),\n true,\n );\n\n if (shouldIgnoreReq) {\n return;\n }\n\n const startTime = hrTime();\n let requestUrl;\n try {\n requestUrl = new URL(request.path, request.origin);\n } catch (err) {\n this._diag.warn('could not determine url.full:', err);\n // Skip instrumenting this request.\n return;\n }\n const urlScheme = requestUrl.protocol.replace(':', '');\n const requestMethod = this.getRequestMethod(request.method);\n const attributes: Attributes = {\n [ATTR_HTTP_REQUEST_METHOD]: requestMethod,\n [ATTR_HTTP_REQUEST_METHOD_ORIGINAL]: request.method,\n [ATTR_URL_FULL]: requestUrl.toString(),\n [ATTR_URL_PATH]: requestUrl.pathname,\n [ATTR_URL_QUERY]: requestUrl.search,\n [ATTR_URL_SCHEME]: urlScheme,\n };\n\n const schemePorts: Record<string, string> = { https: '443', http: '80' };\n const serverAddress = requestUrl.hostname;\n const serverPort = requestUrl.port || schemePorts[urlScheme];\n\n attributes[ATTR_SERVER_ADDRESS] = serverAddress;\n if (serverPort && !isNaN(Number(serverPort))) {\n attributes[ATTR_SERVER_PORT] = Number(serverPort);\n }\n\n // Get user agent from headers\n const headersMap = this.parseRequestHeaders(request);\n const userAgentValues = headersMap.get('user-agent');\n\n if (userAgentValues) {\n // NOTE: having multiple user agents is not expected so\n // we're going to take last one like `curl` does\n // ref: https://curl.se/docs/manpage.html#-A\n const userAgent = Array.isArray(userAgentValues) ? userAgentValues[userAgentValues.length - 1] : userAgentValues;\n attributes[ATTR_USER_AGENT_ORIGINAL] = userAgent;\n }\n\n // Get attributes from the hook if present\n const hookAttributes = safeExecuteInTheMiddle(\n () => config.startSpanHook?.(request),\n e => e && this._diag.error('caught startSpanHook error: ', e),\n true,\n );\n if (hookAttributes) {\n Object.entries(hookAttributes).forEach(([key, val]) => {\n attributes[key] = val;\n });\n }\n\n // Check if parent span is required via config and:\n // - if a parent is required but not present, we use a `NoopSpan` to still\n // propagate context without recording it.\n // - create a span otherwise\n const activeCtx = context.active();\n const currentSpan = trace.getSpan(activeCtx);\n let span: Span;\n\n if (config.requireParentforSpans && (!currentSpan || !trace.isSpanContextValid(currentSpan.spanContext()))) {\n span = trace.wrapSpanContext(INVALID_SPAN_CONTEXT);\n } else {\n span = this.tracer.startSpan(\n requestMethod === '_OTHER' ? 'HTTP' : requestMethod,\n {\n kind: SpanKind.CLIENT,\n attributes: attributes,\n },\n activeCtx,\n );\n }\n\n // Execute the request hook if defined\n safeExecuteInTheMiddle(\n () => config.requestHook?.(span, request),\n e => e && this._diag.error('caught requestHook error: ', e),\n true,\n );\n\n // Context propagation goes last so no hook can tamper\n // the propagation headers\n const requestContext = trace.setSpan(context.active(), span);\n const addedHeaders: Record<string, string> = {};\n propagation.inject(requestContext, addedHeaders);\n\n const headerEntries = Object.entries(addedHeaders);\n\n for (let i = 0; i < headerEntries.length; i++) {\n const pair = headerEntries[i];\n if (!pair) {\n continue;\n }\n const [k, v] = pair;\n\n if (typeof request.addHeader === 'function') {\n request.addHeader(k, v);\n } else if (typeof request.headers === 'string') {\n request.headers += `${k}: ${v}\\r\\n`;\n } else if (Array.isArray(request.headers)) {\n // undici@6.11.0 accidentally, briefly removed `request.addHeader()`.\n request.headers.push(k, v);\n }\n }\n this._recordFromReq.set(request, { span, attributes, startTime });\n }\n\n // This is the 2nd message we receive for each request. It is fired when connection with\n // the remote is established and about to send the first byte. Here we do have info about the\n // remote address and port so we can populate some `network.*` attributes into the span\n private onRequestHeaders({ request, socket }: RequestHeadersMessage): void {\n const record = this._recordFromReq.get(request);\n\n if (!record) {\n return;\n }\n\n const config = this.getConfig();\n const { span } = record;\n const { remoteAddress, remotePort } = socket;\n const spanAttributes: Attributes = {\n [ATTR_NETWORK_PEER_ADDRESS]: remoteAddress,\n [ATTR_NETWORK_PEER_PORT]: remotePort,\n };\n\n // After hooks have been processed (which may modify request headers)\n // we can collect the headers based on the configuration\n if (config.headersToSpanAttributes?.requestHeaders) {\n const headersToAttribs = new Set(config.headersToSpanAttributes.requestHeaders.map(n => n.toLowerCase()));\n const headersMap = this.parseRequestHeaders(request);\n\n for (const [name, value] of headersMap.entries()) {\n if (headersToAttribs.has(name)) {\n const attrValue = Array.isArray(value) ? value : [value];\n spanAttributes[`http.request.header.${name}`] = attrValue;\n }\n }\n }\n\n span.setAttributes(spanAttributes);\n }\n\n // This is the 3rd message we get for each request and it's fired when the server\n // headers are received, body may not be accessible yet.\n // From the response headers we can set the status and content length\n private onResponseHeaders({ request, response }: ResponseHeadersMessage): void {\n const record = this._recordFromReq.get(request);\n\n if (!record) {\n return;\n }\n\n const { span, attributes } = record;\n const spanAttributes: Attributes = {\n [ATTR_HTTP_RESPONSE_STATUS_CODE]: response.statusCode,\n };\n\n const config = this.getConfig();\n\n // Execute the response hook if defined\n safeExecuteInTheMiddle(\n () => config.responseHook?.(span, { request, response }),\n e => e && this._diag.error('caught responseHook error: ', e),\n true,\n );\n\n if (config.headersToSpanAttributes?.responseHeaders) {\n const headersToAttribs = new Set();\n config.headersToSpanAttributes?.responseHeaders.forEach(name => headersToAttribs.add(name.toLowerCase()));\n\n for (let idx = 0; idx < response.headers.length; idx = idx + 2) {\n const nameBuf = response.headers[idx];\n const valueBuf = response.headers[idx + 1];\n if (nameBuf === undefined || valueBuf === undefined) {\n continue;\n }\n const name = nameBuf.toString().toLowerCase();\n const value = valueBuf;\n\n if (headersToAttribs.has(name)) {\n const attrName = `http.response.header.${name}`;\n if (!Object.prototype.hasOwnProperty.call(spanAttributes, attrName)) {\n spanAttributes[attrName] = [value.toString()];\n } else {\n (spanAttributes[attrName] as string[]).push(value.toString());\n }\n }\n }\n }\n\n span.setAttributes(spanAttributes);\n span.setStatus({\n code: response.statusCode >= 400 ? SpanStatusCode.ERROR : SpanStatusCode.UNSET,\n });\n record.attributes = Object.assign(attributes, spanAttributes);\n }\n\n // This is the last event we receive if the request went without any errors\n private onDone({ request }: RequestTrailersMessage): void {\n const record = this._recordFromReq.get(request);\n\n if (!record) {\n return;\n }\n\n const { span, attributes, startTime } = record;\n\n // End the span\n span.end();\n this._recordFromReq.delete(request);\n\n // Record metrics\n this.recordRequestDuration(attributes, startTime);\n }\n\n // This is the event we get when something is wrong in the request like\n // - invalid options when calling `fetch` global API or any undici method for request\n // - connectivity errors such as unreachable host\n // - requests aborted through an `AbortController.signal`\n // NOTE: server errors are considered valid responses and it's the lib consumer\n // who should deal with that.\n private onError({ request, error }: any): void {\n const record = this._recordFromReq.get(request);\n\n if (!record) {\n return;\n }\n\n const { span, attributes, startTime } = record;\n\n // NOTE: in `undici@6.3.0` when request aborted the error type changes from\n // a custom error (`RequestAbortedError`) to a built-in `DOMException` carrying\n // some differences:\n // - `code` is from DOMEXception (ABORT_ERR: 20)\n // - `message` changes\n // - stacktrace is smaller and contains node internal frames\n span.recordException(error);\n span.setStatus({\n code: SpanStatusCode.ERROR,\n message: error.message,\n });\n span.end();\n this._recordFromReq.delete(request);\n\n // Record metrics (with the error)\n attributes[ATTR_ERROR_TYPE] = error.message;\n this.recordRequestDuration(attributes, startTime);\n }\n\n private recordRequestDuration(attributes: Attributes, startTime: HrTime) {\n // Time to record metrics\n const metricsAttributes: Attributes = {};\n // Get the attribs already in span attributes\n const keysToCopy = [\n ATTR_HTTP_RESPONSE_STATUS_CODE,\n ATTR_HTTP_REQUEST_METHOD,\n ATTR_SERVER_ADDRESS,\n ATTR_SERVER_PORT,\n ATTR_URL_SCHEME,\n ATTR_ERROR_TYPE,\n ];\n keysToCopy.forEach(key => {\n if (key in attributes) {\n metricsAttributes[key] = attributes[key];\n }\n });\n\n // Take the duration and record it\n const durationSeconds = hrTimeToMilliseconds(hrTimeDuration(startTime, hrTime())) / 1000;\n this._httpClientDurationHistogram.record(durationSeconds, metricsAttributes);\n }\n\n private getRequestMethod(original: string): string {\n const knownMethods = {\n CONNECT: true,\n OPTIONS: true,\n HEAD: true,\n GET: true,\n POST: true,\n PUT: true,\n PATCH: true,\n DELETE: true,\n TRACE: true,\n // QUERY from https://datatracker.ietf.org/doc/draft-ietf-httpbis-safe-method-w-body/\n QUERY: true,\n };\n\n if (original.toUpperCase() in knownMethods) {\n return original.toUpperCase();\n }\n\n return '_OTHER';\n }\n}\n"],"names":["InstrumentationBase","SDK_VERSION","METRIC_HTTP_CLIENT_REQUEST_DURATION","ValueType","safeExecuteInTheMiddle","hrTime","URL","ATTR_HTTP_REQUEST_METHOD","ATTR_HTTP_REQUEST_METHOD_ORIGINAL","ATTR_URL_FULL","ATTR_URL_PATH","ATTR_URL_QUERY","ATTR_URL_SCHEME","ATTR_SERVER_ADDRESS","ATTR_SERVER_PORT","ATTR_USER_AGENT_ORIGINAL","context","trace","INVALID_SPAN_CONTEXT","SpanKind","propagation","ATTR_NETWORK_PEER_ADDRESS","ATTR_NETWORK_PEER_PORT","ATTR_HTTP_RESPONSE_STATUS_CODE","SpanStatusCode","ATTR_ERROR_TYPE","hrTimeToMilliseconds","hrTimeDuration"],"mappings":";;;;;;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AAmDA,MAAM,YAAA,GAAe,gCAAgC;;AAErD;AACA;AACO,MAAM,qBAAA,SAA8BA,mCAAmB,CAA8B;AAC5F;AACA;;AAEA,kBAAU,cAAA,GAAiB,IAAI,OAAO,GAAuC;;AAI7E,EAAE,WAAW,CAAC,MAAM,GAAgC,EAAE,EAAE;AACxD,IAAI,KAAK,CAAC,YAAY,EAAEC,gBAAW,EAAE,MAAM,CAAA,CAAA,qBAAA,CAAA,SAAA,CAAA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