@sentry/node 10.59.0 → 10.60.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.
Files changed (85) hide show
  1. package/build/cjs/index.js +1 -0
  2. package/build/cjs/index.js.map +1 -1
  3. package/build/cjs/integrations/node-fetch/index.js +7 -8
  4. package/build/cjs/integrations/node-fetch/index.js.map +1 -1
  5. package/build/cjs/integrations/node-fetch/vendored/semconv.js +28 -0
  6. package/build/cjs/integrations/node-fetch/vendored/semconv.js.map +1 -0
  7. package/build/cjs/integrations/node-fetch/vendored/undici.js +91 -127
  8. package/build/cjs/integrations/node-fetch/vendored/undici.js.map +1 -1
  9. package/build/cjs/integrations/tracing/kafka/index.js +1 -11
  10. package/build/cjs/integrations/tracing/kafka/index.js.map +1 -1
  11. package/build/cjs/integrations/tracing/kafka/vendored/instrumentation.js +45 -247
  12. package/build/cjs/integrations/tracing/kafka/vendored/instrumentation.js.map +1 -1
  13. package/build/cjs/integrations/tracing/kafka/vendored/semconv.js +4 -8
  14. package/build/cjs/integrations/tracing/kafka/vendored/semconv.js.map +1 -1
  15. package/build/cjs/integrations/tracing/kafka/vendored/utils.js +113 -0
  16. package/build/cjs/integrations/tracing/kafka/vendored/utils.js.map +1 -0
  17. package/build/cjs/sdk/initOtel.js +2 -1
  18. package/build/cjs/sdk/initOtel.js.map +1 -1
  19. package/build/esm/index.js +1 -1
  20. package/build/esm/integrations/node-fetch/index.js +8 -9
  21. package/build/esm/integrations/node-fetch/index.js.map +1 -1
  22. package/build/esm/integrations/node-fetch/vendored/semconv.js +15 -0
  23. package/build/esm/integrations/node-fetch/vendored/semconv.js.map +1 -0
  24. package/build/esm/integrations/node-fetch/vendored/undici.js +80 -116
  25. package/build/esm/integrations/node-fetch/vendored/undici.js.map +1 -1
  26. package/build/esm/integrations/tracing/kafka/index.js +2 -12
  27. package/build/esm/integrations/tracing/kafka/index.js.map +1 -1
  28. package/build/esm/integrations/tracing/kafka/vendored/instrumentation.js +47 -249
  29. package/build/esm/integrations/tracing/kafka/vendored/instrumentation.js.map +1 -1
  30. package/build/esm/integrations/tracing/kafka/vendored/semconv.js +3 -5
  31. package/build/esm/integrations/tracing/kafka/vendored/semconv.js.map +1 -1
  32. package/build/esm/integrations/tracing/kafka/vendored/utils.js +107 -0
  33. package/build/esm/integrations/tracing/kafka/vendored/utils.js.map +1 -0
  34. package/build/esm/package.json +1 -1
  35. package/build/esm/sdk/initOtel.js +2 -1
  36. package/build/esm/sdk/initOtel.js.map +1 -1
  37. package/build/types/index.d.ts +1 -1
  38. package/build/types/index.d.ts.map +1 -1
  39. package/build/types/integrations/node-fetch/index.d.ts.map +1 -1
  40. package/build/types/integrations/node-fetch/vendored/internal-types.d.ts.map +1 -1
  41. package/build/types/integrations/node-fetch/vendored/semconv.d.ts +13 -0
  42. package/build/types/integrations/node-fetch/vendored/semconv.d.ts.map +1 -0
  43. package/build/types/integrations/node-fetch/vendored/types.d.ts +2 -4
  44. package/build/types/integrations/node-fetch/vendored/types.d.ts.map +1 -1
  45. package/build/types/integrations/node-fetch/vendored/undici.d.ts +6 -7
  46. package/build/types/integrations/node-fetch/vendored/undici.d.ts.map +1 -1
  47. package/build/types/integrations/tracing/kafka/index.d.ts.map +1 -1
  48. package/build/types/integrations/tracing/kafka/vendored/instrumentation.d.ts +3 -13
  49. package/build/types/integrations/tracing/kafka/vendored/instrumentation.d.ts.map +1 -1
  50. package/build/types/integrations/tracing/kafka/vendored/kafkajs-types.d.ts +0 -32
  51. package/build/types/integrations/tracing/kafka/vendored/kafkajs-types.d.ts.map +1 -1
  52. package/build/types/integrations/tracing/kafka/vendored/semconv.d.ts +9 -28
  53. package/build/types/integrations/tracing/kafka/vendored/semconv.d.ts.map +1 -1
  54. package/build/types/integrations/tracing/kafka/vendored/utils.d.ts +29 -0
  55. package/build/types/integrations/tracing/kafka/vendored/utils.d.ts.map +1 -0
  56. package/build/types/sdk/initOtel.d.ts.map +1 -1
  57. package/build/types-ts3.8/index.d.ts +1 -1
  58. package/build/types-ts3.8/integrations/node-fetch/vendored/semconv.d.ts +13 -0
  59. package/build/types-ts3.8/integrations/node-fetch/vendored/types.d.ts +2 -4
  60. package/build/types-ts3.8/integrations/node-fetch/vendored/undici.d.ts +6 -7
  61. package/build/types-ts3.8/integrations/tracing/kafka/vendored/instrumentation.d.ts +3 -13
  62. package/build/types-ts3.8/integrations/tracing/kafka/vendored/kafkajs-types.d.ts +0 -32
  63. package/build/types-ts3.8/integrations/tracing/kafka/vendored/semconv.d.ts +9 -28
  64. package/build/types-ts3.8/integrations/tracing/kafka/vendored/utils.d.ts +29 -0
  65. package/package.json +5 -6
  66. package/build/cjs/integrations/tracing/kafka/vendored/internal-types.js +0 -6
  67. package/build/cjs/integrations/tracing/kafka/vendored/internal-types.js.map +0 -1
  68. package/build/cjs/integrations/tracing/kafka/vendored/propagator.js +0 -22
  69. package/build/cjs/integrations/tracing/kafka/vendored/propagator.js.map +0 -1
  70. package/build/esm/integrations/tracing/kafka/vendored/internal-types.js +0 -4
  71. package/build/esm/integrations/tracing/kafka/vendored/internal-types.js.map +0 -1
  72. package/build/esm/integrations/tracing/kafka/vendored/propagator.js +0 -20
  73. package/build/esm/integrations/tracing/kafka/vendored/propagator.js.map +0 -1
  74. package/build/types/integrations/tracing/kafka/vendored/internal-types.d.ts +0 -9
  75. package/build/types/integrations/tracing/kafka/vendored/internal-types.d.ts.map +0 -1
  76. package/build/types/integrations/tracing/kafka/vendored/propagator.d.ts +0 -3
  77. package/build/types/integrations/tracing/kafka/vendored/propagator.d.ts.map +0 -1
  78. package/build/types/integrations/tracing/kafka/vendored/types.d.ts +0 -26
  79. package/build/types/integrations/tracing/kafka/vendored/types.d.ts.map +0 -1
  80. package/build/types/integrations/tracing/utils/sql-common.d.ts +0 -3
  81. package/build/types/integrations/tracing/utils/sql-common.d.ts.map +0 -1
  82. package/build/types-ts3.8/integrations/tracing/kafka/vendored/internal-types.d.ts +0 -9
  83. package/build/types-ts3.8/integrations/tracing/kafka/vendored/propagator.d.ts +0 -3
  84. package/build/types-ts3.8/integrations/tracing/kafka/vendored/types.d.ts +0 -26
  85. package/build/types-ts3.8/integrations/tracing/utils/sql-common.d.ts +0 -3
@@ -1,28 +1,33 @@
1
1
  import * as diagch from 'diagnostics_channel';
2
2
  import { URL } from 'url';
3
- import { InstrumentationBase, safeExecuteInTheMiddle } from '@opentelemetry/instrumentation';
4
- import { ValueType, context, trace, INVALID_SPAN_CONTEXT, SpanKind, propagation, SpanStatusCode } from '@opentelemetry/api';
5
- import { METRIC_HTTP_CLIENT_REQUEST_DURATION, ATTR_URL_QUERY, ATTR_URL_PATH, ATTR_URL_FULL, ATTR_HTTP_REQUEST_METHOD_ORIGINAL, ATTR_HTTP_RESPONSE_STATUS_CODE, ATTR_ERROR_TYPE, ATTR_HTTP_REQUEST_METHOD, ATTR_SERVER_ADDRESS, ATTR_SERVER_PORT, ATTR_URL_SCHEME, ATTR_USER_AGENT_ORIGINAL, ATTR_NETWORK_PEER_PORT, ATTR_NETWORK_PEER_ADDRESS } from '@opentelemetry/semantic-conventions';
6
- import { SDK_VERSION, timestampInSeconds } from '@sentry/core';
3
+ import { LRUMap, debug, startInactiveSpan, SPAN_STATUS_ERROR, getClient, shouldPropagateTraceForUrl, withActiveSpan, getTraceData } from '@sentry/core';
4
+ import { DEBUG_BUILD } from '../../../debug-build.js';
5
+ import { ATTR_URL_QUERY, ATTR_URL_PATH, ATTR_URL_FULL, ATTR_HTTP_REQUEST_METHOD_ORIGINAL, ATTR_HTTP_RESPONSE_STATUS_CODE, ATTR_URL_SCHEME, ATTR_HTTP_REQUEST_METHOD, ATTR_SERVER_ADDRESS, ATTR_SERVER_PORT, ATTR_USER_AGENT_ORIGINAL, ATTR_NETWORK_PEER_PORT, ATTR_NETWORK_PEER_ADDRESS } from './semconv.js';
7
6
 
8
- const PACKAGE_NAME = "@sentry/instrumentation-undici";
9
- class UndiciInstrumentation extends InstrumentationBase {
10
- constructor(config = {}) {
11
- super(PACKAGE_NAME, SDK_VERSION, config);
12
- this._recordFromReq = /* @__PURE__ */ new WeakMap();
13
- }
14
- // No need to instrument files/modules
15
- init() {
7
+ const SPAN_KIND_CLIENT = 2;
8
+ function safeExecute(fn, onError) {
9
+ try {
10
+ return fn();
11
+ } catch (error) {
12
+ onError(error);
16
13
  return void 0;
17
14
  }
15
+ }
16
+ class UndiciInstrumentation {
17
+ constructor(config = {}) {
18
+ // Keep ref to avoid https://github.com/nodejs/node/issues/42170 bug and for unsubscribing.
19
+ this._channelSubs = [];
20
+ this._spanFromReq = /* @__PURE__ */ new WeakMap();
21
+ // Caches trace-propagation decisions per URL so we don't recompute the `tracePropagationTargets` regexes per request.
22
+ this._propagationDecisionMap = new LRUMap(100);
23
+ this._config = config;
24
+ }
18
25
  disable() {
19
- super.disable();
20
26
  this._channelSubs.forEach((sub) => sub.unsubscribe());
21
27
  this._channelSubs.length = 0;
22
28
  }
29
+ /** Subscribe to the undici diagnostics channels (idempotent). */
23
30
  enable() {
24
- super.enable();
25
- this._channelSubs = this._channelSubs || [];
26
31
  if (this._channelSubs.length > 0) {
27
32
  return;
28
33
  }
@@ -32,16 +37,6 @@ class UndiciInstrumentation extends InstrumentationBase {
32
37
  this.subscribeToChannel("undici:request:trailers", this.onDone.bind(this));
33
38
  this.subscribeToChannel("undici:request:error", this.onError.bind(this));
34
39
  }
35
- _updateMetricInstruments() {
36
- this._httpClientDurationHistogram = this.meter.createHistogram(METRIC_HTTP_CLIENT_REQUEST_DURATION, {
37
- description: "Measures the duration of outbound HTTP requests.",
38
- unit: "s",
39
- valueType: ValueType.DOUBLE,
40
- advice: {
41
- explicitBucketBoundaries: [5e-3, 0.01, 0.025, 0.05, 0.075, 0.1, 0.25, 0.5, 0.75, 1, 2.5, 5, 7.5, 10]
42
- }
43
- });
44
- }
45
40
  subscribeToChannel(diagnosticChannel, onMessage) {
46
41
  const [major = 0, minor = 0] = process.version.replace("v", "").split(".").map((n) => Number(n));
47
42
  const useNewSubscribe = major > 18 || major === 18 && minor >= 19;
@@ -97,22 +92,20 @@ class UndiciInstrumentation extends InstrumentationBase {
97
92
  // create the span and populate some atttributes, then link the span to the request for further
98
93
  // span processing
99
94
  onRequestCreated({ request }) {
100
- const config = this.getConfig();
95
+ const config = this._config;
101
96
  const enabled = config.enabled !== false;
102
- const shouldIgnoreReq = safeExecuteInTheMiddle(
97
+ const shouldIgnoreReq = safeExecute(
103
98
  () => !enabled || request.method === "CONNECT" || config.ignoreRequestHook?.(request),
104
- (e) => e && this._diag.error("caught ignoreRequestHook error: ", e),
105
- true
99
+ (e) => e && DEBUG_BUILD && debug.error("caught ignoreRequestHook error: ", e)
106
100
  );
107
101
  if (shouldIgnoreReq) {
108
102
  return;
109
103
  }
110
- const startTime = timestampInSeconds();
111
104
  let requestUrl;
112
105
  try {
113
106
  requestUrl = new URL(request.path, request.origin);
114
107
  } catch (err) {
115
- this._diag.warn("could not determine url.full:", err);
108
+ DEBUG_BUILD && debug.warn("could not determine url.full:", err);
116
109
  return;
117
110
  }
118
111
  const urlScheme = requestUrl.protocol.replace(":", "");
@@ -138,67 +131,36 @@ class UndiciInstrumentation extends InstrumentationBase {
138
131
  const userAgent = Array.isArray(userAgentValues) ? userAgentValues[userAgentValues.length - 1] : userAgentValues;
139
132
  attributes[ATTR_USER_AGENT_ORIGINAL] = userAgent;
140
133
  }
141
- const hookAttributes = safeExecuteInTheMiddle(
134
+ const hookAttributes = safeExecute(
142
135
  () => config.startSpanHook?.(request),
143
- (e) => e && this._diag.error("caught startSpanHook error: ", e),
144
- true
136
+ (e) => e && DEBUG_BUILD && debug.error("caught startSpanHook error: ", e)
145
137
  );
146
138
  if (hookAttributes) {
147
139
  Object.entries(hookAttributes).forEach(([key, val]) => {
148
140
  attributes[key] = val;
149
141
  });
150
142
  }
151
- const activeCtx = context.active();
152
- const currentSpan = trace.getSpan(activeCtx);
153
- let span;
154
- if (config.requireParentforSpans && (!currentSpan || !trace.isSpanContextValid(currentSpan.spanContext()))) {
155
- span = trace.wrapSpanContext(INVALID_SPAN_CONTEXT);
156
- } else {
157
- span = this.tracer.startSpan(
158
- requestMethod === "_OTHER" ? "HTTP" : requestMethod,
159
- {
160
- kind: SpanKind.CLIENT,
161
- attributes
162
- },
163
- activeCtx
164
- );
165
- }
166
- safeExecuteInTheMiddle(
143
+ const span = startInactiveSpan({
144
+ name: requestMethod === "_OTHER" ? "HTTP" : requestMethod,
145
+ kind: SPAN_KIND_CLIENT,
146
+ attributes
147
+ });
148
+ safeExecute(
167
149
  () => config.requestHook?.(span, request),
168
- (e) => e && this._diag.error("caught requestHook error: ", e),
169
- true
150
+ (e) => e && DEBUG_BUILD && debug.error("caught requestHook error: ", e)
170
151
  );
171
- const requestContext = trace.setSpan(context.active(), span);
172
- const addedHeaders = {};
173
- propagation.inject(requestContext, addedHeaders);
174
- const headerEntries = Object.entries(addedHeaders);
175
- for (let i = 0; i < headerEntries.length; i++) {
176
- const pair = headerEntries[i];
177
- if (!pair) {
178
- continue;
179
- }
180
- const [k, v] = pair;
181
- if (typeof request.addHeader === "function") {
182
- request.addHeader(k, v);
183
- } else if (typeof request.headers === "string") {
184
- request.headers += `${k}: ${v}\r
185
- `;
186
- } else if (Array.isArray(request.headers)) {
187
- request.headers.push(k, v);
188
- }
189
- }
190
- this._recordFromReq.set(request, { span, attributes, startTime });
152
+ this.injectTracePropagationHeaders(span, request, requestUrl.toString());
153
+ this._spanFromReq.set(request, span);
191
154
  }
192
155
  // This is the 2nd message we receive for each request. It is fired when connection with
193
156
  // the remote is established and about to send the first byte. Here we do have info about the
194
157
  // remote address and port so we can populate some `network.*` attributes into the span
195
158
  onRequestHeaders({ request, socket }) {
196
- const record = this._recordFromReq.get(request);
197
- if (!record) {
159
+ const span = this._spanFromReq.get(request);
160
+ if (!span) {
198
161
  return;
199
162
  }
200
- const config = this.getConfig();
201
- const { span } = record;
163
+ const config = this._config;
202
164
  const { remoteAddress, remotePort } = socket;
203
165
  const spanAttributes = {
204
166
  [ATTR_NETWORK_PEER_ADDRESS]: remoteAddress,
@@ -220,19 +182,17 @@ class UndiciInstrumentation extends InstrumentationBase {
220
182
  // headers are received, body may not be accessible yet.
221
183
  // From the response headers we can set the status and content length
222
184
  onResponseHeaders({ request, response }) {
223
- const record = this._recordFromReq.get(request);
224
- if (!record) {
185
+ const span = this._spanFromReq.get(request);
186
+ if (!span) {
225
187
  return;
226
188
  }
227
- const { span, attributes } = record;
228
189
  const spanAttributes = {
229
190
  [ATTR_HTTP_RESPONSE_STATUS_CODE]: response.statusCode
230
191
  };
231
- const config = this.getConfig();
232
- safeExecuteInTheMiddle(
192
+ const config = this._config;
193
+ safeExecute(
233
194
  () => config.responseHook?.(span, { request, response }),
234
- (e) => e && this._diag.error("caught responseHook error: ", e),
235
- true
195
+ (e) => e && DEBUG_BUILD && debug.error("caught responseHook error: ", e)
236
196
  );
237
197
  if (config.headersToSpanAttributes?.responseHeaders) {
238
198
  const headersToAttribs = /* @__PURE__ */ new Set();
@@ -256,21 +216,18 @@ class UndiciInstrumentation extends InstrumentationBase {
256
216
  }
257
217
  }
258
218
  span.setAttributes(spanAttributes);
259
- span.setStatus({
260
- code: response.statusCode >= 400 ? SpanStatusCode.ERROR : SpanStatusCode.UNSET
261
- });
262
- record.attributes = Object.assign(attributes, spanAttributes);
219
+ if (response.statusCode >= 400) {
220
+ span.setStatus({ code: SPAN_STATUS_ERROR });
221
+ }
263
222
  }
264
223
  // This is the last event we receive if the request went without any errors
265
224
  onDone({ request }) {
266
- const record = this._recordFromReq.get(request);
267
- if (!record) {
225
+ const span = this._spanFromReq.get(request);
226
+ if (!span) {
268
227
  return;
269
228
  }
270
- const { span, attributes, startTime } = record;
271
229
  span.end();
272
- this._recordFromReq.delete(request);
273
- this.recordRequestDuration(attributes, startTime);
230
+ this._spanFromReq.delete(request);
274
231
  }
275
232
  // This is the event we get when something is wrong in the request like
276
233
  // - invalid options when calling `fetch` global API or any undici method for request
@@ -279,38 +236,45 @@ class UndiciInstrumentation extends InstrumentationBase {
279
236
  // NOTE: server errors are considered valid responses and it's the lib consumer
280
237
  // who should deal with that.
281
238
  onError({ request, error }) {
282
- const record = this._recordFromReq.get(request);
283
- if (!record) {
239
+ const span = this._spanFromReq.get(request);
240
+ if (!span) {
284
241
  return;
285
242
  }
286
- const { span, attributes, startTime } = record;
287
- span.recordException(error);
288
243
  span.setStatus({
289
- code: SpanStatusCode.ERROR,
244
+ code: SPAN_STATUS_ERROR,
290
245
  message: error.message
291
246
  });
292
247
  span.end();
293
- this._recordFromReq.delete(request);
294
- attributes[ATTR_ERROR_TYPE] = error.message;
295
- this.recordRequestDuration(attributes, startTime);
248
+ this._spanFromReq.delete(request);
296
249
  }
297
- recordRequestDuration(attributes, startTime) {
298
- const metricsAttributes = {};
299
- const keysToCopy = [
300
- ATTR_HTTP_RESPONSE_STATUS_CODE,
301
- ATTR_HTTP_REQUEST_METHOD,
302
- ATTR_SERVER_ADDRESS,
303
- ATTR_SERVER_PORT,
304
- ATTR_URL_SCHEME,
305
- ATTR_ERROR_TYPE
306
- ];
307
- keysToCopy.forEach((key) => {
308
- if (key in attributes) {
309
- metricsAttributes[key] = attributes[key];
250
+ // Propagate the trace data of the given (client) span into the outgoing request headers, gated by
251
+ // `tracePropagationTargets`. Mirrors what `propagation.inject()` did with the SentryPropagator, but
252
+ // via Sentry's `getTraceData()` so we stay off OpenTelemetry's propagation API.
253
+ injectTracePropagationHeaders(span, request, url) {
254
+ const { tracePropagationTargets, propagateTraceparent } = getClient()?.getOptions() ?? {};
255
+ if (!shouldPropagateTraceForUrl(url, tracePropagationTargets, this._propagationDecisionMap)) {
256
+ return;
257
+ }
258
+ const addedHeaders = withActiveSpan(span, () => getTraceData({ propagateTraceparent }));
259
+ const headerEntries = Object.entries(addedHeaders);
260
+ for (let i = 0; i < headerEntries.length; i++) {
261
+ const pair = headerEntries[i];
262
+ if (!pair) {
263
+ continue;
310
264
  }
311
- });
312
- const durationSeconds = timestampInSeconds() - startTime;
313
- this._httpClientDurationHistogram.record(durationSeconds, metricsAttributes);
265
+ const [k, v] = pair;
266
+ if (!v) {
267
+ continue;
268
+ }
269
+ if (typeof request.addHeader === "function") {
270
+ request.addHeader(k, v);
271
+ } else if (typeof request.headers === "string") {
272
+ request.headers += `${k}: ${v}\r
273
+ `;
274
+ } else if (Array.isArray(request.headers)) {
275
+ request.headers.push(k, v);
276
+ }
277
+ }
314
278
  }
315
279
  getRequestMethod(original) {
316
280
  const knownMethods = {
@@ -1 +1 @@
1
- {"version":3,"file":"undici.js","sources":["../../../../../src/integrations/node-fetch/vendored/undici.ts"],"sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n * SPDX-License-Identifier: Apache-2.0\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, 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 {\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, timestampInSeconds } from '@sentry/core';\n\ninterface InstrumentationRecord {\n span: Span;\n attributes: Attributes;\n startTime: number;\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 = timestampInSeconds();\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: number) {\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 = timestampInSeconds() - startTime;\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":[],"mappings":";;;;;;;AA4DA,MAAM,YAAA,GAAe,gCAAA;AAId,MAAM,8BAA8B,mBAAA,CAAiD;AAAA,EAQ1F,WAAA,CAAY,MAAA,GAAsC,EAAC,EAAG;AACpD,IAAA,KAAA,CAAM,YAAA,EAAc,aAAa,MAAM,CAAA;AALzC,IAAA,IAAA,CAAQ,cAAA,uBAAqB,OAAA,EAA8C;AAAA,EAM3E;AAAA;AAAA,EAGmB,IAAA,GAAO;AACxB,IAAA,OAAO,MAAA;AAAA,EACT;AAAA,EAES,OAAA,GAAgB;AACvB,IAAA,KAAA,CAAM,OAAA,EAAQ;AACd,IAAA,IAAA,CAAK,YAAA,CAAa,OAAA,CAAQ,CAAA,GAAA,KAAO,GAAA,CAAI,aAAa,CAAA;AAClD,IAAA,IAAA,CAAK,aAAa,MAAA,GAAS,CAAA;AAAA,EA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AA,CAAsB,YAAwB,SAAA,EAAmB;AAEvE,IAAA,MAAM,oBAAgC,EAAC;AAEvC,IAAA,MAAM,UAAA,GAAa;AAAA,MACjB,8BAAA;AAAA,MACA,wBAAA;AAAA,MACA,mBAAA;AAAA,MACA,gBAAA;AAAA,MACA,eAAA;AAAA,MACA;AAAA,KACF;AACA,IAAA,UAAA,CAAW,QAAQ,CAAA,GAAA,KAAO;AACxB,MAAA,IAAI,OAAO,UAAA,EAAY;AACrB,QAAA,iBAAA,CAAkB,GAAG,CAAA,GAAI,UAAA,CAAW,GAAG,CAAA;AAAA,MACzC;AAAA,IACF,CAAC,CAAA;AAGD,IAAA,MAAM,eAAA,GAAkB,oBAAmB,GAAI,SAAA;AAC/C,IAAA,IAAA,CAAK,4BAAA,CAA6B,MAAA,CAAO,eAAA,EAAiB,iBAAiB,CAAA;AAAA,EAC7E;AAAA,EAEQ,iBAAiB,QAAA,EAA0B;AACjD,IAAA,MAAM,YAAA,GAAe;AAAA,MACnB,OAAA,EAAS,IAAA;AAAA,MACT,OAAA,EAAS,IAAA;AAAA,MACT,IAAA,EAAM,IAAA;AAAA,MACN,GAAA,EAAK,IAAA;AAAA,MACL,IAAA,EAAM,IAAA;AAAA,MACN,GAAA,EAAK,IAAA;AAAA,MACL,KAAA,EAAO,IAAA;AAAA,MACP,MAAA,EAAQ,IAAA;AAAA,MACR,KAAA,EAAO,IAAA;AAAA;AAAA,MAEP,KAAA,EAAO;AAAA,KACT;AAEA,IAAA,IAAI,QAAA,CAAS,WAAA,EAAY,IAAK,YAAA,EAAc;AAC1C,MAAA,OAAO,SAAS,WAAA,EAAY;AAAA,IAC9B;AAEA,IAAA,OAAO,QAAA;AAAA,EACT;AACF;;;;"}
1
+ {"version":3,"file":"undici.js","sources":["../../../../../src/integrations/node-fetch/vendored/undici.ts"],"sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n * SPDX-License-Identifier: Apache-2.0\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 * - Refactored to use Sentry's span APIs instead of OpenTelemetry tracing APIs\n * - Dropped the OTel metrics (no MeterProvider is wired up) and the dead\n * `requireParentforSpans` code path (the SDK always passes `false`)\n * - Dropped the `@opentelemetry/instrumentation` base (undici reports via `diagnostics_channel`,\n * so no module patching was needed) — now a plain class wired up directly by the integration\n */\n\nimport * as diagch from 'diagnostics_channel';\nimport { URL } from 'url';\n\nimport type { Span, SpanAttributes } from '@sentry/core';\nimport {\n debug,\n getClient,\n getTraceData,\n LRUMap,\n shouldPropagateTraceForUrl,\n SPAN_STATUS_ERROR,\n startInactiveSpan,\n withActiveSpan,\n} from '@sentry/core';\nimport { DEBUG_BUILD } from '../../../debug-build';\nimport {\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} from './semconv';\n\nimport type {\n ListenerRecord,\n RequestErrorMessage,\n RequestHeadersMessage,\n RequestMessage,\n RequestTrailersMessage,\n ResponseHeadersMessage,\n} from './internal-types';\nimport type { UndiciInstrumentationConfig, UndiciRequest } from './types';\n\n// `SpanKind.CLIENT`, inlined to avoid importing from `@opentelemetry/api`.\nconst SPAN_KIND_CLIENT = 2;\n\n/** Replaces OTel's `safeExecuteInTheMiddle`: run `fn`, route any error to `onError`, and swallow it. */\nfunction safeExecute<T>(fn: () => T, onError: (error: unknown) => void): T | undefined {\n try {\n return fn();\n } catch (error) {\n onError(error);\n return undefined;\n }\n}\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\n//\n// Not an OTel `InstrumentationBase` (undici reports via `diagnostics_channel`, not module patching);\n// the integration wires this up directly via `enable()` / `disable()`.\nexport class UndiciInstrumentation {\n // Keep ref to avoid https://github.com/nodejs/node/issues/42170 bug and for unsubscribing.\n private _channelSubs: Array<ListenerRecord> = [];\n private _spanFromReq = new WeakMap<UndiciRequest, Span>();\n // Caches trace-propagation decisions per URL so we don't recompute the `tracePropagationTargets` regexes per request.\n private _propagationDecisionMap = new LRUMap<string, boolean>(100);\n private _config: UndiciInstrumentationConfig;\n\n constructor(config: UndiciInstrumentationConfig = {}) {\n this._config = config;\n }\n\n public disable(): void {\n this._channelSubs.forEach(sub => sub.unsubscribe());\n this._channelSubs.length = 0;\n }\n\n /** Subscribe to the undici diagnostics channels (idempotent). */\n public enable(): void {\n // Avoid 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 private subscribeToChannel(\n diagnosticChannel: string,\n onMessage: (message: any, name: string | symbol) => void,\n ): 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): Map<string, string | string[]> {\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._config;\n const enabled = config.enabled !== false;\n const shouldIgnoreReq = safeExecute(\n () => !enabled || request.method === 'CONNECT' || config.ignoreRequestHook?.(request),\n e => e && DEBUG_BUILD && debug.error('caught ignoreRequestHook error: ', e),\n );\n\n if (shouldIgnoreReq) {\n return;\n }\n\n let requestUrl;\n try {\n requestUrl = new URL(request.path, request.origin);\n } catch (err) {\n DEBUG_BUILD && debug.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: SpanAttributes = {\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 = safeExecute(\n () => config.startSpanHook?.(request),\n e => e && DEBUG_BUILD && debug.error('caught startSpanHook error: ', e),\n );\n if (hookAttributes) {\n Object.entries(hookAttributes).forEach(([key, val]) => {\n attributes[key] = val;\n });\n }\n\n const span = startInactiveSpan({\n name: requestMethod === '_OTHER' ? 'HTTP' : requestMethod,\n kind: SPAN_KIND_CLIENT,\n attributes,\n });\n\n // Execute the request hook if defined\n safeExecute(\n () => config.requestHook?.(span, request),\n e => e && DEBUG_BUILD && debug.error('caught requestHook error: ', e),\n );\n\n // Context propagation goes last so no hook can tamper the propagation headers.\n // We propagate the trace data of the freshly created client span (not the active parent span)\n // so downstream services are parented to the http.client span, matching the upstream behavior.\n this.injectTracePropagationHeaders(span, request, requestUrl.toString());\n\n this._spanFromReq.set(request, span);\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 span = this._spanFromReq.get(request);\n\n if (!span) {\n return;\n }\n\n const config = this._config;\n const { remoteAddress, remotePort } = socket;\n const spanAttributes: SpanAttributes = {\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 span = this._spanFromReq.get(request);\n\n if (!span) {\n return;\n }\n\n const spanAttributes: SpanAttributes = {\n [ATTR_HTTP_RESPONSE_STATUS_CODE]: response.statusCode,\n };\n\n const config = this._config;\n\n // Execute the response hook if defined\n safeExecute(\n () => config.responseHook?.(span, { request, response }),\n e => e && DEBUG_BUILD && debug.error('caught responseHook error: ', e),\n );\n\n if (config.headersToSpanAttributes?.responseHeaders) {\n const headersToAttribs = new Set<string>();\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\n // The Sentry pipeline infers `ok` / `not_found` / etc. from `http.response.status_code` when the\n // status is left unset, so we only need to flag erroneous responses explicitly.\n if (response.statusCode >= 400) {\n span.setStatus({ code: SPAN_STATUS_ERROR });\n }\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 span = this._spanFromReq.get(request);\n\n if (!span) {\n return;\n }\n\n span.end();\n this._spanFromReq.delete(request);\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 }: RequestErrorMessage): void {\n const span = this._spanFromReq.get(request);\n\n if (!span) {\n return;\n }\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.setStatus({\n code: SPAN_STATUS_ERROR,\n message: error.message,\n });\n span.end();\n this._spanFromReq.delete(request);\n }\n\n // Propagate the trace data of the given (client) span into the outgoing request headers, gated by\n // `tracePropagationTargets`. Mirrors what `propagation.inject()` did with the SentryPropagator, but\n // via Sentry's `getTraceData()` so we stay off OpenTelemetry's propagation API.\n private injectTracePropagationHeaders(span: Span, request: UndiciRequest, url: string): void {\n const { tracePropagationTargets, propagateTraceparent } = getClient()?.getOptions() ?? {};\n\n if (!shouldPropagateTraceForUrl(url, tracePropagationTargets, this._propagationDecisionMap)) {\n return;\n }\n\n // We make the freshly created client span active so the propagated headers reference it (and not\n // the parent span). Passing `{ span }` to `getTraceData()` is not enough: for an inactive span it\n // resolves to the span's *captured* scope, whose active span is still the parent.\n const addedHeaders = withActiveSpan(span, () => getTraceData({ propagateTraceparent }));\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 if (!v) {\n continue;\n }\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 }\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":[],"mappings":";;;;;;AAwDA,MAAM,gBAAA,GAAmB,CAAA;AAGzB,SAAS,WAAA,CAAe,IAAa,OAAA,EAAkD;AACrF,EAAA,IAAI;AACF,IAAA,OAAO,EAAA,EAAG;AAAA,EACZ,SAAS,KAAA,EAAO;AACd,IAAA,OAAA,CAAQ,KAAK,CAAA;AACb,IAAA,OAAO,MAAA;AAAA,EACT;AACF;AAOO,MAAM,qBAAA,CAAsB;AAAA,EAQjC,WAAA,CAAY,MAAA,GAAsC,EAAC,EAAG;AANtD;AAAA,IAAA,IAAA,CAAQ,eAAsC,EAAC;AAC/C,IAAA,IAAA,CAAQ,YAAA,uBAAmB,OAAA,EAA6B;AAExD;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;AAAA,CAAA;AAAA,MAC/B,CAAA,MAAA,IAAW,KAAA,CAAM,OAAA,CAAQ,OAAA,CAAQ,OAAO,CAAA,EAAG;AAEzC,QAAA,OAAA,CAAQ,OAAA,CAAQ,IAAA,CAAK,CAAA,EAAG,CAAC,CAAA;AAAA,MAC3B;AAAA,IACF;AAAA,EACF;AAAA,EAEQ,iBAAiB,QAAA,EAA0B;AACjD,IAAA,MAAM,YAAA,GAAe;AAAA,MACnB,OAAA,EAAS,IAAA;AAAA,MACT,OAAA,EAAS,IAAA;AAAA,MACT,IAAA,EAAM,IAAA;AAAA,MACN,GAAA,EAAK,IAAA;AAAA,MACL,IAAA,EAAM,IAAA;AAAA,MACN,GAAA,EAAK,IAAA;AAAA,MACL,KAAA,EAAO,IAAA;AAAA,MACP,MAAA,EAAQ,IAAA;AAAA,MACR,KAAA,EAAO,IAAA;AAAA;AAAA,MAEP,KAAA,EAAO;AAAA,KACT;AAEA,IAAA,IAAI,QAAA,CAAS,WAAA,EAAY,IAAK,YAAA,EAAc;AAC1C,MAAA,OAAO,SAAS,WAAA,EAAY;AAAA,IAC9B;AAEA,IAAA,OAAO,QAAA;AAAA,EACT;AACF;;;;"}
@@ -1,19 +1,9 @@
1
1
  import { KafkaJsInstrumentation } from './vendored/instrumentation.js';
2
2
  import { defineIntegration } from '@sentry/core';
3
- import { generateInstrumentOnce, addOriginToSpan } from '@sentry/node-core';
3
+ import { generateInstrumentOnce } from '@sentry/node-core';
4
4
 
5
5
  const INTEGRATION_NAME = "Kafka";
6
- const instrumentKafka = generateInstrumentOnce(
7
- INTEGRATION_NAME,
8
- () => new KafkaJsInstrumentation({
9
- consumerHook(span) {
10
- addOriginToSpan(span, "auto.kafkajs.otel.consumer");
11
- },
12
- producerHook(span) {
13
- addOriginToSpan(span, "auto.kafkajs.otel.producer");
14
- }
15
- })
16
- );
6
+ const instrumentKafka = generateInstrumentOnce(INTEGRATION_NAME, () => new KafkaJsInstrumentation());
17
7
  const _kafkaIntegration = (() => {
18
8
  return {
19
9
  name: INTEGRATION_NAME,
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../../../../../src/integrations/tracing/kafka/index.ts"],"sourcesContent":["import { KafkaJsInstrumentation } from './vendored/instrumentation';\nimport type { IntegrationFn } from '@sentry/core';\nimport { defineIntegration } from '@sentry/core';\nimport { addOriginToSpan, generateInstrumentOnce } from '@sentry/node-core';\n\nconst INTEGRATION_NAME = 'Kafka';\n\nexport const instrumentKafka = generateInstrumentOnce(\n INTEGRATION_NAME,\n () =>\n new KafkaJsInstrumentation({\n consumerHook(span) {\n addOriginToSpan(span, 'auto.kafkajs.otel.consumer');\n },\n producerHook(span) {\n addOriginToSpan(span, 'auto.kafkajs.otel.producer');\n },\n }),\n);\n\nconst _kafkaIntegration = (() => {\n return {\n name: INTEGRATION_NAME,\n setupOnce() {\n instrumentKafka();\n },\n };\n}) satisfies IntegrationFn;\n\n/**\n * Adds Sentry tracing instrumentation for the [kafkajs](https://www.npmjs.com/package/kafkajs) library.\n *\n * For more information, see the [`kafkaIntegration` documentation](https://docs.sentry.io/platforms/javascript/guides/node/configuration/integrations/kafka/).\n *\n * @example\n * ```javascript\n * const Sentry = require('@sentry/node');\n *\n * Sentry.init({\n * integrations: [Sentry.kafkaIntegration()],\n * });\n */\nexport const kafkaIntegration = defineIntegration(_kafkaIntegration);\n"],"names":[],"mappings":";;;;AAKA,MAAM,gBAAA,GAAmB,OAAA;AAElB,MAAM,eAAA,GAAkB,sBAAA;AAAA,EAC7B,gBAAA;AAAA,EACA,MACE,IAAI,sBAAA,CAAuB;AAAA,IACzB,aAAa,IAAA,EAAM;AACjB,MAAA,eAAA,CAAgB,MAAM,4BAA4B,CAAA;AAAA,IACpD,CAAA;AAAA,IACA,aAAa,IAAA,EAAM;AACjB,MAAA,eAAA,CAAgB,MAAM,4BAA4B,CAAA;AAAA,IACpD;AAAA,GACD;AACL;AAEA,MAAM,qBAAqB,MAAM;AAC/B,EAAA,OAAO;AAAA,IACL,IAAA,EAAM,gBAAA;AAAA,IACN,SAAA,GAAY;AACV,MAAA,eAAA,EAAgB;AAAA,IAClB;AAAA,GACF;AACF,CAAA,CAAA;AAeO,MAAM,gBAAA,GAAmB,kBAAkB,iBAAiB;;;;"}
1
+ {"version":3,"file":"index.js","sources":["../../../../../src/integrations/tracing/kafka/index.ts"],"sourcesContent":["import { KafkaJsInstrumentation } from './vendored/instrumentation';\nimport type { IntegrationFn } from '@sentry/core';\nimport { defineIntegration } from '@sentry/core';\nimport { generateInstrumentOnce } from '@sentry/node-core';\n\nconst INTEGRATION_NAME = 'Kafka';\n\nexport const instrumentKafka = generateInstrumentOnce(INTEGRATION_NAME, () => new KafkaJsInstrumentation());\n\nconst _kafkaIntegration = (() => {\n return {\n name: INTEGRATION_NAME,\n setupOnce() {\n instrumentKafka();\n },\n };\n}) satisfies IntegrationFn;\n\n/**\n * Adds Sentry tracing instrumentation for the [kafkajs](https://www.npmjs.com/package/kafkajs) library.\n *\n * For more information, see the [`kafkaIntegration` documentation](https://docs.sentry.io/platforms/javascript/guides/node/configuration/integrations/kafka/).\n *\n * @example\n * ```javascript\n * const Sentry = require('@sentry/node');\n *\n * Sentry.init({\n * integrations: [Sentry.kafkaIntegration()],\n * });\n */\nexport const kafkaIntegration = defineIntegration(_kafkaIntegration);\n"],"names":[],"mappings":";;;;AAKA,MAAM,gBAAA,GAAmB,OAAA;AAElB,MAAM,kBAAkB,sBAAA,CAAuB,gBAAA,EAAkB,MAAM,IAAI,wBAAwB;AAE1G,MAAM,qBAAqB,MAAM;AAC/B,EAAA,OAAO;AAAA,IACL,IAAA,EAAM,gBAAA;AAAA,IACN,SAAA,GAAY;AACV,MAAA,eAAA,EAAgB;AAAA,IAClB;AAAA,GACF;AACF,CAAA,CAAA;AAeO,MAAM,gBAAA,GAAmB,kBAAkB,iBAAiB;;;;"}