dd-trace 5.137.0 → 5.138.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/index.d.ts +56 -0
- package/initialize.mjs +5 -3
- package/package.json +9 -8
- package/packages/datadog-instrumentations/src/ai.js +88 -127
- package/packages/datadog-instrumentations/src/aws-lambda.js +9 -0
- package/packages/datadog-instrumentations/src/helpers/hooks.js +0 -1
- package/packages/datadog-instrumentations/src/helpers/instrument.js +1 -3
- package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentation-registry.js +4 -1
- package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/ai.js +2 -0
- package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/graphql-jit.js +5 -3
- package/packages/datadog-instrumentations/src/modelcontextprotocol-sdk.js +26 -2
- package/packages/datadog-instrumentations/src/modelcontextprotocol-server.js +3 -1
- package/packages/datadog-instrumentations/src/path-to-regexp.js +11 -11
- package/packages/datadog-instrumentations/src/router.js +17 -1
- package/packages/datadog-instrumentations/src/vitest-main-no-worker-init.js +1 -1
- package/packages/datadog-plugin-aws-lambda/src/context/events.js +167 -0
- package/packages/datadog-plugin-aws-lambda/src/context/extractor.js +153 -0
- package/packages/datadog-plugin-aws-lambda/src/context/http.js +50 -0
- package/packages/datadog-plugin-aws-lambda/src/context/span-context.js +26 -0
- package/packages/datadog-plugin-aws-lambda/src/context/step-functions.js +142 -0
- package/packages/datadog-plugin-aws-lambda/src/context/types.d.ts +17 -0
- package/packages/datadog-plugin-aws-lambda/src/context/xray.js +67 -0
- package/packages/datadog-plugin-aws-lambda/src/index.js +52 -4
- package/packages/datadog-plugin-azure-functions/src/index.js +68 -12
- package/packages/datadog-plugin-fetch/src/index.js +7 -0
- package/packages/datadog-plugin-http/src/client.js +12 -0
- package/packages/datadog-plugin-http/src/server.js +18 -4
- package/packages/dd-trace/src/aiguard/client.js +7 -9
- package/packages/dd-trace/src/aiguard/evaluation.js +7 -2
- package/packages/dd-trace/src/aiguard/messages/utils.js +2 -2
- package/packages/dd-trace/src/aiguard/sdk.js +7 -2
- package/packages/dd-trace/src/appsec/api_security/normalized-route.js +273 -167
- package/packages/dd-trace/src/appsec/channels.js +1 -0
- package/packages/dd-trace/src/appsec/iast/taint-tracking/plugin.js +21 -14
- package/packages/dd-trace/src/appsec/index.js +3 -0
- package/packages/dd-trace/src/appsec/rasp/index.js +57 -3
- package/packages/dd-trace/src/appsec/rasp/utils.js +14 -0
- package/packages/dd-trace/src/carrier.js +7 -1
- package/packages/dd-trace/src/ci-visibility/dynamic-instrumentation/index.js +4 -2
- package/packages/dd-trace/src/ci-visibility/dynamic-instrumentation/worker/index.js +31 -19
- package/packages/dd-trace/src/config/generated-config-types.d.ts +10 -3
- package/packages/dd-trace/src/config/index.js +28 -2
- package/packages/dd-trace/src/config/parsers.js +25 -0
- package/packages/dd-trace/src/config/supported-configurations.json +27 -7
- package/packages/dd-trace/src/datastreams/http.js +57 -0
- package/packages/dd-trace/src/datastreams/index.js +24 -0
- package/packages/dd-trace/src/datastreams/pathway.js +33 -4
- package/packages/dd-trace/src/datastreams/processor.js +22 -3
- package/packages/dd-trace/src/lambda/handler-paths.js +1 -1
- package/packages/dd-trace/src/llmobs/constants/tags.js +1 -0
- package/packages/dd-trace/src/llmobs/plugins/modelcontextprotocol-sdk/index.js +33 -1
- package/packages/dd-trace/src/llmobs/plugins/modelcontextprotocol-sdk/utils.js +102 -1
- package/packages/dd-trace/src/llmobs/span_processor.js +3 -0
- package/packages/dd-trace/src/llmobs/tagger.js +9 -0
- package/packages/dd-trace/src/noop/span.js +0 -4
- package/packages/dd-trace/src/openfeature/flagging_provider.js +17 -0
- package/packages/dd-trace/src/opentelemetry/logs/otlp_transformer.js +2 -1
- package/packages/dd-trace/src/opentelemetry/metrics/otlp_transformer.js +2 -1
- package/packages/dd-trace/src/opentelemetry/otlp/otlp_transformer_base.js +16 -1
- package/packages/dd-trace/src/opentelemetry/trace/index.js +5 -4
- package/packages/dd-trace/src/opentelemetry/trace/otlp_http_trace_exporter.js +10 -6
- package/packages/dd-trace/src/opentelemetry/trace/otlp_transformer.js +42 -26
- package/packages/dd-trace/src/opentracing/propagation/text_map.js +4 -4
- package/packages/dd-trace/src/plugin_manager.js +2 -0
- package/packages/dd-trace/src/plugins/util/inferred_proxy.js +3 -5
- package/packages/dd-trace/src/plugins/util/url.js +1 -1
- package/packages/dd-trace/src/register-loader.js +43 -0
- package/register.js +10 -44
- package/register.mjs +27 -0
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
3
|
const OtlpTransformerBase = require('../otlp/otlp_transformer_base')
|
|
4
|
+
const { isInt64 } = require('../otlp/otlp_transformer_base')
|
|
4
5
|
const { getProtobufTypes } = require('../otlp/protobuf_loader')
|
|
5
6
|
const { AUTO_KEEP } = require('../../../../../ext/priority')
|
|
6
7
|
const { VERSION } = require('../../../../../version')
|
|
@@ -8,7 +9,7 @@ const { SAMPLING_PRIORITY_KEY } = require('../../constants')
|
|
|
8
9
|
const id = require('../../id')
|
|
9
10
|
const { eventTimeNano } = require('../../encode/tags-processors')
|
|
10
11
|
|
|
11
|
-
const { protoSpanKind } = getProtobufTypes()
|
|
12
|
+
const { protoSpanKind, protoTraceService } = getProtobufTypes()
|
|
12
13
|
const SPAN_KIND_UNSPECIFIED = protoSpanKind.values.SPAN_KIND_UNSPECIFIED
|
|
13
14
|
const SPAN_KIND_INTERNAL = protoSpanKind.values.SPAN_KIND_INTERNAL
|
|
14
15
|
const SPAN_KIND_SERVER = protoSpanKind.values.SPAN_KIND_SERVER
|
|
@@ -81,18 +82,19 @@ const EXCLUDED_META_KEYS = new Set([
|
|
|
81
82
|
const DD_ERROR_META_KEYS = new Set(['error.message'])
|
|
82
83
|
|
|
83
84
|
/**
|
|
84
|
-
* OtlpTraceTransformer transforms DD-formatted spans to OTLP trace
|
|
85
|
+
* OtlpTraceTransformer transforms DD-formatted spans to OTLP trace format.
|
|
85
86
|
*
|
|
86
87
|
* This implementation follows the OTLP trace data model:
|
|
87
88
|
* https://github.com/open-telemetry/opentelemetry-proto/blob/v1.7.0/opentelemetry/proto/trace/v1/trace.proto
|
|
88
89
|
*
|
|
89
90
|
* It receives DD-formatted spans (from span_format.js) and produces
|
|
90
|
-
* an ExportTraceServiceRequest serialized as JSON (http/json
|
|
91
|
+
* an ExportTraceServiceRequest serialized as JSON (http/json) or protobuf (http/protobuf).
|
|
91
92
|
*
|
|
92
93
|
* @class OtlpTraceTransformer
|
|
93
94
|
* @augments OtlpTransformerBase
|
|
94
95
|
*/
|
|
95
96
|
class OtlpTraceTransformer extends OtlpTransformerBase {
|
|
97
|
+
#isJson
|
|
96
98
|
#otelTraceSemanticsEnabled
|
|
97
99
|
|
|
98
100
|
// Span meta entries with the same key and value as a resource attribute are already carried by
|
|
@@ -104,10 +106,12 @@ class OtlpTraceTransformer extends OtlpTransformerBase {
|
|
|
104
106
|
* Creates a new OtlpTraceTransformer instance.
|
|
105
107
|
*
|
|
106
108
|
* @param {import('@opentelemetry/api').Attributes} resourceAttributes - Resource attributes
|
|
109
|
+
* @param {string} protocol - OTLP protocol (http/protobuf or http/json)
|
|
107
110
|
* @param {boolean} [otelTraceSemanticsEnabled] - When true, do not emit Datadog-only attributes as span attributes
|
|
108
111
|
*/
|
|
109
|
-
constructor (resourceAttributes, otelTraceSemanticsEnabled) {
|
|
110
|
-
super(resourceAttributes,
|
|
112
|
+
constructor (resourceAttributes, protocol, otelTraceSemanticsEnabled) {
|
|
113
|
+
super(resourceAttributes, protocol, 'traces')
|
|
114
|
+
this.#isJson = this.protocol === 'http/json'
|
|
111
115
|
this.#otelTraceSemanticsEnabled = otelTraceSemanticsEnabled
|
|
112
116
|
this.#resourceAttributes = resourceAttributes
|
|
113
117
|
}
|
|
@@ -122,10 +126,10 @@ class OtlpTraceTransformer extends OtlpTransformerBase {
|
|
|
122
126
|
}
|
|
123
127
|
|
|
124
128
|
/**
|
|
125
|
-
* Transforms DD-formatted spans to OTLP
|
|
129
|
+
* Transforms DD-formatted spans to OTLP format based on the configured protocol.
|
|
126
130
|
*
|
|
127
131
|
* @param {DDFormattedSpan[]} spans - Array of DD-formatted spans to transform
|
|
128
|
-
* @returns {Buffer} JSON-encoded trace data
|
|
132
|
+
* @returns {Buffer} JSON- or protobuf-encoded trace data
|
|
129
133
|
*/
|
|
130
134
|
transformSpans (spans) {
|
|
131
135
|
const traceData = {
|
|
@@ -134,7 +138,9 @@ class OtlpTraceTransformer extends OtlpTransformerBase {
|
|
|
134
138
|
scopeSpans: this.#transformScopeSpans(spans),
|
|
135
139
|
}],
|
|
136
140
|
}
|
|
137
|
-
return this
|
|
141
|
+
return this.#isJson
|
|
142
|
+
? this.serializeToJson(traceData)
|
|
143
|
+
: this.serializeToProtobuf(protoTraceService, traceData)
|
|
138
144
|
}
|
|
139
145
|
|
|
140
146
|
/**
|
|
@@ -182,9 +188,9 @@ class OtlpTraceTransformer extends OtlpTransformerBase {
|
|
|
182
188
|
const samplingPriority = span.metrics?.[SAMPLING_PRIORITY_KEY]
|
|
183
189
|
|
|
184
190
|
return {
|
|
185
|
-
traceId: span.trace_id.toTraceIdHex(traceIdHigh).padStart(32, '0'),
|
|
186
|
-
spanId: this.#
|
|
187
|
-
parentSpanId: parentId && !parentId.equals(ZERO_ID) ? this.#
|
|
191
|
+
traceId: this.#encodeId(span.trace_id.toTraceIdHex(traceIdHigh).padStart(32, '0')),
|
|
192
|
+
spanId: this.#encodeSpanId(span.span_id),
|
|
193
|
+
parentSpanId: parentId && !parentId.equals(ZERO_ID) ? this.#encodeSpanId(parentId) : undefined,
|
|
188
194
|
traceState: span.trace_state,
|
|
189
195
|
name: span.resource,
|
|
190
196
|
kind: this.#mapSpanKind(span.meta?.['span.kind']),
|
|
@@ -245,7 +251,7 @@ class OtlpTraceTransformer extends OtlpTransformerBase {
|
|
|
245
251
|
// Add metrics as numeric attributes
|
|
246
252
|
if (span.metrics) {
|
|
247
253
|
for (const [key, value] of Object.entries(span.metrics)) {
|
|
248
|
-
if (
|
|
254
|
+
if (isInt64(value)) {
|
|
249
255
|
attributes.push({ key, value: { intValue: value } })
|
|
250
256
|
} else {
|
|
251
257
|
attributes.push({ key, value: { doubleValue: value } })
|
|
@@ -253,14 +259,14 @@ class OtlpTraceTransformer extends OtlpTransformerBase {
|
|
|
253
259
|
}
|
|
254
260
|
}
|
|
255
261
|
|
|
256
|
-
//
|
|
257
|
-
//
|
|
258
|
-
//
|
|
259
|
-
//
|
|
262
|
+
// meta_struct values carry their JSON serialization so receivers decode the same bytes for every
|
|
263
|
+
// protocol; only http/json additionally base64-encodes bytesValue, per the proto JSON mapping.
|
|
264
|
+
// TODO: meta_struct values are logically raw bytes. Sending them without JSON.stringify requires
|
|
265
|
+
// the backend decoding side to accept the unencoded bytes first.
|
|
260
266
|
if (span.meta_struct) {
|
|
261
267
|
for (const [key, value] of Object.entries(span.meta_struct)) {
|
|
262
268
|
const bytes = Buffer.from(JSON.stringify(value))
|
|
263
|
-
attributes.push({ key, value: { bytesValue: bytes.toString('base64') } })
|
|
269
|
+
attributes.push({ key, value: { bytesValue: this.#isJson ? bytes.toString('base64') : bytes } })
|
|
264
270
|
}
|
|
265
271
|
}
|
|
266
272
|
|
|
@@ -352,8 +358,8 @@ class OtlpTraceTransformer extends OtlpTransformerBase {
|
|
|
352
358
|
*/
|
|
353
359
|
#transformLink (link) {
|
|
354
360
|
return {
|
|
355
|
-
traceId: this.#
|
|
356
|
-
spanId: this.#
|
|
361
|
+
traceId: this.#encodeHexId(link.trace_id, 16),
|
|
362
|
+
spanId: this.#encodeHexId(link.span_id, 8),
|
|
357
363
|
traceState: link.tracestate || '',
|
|
358
364
|
attributes: this.transformAttributes(link.attributes ?? {}),
|
|
359
365
|
droppedAttributesCount: 0,
|
|
@@ -362,22 +368,32 @@ class OtlpTraceTransformer extends OtlpTransformerBase {
|
|
|
362
368
|
}
|
|
363
369
|
|
|
364
370
|
/** @param {Identifier} identifier */
|
|
365
|
-
#
|
|
366
|
-
return identifier.toString(16).slice(-16)
|
|
371
|
+
#encodeSpanId (identifier) {
|
|
372
|
+
return this.#encodeId(identifier.toString(16).slice(-16))
|
|
367
373
|
}
|
|
368
374
|
|
|
369
375
|
/**
|
|
370
|
-
* Normalizes a hex string to the specified byte length.
|
|
376
|
+
* Normalizes a hex string to the specified byte length, then encodes it for the wire.
|
|
371
377
|
* Pads with leading zeros if the hex string is shorter than expected.
|
|
372
|
-
* Per the OTLP http/json spec, trace-ids and span-ids must be hex-encoded strings.
|
|
373
378
|
*
|
|
374
379
|
* @param {string | undefined} hexString - Hex string to normalize
|
|
375
380
|
* @param {number} targetLength - Target byte length
|
|
376
381
|
*/
|
|
377
|
-
#
|
|
378
|
-
if (!hexString) return '0'.repeat(targetLength * 2)
|
|
382
|
+
#encodeHexId (hexString, targetLength) {
|
|
383
|
+
if (!hexString) return this.#encodeId('0'.repeat(targetLength * 2))
|
|
379
384
|
const cleanHex = hexString.startsWith('0x') ? hexString.slice(2) : hexString
|
|
380
|
-
return cleanHex.padStart(targetLength * 2, '0')
|
|
385
|
+
return this.#encodeId(cleanHex.padStart(targetLength * 2, '0'))
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
/**
|
|
389
|
+
* Encodes a trace or span ID. OTLP http/json requires hex-encoded strings instead of the
|
|
390
|
+
* base64 the proto JSON mapping would use for bytes; http/protobuf carries the raw bytes.
|
|
391
|
+
*
|
|
392
|
+
* @param {string} hex - Hex-encoded ID
|
|
393
|
+
* @returns {string | Buffer}
|
|
394
|
+
*/
|
|
395
|
+
#encodeId (hex) {
|
|
396
|
+
return this.#isJson ? hex : Buffer.from(hex, 'hex')
|
|
381
397
|
}
|
|
382
398
|
}
|
|
383
399
|
|
|
@@ -333,8 +333,8 @@ class TextMapPropagator {
|
|
|
333
333
|
this.#b3InjectIsSingleHeader = true
|
|
334
334
|
this.#extractB3Context = extractB3SingleContext
|
|
335
335
|
} else {
|
|
336
|
-
const envName = getValidatedConfiguredEnvName('DD_TRACE_PROPAGATION_STYLE')
|
|
337
|
-
|
|
336
|
+
const envName = getValidatedConfiguredEnvName('DD_TRACE_PROPAGATION_STYLE') ??
|
|
337
|
+
getValidatedConfiguredEnvName('OTEL_PROPAGATORS')
|
|
338
338
|
this.#extractB3Context = envName === 'OTEL_PROPAGATORS'
|
|
339
339
|
? extractB3SingleContext
|
|
340
340
|
: extractB3MultiContext
|
|
@@ -355,13 +355,13 @@ class TextMapPropagator {
|
|
|
355
355
|
|
|
356
356
|
let envName
|
|
357
357
|
if (origin === 'calculated' && !experimentalEnabled && sharedOrigin !== 'remote_config') {
|
|
358
|
-
envName = getValidatedConfiguredEnvName('DD_TRACE_PROPAGATION_STYLE')
|
|
358
|
+
envName = getValidatedConfiguredEnvName('DD_TRACE_PROPAGATION_STYLE') ??
|
|
359
|
+
getValidatedConfiguredEnvName('OTEL_PROPAGATORS')
|
|
359
360
|
} else if (origin === 'env_var' ||
|
|
360
361
|
origin === 'local_stable_config' ||
|
|
361
362
|
origin === 'fleet_stable_config') {
|
|
362
363
|
envName = getValidatedConfiguredEnvName('DD_TRACE_PROPAGATION_STYLE_INJECT')
|
|
363
364
|
}
|
|
364
|
-
// eslint-disable-next-line eslint-rules/eslint-env-aliases
|
|
365
365
|
this.#b3InjectIsSingleHeader = envName === 'OTEL_PROPAGATORS'
|
|
366
366
|
this.#b3InjectOrigin = origin
|
|
367
367
|
this.#b3ExperimentalEnabled = experimentalEnabled
|
|
@@ -190,6 +190,7 @@ module.exports = class PluginManager {
|
|
|
190
190
|
codeOriginForSpans,
|
|
191
191
|
dbmPropagationMode,
|
|
192
192
|
dsmEnabled,
|
|
193
|
+
DD_DATA_STREAMS_HTTP_ENABLED,
|
|
193
194
|
DD_TRACE_HTTP_CLIENT_ERROR_STATUSES,
|
|
194
195
|
DD_TRACE_HTTP_SERVER_ERROR_STATUSES,
|
|
195
196
|
clientIpEnabled,
|
|
@@ -219,6 +220,7 @@ module.exports = class PluginManager {
|
|
|
219
220
|
codeOriginForSpans,
|
|
220
221
|
dbmPropagationMode,
|
|
221
222
|
dsmEnabled,
|
|
223
|
+
DD_DATA_STREAMS_HTTP_ENABLED,
|
|
222
224
|
DD_TRACE_MEMCACHED_COMMAND_ENABLED,
|
|
223
225
|
DD_TRACE_OTEL_SEMANTICS_ENABLED,
|
|
224
226
|
site,
|
|
@@ -143,16 +143,14 @@ function extractInferredProxyContext (headers) {
|
|
|
143
143
|
return null
|
|
144
144
|
}
|
|
145
145
|
|
|
146
|
+
const requestPath = headers[PROXY_HEADER_PATH]
|
|
147
|
+
|
|
146
148
|
return {
|
|
147
149
|
requestTime: headers[PROXY_HEADER_START_TIME_MS]
|
|
148
150
|
? Number.parseInt(headers[PROXY_HEADER_START_TIME_MS], 10)
|
|
149
151
|
: Date.now(),
|
|
150
152
|
method: headers[PROXY_HEADER_HTTPMETHOD],
|
|
151
|
-
path:
|
|
152
|
-
? (headers[PROXY_HEADER_PATH].startsWith('/')
|
|
153
|
-
? headers[PROXY_HEADER_PATH]
|
|
154
|
-
: '/' + headers[PROXY_HEADER_PATH])
|
|
155
|
-
: headers[PROXY_HEADER_PATH],
|
|
153
|
+
path: requestPath && !requestPath.startsWith('/') ? '/' + requestPath : requestPath,
|
|
156
154
|
stage: headers[PROXY_HEADER_STAGE],
|
|
157
155
|
domainName: headers[PROXY_HEADER_DOMAIN],
|
|
158
156
|
proxySystemName: headers[PROXY_HEADER_SYSTEM],
|
|
@@ -143,7 +143,7 @@ function buildClientHttpUrl (config, base, pathname, strippedUrl) {
|
|
|
143
143
|
*/
|
|
144
144
|
function extractPathFromUrl (url) {
|
|
145
145
|
if (!url) return '/'
|
|
146
|
-
const match =
|
|
146
|
+
const match = PATH_REGEX.exec(url)
|
|
147
147
|
|
|
148
148
|
return match?.groups?.path || '/'
|
|
149
149
|
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
// CommonJS and ESM preloads can both be used in the same process.
|
|
4
|
+
let registered = false
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* @param {typeof import('node:module').register | undefined} registerAsync
|
|
8
|
+
* @param {URL} parentURL
|
|
9
|
+
* @param {() => boolean | undefined} [tryRegisterSync] Returns undefined when sync hooks are unsupported.
|
|
10
|
+
*/
|
|
11
|
+
function registerLoader (registerAsync, parentURL, tryRegisterSync) {
|
|
12
|
+
if (registered) return
|
|
13
|
+
|
|
14
|
+
let syncResult
|
|
15
|
+
let syncError
|
|
16
|
+
try {
|
|
17
|
+
syncResult = tryRegisterSync?.()
|
|
18
|
+
} catch (error) {
|
|
19
|
+
syncResult = false
|
|
20
|
+
syncError = error
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
if (syncResult) {
|
|
24
|
+
registered = true
|
|
25
|
+
return
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
if (syncResult === false) {
|
|
29
|
+
let message = 'dd-trace could not register synchronous loader hooks.'
|
|
30
|
+
if (registerAsync) message += ' Falling back to the asynchronous loader.'
|
|
31
|
+
if (syncError?.message) message += ` ${syncError.message}`
|
|
32
|
+
process.emitWarning(message)
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// Node.js removes module.register in nodejs/node#67090.
|
|
36
|
+
if (registerAsync) {
|
|
37
|
+
const { getLoaderRegisterOptions } = require('./esm-module-load')
|
|
38
|
+
registerAsync('./loader-hook.mjs', parentURL, getLoaderRegisterOptions())
|
|
39
|
+
registered = true
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
module.exports = registerLoader
|
package/register.js
CHANGED
|
@@ -4,48 +4,24 @@
|
|
|
4
4
|
|
|
5
5
|
const { register } = require('node:module')
|
|
6
6
|
const { pathToFileURL } = require('node:url')
|
|
7
|
-
const { NODE_MAJOR, NODE_MINOR, NODE_PATCH } = require('./version')
|
|
8
|
-
|
|
9
|
-
const parentURL = pathToFileURL(__filename)
|
|
10
|
-
let isSyncLoaderRegistered = false
|
|
11
7
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
let syncRegistrationError
|
|
15
|
-
try {
|
|
16
|
-
({ registerSyncLoaderHooks } = require('./loader-hook.mjs'))
|
|
17
|
-
if (registerSyncLoaderHooks) {
|
|
18
|
-
isSyncLoaderRegistered = registerSyncLoaderHooks()
|
|
19
|
-
}
|
|
20
|
-
} catch (error) {
|
|
21
|
-
syncRegistrationError = error
|
|
22
|
-
}
|
|
8
|
+
const registerLoader = require('./packages/dd-trace/src/register-loader')
|
|
9
|
+
const { NODE_MAJOR, NODE_MINOR, NODE_PATCH } = require('./version')
|
|
23
10
|
|
|
24
|
-
|
|
25
|
-
warnSyncLoaderFallback(syncRegistrationError)
|
|
26
|
-
}
|
|
27
|
-
}
|
|
11
|
+
registerLoader(register, pathToFileURL(__filename), tryRegisterSyncLoader)
|
|
28
12
|
|
|
29
|
-
|
|
30
|
-
if (!
|
|
31
|
-
const { getLoaderRegisterOptions } = require('./packages/dd-trace/src/esm-module-load')
|
|
32
|
-
register('./loader-hook.mjs', parentURL, getLoaderRegisterOptions())
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
function shouldRegisterSyncLoaderHooks () {
|
|
36
|
-
if (!isSyncLoaderHookVersionSupported()) {
|
|
37
|
-
return false
|
|
38
|
-
}
|
|
13
|
+
function tryRegisterSyncLoader () {
|
|
14
|
+
if (!isSyncLoaderHookVersionSupported()) return
|
|
39
15
|
|
|
40
16
|
try {
|
|
41
|
-
|
|
17
|
+
if (!require('import-in-the-middle/create-hook.mjs').supportsSyncHooks()) return
|
|
42
18
|
} catch (error) {
|
|
43
|
-
if (error?.code
|
|
44
|
-
|
|
45
|
-
}
|
|
19
|
+
if (error?.code === 'ERR_REQUIRE_ESM') return
|
|
20
|
+
throw error
|
|
46
21
|
}
|
|
47
22
|
|
|
48
|
-
|
|
23
|
+
const { registerSyncLoaderHooks } = require('./loader-hook.mjs')
|
|
24
|
+
return registerSyncLoaderHooks?.() ?? false
|
|
49
25
|
}
|
|
50
26
|
|
|
51
27
|
function isSyncLoaderHookVersionSupported () {
|
|
@@ -55,13 +31,3 @@ function isSyncLoaderHookVersionSupported () {
|
|
|
55
31
|
if (NODE_MAJOR === 22) return NODE_MINOR > 22 || (NODE_MINOR === 22 && NODE_PATCH >= 3)
|
|
56
32
|
return false
|
|
57
33
|
}
|
|
58
|
-
|
|
59
|
-
function warnSyncLoaderFallback (error) {
|
|
60
|
-
let message = 'dd-trace could not register synchronous loader hooks. Falling back to the asynchronous loader.'
|
|
61
|
-
|
|
62
|
-
if (error?.message) {
|
|
63
|
-
message += ` ${error.message}`
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
process.emitWarning(message)
|
|
67
|
-
}
|
package/register.mjs
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Registers the dd-trace loader hooks from an ES module. Unlike register.js, it loads the
|
|
3
|
+
* synchronous hooks through `import()`, so it does not depend on require(esm), which AWS Lambda
|
|
4
|
+
* disables. Without require(esm), register.js can only use the asynchronous `module.register`
|
|
5
|
+
* loader, which Node.js 26 deprecates.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
/* eslint n/no-unsupported-features/node-builtins: ['error', { ignores: ['module.register'] }] */
|
|
9
|
+
|
|
10
|
+
import * as Module from 'node:module'
|
|
11
|
+
|
|
12
|
+
import { supportsSyncHooks } from 'import-in-the-middle/supports-sync-hooks.mjs'
|
|
13
|
+
|
|
14
|
+
import registerLoader from './packages/dd-trace/src/register-loader.js'
|
|
15
|
+
|
|
16
|
+
let registerSyncLoaderHooks
|
|
17
|
+
|
|
18
|
+
if (supportsSyncHooks()) {
|
|
19
|
+
try {
|
|
20
|
+
({ registerSyncLoaderHooks } = await import('./loader-hook.mjs'))
|
|
21
|
+
registerSyncLoaderHooks ??= () => false
|
|
22
|
+
} catch (error) {
|
|
23
|
+
registerSyncLoaderHooks = () => { throw error }
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
registerLoader(Module.register, new URL(import.meta.url), registerSyncLoaderHooks)
|