@sentry/node 10.50.0-alpha.0 → 10.51.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/integrations/tracing/langgraph/instrumentation.js +70 -25
- package/build/cjs/integrations/tracing/langgraph/instrumentation.js.map +1 -1
- package/build/cjs/integrations/tracing/prisma.js +6 -2
- package/build/cjs/integrations/tracing/prisma.js.map +1 -1
- 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/integrations/tracing/langgraph/instrumentation.js +71 -26
- package/build/esm/integrations/tracing/langgraph/instrumentation.js.map +1 -1
- package/build/esm/integrations/tracing/prisma.js +6 -2
- package/build/esm/integrations/tracing/prisma.js.map +1 -1
- 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/integrations/tracing/langgraph/instrumentation.d.ts +1 -1
- package/build/types/integrations/tracing/langgraph/instrumentation.d.ts.map +1 -1
- package/build/types/integrations/tracing/prisma.d.ts.map +1 -1
- 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/build/types-ts3.8/integrations/tracing/langgraph/instrumentation.d.ts +1 -1
- 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
|
@@ -0,0 +1,482 @@
|
|
|
1
|
+
import * as diagch from 'diagnostics_channel';
|
|
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 { hrTime, hrTimeToMilliseconds, hrTimeDuration } from '@opentelemetry/core';
|
|
6
|
+
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';
|
|
7
|
+
import { SDK_VERSION } from '@sentry/core';
|
|
8
|
+
|
|
9
|
+
/*
|
|
10
|
+
* Copyright The OpenTelemetry Authors
|
|
11
|
+
*
|
|
12
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
13
|
+
* you may not use this file except in compliance with the License.
|
|
14
|
+
* You may obtain a copy of the License at
|
|
15
|
+
*
|
|
16
|
+
* https://www.apache.org/licenses/LICENSE-2.0
|
|
17
|
+
*
|
|
18
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
19
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
20
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
21
|
+
* See the License for the specific language governing permissions and
|
|
22
|
+
* limitations under the License.
|
|
23
|
+
*
|
|
24
|
+
* NOTICE from the Sentry authors:
|
|
25
|
+
* - Vendored from: https://github.com/open-telemetry/opentelemetry-js-contrib/tree/ed97091c9890dd18e52759f2ea98e9d7593b3ae4/packages/instrumentation-undici
|
|
26
|
+
* - Upstream version: @opentelemetry/instrumentation-undici@0.24.0
|
|
27
|
+
* - Tracking issue: https://github.com/getsentry/sentry-javascript/issues/20165
|
|
28
|
+
* - Minor TypeScript strictness adjustments for this repository's compiler settings
|
|
29
|
+
*/
|
|
30
|
+
/* eslint-disable -- vendored @opentelemetry/instrumentation-undici (#20165) */
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
const PACKAGE_NAME = '@sentry/instrumentation-undici';
|
|
34
|
+
|
|
35
|
+
// A combination of https://github.com/elastic/apm-agent-nodejs and
|
|
36
|
+
// https://github.com/gadget-inc/opentelemetry-instrumentations/blob/main/packages/opentelemetry-instrumentation-undici/src/index.ts
|
|
37
|
+
class UndiciInstrumentation extends InstrumentationBase {
|
|
38
|
+
// Keep ref to avoid https://github.com/nodejs/node/issues/42170 bug and for
|
|
39
|
+
// unsubscribing.
|
|
40
|
+
|
|
41
|
+
__init() {this._recordFromReq = new WeakMap();}
|
|
42
|
+
|
|
43
|
+
constructor(config = {}) {
|
|
44
|
+
super(PACKAGE_NAME, SDK_VERSION, config);UndiciInstrumentation.prototype.__init.call(this); }
|
|
45
|
+
|
|
46
|
+
// No need to instrument files/modules
|
|
47
|
+
init() {
|
|
48
|
+
return undefined;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
disable() {
|
|
52
|
+
super.disable();
|
|
53
|
+
this._channelSubs.forEach(sub => sub.unsubscribe());
|
|
54
|
+
this._channelSubs.length = 0;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
enable() {
|
|
58
|
+
// "enabled" handling is currently a bit messy with InstrumentationBase.
|
|
59
|
+
// If constructed with `{enabled: false}`, this `.enable()` is still called,
|
|
60
|
+
// and `this.getConfig().enabled !== this.isEnabled()`, creating confusion.
|
|
61
|
+
//
|
|
62
|
+
// For now, this class will setup for instrumenting if `.enable()` is
|
|
63
|
+
// called, but use `this.getConfig().enabled` to determine if
|
|
64
|
+
// instrumentation should be generated. This covers the more likely common
|
|
65
|
+
// case of config being given a construction time, rather than later via
|
|
66
|
+
// `instance.enable()`, `.disable()`, or `.setConfig()` calls.
|
|
67
|
+
super.enable();
|
|
68
|
+
|
|
69
|
+
// This method is called by the super-class constructor before ours is
|
|
70
|
+
// called. So we need to ensure the property is initalized.
|
|
71
|
+
this._channelSubs = this._channelSubs || [];
|
|
72
|
+
|
|
73
|
+
// Avoid to duplicate subscriptions
|
|
74
|
+
if (this._channelSubs.length > 0) {
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
this.subscribeToChannel('undici:request:create', this.onRequestCreated.bind(this));
|
|
79
|
+
this.subscribeToChannel('undici:client:sendHeaders', this.onRequestHeaders.bind(this));
|
|
80
|
+
this.subscribeToChannel('undici:request:headers', this.onResponseHeaders.bind(this));
|
|
81
|
+
this.subscribeToChannel('undici:request:trailers', this.onDone.bind(this));
|
|
82
|
+
this.subscribeToChannel('undici:request:error', this.onError.bind(this));
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
_updateMetricInstruments() {
|
|
86
|
+
this._httpClientDurationHistogram = this.meter.createHistogram(METRIC_HTTP_CLIENT_REQUEST_DURATION, {
|
|
87
|
+
description: 'Measures the duration of outbound HTTP requests.',
|
|
88
|
+
unit: 's',
|
|
89
|
+
valueType: ValueType.DOUBLE,
|
|
90
|
+
advice: {
|
|
91
|
+
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],
|
|
92
|
+
},
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
subscribeToChannel(diagnosticChannel, onMessage) {
|
|
97
|
+
// `diagnostics_channel` had a ref counting bug until v18.19.0.
|
|
98
|
+
// https://github.com/nodejs/node/pull/47520
|
|
99
|
+
const [major = 0, minor = 0] = process.version
|
|
100
|
+
.replace('v', '')
|
|
101
|
+
.split('.')
|
|
102
|
+
.map(n => Number(n));
|
|
103
|
+
const useNewSubscribe = major > 18 || (major === 18 && minor >= 19);
|
|
104
|
+
|
|
105
|
+
let unsubscribe;
|
|
106
|
+
if (useNewSubscribe) {
|
|
107
|
+
diagch.subscribe?.(diagnosticChannel, onMessage);
|
|
108
|
+
unsubscribe = () => diagch.unsubscribe?.(diagnosticChannel, onMessage);
|
|
109
|
+
} else {
|
|
110
|
+
const channel = diagch.channel(diagnosticChannel);
|
|
111
|
+
channel.subscribe(onMessage);
|
|
112
|
+
unsubscribe = () => channel.unsubscribe(onMessage);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
this._channelSubs.push({
|
|
116
|
+
name: diagnosticChannel,
|
|
117
|
+
unsubscribe,
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
parseRequestHeaders(request) {
|
|
122
|
+
const result = new Map();
|
|
123
|
+
|
|
124
|
+
if (Array.isArray(request.headers)) {
|
|
125
|
+
// headers are an array [k1, v2, k2, v2] (undici v6+)
|
|
126
|
+
// values could be string or a string[] for multiple values
|
|
127
|
+
for (let i = 0; i < request.headers.length; i += 2) {
|
|
128
|
+
const key = request.headers[i];
|
|
129
|
+
const value = request.headers[i + 1];
|
|
130
|
+
|
|
131
|
+
// Key should always be a string, but the types don't know that, and let's be safe
|
|
132
|
+
if (typeof key === 'string' && value !== undefined) {
|
|
133
|
+
result.set(key.toLowerCase(), value);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
} else if (typeof request.headers === 'string') {
|
|
137
|
+
// headers are a raw string (undici v5)
|
|
138
|
+
// headers could be repeated in several lines for multiple values
|
|
139
|
+
const headers = request.headers.split('\r\n');
|
|
140
|
+
for (const line of headers) {
|
|
141
|
+
if (!line) {
|
|
142
|
+
continue;
|
|
143
|
+
}
|
|
144
|
+
const colonIndex = line.indexOf(':');
|
|
145
|
+
if (colonIndex === -1) {
|
|
146
|
+
// Invalid header? Probably this can't happen, but again let's be safe.
|
|
147
|
+
continue;
|
|
148
|
+
}
|
|
149
|
+
const key = line.substring(0, colonIndex).toLowerCase();
|
|
150
|
+
const value = line.substring(colonIndex + 1).trim();
|
|
151
|
+
const allValues = result.get(key);
|
|
152
|
+
|
|
153
|
+
if (allValues && Array.isArray(allValues)) {
|
|
154
|
+
allValues.push(value);
|
|
155
|
+
} else if (allValues) {
|
|
156
|
+
result.set(key, [allValues, value]);
|
|
157
|
+
} else {
|
|
158
|
+
result.set(key, value);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
return result;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
// This is the 1st message we receive for each request (fired after request creation). Here we will
|
|
166
|
+
// create the span and populate some atttributes, then link the span to the request for further
|
|
167
|
+
// span processing
|
|
168
|
+
onRequestCreated({ request }) {
|
|
169
|
+
// Ignore if:
|
|
170
|
+
// - instrumentation is disabled
|
|
171
|
+
// - ignored by config
|
|
172
|
+
// - method is 'CONNECT'
|
|
173
|
+
const config = this.getConfig();
|
|
174
|
+
const enabled = config.enabled !== false;
|
|
175
|
+
const shouldIgnoreReq = safeExecuteInTheMiddle(
|
|
176
|
+
() => !enabled || request.method === 'CONNECT' || config.ignoreRequestHook?.(request),
|
|
177
|
+
e => e && this._diag.error('caught ignoreRequestHook error: ', e),
|
|
178
|
+
true,
|
|
179
|
+
);
|
|
180
|
+
|
|
181
|
+
if (shouldIgnoreReq) {
|
|
182
|
+
return;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
const startTime = hrTime();
|
|
186
|
+
let requestUrl;
|
|
187
|
+
try {
|
|
188
|
+
requestUrl = new URL(request.path, request.origin);
|
|
189
|
+
} catch (err) {
|
|
190
|
+
this._diag.warn('could not determine url.full:', err);
|
|
191
|
+
// Skip instrumenting this request.
|
|
192
|
+
return;
|
|
193
|
+
}
|
|
194
|
+
const urlScheme = requestUrl.protocol.replace(':', '');
|
|
195
|
+
const requestMethod = this.getRequestMethod(request.method);
|
|
196
|
+
const attributes = {
|
|
197
|
+
[ATTR_HTTP_REQUEST_METHOD]: requestMethod,
|
|
198
|
+
[ATTR_HTTP_REQUEST_METHOD_ORIGINAL]: request.method,
|
|
199
|
+
[ATTR_URL_FULL]: requestUrl.toString(),
|
|
200
|
+
[ATTR_URL_PATH]: requestUrl.pathname,
|
|
201
|
+
[ATTR_URL_QUERY]: requestUrl.search,
|
|
202
|
+
[ATTR_URL_SCHEME]: urlScheme,
|
|
203
|
+
};
|
|
204
|
+
|
|
205
|
+
const schemePorts = { https: '443', http: '80' };
|
|
206
|
+
const serverAddress = requestUrl.hostname;
|
|
207
|
+
const serverPort = requestUrl.port || schemePorts[urlScheme];
|
|
208
|
+
|
|
209
|
+
attributes[ATTR_SERVER_ADDRESS] = serverAddress;
|
|
210
|
+
if (serverPort && !isNaN(Number(serverPort))) {
|
|
211
|
+
attributes[ATTR_SERVER_PORT] = Number(serverPort);
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
// Get user agent from headers
|
|
215
|
+
const headersMap = this.parseRequestHeaders(request);
|
|
216
|
+
const userAgentValues = headersMap.get('user-agent');
|
|
217
|
+
|
|
218
|
+
if (userAgentValues) {
|
|
219
|
+
// NOTE: having multiple user agents is not expected so
|
|
220
|
+
// we're going to take last one like `curl` does
|
|
221
|
+
// ref: https://curl.se/docs/manpage.html#-A
|
|
222
|
+
const userAgent = Array.isArray(userAgentValues) ? userAgentValues[userAgentValues.length - 1] : userAgentValues;
|
|
223
|
+
attributes[ATTR_USER_AGENT_ORIGINAL] = userAgent;
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
// Get attributes from the hook if present
|
|
227
|
+
const hookAttributes = safeExecuteInTheMiddle(
|
|
228
|
+
() => config.startSpanHook?.(request),
|
|
229
|
+
e => e && this._diag.error('caught startSpanHook error: ', e),
|
|
230
|
+
true,
|
|
231
|
+
);
|
|
232
|
+
if (hookAttributes) {
|
|
233
|
+
Object.entries(hookAttributes).forEach(([key, val]) => {
|
|
234
|
+
attributes[key] = val;
|
|
235
|
+
});
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
// Check if parent span is required via config and:
|
|
239
|
+
// - if a parent is required but not present, we use a `NoopSpan` to still
|
|
240
|
+
// propagate context without recording it.
|
|
241
|
+
// - create a span otherwise
|
|
242
|
+
const activeCtx = context.active();
|
|
243
|
+
const currentSpan = trace.getSpan(activeCtx);
|
|
244
|
+
let span;
|
|
245
|
+
|
|
246
|
+
if (config.requireParentforSpans && (!currentSpan || !trace.isSpanContextValid(currentSpan.spanContext()))) {
|
|
247
|
+
span = trace.wrapSpanContext(INVALID_SPAN_CONTEXT);
|
|
248
|
+
} else {
|
|
249
|
+
span = this.tracer.startSpan(
|
|
250
|
+
requestMethod === '_OTHER' ? 'HTTP' : requestMethod,
|
|
251
|
+
{
|
|
252
|
+
kind: SpanKind.CLIENT,
|
|
253
|
+
attributes: attributes,
|
|
254
|
+
},
|
|
255
|
+
activeCtx,
|
|
256
|
+
);
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
// Execute the request hook if defined
|
|
260
|
+
safeExecuteInTheMiddle(
|
|
261
|
+
() => config.requestHook?.(span, request),
|
|
262
|
+
e => e && this._diag.error('caught requestHook error: ', e),
|
|
263
|
+
true,
|
|
264
|
+
);
|
|
265
|
+
|
|
266
|
+
// Context propagation goes last so no hook can tamper
|
|
267
|
+
// the propagation headers
|
|
268
|
+
const requestContext = trace.setSpan(context.active(), span);
|
|
269
|
+
const addedHeaders = {};
|
|
270
|
+
propagation.inject(requestContext, addedHeaders);
|
|
271
|
+
|
|
272
|
+
const headerEntries = Object.entries(addedHeaders);
|
|
273
|
+
|
|
274
|
+
for (let i = 0; i < headerEntries.length; i++) {
|
|
275
|
+
const pair = headerEntries[i];
|
|
276
|
+
if (!pair) {
|
|
277
|
+
continue;
|
|
278
|
+
}
|
|
279
|
+
const [k, v] = pair;
|
|
280
|
+
|
|
281
|
+
if (typeof request.addHeader === 'function') {
|
|
282
|
+
request.addHeader(k, v);
|
|
283
|
+
} else if (typeof request.headers === 'string') {
|
|
284
|
+
request.headers += `${k}: ${v}\r\n`;
|
|
285
|
+
} else if (Array.isArray(request.headers)) {
|
|
286
|
+
// undici@6.11.0 accidentally, briefly removed `request.addHeader()`.
|
|
287
|
+
request.headers.push(k, v);
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
this._recordFromReq.set(request, { span, attributes, startTime });
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
// This is the 2nd message we receive for each request. It is fired when connection with
|
|
294
|
+
// the remote is established and about to send the first byte. Here we do have info about the
|
|
295
|
+
// remote address and port so we can populate some `network.*` attributes into the span
|
|
296
|
+
onRequestHeaders({ request, socket }) {
|
|
297
|
+
const record = this._recordFromReq.get(request);
|
|
298
|
+
|
|
299
|
+
if (!record) {
|
|
300
|
+
return;
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
const config = this.getConfig();
|
|
304
|
+
const { span } = record;
|
|
305
|
+
const { remoteAddress, remotePort } = socket;
|
|
306
|
+
const spanAttributes = {
|
|
307
|
+
[ATTR_NETWORK_PEER_ADDRESS]: remoteAddress,
|
|
308
|
+
[ATTR_NETWORK_PEER_PORT]: remotePort,
|
|
309
|
+
};
|
|
310
|
+
|
|
311
|
+
// After hooks have been processed (which may modify request headers)
|
|
312
|
+
// we can collect the headers based on the configuration
|
|
313
|
+
if (config.headersToSpanAttributes?.requestHeaders) {
|
|
314
|
+
const headersToAttribs = new Set(config.headersToSpanAttributes.requestHeaders.map(n => n.toLowerCase()));
|
|
315
|
+
const headersMap = this.parseRequestHeaders(request);
|
|
316
|
+
|
|
317
|
+
for (const [name, value] of headersMap.entries()) {
|
|
318
|
+
if (headersToAttribs.has(name)) {
|
|
319
|
+
const attrValue = Array.isArray(value) ? value : [value];
|
|
320
|
+
spanAttributes[`http.request.header.${name}`] = attrValue;
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
span.setAttributes(spanAttributes);
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
// This is the 3rd message we get for each request and it's fired when the server
|
|
329
|
+
// headers are received, body may not be accessible yet.
|
|
330
|
+
// From the response headers we can set the status and content length
|
|
331
|
+
onResponseHeaders({ request, response }) {
|
|
332
|
+
const record = this._recordFromReq.get(request);
|
|
333
|
+
|
|
334
|
+
if (!record) {
|
|
335
|
+
return;
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
const { span, attributes } = record;
|
|
339
|
+
const spanAttributes = {
|
|
340
|
+
[ATTR_HTTP_RESPONSE_STATUS_CODE]: response.statusCode,
|
|
341
|
+
};
|
|
342
|
+
|
|
343
|
+
const config = this.getConfig();
|
|
344
|
+
|
|
345
|
+
// Execute the response hook if defined
|
|
346
|
+
safeExecuteInTheMiddle(
|
|
347
|
+
() => config.responseHook?.(span, { request, response }),
|
|
348
|
+
e => e && this._diag.error('caught responseHook error: ', e),
|
|
349
|
+
true,
|
|
350
|
+
);
|
|
351
|
+
|
|
352
|
+
if (config.headersToSpanAttributes?.responseHeaders) {
|
|
353
|
+
const headersToAttribs = new Set();
|
|
354
|
+
config.headersToSpanAttributes?.responseHeaders.forEach(name => headersToAttribs.add(name.toLowerCase()));
|
|
355
|
+
|
|
356
|
+
for (let idx = 0; idx < response.headers.length; idx = idx + 2) {
|
|
357
|
+
const nameBuf = response.headers[idx];
|
|
358
|
+
const valueBuf = response.headers[idx + 1];
|
|
359
|
+
if (nameBuf === undefined || valueBuf === undefined) {
|
|
360
|
+
continue;
|
|
361
|
+
}
|
|
362
|
+
const name = nameBuf.toString().toLowerCase();
|
|
363
|
+
const value = valueBuf;
|
|
364
|
+
|
|
365
|
+
if (headersToAttribs.has(name)) {
|
|
366
|
+
const attrName = `http.response.header.${name}`;
|
|
367
|
+
if (!Object.prototype.hasOwnProperty.call(spanAttributes, attrName)) {
|
|
368
|
+
spanAttributes[attrName] = [value.toString()];
|
|
369
|
+
} else {
|
|
370
|
+
(spanAttributes[attrName] ).push(value.toString());
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
span.setAttributes(spanAttributes);
|
|
377
|
+
span.setStatus({
|
|
378
|
+
code: response.statusCode >= 400 ? SpanStatusCode.ERROR : SpanStatusCode.UNSET,
|
|
379
|
+
});
|
|
380
|
+
record.attributes = Object.assign(attributes, spanAttributes);
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
// This is the last event we receive if the request went without any errors
|
|
384
|
+
onDone({ request }) {
|
|
385
|
+
const record = this._recordFromReq.get(request);
|
|
386
|
+
|
|
387
|
+
if (!record) {
|
|
388
|
+
return;
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
const { span, attributes, startTime } = record;
|
|
392
|
+
|
|
393
|
+
// End the span
|
|
394
|
+
span.end();
|
|
395
|
+
this._recordFromReq.delete(request);
|
|
396
|
+
|
|
397
|
+
// Record metrics
|
|
398
|
+
this.recordRequestDuration(attributes, startTime);
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
// This is the event we get when something is wrong in the request like
|
|
402
|
+
// - invalid options when calling `fetch` global API or any undici method for request
|
|
403
|
+
// - connectivity errors such as unreachable host
|
|
404
|
+
// - requests aborted through an `AbortController.signal`
|
|
405
|
+
// NOTE: server errors are considered valid responses and it's the lib consumer
|
|
406
|
+
// who should deal with that.
|
|
407
|
+
onError({ request, error }) {
|
|
408
|
+
const record = this._recordFromReq.get(request);
|
|
409
|
+
|
|
410
|
+
if (!record) {
|
|
411
|
+
return;
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
const { span, attributes, startTime } = record;
|
|
415
|
+
|
|
416
|
+
// NOTE: in `undici@6.3.0` when request aborted the error type changes from
|
|
417
|
+
// a custom error (`RequestAbortedError`) to a built-in `DOMException` carrying
|
|
418
|
+
// some differences:
|
|
419
|
+
// - `code` is from DOMEXception (ABORT_ERR: 20)
|
|
420
|
+
// - `message` changes
|
|
421
|
+
// - stacktrace is smaller and contains node internal frames
|
|
422
|
+
span.recordException(error);
|
|
423
|
+
span.setStatus({
|
|
424
|
+
code: SpanStatusCode.ERROR,
|
|
425
|
+
message: error.message,
|
|
426
|
+
});
|
|
427
|
+
span.end();
|
|
428
|
+
this._recordFromReq.delete(request);
|
|
429
|
+
|
|
430
|
+
// Record metrics (with the error)
|
|
431
|
+
attributes[ATTR_ERROR_TYPE] = error.message;
|
|
432
|
+
this.recordRequestDuration(attributes, startTime);
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
recordRequestDuration(attributes, startTime) {
|
|
436
|
+
// Time to record metrics
|
|
437
|
+
const metricsAttributes = {};
|
|
438
|
+
// Get the attribs already in span attributes
|
|
439
|
+
const keysToCopy = [
|
|
440
|
+
ATTR_HTTP_RESPONSE_STATUS_CODE,
|
|
441
|
+
ATTR_HTTP_REQUEST_METHOD,
|
|
442
|
+
ATTR_SERVER_ADDRESS,
|
|
443
|
+
ATTR_SERVER_PORT,
|
|
444
|
+
ATTR_URL_SCHEME,
|
|
445
|
+
ATTR_ERROR_TYPE,
|
|
446
|
+
];
|
|
447
|
+
keysToCopy.forEach(key => {
|
|
448
|
+
if (key in attributes) {
|
|
449
|
+
metricsAttributes[key] = attributes[key];
|
|
450
|
+
}
|
|
451
|
+
});
|
|
452
|
+
|
|
453
|
+
// Take the duration and record it
|
|
454
|
+
const durationSeconds = hrTimeToMilliseconds(hrTimeDuration(startTime, hrTime())) / 1000;
|
|
455
|
+
this._httpClientDurationHistogram.record(durationSeconds, metricsAttributes);
|
|
456
|
+
}
|
|
457
|
+
|
|
458
|
+
getRequestMethod(original) {
|
|
459
|
+
const knownMethods = {
|
|
460
|
+
CONNECT: true,
|
|
461
|
+
OPTIONS: true,
|
|
462
|
+
HEAD: true,
|
|
463
|
+
GET: true,
|
|
464
|
+
POST: true,
|
|
465
|
+
PUT: true,
|
|
466
|
+
PATCH: true,
|
|
467
|
+
DELETE: true,
|
|
468
|
+
TRACE: true,
|
|
469
|
+
// QUERY from https://datatracker.ietf.org/doc/draft-ietf-httpbis-safe-method-w-body/
|
|
470
|
+
QUERY: true,
|
|
471
|
+
};
|
|
472
|
+
|
|
473
|
+
if (original.toUpperCase() in knownMethods) {
|
|
474
|
+
return original.toUpperCase();
|
|
475
|
+
}
|
|
476
|
+
|
|
477
|
+
return '_OTHER';
|
|
478
|
+
}
|
|
479
|
+
}
|
|
480
|
+
|
|
481
|
+
export { UndiciInstrumentation };
|
|
482
|
+
//# 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":[],"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,SAA8B,mBAAmB,CAA8B;AAC5F;AACA;;AAEA,kBAAU,cAAA,GAAiB,IAAI,OAAO,GAAuC;;AAI7E,EAAE,WAAW,CAAC,MAAM,GAAgC,EAAE,EAAE;AACxD,IAAI,KAAK,CAAC,YAAY,EAAE,WAAW,EAAE,MAAM,CAAA,CAAA,qBAAA,CAAA,SAAA,CAAA,MAAA,CAAA,IAAA,CAAA,IAAA,CAAA,CAC3C,EAAE;;AAEF;AACA,IAAqB,IAAI,GAAG;AAC5B,IAAI,OAAO,SAAS;AACpB,EAAE;;AAEF,GAAW,OAAO,GAAS;AAC3B,IAAI,KAAK,CAAC,OAAO,EAAE;AACnB,IAAI,IAAI,CAAC,YAAY,CAAC,OAAO,CAAC,GAAA,IAAO,GAAG,CAAC,WAAW,EAAE,CAAC;AACvD,IAAI,IAAI,CAAC,YAAY,CAAC,MAAA,GAAS,CAAC;AAChC,EAAE;;AAEF,GAAW,MAAM,GAAS;AAC1B;AACA;AACA;AACA;AACA;AAC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A,MAAA,CAAA,eAAA,EAAA,iBAAA,CAAA;AACA,EAAA;;AAEA,GAAA,gBAAA,CAAA,QAAA,EAAA;AACA,IAAA,MAAA,YAAA,GAAA;AACA,MAAA,OAAA,EAAA,IAAA;AACA,MAAA,OAAA,EAAA,IAAA;AACA,MAAA,IAAA,EAAA,IAAA;AACA,MAAA,GAAA,EAAA,IAAA;AACA,MAAA,IAAA,EAAA,IAAA;AACA,MAAA,GAAA,EAAA,IAAA;AACA,MAAA,KAAA,EAAA,IAAA;AACA,MAAA,MAAA,EAAA,IAAA;AACA,MAAA,KAAA,EAAA,IAAA;AACA;AACA,MAAA,KAAA,EAAA,IAAA;AACA,KAAA;;AAEA,IAAA,IAAA,QAAA,CAAA,WAAA,EAAA,IAAA,YAAA,EAAA;AACA,MAAA,OAAA,QAAA,CAAA,WAAA,EAAA;AACA,IAAA;;AAEA,IAAA,OAAA,QAAA;AACA,EAAA;AACA;;;;"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { InstrumentationBase, InstrumentationNodeModuleDefinition, InstrumentationNodeModuleFile } from '@opentelemetry/instrumentation';
|
|
2
|
-
import { SDK_VERSION, instrumentLangGraph } from '@sentry/core';
|
|
2
|
+
import { SDK_VERSION, getClient, instrumentLangGraph, instrumentCreateReactAgent } from '@sentry/core';
|
|
3
3
|
|
|
4
4
|
const supportedVersions = ['>=0.0.0 <2.0.0'];
|
|
5
5
|
|
|
@@ -15,39 +15,84 @@ class SentryLangGraphInstrumentation extends InstrumentationBase {
|
|
|
15
15
|
* Initializes the instrumentation by defining the modules to be patched.
|
|
16
16
|
*/
|
|
17
17
|
init() {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
18
|
+
return [
|
|
19
|
+
new InstrumentationNodeModuleDefinition(
|
|
20
|
+
'@langchain/langgraph',
|
|
21
|
+
supportedVersions,
|
|
22
|
+
this._patch.bind(this),
|
|
23
|
+
exports$1 => exports$1,
|
|
24
|
+
[
|
|
25
|
+
new InstrumentationNodeModuleFile(
|
|
26
|
+
/**
|
|
27
|
+
* In CJS, LangGraph packages re-export from dist/index.cjs files.
|
|
28
|
+
* Patching only the root module sometimes misses the real implementation or
|
|
29
|
+
* gets overwritten when that file is loaded. We add a file-level patch so that
|
|
30
|
+
* _patch runs again on the concrete implementation
|
|
31
|
+
*/
|
|
32
|
+
'@langchain/langgraph/dist/index.cjs',
|
|
33
|
+
supportedVersions,
|
|
34
|
+
this._patch.bind(this),
|
|
35
|
+
exports$1 => exports$1,
|
|
36
|
+
),
|
|
37
|
+
new InstrumentationNodeModuleFile(
|
|
38
|
+
/**
|
|
39
|
+
* In CJS, the prebuilt submodule re-exports from dist/prebuilt/index.cjs.
|
|
40
|
+
* We add a file-level patch under the main module so that CJS require()
|
|
41
|
+
* of @langchain/langgraph/prebuilt gets patched.
|
|
42
|
+
*/
|
|
43
|
+
'@langchain/langgraph/dist/prebuilt/index.cjs',
|
|
44
|
+
supportedVersions,
|
|
45
|
+
this._patch.bind(this),
|
|
46
|
+
exports$1 => exports$1,
|
|
47
|
+
),
|
|
48
|
+
],
|
|
49
|
+
),
|
|
50
|
+
new InstrumentationNodeModuleDefinition(
|
|
51
|
+
'@langchain/langgraph/prebuilt',
|
|
52
|
+
supportedVersions,
|
|
53
|
+
this._patch.bind(this),
|
|
54
|
+
exports$1 => exports$1,
|
|
55
|
+
[
|
|
56
|
+
new InstrumentationNodeModuleFile(
|
|
57
|
+
/**
|
|
58
|
+
* In CJS, the prebuilt submodule re-exports from dist/prebuilt/index.cjs.
|
|
59
|
+
* We add file-level patches so _patch runs on the concrete implementation.
|
|
60
|
+
*/
|
|
61
|
+
'@langchain/langgraph/dist/prebuilt/index.cjs',
|
|
62
|
+
supportedVersions,
|
|
63
|
+
this._patch.bind(this),
|
|
64
|
+
exports$1 => exports$1,
|
|
65
|
+
),
|
|
66
|
+
],
|
|
67
|
+
),
|
|
68
|
+
];
|
|
39
69
|
}
|
|
40
70
|
|
|
41
71
|
/**
|
|
42
72
|
* Core patch logic applying instrumentation to the LangGraph module.
|
|
43
73
|
*/
|
|
44
74
|
_patch(exports$1) {
|
|
75
|
+
const client = getClient();
|
|
76
|
+
const options = {
|
|
77
|
+
...this.getConfig(),
|
|
78
|
+
recordInputs: this.getConfig().recordInputs ?? client?.getOptions().sendDefaultPii,
|
|
79
|
+
recordOutputs: this.getConfig().recordOutputs ?? client?.getOptions().sendDefaultPii,
|
|
80
|
+
};
|
|
81
|
+
|
|
45
82
|
// Patch StateGraph.compile to instrument both compile() and invoke()
|
|
46
83
|
if (exports$1.StateGraph && typeof exports$1.StateGraph === 'function') {
|
|
47
|
-
instrumentLangGraph(
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
84
|
+
instrumentLangGraph(exports$1.StateGraph.prototype , options);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
// Patch createReactAgent to instrument agent creation and invocation
|
|
88
|
+
if (exports$1.createReactAgent && typeof exports$1.createReactAgent === 'function') {
|
|
89
|
+
const originalCreateReactAgent = exports$1.createReactAgent;
|
|
90
|
+
Object.defineProperty(exports$1, 'createReactAgent', {
|
|
91
|
+
value: instrumentCreateReactAgent(originalCreateReactAgent , options),
|
|
92
|
+
writable: true,
|
|
93
|
+
enumerable: true,
|
|
94
|
+
configurable: true,
|
|
95
|
+
});
|
|
51
96
|
}
|
|
52
97
|
|
|
53
98
|
return exports$1;
|