dd-trace 6.25.0 → 6.26.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 (141) hide show
  1. package/README.md +3 -0
  2. package/ci/cypress/support.js +2 -1
  3. package/ci/vitest-no-worker-init-node-setup.mjs +2 -1
  4. package/ci/vitest-no-worker-init-runner-setup.mjs +2 -1
  5. package/ci/vitest-no-worker-init-setup.mjs +729 -724
  6. package/ci/vitest-no-worker-init-v5-setup.mjs +2 -1
  7. package/package.json +33 -30
  8. package/packages/datadog-esbuild/index.js +8 -15
  9. package/packages/datadog-esbuild/src/log.js +2 -29
  10. package/packages/datadog-instrumentations/src/ai.js +6 -1
  11. package/packages/datadog-instrumentations/src/cypress-config.js +20 -9
  12. package/packages/datadog-instrumentations/src/helpers/bundler-esm-exports.js +23 -1
  13. package/packages/datadog-instrumentations/src/helpers/bundler-log.js +38 -0
  14. package/packages/datadog-instrumentations/src/helpers/bundler-transform.js +9 -6
  15. package/packages/datadog-instrumentations/src/helpers/fetch.js +51 -6
  16. package/packages/datadog-instrumentations/src/helpers/rewriter/index.js +6 -0
  17. package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentation-registry.js +8 -0
  18. package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/modelcontextprotocol-client.js +30 -0
  19. package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/modelcontextprotocol-server.js +23 -0
  20. package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/next.js +21 -0
  21. package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/postgres.js +33 -4
  22. package/packages/datadog-instrumentations/src/helpers/rewriter/target-patterns.json +30 -0
  23. package/packages/datadog-instrumentations/src/helpers/rewriter/targets.json +6 -0
  24. package/packages/datadog-instrumentations/src/helpers/rewriter/transforms/postgres.js +122 -0
  25. package/packages/datadog-instrumentations/src/microgateway-core.js +1 -2
  26. package/packages/datadog-instrumentations/src/modelcontextprotocol-client.js +21 -0
  27. package/packages/datadog-instrumentations/src/modelcontextprotocol-sdk.js +7 -1
  28. package/packages/datadog-instrumentations/src/modelcontextprotocol-server.js +41 -0
  29. package/packages/datadog-instrumentations/src/next.js +184 -20
  30. package/packages/datadog-instrumentations/src/router.js +35 -12
  31. package/packages/datadog-instrumentations/src/vitest-main.js +10 -2
  32. package/packages/datadog-plugin-aws-lambda/src/arn.js +41 -0
  33. package/packages/datadog-plugin-aws-lambda/src/event-type-guards.js +170 -0
  34. package/packages/datadog-plugin-aws-lambda/src/trigger.js +339 -0
  35. package/packages/datadog-plugin-aws-sdk/src/services/dynamodb.js +7 -0
  36. package/packages/datadog-plugin-aws-sdk/src/services/kinesis.js +32 -10
  37. package/packages/datadog-plugin-aws-sdk/src/services/lambda.js +10 -1
  38. package/packages/datadog-plugin-aws-sdk/src/services/sqs.js +4 -0
  39. package/packages/datadog-plugin-aws-sdk/src/services/stepfunctions.js +3 -0
  40. package/packages/datadog-plugin-cypress/src/cypress-plugin.js +30 -4
  41. package/packages/datadog-plugin-cypress/src/support.mjs +1353 -0
  42. package/packages/datadog-plugin-express/src/code_origin.js +2 -2
  43. package/packages/datadog-plugin-fastify/src/code_origin.js +2 -2
  44. package/packages/datadog-plugin-google-cloud-pubsub/src/consumer.js +10 -0
  45. package/packages/datadog-plugin-google-cloud-pubsub/src/producer.js +2 -0
  46. package/packages/datadog-plugin-google-cloud-pubsub/src/pubsub-push-subscription.js +7 -0
  47. package/packages/datadog-plugin-google-cloud-pubsub/src/resource-names.js +24 -0
  48. package/packages/datadog-plugin-graphql/src/tools/transforms.js +1 -0
  49. package/packages/datadog-plugin-http/src/client.js +2 -1
  50. package/packages/datadog-plugin-http2/src/client.js +2 -1
  51. package/packages/datadog-plugin-modelcontextprotocol-sdk/src/tracing.js +28 -2
  52. package/packages/datadog-plugin-modelcontextprotocol-sdk/src/utils.js +1 -0
  53. package/packages/datadog-plugin-mongodb-core/src/query.js +17 -1
  54. package/packages/datadog-plugin-postgres/src/index.js +118 -41
  55. package/packages/datadog-plugin-supabase/src/supabase-auth-js-gotrueclient-getuser.js +18 -8
  56. package/packages/datadog-plugin-supabase/src/supabase-functions-js-functionsclient-invoke.js +49 -13
  57. package/packages/datadog-plugin-supabase/src/supabase-storage-js-handle-request.js +34 -9
  58. package/packages/datadog-plugin-vitest/src/index.js +3 -2
  59. package/packages/datadog-plugin-ws/src/close.js +3 -5
  60. package/packages/datadog-plugin-ws/src/producer.js +1 -4
  61. package/packages/datadog-plugin-ws/src/receiver.js +3 -5
  62. package/packages/datadog-plugin-ws/src/server.js +44 -13
  63. package/packages/datadog-vite/index.js +537 -0
  64. package/packages/datadog-vite/src/log.js +5 -0
  65. package/packages/datadog-webpack/src/log.js +2 -29
  66. package/packages/dd-trace/src/aiguard/index.js +1 -1
  67. package/packages/dd-trace/src/aiguard/integrations/index.js +6 -5
  68. package/packages/dd-trace/src/appsec/blocking/index.js +17 -1
  69. package/packages/dd-trace/src/appsec/channels.js +7 -0
  70. package/packages/dd-trace/src/appsec/downstream_requests.js +105 -0
  71. package/packages/dd-trace/src/appsec/graphql.js +10 -13
  72. package/packages/dd-trace/src/appsec/handlers/auth.js +1 -3
  73. package/packages/dd-trace/src/appsec/handlers/http-request.js +60 -65
  74. package/packages/dd-trace/src/appsec/handlers/http-response.js +61 -7
  75. package/packages/dd-trace/src/appsec/handlers/payments.js +23 -27
  76. package/packages/dd-trace/src/appsec/index.js +6 -0
  77. package/packages/dd-trace/src/appsec/lambda.js +17 -17
  78. package/packages/dd-trace/src/appsec/rasp/command_injection.js +4 -4
  79. package/packages/dd-trace/src/appsec/rasp/index.js +8 -1
  80. package/packages/dd-trace/src/appsec/rasp/lfi.js +2 -2
  81. package/packages/dd-trace/src/appsec/rasp/sql_injection.js +7 -17
  82. package/packages/dd-trace/src/appsec/rasp/ssrf.js +80 -16
  83. package/packages/dd-trace/src/appsec/rasp/utils.js +33 -3
  84. package/packages/dd-trace/src/appsec/recommended.json +70 -3
  85. package/packages/dd-trace/src/appsec/reporter.js +9 -0
  86. package/packages/dd-trace/src/appsec/sdk/set_user.js +3 -3
  87. package/packages/dd-trace/src/appsec/sdk/track_event.js +4 -4
  88. package/packages/dd-trace/src/appsec/sdk/user_blocking.js +1 -1
  89. package/packages/dd-trace/src/appsec/user_tracking.js +6 -8
  90. package/packages/dd-trace/src/appsec/waf/index.js +65 -6
  91. package/packages/dd-trace/src/appsec/waf/waf_context_wrapper.js +33 -38
  92. package/packages/dd-trace/src/appsec/waf/waf_manager.js +18 -2
  93. package/packages/dd-trace/src/config/generated-config-types.d.ts +4 -2
  94. package/packages/dd-trace/src/config/index.js +46 -26
  95. package/packages/dd-trace/src/config/parsers.js +35 -0
  96. package/packages/dd-trace/src/config/remote-config-layers.js +38 -0
  97. package/packages/dd-trace/src/config/remote_config.js +2 -1
  98. package/packages/dd-trace/src/config/supported-configurations.json +14 -6
  99. package/packages/dd-trace/src/datastreams/fnv.js +27 -0
  100. package/packages/dd-trace/src/datastreams/pathway.js +113 -28
  101. package/packages/dd-trace/src/datastreams/processor.js +5 -4
  102. package/packages/dd-trace/src/debugger/config.js +1 -1
  103. package/packages/dd-trace/src/debugger/devtools_client/request-options.js +7 -9
  104. package/packages/dd-trace/src/debugger/devtools_client/send.js +1 -1
  105. package/packages/dd-trace/src/debugger/devtools_client/state.js +3 -1
  106. package/packages/dd-trace/src/debugger/devtools_client/tags.js +1 -1
  107. package/packages/dd-trace/src/debugger/index.js +2 -2
  108. package/packages/dd-trace/src/debugger/inspect-segment.js +3 -2
  109. package/packages/dd-trace/src/debugger/pause-duration-histogram.js +4 -1
  110. package/packages/dd-trace/src/debugger/probe_sampler.js +39 -17
  111. package/packages/dd-trace/src/debugger/unsupported-runtime.js +2 -0
  112. package/packages/dd-trace/src/git_metadata.js +2 -1
  113. package/packages/dd-trace/src/index.js +6 -3
  114. package/packages/dd-trace/src/lambda/facade.js +6 -5
  115. package/packages/dd-trace/src/llmobs/plugins/modelcontextprotocol-sdk/index.js +54 -3
  116. package/packages/dd-trace/src/llmobs/plugins/modelcontextprotocol-sdk/utils.js +81 -1
  117. package/packages/dd-trace/src/openfeature/agentless_configuration_source.js +3 -0
  118. package/packages/dd-trace/src/openfeature/configuration_source.js +20 -0
  119. package/packages/dd-trace/src/plugins/ci_plugin.js +104 -9
  120. package/packages/dd-trace/src/plugins/index.js +2 -0
  121. package/packages/dd-trace/src/plugins/util/ci.js +34 -0
  122. package/packages/dd-trace/src/plugins/util/http-otel-semantics.js +9 -14
  123. package/packages/dd-trace/src/plugins/util/test.js +28 -1
  124. package/packages/dd-trace/src/plugins/util/url.js +8 -5
  125. package/packages/dd-trace/src/plugins/util/user-provided-git.js +4 -4
  126. package/packages/dd-trace/src/process-tags/index.js +1 -1
  127. package/packages/dd-trace/src/profiler.js +74 -12
  128. package/packages/dd-trace/src/profiling/profiler.js +30 -2
  129. package/packages/dd-trace/src/profiling/profilers/space.js +3 -1
  130. package/packages/dd-trace/src/profiling/profilers/wall.js +4 -4
  131. package/packages/dd-trace/src/profiling/remote-config.js +354 -0
  132. package/packages/dd-trace/src/profiling/runtime-capabilities.js +11 -0
  133. package/packages/dd-trace/src/propagation-hash/index.js +7 -0
  134. package/packages/dd-trace/src/proxy.js +13 -1
  135. package/vendor/dist/@opentelemetry/core/LICENSE +11 -0
  136. package/vendor/dist/@opentelemetry/core/index.js +1 -1
  137. package/vite.d.ts +7 -0
  138. package/vite.js +3 -0
  139. package/lambda.d.ts +0 -39
  140. package/lambda.js +0 -3
  141. package/packages/datadog-plugin-cypress/src/support.js +0 -1348
@@ -87,7 +87,7 @@ function trackLogin (framework, login, user, success, rootSpan) {
87
87
 
88
88
  let newTags
89
89
 
90
- const persistent = {
90
+ const requestData = {
91
91
  [addresses.USER_LOGIN]: login,
92
92
  }
93
93
 
@@ -116,11 +116,11 @@ function trackLogin (framework, login, user, success, rootSpan) {
116
116
 
117
117
  if (shouldSetTag('usr.id')) {
118
118
  newTags['usr.id'] = userId
119
- persistent[addresses.USER_ID] = userId
119
+ requestData[addresses.USER_ID] = userId
120
120
  }
121
121
  }
122
122
 
123
- persistent[addresses.LOGIN_SUCCESS] = null
123
+ requestData[addresses.LOGIN_SUCCESS] = null
124
124
  } else {
125
125
  newTags = {
126
126
  'appsec.events.users.login.failure.track': 'true',
@@ -146,14 +146,14 @@ function trackLogin (framework, login, user, success, rootSpan) {
146
146
  }
147
147
  */
148
148
 
149
- persistent[addresses.LOGIN_FAILURE] = null
149
+ requestData[addresses.LOGIN_FAILURE] = null
150
150
  }
151
151
 
152
152
  keepTrace(rootSpan, ASM)
153
153
 
154
154
  rootSpan.addTags(newTags)
155
155
 
156
- return waf.run({ persistent })
156
+ return waf.run(requestData)
157
157
  }
158
158
 
159
159
  function trackUser (user, rootSpan) {
@@ -177,9 +177,7 @@ function trackUser (user, rootSpan) {
177
177
  })
178
178
 
179
179
  return waf.run({
180
- persistent: {
181
- [addresses.USER_ID]: userId,
182
- },
180
+ [addresses.USER_ID]: userId,
183
181
  })
184
182
  }
185
183
  }
@@ -37,6 +37,9 @@ const waf = {
37
37
  removeConfig,
38
38
  checkAsmDdFallback,
39
39
  run: noop,
40
+ runSubContext: noop,
41
+ disposeSubContext,
42
+ getRequest,
40
43
  disposeContext: noop,
41
44
  WafUpdateError,
42
45
  }
@@ -55,6 +58,7 @@ function init (rules, config) {
55
58
 
56
59
  waf.wafManager = new WAFManager(rules, config)
57
60
 
61
+ waf.runSubContext = runSubContext
58
62
  waf.run = run
59
63
  waf.disposeContext = disposeContext
60
64
  }
@@ -65,6 +69,7 @@ function destroy () {
65
69
  waf.wafManager = null
66
70
  }
67
71
 
72
+ waf.runSubContext = noop
68
73
  waf.run = noop
69
74
  waf.disposeContext = noop
70
75
  }
@@ -116,7 +121,7 @@ function removeConfig (configPath) {
116
121
  // @see packages/dd-trace/test/appsec/lambda.spec.js
117
122
 
118
123
  /**
119
- * @param {object} data - WAF address data ({ persistent, ephemeral })
124
+ * @param {object} data - Flat WAF address map
120
125
  * @param {object} req - Request key for WAF context lookup. May be an HTTP
121
126
  * IncomingMessage or a plain object (Lambda invocation key).
122
127
  * @param {string} [raspRule] - RASP rule identifier
@@ -132,7 +137,19 @@ function run (data, req, raspRule, rootSpan) {
132
137
  }
133
138
 
134
139
  const wafContext = waf.wafManager.getWAFContext(req)
135
- const result = wafContext.run(data, raspRule, req, rootSpan)
140
+ if (!wafContext) return
141
+ return runContext(data, wafContext, raspRule, rootSpan)
142
+ }
143
+
144
+ /**
145
+ * @param {object} data - Flat WAF address map.
146
+ * @param {import('./waf_context_wrapper')} wafContext - Context selected for this evaluation.
147
+ * @param {object} [raspRule] - RASP rule metadata.
148
+ * @param {object} [rootSpan] - Explicit Lambda root span.
149
+ */
150
+ function runContext (data, wafContext, raspRule, rootSpan) {
151
+ const req = wafContext.parent ? wafContext.parent.req : wafContext.req
152
+ const result = wafContext.run(data, raspRule, rootSpan)
136
153
 
137
154
  if (result?.keep) {
138
155
  if (limiter.isAllowed()) {
@@ -146,12 +163,54 @@ function run (data, req, raspRule, rootSpan) {
146
163
  return result
147
164
  }
148
165
 
149
- function disposeContext (req) {
150
- const wafContext = waf.wafManager.getWAFContext(req)
166
+ /**
167
+ * @typedef {{ wafSubcontext?: import('./waf_context_wrapper') }} SubcontextState
168
+ */
151
169
 
152
- if (wafContext && !wafContext.ddwafContext.disposed) {
153
- wafContext.dispose()
170
+ /**
171
+ * Evaluate an isolated check, or reuse a subcontext across calls carrying the same state.
172
+ * @param {object} data - Flat WAF address map.
173
+ * @param {object} [raspRule] - RASP rule metadata.
174
+ * @param {SubcontextState} [state] - Instrumentation context, released by calling disposeSubContext.
175
+ * @param {object} [req] - Explicit request when the publisher provides it.
176
+ */
177
+ function runSubContext (data, raspRule, state, req) {
178
+ let subcontext = state?.wafSubcontext
179
+ if (!subcontext) {
180
+ req ||= getActiveRequest()
181
+ if (!req) return
182
+ const context = waf.wafManager.getWAFContext(req)
183
+ if (!context) return
184
+ if (context.ddwafContext.disposed) return runContext(data, context, raspRule)
185
+ // Stateful checks can need response inputs even when no request inputs are known.
186
+ if (!state && (data === null || typeof data !== 'object' ||
187
+ !Object.keys(data).some(key => context.knownAddresses.has(key)))) return
188
+ subcontext = context.createSubcontext()
189
+ if (!subcontext) return
190
+ if (state) state.wafSubcontext = subcontext
154
191
  }
192
+ try {
193
+ return runContext(data, subcontext, raspRule)
194
+ } finally {
195
+ if (!state) subcontext.dispose()
196
+ }
197
+ }
198
+
199
+ /** @param {SubcontextState} state - Instrumentation context bound by runSubContext. */
200
+ function getRequest (state) {
201
+ return state.wafSubcontext?.parent.req
202
+ }
203
+
204
+ /** @param {SubcontextState} state - Instrumentation context whose evaluation is complete. */
205
+ function disposeSubContext (state) {
206
+ const subcontext = state.wafSubcontext
207
+ if (!subcontext) return
208
+ state.wafSubcontext = undefined
209
+ subcontext.dispose()
210
+ }
211
+
212
+ function disposeContext (req) {
213
+ waf.wafManager.disposeContext(req)
155
214
  }
156
215
 
157
216
  function noop () {}
@@ -6,14 +6,16 @@ const addresses = require('../addresses')
6
6
  const { getBlockingAction } = require('../blocking')
7
7
  const { wafRunFinished } = require('../channels')
8
8
 
9
- // TODO: remove once ephemeral addresses are implemented
9
+ // Some HTTP hooks can supply the same query more than once.
10
10
  const preventDuplicateAddresses = new Set([
11
11
  addresses.HTTP_INCOMING_QUERY,
12
12
  ])
13
13
 
14
14
  class WAFContextWrapper {
15
- constructor (ddwafContext, wafTimeout, wafVersion, rulesVersion, knownAddresses) {
15
+ constructor (ddwafContext, wafTimeout, wafVersion, rulesVersion, knownAddresses, req, parent) {
16
16
  this.ddwafContext = ddwafContext
17
+ this.parent = parent
18
+ this.req = req
17
19
  this.wafTimeout = wafTimeout
18
20
  this.wafVersion = wafVersion
19
21
  this.rulesVersion = rulesVersion
@@ -36,7 +38,7 @@ class WAFContextWrapper {
36
38
  }
37
39
  }
38
40
 
39
- run ({ persistent, ephemeral }, raspRule, req, rootSpan) {
41
+ run (data, raspRule, rootSpan) {
40
42
  if (this.ddwafContext.disposed) {
41
43
  log.warn('[ASM] Calling run on a disposed context')
42
44
  if (raspRule) {
@@ -46,9 +48,8 @@ class WAFContextWrapper {
46
48
  return
47
49
  }
48
50
 
49
- // SPECIAL CASE FOR USER_ID
50
- // TODO: make this universal
51
- const userId = persistent?.[addresses.USER_ID] || ephemeral?.[addresses.USER_ID]
51
+ const req = this.req
52
+ const userId = data?.[addresses.USER_ID]
52
53
  if (userId) {
53
54
  const cachedResults = this.cachedUserIdResults.get(userId)
54
55
  if (cachedResults) {
@@ -61,42 +62,17 @@ class WAFContextWrapper {
61
62
  // Cloned lazily; only the preventDuplicateAddresses branch below adds to it.
62
63
  let newAddressesToSkip
63
64
 
64
- if (persistent !== null && typeof persistent === 'object') {
65
- const persistentInputs = {}
66
-
67
- let hasPersistentInputs = false
68
- for (const key of Object.keys(persistent)) {
65
+ if (data !== null && typeof data === 'object') {
66
+ for (const key of Object.keys(data)) {
69
67
  if (!this.addressesToSkip.has(key) && this.knownAddresses.has(key)) {
70
- hasPersistentInputs = true
71
- persistentInputs[key] = persistent[key]
72
- if (preventDuplicateAddresses.has(key)) {
68
+ payloadHasData = true
69
+ payload[key] = data[key]
70
+ if (!this.parent && preventDuplicateAddresses.has(key)) {
73
71
  newAddressesToSkip ??= new Set(this.addressesToSkip)
74
72
  newAddressesToSkip.add(key)
75
73
  }
76
74
  }
77
75
  }
78
-
79
- if (hasPersistentInputs) {
80
- payload.persistent = persistentInputs
81
- payloadHasData = true
82
- }
83
- }
84
-
85
- if (ephemeral !== null && typeof ephemeral === 'object') {
86
- const ephemeralInputs = {}
87
-
88
- let hasEphemeral = false
89
- for (const key of Object.keys(ephemeral)) {
90
- if (this.knownAddresses.has(key)) {
91
- hasEphemeral = true
92
- ephemeralInputs[key] = ephemeral[key]
93
- }
94
- }
95
-
96
- if (hasEphemeral) {
97
- payload.ephemeral = ephemeralInputs
98
- payloadHasData = true
99
- }
100
76
  }
101
77
 
102
78
  if (!payloadHasData) return
@@ -168,7 +144,7 @@ class WAFContextWrapper {
168
144
  metrics.errorCode = err.errorCode ?? -127
169
145
  } finally {
170
146
  if (wafRunFinished.hasSubscribers) {
171
- wafRunFinished.publish({ payload })
147
+ wafRunFinished.publish({ payload, req, isSubcontext: !!this.parent })
172
148
  }
173
149
 
174
150
  Reporter.reportMetrics(metrics, raspRule, req, rootSpan)
@@ -195,8 +171,27 @@ class WAFContextWrapper {
195
171
  }
196
172
  }
197
173
 
174
+ createSubcontext () {
175
+ if (this.parent || this.ddwafContext.disposed) return
176
+ try {
177
+ const subcontext = new WAFContextWrapper(
178
+ this.ddwafContext.createSubcontext(), this.wafTimeout, this.wafVersion,
179
+ this.rulesVersion, this.knownAddresses, this.req, this
180
+ )
181
+ this.subcontexts ??= new Set()
182
+ this.subcontexts.add(subcontext)
183
+ return subcontext
184
+ } catch (error) {
185
+ log.error('[ASM] Error creating an AppSec WAF subcontext', error)
186
+ }
187
+ }
188
+
198
189
  dispose () {
199
- this.ddwafContext.dispose()
190
+ this.parent?.subcontexts.delete(this)
191
+ if (this.subcontexts) {
192
+ for (const subcontext of this.subcontexts) subcontext.dispose()
193
+ }
194
+ if (!this.ddwafContext.disposed) this.ddwafContext.dispose()
200
195
  }
201
196
  }
202
197
 
@@ -53,14 +53,19 @@ class WAFManager {
53
53
 
54
54
  getWAFContext (req) {
55
55
  let wafContext = contexts.get(req)
56
+ if (wafContext === null) return
56
57
 
57
58
  if (!wafContext) {
59
+ const context = this.ddwaf.createContext()
60
+ if (context === null) return
61
+
58
62
  wafContext = new WAFContextWrapper(
59
- this.ddwaf.createContext(),
63
+ context,
60
64
  this.wafTimeout,
61
65
  this.ddwafVersion,
62
66
  this.rulesVersion,
63
- this.ddwaf.knownAddresses
67
+ this.ddwaf.knownAddresses,
68
+ req
64
69
  )
65
70
  contexts.set(req, wafContext)
66
71
  }
@@ -68,6 +73,17 @@ class WAFManager {
68
73
  return wafContext
69
74
  }
70
75
 
76
+ /** @param {object} req Request whose evaluations have finished. */
77
+ disposeContext (req) {
78
+ const context = contexts.get(req)
79
+ if (context) {
80
+ context.dispose()
81
+ } else {
82
+ // No native context exists when all rules were removed; late callbacks must still stay disabled.
83
+ contexts.set(req, null)
84
+ }
85
+ }
86
+
71
87
  setRulesVersion () {
72
88
  if (this.ddwaf.diagnostics.ruleset_version) {
73
89
  this.rulesVersion = this.ddwaf.diagnostics.ruleset_version
@@ -9,6 +9,7 @@ export interface GeneratedConfig {
9
9
  aiguard: {
10
10
  DD_AI_GUARD_ANALYZE_STREAM_RESPONSES_ENABLED: boolean;
11
11
  DD_AI_GUARD_BLOCK: boolean;
12
+ DD_AI_GUARD_DISABLED_INTEGRATIONS: string[] | undefined;
12
13
  DD_AI_GUARD_ENABLED: boolean;
13
14
  DD_AI_GUARD_ENDPOINT: string | undefined;
14
15
  DD_AI_GUARD_MAX_CONTENT_SIZE: number;
@@ -529,7 +530,7 @@ export interface GeneratedConfig {
529
530
  OTEL_METRIC_EXPORT_TIMEOUT: number;
530
531
  OTEL_METRICS_EXPORTER: "none" | "otlp" | undefined;
531
532
  OTEL_RESOURCE_ATTRIBUTES: Record<string, string>;
532
- OTEL_SDK_DISABLED: boolean;
533
+ OTEL_SDK_DISABLED: boolean | undefined;
533
534
  OTEL_TRACES_EXPORTER: "none" | "otlp" | undefined;
534
535
  OTEL_TRACES_SAMPLER: "always_on" | "always_off" | "traceidratio" | "parentbased_always_on" | "parentbased_always_off" | "parentbased_traceidratio";
535
536
  OTEL_TRACES_SAMPLER_ARG: number | undefined;
@@ -645,6 +646,7 @@ export interface GeneratedEnvVarConfig {
645
646
  DD_AGENTLESS_LOG_SUBMISSION_URL: string | undefined;
646
647
  DD_AI_GUARD_ANALYZE_STREAM_RESPONSES_ENABLED: boolean;
647
648
  DD_AI_GUARD_BLOCK: boolean;
649
+ DD_AI_GUARD_DISABLED_INTEGRATIONS: string[] | undefined;
648
650
  DD_AI_GUARD_ENABLED: boolean;
649
651
  DD_AI_GUARD_ENDPOINT: string | undefined;
650
652
  DD_AI_GUARD_MAX_CONTENT_SIZE: number;
@@ -1224,7 +1226,7 @@ export interface GeneratedEnvVarConfig {
1224
1226
  OTEL_METRICS_EXPORTER: "none" | "otlp" | undefined;
1225
1227
  OTEL_PROPAGATORS: string[];
1226
1228
  OTEL_RESOURCE_ATTRIBUTES: Record<string, string>;
1227
- OTEL_SDK_DISABLED: boolean;
1229
+ OTEL_SDK_DISABLED: boolean | undefined;
1228
1230
  OTEL_SERVICE_NAME: string | undefined;
1229
1231
  OTEL_TRACES_EXPORTER: "none" | "otlp" | undefined;
1230
1232
  OTEL_TRACES_SAMPLER: "always_on" | "always_off" | "traceidratio" | "parentbased_always_on" | "parentbased_always_off" | "parentbased_traceidratio";
@@ -437,6 +437,15 @@ class Config extends ConfigBase {
437
437
  this.OTEL_METRICS_EXPORTER === 'none') {
438
438
  setAndTrack(this, 'DD_METRICS_OTEL_ENABLED', false)
439
439
  }
440
+ // OTEL_SDK_DISABLED disables every OpenTelemetry signal, so unlike the other OTel settings it
441
+ // overrides an explicit Datadog opt-in. Tracing is handled at the entry point (src/index.js),
442
+ // where an explicit DD_TRACE_ENABLED takes precedence. That override keeps tracing only: OTLP
443
+ // span metrics are part of the metrics signal.
444
+ if (this.OTEL_SDK_DISABLED) {
445
+ this.#deactivateForOtelSdkDisabled('DD_METRICS_OTEL_ENABLED')
446
+ this.#deactivateForOtelSdkDisabled('DD_LOGS_OTEL_ENABLED')
447
+ this.#deactivateForOtelSdkDisabled('OTEL_TRACES_SPAN_METRICS_ENABLED')
448
+ }
440
449
 
441
450
  const agentlessTracingEnabled = this.DD_AGENTLESS_ENABLED ||
442
451
  isTrue(getEnvironmentVariable('_DD_APM_TRACING_AGENTLESS_ENABLED'))
@@ -834,11 +843,11 @@ class Config extends ConfigBase {
834
843
 
835
844
  const unsupportedRuntime = getUnsupportedRuntime()
836
845
  if (unsupportedRuntime !== undefined) {
837
- this.#deactivateOnUnsupportedRuntime(
846
+ this.#deactivate(
838
847
  'dynamicInstrumentation.DD_DYNAMIC_INSTRUMENTATION_ENABLED',
839
848
  `Live Debugger/Dynamic Instrumentation is disabled, because it is not supported on ${unsupportedRuntime}.`
840
849
  )
841
- this.#deactivateOnUnsupportedRuntime(
850
+ this.#deactivate(
842
851
  'testOptimization.DD_TEST_FAILED_TEST_REPLAY_ENABLED',
843
852
  'Failed Test Replay is disabled, ' +
844
853
  `because Live Debugger/Dynamic Instrumentation is not supported on ${unsupportedRuntime}.`
@@ -852,13 +861,20 @@ class Config extends ConfigBase {
852
861
  }
853
862
 
854
863
  /**
855
- * Only explains the deactivation of an option that was explicitly set, since Failed Test Replay is enabled by
856
- * default.
864
+ * @param {'DD_METRICS_OTEL_ENABLED' | 'DD_LOGS_OTEL_ENABLED' | 'OTEL_TRACES_SPAN_METRICS_ENABLED'} name
865
+ */
866
+ #deactivateForOtelSdkDisabled (name) {
867
+ this.#deactivate(name, `${name} is disabled, because OTEL_SDK_DISABLED=true disables the OpenTelemetry SDK.`)
868
+ }
869
+
870
+ /**
871
+ * Deactivates an option. Only explains why once, and only when the option was explicitly set: defaults such as
872
+ * Failed Test Replay need no explanation, and recalculating the config must not repeat it.
857
873
  *
858
874
  * @param {ConfigPath} name
859
875
  * @param {string} reason
860
876
  */
861
- #deactivateOnUnsupportedRuntime (name, reason) {
877
+ #deactivate (name, reason) {
862
878
  if (!get(this, name)) return
863
879
 
864
880
  if (this.startupLogs && trackedConfigOrigins.has(name) && !this.#explainedDeactivations.has(name)) {
@@ -924,35 +940,39 @@ function getFromOtelSamplerMap (otelTracesSampler, otelTracesSamplerArg) {
924
940
  function warnWrongOtelSettings () {
925
941
  // This mostly works for non-aliased environment variables only.
926
942
  // TODO: Adjust this to work across all sources.
927
- for (const [otelEnvVar, ddEnvVar, key = otelEnvVar] of [
943
+ // eslint-disable-next-line eslint-rules/eslint-process-env
944
+ const envs = process.env
945
+ // Each OpenTelemetry variable lists its Datadog equivalents, then the config path tracking its value when it
946
+ // differs from the variable name. The first equivalent tags `otel.env.invalid`.
947
+ for (const [otelEnvVar, ddEnvVars, key = otelEnvVar] of /** @type {Array<[string, string[], string?]>} */ ([
928
948
  // eslint-disable-next-line eslint-rules/eslint-env-aliases
929
- ['OTEL_LOG_LEVEL', 'DD_TRACE_LOG_LEVEL', 'logLevel'],
949
+ ['OTEL_LOG_LEVEL', ['DD_TRACE_LOG_LEVEL'], 'logLevel'],
930
950
  // eslint-disable-next-line eslint-rules/eslint-env-aliases
931
- ['OTEL_PROPAGATORS', 'DD_TRACE_PROPAGATION_STYLE', 'DD_TRACE_PROPAGATION_STYLE'],
951
+ ['OTEL_PROPAGATORS', ['DD_TRACE_PROPAGATION_STYLE'], 'DD_TRACE_PROPAGATION_STYLE'],
932
952
  // eslint-disable-next-line eslint-rules/eslint-env-aliases
933
- ['OTEL_SERVICE_NAME', 'DD_SERVICE', 'service'],
934
- ['OTEL_TRACES_SAMPLER', 'DD_TRACE_SAMPLE_RATE'],
935
- ['OTEL_TRACES_SAMPLER_ARG', 'DD_TRACE_SAMPLE_RATE'],
936
- ['OTEL_TRACES_EXPORTER', 'DD_TRACE_ENABLED'],
937
- ['OTEL_METRICS_EXPORTER', 'DD_RUNTIME_METRICS_ENABLED'],
938
- ['OTEL_RESOURCE_ATTRIBUTES', 'DD_TAGS'],
939
- ['OTEL_SDK_DISABLED', 'DD_TRACE_OTEL_ENABLED'],
940
- ['OTEL_LOGS_EXPORTER'],
941
- ]) {
942
- // eslint-disable-next-line eslint-rules/eslint-process-env
943
- const envs = process.env
953
+ ['OTEL_SERVICE_NAME', ['DD_SERVICE'], 'service'],
954
+ ['OTEL_TRACES_SAMPLER', ['DD_TRACE_SAMPLE_RATE']],
955
+ ['OTEL_TRACES_SAMPLER_ARG', ['DD_TRACE_SAMPLE_RATE']],
956
+ ['OTEL_TRACES_EXPORTER', ['DD_TRACE_ENABLED']],
957
+ ['OTEL_METRICS_EXPORTER', ['DD_RUNTIME_METRICS_ENABLED']],
958
+ ['OTEL_RESOURCE_ATTRIBUTES', ['DD_TAGS']],
959
+ // OTEL_SDK_DISABLED maps to DD_TRACE_ENABLED and also gates the DD_TRACE_OTEL_ENABLED provider hook.
960
+ // DD_TRACE_OTEL_ENABLED comes first to keep the established `otel.env.invalid` tag.
961
+ ['OTEL_SDK_DISABLED', ['DD_TRACE_OTEL_ENABLED', 'DD_TRACE_ENABLED']],
962
+ ['OTEL_LOGS_EXPORTER', []],
963
+ ])) {
964
+ if (!envs[otelEnvVar]) continue
965
+
944
966
  const otelSource = trackedConfigOrigins.get(/** @type {ConfigPath} */ (key))
945
- const otelEnvValue = envs[otelEnvVar]
946
- if (otelEnvValue) {
967
+ for (const ddEnvVar of ddEnvVars) {
947
968
  if (envs[ddEnvVar]) {
948
969
  log.warn('Conflicting %s and %s environment variables are set for %s', ddEnvVar, otelEnvVar, otelSource)
949
970
  increaseCounter('otel.env.hiding', ddEnvVar, otelEnvVar)
950
971
  }
951
-
952
- const invalidOtelValue = !otelSource
953
- if (invalidOtelValue) {
954
- increaseCounter('otel.env.invalid', ddEnvVar, otelEnvVar)
955
- }
972
+ }
973
+ // An invalid value is one mistake, however many Datadog equivalents the variable has.
974
+ if (!otelSource) {
975
+ increaseCounter('otel.env.invalid', ddEnvVars[0], otelEnvVar)
956
976
  }
957
977
  }
958
978
  }
@@ -105,6 +105,41 @@ const transformers = {
105
105
  }
106
106
  return tags
107
107
  },
108
+ /**
109
+ * Resolves an OpenTelemetry exporter list (e.g. `console,otlp`) to the single exporter the
110
+ * tracer supports. `none` disables export and cannot be combined with any other entry: such a
111
+ * list is invalid and resolves to unset. Otherwise `otlp` anywhere selects OTLP. Other entries
112
+ * are ignored with a warning; a list without a supported entry resolves to unset.
113
+ *
114
+ * @param {string[]} value
115
+ * @param {string} optionName
116
+ * @param {string} source
117
+ * @param {boolean} [reportInvalid]
118
+ * @returns {'none' | 'otlp' | undefined}
119
+ */
120
+ parseOtelExporterList (value, optionName, source, reportInvalid = true) {
121
+ const entries = transformers.toLowerCase(value)
122
+
123
+ if (entries.includes('none')) {
124
+ if (entries.every(entry => entry === 'none')) {
125
+ return 'none'
126
+ }
127
+ if (reportInvalid) {
128
+ warnInvalidValue(entries.join(','), optionName, source, "'none' cannot be combined with other exporters")
129
+ }
130
+ return
131
+ }
132
+
133
+ const exporter = entries.includes('otlp') ? 'otlp' : undefined
134
+
135
+ const ignored = entries.filter(entry => entry !== 'otlp')
136
+ if (ignored.length > 0 && reportInvalid) {
137
+ const outcome = exporter === undefined ? 'picked default' : null
138
+ warnInvalidValue(ignored.join(','), optionName, source, 'Unsupported exporters ignored', undefined, outcome)
139
+ }
140
+
141
+ return exporter
142
+ },
108
143
  normalizeProfilingEnabled (configValue) {
109
144
  if (configValue == null) {
110
145
  return
@@ -0,0 +1,38 @@
1
+ 'use strict'
2
+
3
+ const { getEnvironmentVariables } = require('./helper')
4
+
5
+ /**
6
+ * @typedef {ReturnType<import('./index')>} Config
7
+ * @typedef {'APM_TRACING' | 'APM_PROFILING'} Product
8
+ * @typedef {Partial<Record<import('./helper').SupportedEnvKey, string>>} Settings
9
+ */
10
+
11
+ /** @type {WeakMap<Config, Record<Product, Settings | null>>} */
12
+ const layersByConfig = new WeakMap()
13
+
14
+ /**
15
+ * Replace a product's settings and apply the settings of every active product. For a setting
16
+ * both products supply, APM_PROFILING takes precedence over the broader APM_TRACING, whatever the
17
+ * order of updates.
18
+ *
19
+ * @param {Config} config
20
+ * @param {Product} product
21
+ * @param {Settings | null} settings
22
+ */
23
+ module.exports = function applyRemoteConfig (config, product, settings) {
24
+ let layers = layersByConfig.get(config)
25
+ if (layers === undefined) {
26
+ layers = { APM_TRACING: null, APM_PROFILING: null }
27
+ layersByConfig.set(config, layers)
28
+ }
29
+ layers[product] = settings
30
+
31
+ const { APM_TRACING: tracing, APM_PROFILING: profiling } = layers
32
+ if (tracing === null || profiling === null) {
33
+ config.setRemoteConfig(tracing ?? profiling)
34
+ return
35
+ }
36
+ // Resolve aliases first, so that each setting has a single key across products.
37
+ config.setRemoteConfig({ ...getEnvironmentVariables(tracing, true), ...getEnvironmentVariables(profiling, true) })
38
+ }
@@ -2,6 +2,7 @@
2
2
 
3
3
  const RemoteConfigCapabilities = require('../remote_config/capabilities')
4
4
  const log = require('../log')
5
+ const applyRemoteConfig = require('./remote-config-layers')
5
6
 
6
7
  module.exports = {
7
8
  enable,
@@ -181,7 +182,7 @@ function enable (rc, config, onConfigUpdated) {
181
182
  transaction.ack(item.path)
182
183
  }
183
184
 
184
- config.setRemoteConfig(sdkConfigManager.getMergedConfig())
185
+ applyRemoteConfig(config, 'APM_TRACING', sdkConfigManager.getMergedConfig())
185
186
 
186
187
  onConfigUpdated()
187
188
  })
@@ -185,6 +185,15 @@
185
185
  ]
186
186
  }
187
187
  ],
188
+ "DD_AI_GUARD_DISABLED_INTEGRATIONS": [
189
+ {
190
+ "implementation": "A",
191
+ "type": "array",
192
+ "namespace": "aiguard",
193
+ "default": null,
194
+ "description": "Comma-separated integration names for which AI Guard automatic evaluation is disabled."
195
+ }
196
+ ],
188
197
  "DD_AI_GUARD_ANALYZE_STREAM_RESPONSES_ENABLED": [
189
198
  {
190
199
  "implementation": "A",
@@ -4767,18 +4776,17 @@
4767
4776
  ],
4768
4777
  "OTEL_SDK_DISABLED": [
4769
4778
  {
4770
- "implementation": "C",
4779
+ "implementation": "B",
4771
4780
  "type": "boolean",
4772
- "default": "true"
4781
+ "default": null
4773
4782
  }
4774
4783
  ],
4775
4784
  "OTEL_TRACES_EXPORTER": [
4776
4785
  {
4777
- "implementation": "H",
4778
- "type": "string",
4786
+ "implementation": "J",
4787
+ "type": "array",
4779
4788
  "default": null,
4780
- "allowed": "none|otlp",
4781
- "transform": "toLowerCase"
4789
+ "transform": "parseOtelExporterList"
4782
4790
  }
4783
4791
  ],
4784
4792
  "OTEL_TRACES_SAMPLER": [
@@ -20,6 +20,33 @@ function fnv64 (data) {
20
20
  return fnv(byteArray, FNV1_64_INIT, FNV_64_PRIME, 2n ** 64n)
21
21
  }
22
22
 
23
+ /**
24
+ * FNV-1 64 of `data`, written into `target` at `offset` as a uint64 little-endian. With `seed`, an
25
+ * earlier result in the same layout, it continues that hash, like dd-trace-java's
26
+ * FNV64Hash.continueHash.
27
+ *
28
+ * Same hash as `fnv64`, computed on two uint32 halves because BigInt arithmetic per byte is several
29
+ * times slower on the per-message DSM path. FNV_64_PRIME is 2^40 + 0x1b3, so multiplying by it is
30
+ * a 40-bit shift plus a multiply by 0x1b3, and every intermediate stays below 2^53.
31
+ *
32
+ * @param {Uint8Array} data
33
+ * @param {Buffer} target
34
+ * @param {number} offset
35
+ * @param {Buffer} [seed]
36
+ */
37
+ function writeFnv64LE (data, target, offset, seed) {
38
+ let high = seed === undefined ? 0xCB_F2_9C_E4 : seed.readUInt32LE(4)
39
+ let low = seed === undefined ? 0x84_22_23_25 : seed.readUInt32LE(0)
40
+ for (let i = 0; i < data.length; i++) {
41
+ const lowProduct = low * 0x1_B3
42
+ high = (high * 0x1_B3 + Math.floor(lowProduct / 0x1_00_00_00_00) + (low << 8)) >>> 0
43
+ low = ((lowProduct >>> 0) ^ data[i]) >>> 0
44
+ }
45
+ target.writeUInt32LE(low, offset)
46
+ target.writeUInt32LE(high, offset + 4)
47
+ }
48
+
23
49
  module.exports = {
24
50
  fnv64,
51
+ writeFnv64LE,
25
52
  }