dd-trace 6.15.0 → 6.16.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/README.md +15 -0
- package/ci/test-optimization-validation/framework-adapters/cucumber.js +4 -2
- package/ci/test-optimization-validation/package-check.js +4 -1
- package/ci/test-optimization-validation/scenarios/ci-wiring.js +1 -1
- package/index.d.ts +4 -0
- package/next.d.ts +27 -0
- package/next.js +3 -0
- package/package.json +15 -11
- package/packages/datadog-esbuild/index.js +14 -1
- package/packages/datadog-esbuild/src/resolver.js +284 -0
- package/packages/datadog-esbuild/src/utils.js +163 -119
- package/packages/datadog-instrumentations/src/ai.js +39 -97
- package/packages/datadog-instrumentations/src/anthropic.js +76 -134
- package/packages/datadog-instrumentations/src/aws-durable-execution-sdk-js.js +1 -1
- package/packages/datadog-instrumentations/src/azure-cosmos.js +1 -1
- package/packages/datadog-instrumentations/src/azure-durable-functions.js +23 -9
- package/packages/datadog-instrumentations/src/azure-functions.js +48 -0
- package/packages/datadog-instrumentations/src/bullmq.js +1 -1
- package/packages/datadog-instrumentations/src/claude-agent-sdk.js +1 -1
- package/packages/datadog-instrumentations/src/dd-trace-api.js +2 -2
- package/packages/datadog-instrumentations/src/graphql.js +1 -1
- package/packages/datadog-instrumentations/src/helpers/bundler-register.js +39 -14
- package/packages/datadog-instrumentations/src/helpers/instrument.js +25 -8
- package/packages/datadog-instrumentations/src/helpers/instrumentation-utils.js +72 -0
- package/packages/datadog-instrumentations/src/helpers/register.js +9 -64
- package/packages/datadog-instrumentations/src/helpers/rewriter/index.js +46 -14
- package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/azure-durable-functions.js +17 -0
- package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/index.js +1 -0
- package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/webdriverio.js +6 -7
- package/packages/datadog-instrumentations/src/helpers/rewriter/targets.json +1 -0
- package/packages/datadog-instrumentations/src/helpers/rewriter/transforms.js +99 -70
- package/packages/datadog-instrumentations/src/langchain.js +1 -1
- package/packages/datadog-instrumentations/src/langgraph.js +1 -1
- package/packages/datadog-instrumentations/src/mercurius.js +1 -1
- package/packages/datadog-instrumentations/src/modelcontextprotocol-sdk.js +1 -1
- package/packages/datadog-instrumentations/src/openai-agents.js +1 -1
- package/packages/datadog-instrumentations/src/openai.js +54 -76
- package/packages/datadog-instrumentations/src/vitest-worker.js +7 -10
- package/packages/datadog-plugin-aws-sdk/src/services/bedrockruntime/utils.js +7 -1
- package/packages/datadog-plugin-azure-cosmos/src/index.js +1 -1
- package/packages/datadog-plugin-azure-durable-functions/src/index.js +96 -1
- package/packages/datadog-plugin-google-cloud-pubsub/src/consumer.js +2 -24
- package/packages/datadog-plugin-google-cloud-pubsub/src/pubsub-push-subscription.js +2 -36
- package/packages/datadog-plugin-google-cloud-pubsub/src/pubsub-request-context.js +31 -0
- package/packages/datadog-plugin-graphql/src/resolve-error.js +33 -11
- package/packages/datadog-turbopack/index.js +212 -0
- package/packages/datadog-turbopack/src/constants.js +5 -0
- package/packages/datadog-turbopack/src/loader.js +500 -0
- package/packages/dd-trace/src/aiguard/index.js +2 -1
- package/packages/dd-trace/src/aiguard/integrations/anthropic.js +53 -25
- package/packages/dd-trace/src/aiguard/integrations/evaluate.js +49 -25
- package/packages/dd-trace/src/aiguard/integrations/index.js +3 -2
- package/packages/dd-trace/src/aiguard/integrations/openai.js +59 -30
- package/packages/dd-trace/src/aiguard/integrations/vercel-ai.js +116 -42
- package/packages/dd-trace/src/aiguard/messages/utils.js +29 -1
- package/packages/dd-trace/src/aiguard/messages/vercel-ai.js +25 -0
- package/packages/dd-trace/src/appsec/iast/vulnerabilities-formatter/evidence-redaction/sensitive-analyzers/url-sensitive-analyzer.js +2 -2
- package/packages/dd-trace/src/appsec/telemetry/api_security.js +1 -3
- package/packages/dd-trace/src/appsec/telemetry/common.js +4 -0
- package/packages/dd-trace/src/appsec/telemetry/index.js +23 -5
- package/packages/dd-trace/src/appsec/telemetry/rasp.js +1 -20
- package/packages/dd-trace/src/appsec/telemetry/user.js +1 -3
- package/packages/dd-trace/src/appsec/telemetry/waf.js +1 -20
- package/packages/dd-trace/src/config/generated-config-types.d.ts +2 -0
- package/packages/dd-trace/src/config/helper.js +10 -2
- package/packages/dd-trace/src/config/index.js +20 -5
- package/packages/dd-trace/src/config/supported-configurations.json +8 -0
- package/packages/dd-trace/src/debugger/devtools_client/breakpoints.js +14 -7
- package/packages/dd-trace/src/debugger/devtools_client/probe_sampler.js +14 -1
- package/packages/dd-trace/src/evp_proxy/discovery.js +3 -4
- package/packages/dd-trace/src/evp_proxy/path.js +12 -3
- package/packages/dd-trace/src/exporters/common/docker.js +4 -1
- package/packages/dd-trace/src/exporters/common/proxy.js +3 -0
- package/packages/dd-trace/src/opentelemetry/metrics/index.js +1 -1
- package/packages/dd-trace/src/opentelemetry/metrics/meter_provider.js +5 -4
- package/packages/dd-trace/src/opentelemetry/metrics/periodic_metric_reader.js +106 -25
- package/packages/dd-trace/src/opentelemetry/otlp/otlp_http_exporter_base.js +7 -1
- package/packages/dd-trace/src/plugin_manager.js +9 -3
- package/packages/dd-trace/src/plugins/index.js +1 -0
- package/packages/dd-trace/src/plugins/util/test.js +4 -1
- package/packages/dd-trace/src/llmobs/plugins/claude-agent-sdk/utils.js +0 -10
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
const fs = require('node:fs')
|
|
4
|
+
const Module = require('node:module')
|
|
5
|
+
const path = require('node:path')
|
|
6
|
+
|
|
7
|
+
const satisfies = require('../../vendor/dist/semifies')
|
|
8
|
+
const hooks = require('../datadog-instrumentations/src/helpers/hooks')
|
|
9
|
+
const { SYNTHETIC_EXTENSION } = require('./src/constants')
|
|
10
|
+
|
|
11
|
+
const BUILTIN_MODULES = new Set(Module.builtinModules)
|
|
12
|
+
const loader = path.join(__dirname, 'src/loader.js')
|
|
13
|
+
const EXTENSIONLESS_PATH_PATTERN = /(?:^|\/)[^/.]+$/
|
|
14
|
+
const PHASE_PRODUCTION_SERVER = 'phase-production-server'
|
|
15
|
+
const SOURCE_EXTENSIONS = ['*.js', '*.cjs', '*.mjs', '*.jsx', '*.ts', '*.cts', '*.mts', '*.tsx']
|
|
16
|
+
const SOURCE_PATH_PATTERN = /\.(?:cjs|cts|js|jsx|mjs|mts|ts|tsx)$/
|
|
17
|
+
const PACKAGE_PATH_PATTERN = createPackagePathPattern()
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Adds Datadog instrumentation to a Next.js Turbopack configuration.
|
|
21
|
+
*
|
|
22
|
+
* @param {object|Promise<object>|Function} [nextConfig]
|
|
23
|
+
* @returns {Function}
|
|
24
|
+
*/
|
|
25
|
+
function withDatadogTurbopack (nextConfig = {}) {
|
|
26
|
+
const nextMajor = getNextMajor()
|
|
27
|
+
|
|
28
|
+
return function datadogNextConfig (...args) {
|
|
29
|
+
const config = typeof nextConfig === 'function'
|
|
30
|
+
? nextConfig.apply(this, args)
|
|
31
|
+
: nextConfig
|
|
32
|
+
if (config && typeof config.then === 'function') {
|
|
33
|
+
return config.then(config => configureTurbopack(config, args[0], nextMajor))
|
|
34
|
+
}
|
|
35
|
+
return configureTurbopack(config, args[0], nextMajor)
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* @param {object|undefined} config
|
|
41
|
+
* @param {unknown} phase
|
|
42
|
+
* @param {number} nextMajor
|
|
43
|
+
* @returns {object}
|
|
44
|
+
*/
|
|
45
|
+
function configureTurbopack (config, phase, nextMajor) {
|
|
46
|
+
const normalized = normalizeConfig(config)
|
|
47
|
+
if (phase === PHASE_PRODUCTION_SERVER || hasDatadogLoader(normalized.turbopack?.rules)) return normalized
|
|
48
|
+
|
|
49
|
+
const turbopack = normalized.turbopack ?? {}
|
|
50
|
+
const configured = nextMajor === 15 ? addLegacyRule(turbopack) : addModernRules(turbopack)
|
|
51
|
+
return { ...normalized, turbopack: configured }
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* @param {object|undefined} config
|
|
56
|
+
* @returns {object}
|
|
57
|
+
*/
|
|
58
|
+
function normalizeConfig (config) {
|
|
59
|
+
if (config === undefined) return {}
|
|
60
|
+
if (!isObject(config)) {
|
|
61
|
+
throw new TypeError('withDatadogTurbopack expects a Next.js configuration object, promise, or function')
|
|
62
|
+
}
|
|
63
|
+
if (config.turbopack !== undefined && !isObject(config.turbopack)) {
|
|
64
|
+
throw new TypeError('nextConfig.turbopack must be an object')
|
|
65
|
+
}
|
|
66
|
+
if (config.turbopack?.rules !== undefined && !isObject(config.turbopack.rules)) {
|
|
67
|
+
throw new TypeError('nextConfig.turbopack.rules must be an object')
|
|
68
|
+
}
|
|
69
|
+
if (config.turbopack?.conditions !== undefined && !isObject(config.turbopack.conditions)) {
|
|
70
|
+
throw new TypeError('nextConfig.turbopack.conditions must be an object')
|
|
71
|
+
}
|
|
72
|
+
return config
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* @param {unknown} value
|
|
77
|
+
* @returns {boolean}
|
|
78
|
+
*/
|
|
79
|
+
function isObject (value) {
|
|
80
|
+
return Boolean(value) && typeof value === 'object' && !Array.isArray(value)
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* @param {object} turbopack
|
|
85
|
+
* @returns {object}
|
|
86
|
+
*/
|
|
87
|
+
function addModernRules (turbopack) {
|
|
88
|
+
const rules = { ...turbopack.rules }
|
|
89
|
+
for (const extension of SOURCE_EXTENSIONS) {
|
|
90
|
+
appendRule(rules, extension, {
|
|
91
|
+
condition: { all: ['node', 'foreign', { path: PACKAGE_PATH_PATTERN }] },
|
|
92
|
+
loaders: [createLoader()],
|
|
93
|
+
})
|
|
94
|
+
}
|
|
95
|
+
appendRule(rules, '*', {
|
|
96
|
+
as: `*${SYNTHETIC_EXTENSION}`,
|
|
97
|
+
condition: {
|
|
98
|
+
all: ['node', 'foreign', { path: PACKAGE_PATH_PATTERN }, { path: EXTENSIONLESS_PATH_PATTERN }],
|
|
99
|
+
},
|
|
100
|
+
loaders: [createLoader()],
|
|
101
|
+
})
|
|
102
|
+
return { ...turbopack, rules }
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* @param {Record<string, object|object[]>} rules
|
|
107
|
+
* @param {string} extension
|
|
108
|
+
* @param {object} rule
|
|
109
|
+
*/
|
|
110
|
+
function appendRule (rules, extension, rule) {
|
|
111
|
+
const existing = rules[extension]
|
|
112
|
+
if (existing === undefined) {
|
|
113
|
+
rules[extension] = rule
|
|
114
|
+
} else {
|
|
115
|
+
rules[extension] = Array.isArray(existing) ? [...existing, rule] : [existing, rule]
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* @param {object} turbopack
|
|
121
|
+
* @returns {object}
|
|
122
|
+
*/
|
|
123
|
+
function addLegacyRule (turbopack) {
|
|
124
|
+
const name = '#dd-trace/modules'
|
|
125
|
+
const conditions = { ...turbopack.conditions }
|
|
126
|
+
const rules = { ...turbopack.rules }
|
|
127
|
+
if (Object.hasOwn(conditions, name) || Object.hasOwn(rules, name)) {
|
|
128
|
+
throw new Error(`Next.js Turbopack configuration already uses the reserved condition ${name}`)
|
|
129
|
+
}
|
|
130
|
+
conditions[name] = {
|
|
131
|
+
all: [
|
|
132
|
+
{ path: PACKAGE_PATH_PATTERN },
|
|
133
|
+
{ any: [{ path: SOURCE_PATH_PATTERN }, { path: EXTENSIONLESS_PATH_PATTERN }] },
|
|
134
|
+
],
|
|
135
|
+
}
|
|
136
|
+
rules[name] = { node: { foreign: { loaders: [createLoader()] } } }
|
|
137
|
+
return { ...turbopack, conditions, rules }
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* @returns {{ loader: string, options: object }}
|
|
142
|
+
*/
|
|
143
|
+
function createLoader () {
|
|
144
|
+
return { loader, options: {} }
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* @param {unknown} value
|
|
149
|
+
* @returns {boolean}
|
|
150
|
+
*/
|
|
151
|
+
function hasDatadogLoader (value) {
|
|
152
|
+
if (Array.isArray(value)) return value.some(hasDatadogLoader)
|
|
153
|
+
if (!value || typeof value !== 'object') return false
|
|
154
|
+
if (/** @type {{ loader?: unknown }} */ (value).loader === loader) return true
|
|
155
|
+
return Object.values(value).some(hasDatadogLoader)
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* @returns {RegExp}
|
|
160
|
+
*/
|
|
161
|
+
function createPackagePathPattern () {
|
|
162
|
+
const names = []
|
|
163
|
+
for (const name of Object.keys(hooks)) {
|
|
164
|
+
if (!name.startsWith('.') && !BUILTIN_MODULES.has(name)) names.push(escapeRegExp(name))
|
|
165
|
+
}
|
|
166
|
+
names.sort()
|
|
167
|
+
return new RegExp(`(?:^|/)(?:${names.join('|')})(?:/|$)`)
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
* @param {string} value
|
|
172
|
+
* @returns {string}
|
|
173
|
+
*/
|
|
174
|
+
function escapeRegExp (value) {
|
|
175
|
+
return value.replaceAll(/[.*+?^${}()|[\]\\]/g, String.raw`\$&`)
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
/**
|
|
179
|
+
* @returns {number}
|
|
180
|
+
*/
|
|
181
|
+
function getNextMajor () {
|
|
182
|
+
const entrypoints = []
|
|
183
|
+
if (require.main?.filename) entrypoints.push(require.main.filename)
|
|
184
|
+
entrypoints.push(path.join(process.cwd(), 'package.json'))
|
|
185
|
+
|
|
186
|
+
let version
|
|
187
|
+
let resolutionError
|
|
188
|
+
for (const entrypoint of entrypoints) {
|
|
189
|
+
try {
|
|
190
|
+
const appRequire = Module.createRequire(entrypoint)
|
|
191
|
+
version = JSON.parse(fs.readFileSync(appRequire.resolve('next/package.json'), 'utf8')).version
|
|
192
|
+
break
|
|
193
|
+
} catch (error) {
|
|
194
|
+
resolutionError = error
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
if (!version) {
|
|
198
|
+
throw new Error('withDatadogTurbopack could not resolve the active Next.js installation', {
|
|
199
|
+
cause: resolutionError,
|
|
200
|
+
})
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
if (!satisfies(version, '>=0')) {
|
|
204
|
+
throw new Error(`withDatadogTurbopack could not parse Next.js version ${version}`)
|
|
205
|
+
}
|
|
206
|
+
if (!satisfies(version, '>=15.5.0')) {
|
|
207
|
+
throw new RangeError(`withDatadogTurbopack requires Next.js 15.5 or newer; found ${version}`)
|
|
208
|
+
}
|
|
209
|
+
return Number.parseInt(version, 10)
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
module.exports = { withDatadogTurbopack }
|