dd-trace 5.57.1 → 5.59.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 (206) hide show
  1. package/LICENSE-3rdparty.csv +3 -1
  2. package/ci/cypress/after-run.js +2 -0
  3. package/ci/cypress/after-spec.js +2 -0
  4. package/ci/cypress/plugin.js +2 -0
  5. package/ci/cypress/polyfills.js +2 -0
  6. package/ci/cypress/support.js +2 -0
  7. package/ci/init.js +2 -0
  8. package/index.d.ts +7 -0
  9. package/init.js +1 -6
  10. package/initialize.mjs +2 -0
  11. package/package.json +40 -9
  12. package/packages/datadog-code-origin/index.js +14 -9
  13. package/packages/datadog-instrumentations/src/apollo.js +7 -10
  14. package/packages/datadog-instrumentations/src/avsc.js +2 -0
  15. package/packages/datadog-instrumentations/src/azure-functions.js +1 -1
  16. package/packages/datadog-instrumentations/src/child_process.js +22 -43
  17. package/packages/datadog-instrumentations/src/cucumber.js +10 -8
  18. package/packages/datadog-instrumentations/src/cypress.js +2 -0
  19. package/packages/datadog-instrumentations/src/fastify.js +19 -1
  20. package/packages/datadog-instrumentations/src/graphql.js +9 -0
  21. package/packages/datadog-instrumentations/src/helpers/hooks.js +1 -0
  22. package/packages/datadog-instrumentations/src/helpers/register.js +2 -2
  23. package/packages/datadog-instrumentations/src/hono.js +102 -0
  24. package/packages/datadog-instrumentations/src/jest.js +1 -1
  25. package/packages/datadog-instrumentations/src/langchain.js +21 -0
  26. package/packages/datadog-instrumentations/src/mocha/common.js +2 -0
  27. package/packages/datadog-instrumentations/src/mocha.js +2 -0
  28. package/packages/datadog-instrumentations/src/mysql2.js +6 -6
  29. package/packages/datadog-instrumentations/src/next.js +3 -1
  30. package/packages/datadog-instrumentations/src/nyc.js +2 -0
  31. package/packages/datadog-instrumentations/src/oracledb.js +24 -2
  32. package/packages/datadog-instrumentations/src/orchestrion-config/index.js +32 -0
  33. package/packages/datadog-instrumentations/src/playwright.js +5 -1
  34. package/packages/datadog-instrumentations/src/protobufjs.js +2 -0
  35. package/packages/datadog-instrumentations/src/selenium.js +2 -0
  36. package/packages/datadog-instrumentations/src/tedious.js +12 -17
  37. package/packages/datadog-instrumentations/src/vitest.js +2 -0
  38. package/packages/datadog-plugin-avsc/src/index.js +2 -0
  39. package/packages/datadog-plugin-avsc/src/schema_iterator.js +2 -0
  40. package/packages/datadog-plugin-aws-sdk/src/base.js +51 -1
  41. package/packages/datadog-plugin-aws-sdk/src/services/bedrockruntime/index.js +2 -0
  42. package/packages/datadog-plugin-child_process/src/index.js +30 -10
  43. package/packages/datadog-plugin-child_process/src/scrub-cmd-params.js +1 -1
  44. package/packages/datadog-plugin-cypress/src/after-run.js +2 -0
  45. package/packages/datadog-plugin-cypress/src/after-spec.js +2 -0
  46. package/packages/datadog-plugin-cypress/src/cypress-plugin.js +8 -3
  47. package/packages/datadog-plugin-cypress/src/index.js +2 -0
  48. package/packages/datadog-plugin-cypress/src/plugin.js +2 -0
  49. package/packages/datadog-plugin-cypress/src/support.js +21 -25
  50. package/packages/datadog-plugin-google-cloud-vertexai/src/utils.js +2 -0
  51. package/packages/datadog-plugin-graphql/src/tools/index.js +0 -2
  52. package/packages/datadog-plugin-graphql/src/tools/signature.js +0 -2
  53. package/packages/datadog-plugin-graphql/src/tools/transforms.js +0 -2
  54. package/packages/datadog-plugin-graphql/src/utils.js +2 -0
  55. package/packages/datadog-plugin-hono/src/index.js +28 -0
  56. package/packages/datadog-plugin-http/src/client.js +3 -4
  57. package/packages/datadog-plugin-http2/src/client.js +9 -8
  58. package/packages/datadog-plugin-jest/src/index.js +2 -0
  59. package/packages/datadog-plugin-jest/src/util.js +2 -0
  60. package/packages/datadog-plugin-kafkajs/src/batch-consumer.js +2 -0
  61. package/packages/datadog-plugin-langchain/src/handlers/chain.js +1 -1
  62. package/packages/datadog-plugin-langchain/src/handlers/language_models/chat_model.js +1 -1
  63. package/packages/datadog-plugin-langchain/src/handlers/language_models/llm.js +1 -1
  64. package/packages/datadog-plugin-langchain/src/tracing.js +36 -4
  65. package/packages/datadog-plugin-nyc/src/index.js +2 -0
  66. package/packages/datadog-plugin-oracledb/src/connection-parser.js +37 -0
  67. package/packages/datadog-plugin-oracledb/src/index.js +15 -17
  68. package/packages/datadog-plugin-protobufjs/src/index.js +2 -0
  69. package/packages/datadog-plugin-protobufjs/src/schema_iterator.js +2 -0
  70. package/packages/datadog-plugin-selenium/src/index.js +2 -0
  71. package/packages/datadog-plugin-tedious/src/index.js +10 -9
  72. package/packages/datadog-plugin-vitest/src/index.js +2 -0
  73. package/packages/dd-trace/src/appsec/iast/analyzers/injection-analyzer.js +6 -4
  74. package/packages/dd-trace/src/appsec/iast/analyzers/ssrf-analyzer.js +9 -0
  75. package/packages/dd-trace/src/appsec/iast/iast-context.js +5 -1
  76. package/packages/dd-trace/src/appsec/iast/index.js +2 -0
  77. package/packages/dd-trace/src/appsec/iast/overhead-controller.js +1 -1
  78. package/packages/dd-trace/src/appsec/iast/taint-tracking/operations-taint-object.js +5 -2
  79. package/packages/dd-trace/src/appsec/iast/taint-tracking/rewriter-esm.mjs +0 -2
  80. package/packages/dd-trace/src/appsec/iast/taint-tracking/rewriter.js +2 -0
  81. package/packages/dd-trace/src/appsec/iast/vulnerabilities-formatter/evidence-redaction/sensitive-regex.js +2 -0
  82. package/packages/dd-trace/src/appsec/iast/vulnerabilities-formatter/index.js +1 -0
  83. package/packages/dd-trace/src/appsec/iast/vulnerabilities.js +2 -0
  84. package/packages/dd-trace/src/appsec/iast/vulnerability-reporter.js +3 -3
  85. package/packages/dd-trace/src/appsec/rasp/fs-plugin.js +18 -11
  86. package/packages/dd-trace/src/appsec/rasp/utils.js +1 -1
  87. package/packages/dd-trace/src/appsec/recommended.json +88 -2
  88. package/packages/dd-trace/src/appsec/reporter.js +68 -14
  89. package/packages/dd-trace/src/appsec/rule_manager.js +63 -171
  90. package/packages/dd-trace/src/appsec/sdk/track_event.js +3 -5
  91. package/packages/dd-trace/src/appsec/stack_trace.js +11 -11
  92. package/packages/dd-trace/src/appsec/telemetry/common.js +2 -2
  93. package/packages/dd-trace/src/appsec/telemetry/index.js +8 -0
  94. package/packages/dd-trace/src/appsec/telemetry/waf.js +5 -3
  95. package/packages/dd-trace/src/appsec/waf/diagnostics.js +15 -0
  96. package/packages/dd-trace/src/appsec/waf/index.js +47 -6
  97. package/packages/dd-trace/src/appsec/waf/waf_context_wrapper.js +2 -2
  98. package/packages/dd-trace/src/appsec/waf/waf_manager.js +22 -12
  99. package/packages/dd-trace/src/ci-visibility/dynamic-instrumentation/index.js +3 -3
  100. package/packages/dd-trace/src/ci-visibility/early-flake-detection/get-known-tests.js +2 -0
  101. package/packages/dd-trace/src/ci-visibility/exporters/git/git_metadata.js +3 -1
  102. package/packages/dd-trace/src/ci-visibility/intelligent-test-runner/get-skippable-suites.js +2 -0
  103. package/packages/dd-trace/src/ci-visibility/log-submission/log-submission-plugin.js +2 -0
  104. package/packages/dd-trace/src/ci-visibility/requests/get-library-configuration.js +2 -0
  105. package/packages/dd-trace/src/ci-visibility/telemetry.js +2 -0
  106. package/packages/dd-trace/src/ci-visibility/test-api-manual/test-api-manual-plugin.js +2 -0
  107. package/packages/dd-trace/src/ci-visibility/test-management/get-test-management-tests.js +7 -3
  108. package/packages/dd-trace/src/config.js +15 -4
  109. package/packages/dd-trace/src/config_stable.js +2 -0
  110. package/packages/dd-trace/src/constants.js +1 -2
  111. package/packages/dd-trace/src/datastreams/checkpointer.js +2 -0
  112. package/packages/dd-trace/src/datastreams/context.js +2 -0
  113. package/packages/dd-trace/src/datastreams/encoding.js +2 -0
  114. package/packages/dd-trace/src/datastreams/fnv.js +2 -0
  115. package/packages/dd-trace/src/datastreams/pathway.js +11 -9
  116. package/packages/dd-trace/src/datastreams/processor.js +8 -7
  117. package/packages/dd-trace/src/datastreams/schemas/schema.js +2 -0
  118. package/packages/dd-trace/src/datastreams/schemas/schema_builder.js +45 -36
  119. package/packages/dd-trace/src/datastreams/schemas/schema_sampler.js +2 -0
  120. package/packages/dd-trace/src/datastreams/writer.js +2 -0
  121. package/packages/dd-trace/src/debugger/devtools_client/index.js +12 -4
  122. package/packages/dd-trace/src/debugger/devtools_client/inspector_promises_polyfill.js +2 -0
  123. package/packages/dd-trace/src/debugger/devtools_client/remote_config.js +8 -5
  124. package/packages/dd-trace/src/debugger/devtools_client/snapshot/symbols.js +1 -1
  125. package/packages/dd-trace/src/debugger/index.js +36 -9
  126. package/packages/dd-trace/src/encode/tags-processors.js +2 -0
  127. package/packages/dd-trace/src/exporters/common/agent-info-exporter.js +2 -0
  128. package/packages/dd-trace/src/exporters/common/request.js +1 -1
  129. package/packages/dd-trace/src/exporters/common/util.js +2 -0
  130. package/packages/dd-trace/src/exporters/span-stats/index.js +2 -0
  131. package/packages/dd-trace/src/exporters/span-stats/writer.js +2 -0
  132. package/packages/dd-trace/src/external-logger/src/index.js +2 -0
  133. package/packages/dd-trace/src/git_metadata_tagger.js +2 -0
  134. package/packages/dd-trace/src/git_properties.js +2 -0
  135. package/packages/dd-trace/src/guardrails/index.js +3 -4
  136. package/packages/dd-trace/src/guardrails/log.js +2 -2
  137. package/packages/dd-trace/src/guardrails/telemetry.js +16 -14
  138. package/packages/dd-trace/src/guardrails/util.js +0 -2
  139. package/packages/dd-trace/src/heap_snapshots.js +58 -0
  140. package/packages/dd-trace/src/llmobs/noop.js +1 -1
  141. package/packages/dd-trace/src/llmobs/plugins/bedrockruntime.js +2 -0
  142. package/packages/dd-trace/src/llmobs/plugins/langchain/handlers/index.js +5 -0
  143. package/packages/dd-trace/src/llmobs/plugins/langchain/handlers/tool.js +15 -0
  144. package/packages/dd-trace/src/llmobs/plugins/langchain/handlers/vectorstore.js +36 -0
  145. package/packages/dd-trace/src/llmobs/plugins/langchain/index.js +47 -4
  146. package/packages/dd-trace/src/llmobs/span_processor.js +1 -1
  147. package/packages/dd-trace/src/llmobs/tagger.js +10 -1
  148. package/packages/dd-trace/src/log/log.js +1 -1
  149. package/packages/dd-trace/src/noop/dogstatsd.js +2 -0
  150. package/packages/dd-trace/src/opentracing/propagation/text_map_dsm.js +2 -0
  151. package/packages/dd-trace/src/opentracing/span.js +1 -1
  152. package/packages/dd-trace/src/payload-tagging/config/index.js +2 -0
  153. package/packages/dd-trace/src/payload-tagging/index.js +3 -1
  154. package/packages/dd-trace/src/payload-tagging/tagging.js +4 -2
  155. package/packages/dd-trace/src/plugins/apollo.js +2 -0
  156. package/packages/dd-trace/src/plugins/ci_plugin.js +8 -3
  157. package/packages/dd-trace/src/plugins/index.js +1 -0
  158. package/packages/dd-trace/src/plugins/outbound.js +7 -0
  159. package/packages/dd-trace/src/plugins/util/ci.js +2 -0
  160. package/packages/dd-trace/src/plugins/util/env.js +2 -0
  161. package/packages/dd-trace/src/plugins/util/git.js +40 -5
  162. package/packages/dd-trace/src/plugins/util/inferred_proxy.js +2 -0
  163. package/packages/dd-trace/src/plugins/util/llm.js +2 -0
  164. package/packages/dd-trace/src/plugins/util/serverless.js +2 -0
  165. package/packages/dd-trace/src/plugins/util/stacktrace.js +178 -50
  166. package/packages/dd-trace/src/plugins/util/tags.js +17 -1
  167. package/packages/dd-trace/src/plugins/util/test.js +9 -4
  168. package/packages/dd-trace/src/plugins/util/url.js +2 -0
  169. package/packages/dd-trace/src/plugins/util/user-provided-git.js +2 -0
  170. package/packages/dd-trace/src/profiling/exporters/event_serializer.js +4 -0
  171. package/packages/dd-trace/src/profiling/profiler.js +89 -70
  172. package/packages/dd-trace/src/profiling/profilers/event_plugins/dns.js +2 -0
  173. package/packages/dd-trace/src/profiling/profilers/event_plugins/dns_lookup.js +2 -0
  174. package/packages/dd-trace/src/profiling/profilers/event_plugins/dns_lookupservice.js +2 -0
  175. package/packages/dd-trace/src/profiling/profilers/event_plugins/dns_resolve.js +2 -0
  176. package/packages/dd-trace/src/profiling/profilers/event_plugins/dns_reverse.js +2 -0
  177. package/packages/dd-trace/src/profiling/profilers/event_plugins/event.js +2 -0
  178. package/packages/dd-trace/src/profiling/profilers/event_plugins/fs.js +2 -0
  179. package/packages/dd-trace/src/profiling/profilers/event_plugins/net.js +2 -0
  180. package/packages/dd-trace/src/profiling/profilers/events.js +2 -0
  181. package/packages/dd-trace/src/profiling/profilers/wall.js +2 -2
  182. package/packages/dd-trace/src/profiling/webspan-utils.js +2 -0
  183. package/packages/dd-trace/src/proxy.js +4 -0
  184. package/packages/dd-trace/src/remote_config/capabilities.js +3 -1
  185. package/packages/dd-trace/src/remote_config/index.js +4 -0
  186. package/packages/dd-trace/src/service-naming/index.js +2 -0
  187. package/packages/dd-trace/src/service-naming/schemas/definition.js +4 -9
  188. package/packages/dd-trace/src/service-naming/schemas/util.js +2 -0
  189. package/packages/dd-trace/src/service-naming/schemas/v0/graphql.js +2 -0
  190. package/packages/dd-trace/src/service-naming/schemas/v0/index.js +2 -0
  191. package/packages/dd-trace/src/service-naming/schemas/v0/messaging.js +2 -0
  192. package/packages/dd-trace/src/service-naming/schemas/v0/serverless.js +2 -0
  193. package/packages/dd-trace/src/service-naming/schemas/v0/storage.js +2 -0
  194. package/packages/dd-trace/src/service-naming/schemas/v0/web.js +2 -0
  195. package/packages/dd-trace/src/service-naming/schemas/v1/graphql.js +2 -0
  196. package/packages/dd-trace/src/service-naming/schemas/v1/index.js +2 -0
  197. package/packages/dd-trace/src/service-naming/schemas/v1/messaging.js +2 -0
  198. package/packages/dd-trace/src/service-naming/schemas/v1/serverless.js +2 -0
  199. package/packages/dd-trace/src/service-naming/schemas/v1/storage.js +4 -1
  200. package/packages/dd-trace/src/service-naming/schemas/v1/web.js +2 -0
  201. package/packages/dd-trace/src/span_stats.js +2 -0
  202. package/packages/dd-trace/src/supported-configurations.json +5 -0
  203. package/packages/dd-trace/src/telemetry/send-data.js +2 -0
  204. package/register.js +4 -0
  205. package/version.js +0 -3
  206. package/packages/dd-trace/src/payload-tagging/jsonpath-plus.js +0 -2094
@@ -130,7 +130,7 @@ function trackUserLoginFailureV2 (tracer, login, exists, metadata) {
130
130
 
131
131
  const wafData = { login }
132
132
 
133
- if (typeof exists === 'object' && metadata === undefined) {
133
+ if (exists !== null && typeof exists === 'object' && metadata === undefined) {
134
134
  metadata = exists
135
135
  exists = false
136
136
  }
@@ -167,10 +167,8 @@ function flattenFields (fields, depth = 0) {
167
167
  result[`${key}.${flatKey}`] = flatValue[flatKey]
168
168
  }
169
169
  }
170
- } else {
171
- if (value !== undefined) {
172
- result[key] = value
173
- }
170
+ } else if (value !== undefined) {
171
+ result[key] = value
174
172
  }
175
173
  }
176
174
 
@@ -9,36 +9,36 @@ const STACK_TRACE_NAMESPACES = {
9
9
  IAST: 'vulnerability'
10
10
  }
11
11
 
12
- function getCallSiteList (maxDepth = 100) {
12
+ function prepareStackTrace (_, callsites) {
13
+ return callsites
14
+ }
15
+
16
+ function getCallSiteList (maxDepth = 100, constructorOpt) {
13
17
  const previousPrepareStackTrace = Error.prepareStackTrace
14
18
  const previousStackTraceLimit = Error.stackTraceLimit
15
- let callsiteList
16
19
  // Since some frames will be discarded because they come from tracer codebase, a buffer is added
17
20
  // to the limit in order to get as close as `maxDepth` number of frames.
18
21
  Error.stackTraceLimit = maxDepth + LIBRARY_FRAMES_BUFFER
19
22
 
20
23
  try {
21
- Error.prepareStackTrace = function (_, callsites) {
22
- callsiteList = callsites
23
- }
24
- const e = new Error('message')
25
- e.stack
24
+ Error.prepareStackTrace = prepareStackTrace
25
+ const obj = {}
26
+ Error.captureStackTrace(obj, constructorOpt)
27
+ return obj.stack
26
28
  } finally {
27
29
  Error.prepareStackTrace = previousPrepareStackTrace
28
30
  Error.stackTraceLimit = previousStackTraceLimit
29
31
  }
30
-
31
- return callsiteList
32
32
  }
33
33
 
34
34
  function filterOutFramesFromLibrary (callSiteList) {
35
35
  return callSiteList.filter(callSite => !callSite.getFileName()?.startsWith(ddBasePath))
36
36
  }
37
37
 
38
- function getCallsiteFrames (maxDepth = 32, callSiteListGetter = getCallSiteList) {
38
+ function getCallsiteFrames (maxDepth = 32, constructorOpt = getCallsiteFrames, callSiteListGetter = getCallSiteList) {
39
39
  if (maxDepth < 1) maxDepth = Infinity
40
40
 
41
- const callSiteList = callSiteListGetter(maxDepth)
41
+ const callSiteList = callSiteListGetter(maxDepth, constructorOpt)
42
42
  const filteredFrames = filterOutFramesFromLibrary(callSiteList)
43
43
 
44
44
  const half = filteredFrames.length > maxDepth ? Math.round(maxDepth / 2) : Infinity
@@ -1,4 +1,4 @@
1
- 'use strinct'
1
+ 'use strict'
2
2
 
3
3
  const DD_TELEMETRY_REQUEST_METRICS = Symbol('_dd.appsec.telemetry.request.metrics')
4
4
 
@@ -17,7 +17,7 @@ const tags = {
17
17
  function getVersionsTags (wafVersion, rulesVersion) {
18
18
  return {
19
19
  [tags.WAF_VERSION]: wafVersion,
20
- [tags.EVENT_RULES_VERSION]: rulesVersion
20
+ [tags.EVENT_RULES_VERSION]: rulesVersion || 'unknown'
21
21
  }
22
22
  }
23
23
 
@@ -13,6 +13,7 @@ const {
13
13
  trackWafMetrics,
14
14
  incrementWafInit,
15
15
  incrementWafUpdates,
16
+ incrementWafConfigErrors,
16
17
  incrementWafRequests
17
18
  } = require('./waf')
18
19
  const telemetryMetrics = require('../../telemetry/metrics')
@@ -151,6 +152,12 @@ function incrementWafUpdatesMetric (wafVersion, rulesVersion, success) {
151
152
  incrementWafUpdates(wafVersion, rulesVersion, success)
152
153
  }
153
154
 
155
+ function incrementWafConfigErrorsMetric (wafVersion, rulesVersion) {
156
+ if (!enabled) return
157
+
158
+ incrementWafConfigErrors(wafVersion, rulesVersion)
159
+ }
160
+
154
161
  function incrementWafRequestsMetric (req) {
155
162
  if (!req || !enabled) return
156
163
 
@@ -197,6 +204,7 @@ module.exports = {
197
204
  updateRaspRuleSkippedMetricTags,
198
205
  incrementWafInitMetric,
199
206
  incrementWafUpdatesMetric,
207
+ incrementWafConfigErrorsMetric,
200
208
  incrementWafRequestsMetric,
201
209
  incrementMissingUserLoginMetric,
202
210
  incrementMissingUserIdMetric,
@@ -103,10 +103,11 @@ function incrementWafInit (wafVersion, rulesVersion, success) {
103
103
  function incrementWafUpdates (wafVersion, rulesVersion, success) {
104
104
  const versionsTags = getVersionsTags(wafVersion, rulesVersion)
105
105
  appsecMetrics.count('waf.updates', { ...versionsTags, success }).inc()
106
+ }
106
107
 
107
- if (!success) {
108
- appsecMetrics.count('waf.config_errors', versionsTags).inc()
109
- }
108
+ function incrementWafConfigErrors (wafVersion, rulesVersion) {
109
+ const versionsTags = getVersionsTags(wafVersion, rulesVersion)
110
+ appsecMetrics.count('waf.config_errors', versionsTags).inc()
110
111
  }
111
112
 
112
113
  function incrementWafRequests (store) {
@@ -137,5 +138,6 @@ module.exports = {
137
138
  trackWafMetrics,
138
139
  incrementWafInit,
139
140
  incrementWafUpdates,
141
+ incrementWafConfigErrors,
140
142
  incrementWafRequests
141
143
  }
@@ -0,0 +1,15 @@
1
+ 'use strict'
2
+
3
+ module.exports = {
4
+ DIAGNOSTIC_KEYS: [
5
+ 'rules',
6
+ 'custom_rules',
7
+ 'exclusions',
8
+ 'actions',
9
+ 'processors',
10
+ 'scanners',
11
+ 'rules_override',
12
+ 'rules_data',
13
+ 'exclusion_data'
14
+ ]
15
+ }
@@ -2,14 +2,26 @@
2
2
 
3
3
  const { storage } = require('../../../../datadog-core')
4
4
  const log = require('../../log')
5
+ const Reporter = require('../reporter')
6
+
7
+ class WafUpdateError extends Error {
8
+ constructor (diagnosticErrors) {
9
+ super('WafUpdateError')
10
+ this.name = 'WafUpdateError'
11
+ this.diagnosticErrors = diagnosticErrors
12
+ }
13
+ }
5
14
 
6
15
  const waf = {
7
16
  wafManager: null,
8
17
  init,
9
18
  destroy,
10
- update,
19
+ updateConfig,
20
+ removeConfig,
21
+ checkAsmDdFallback,
11
22
  run: noop,
12
- disposeContext: noop
23
+ disposeContext: noop,
24
+ WafUpdateError
13
25
  }
14
26
 
15
27
  function init (rules, config) {
@@ -34,14 +46,43 @@ function destroy () {
34
46
  waf.disposeContext = noop
35
47
  }
36
48
 
37
- function update (newRules) {
38
- // TODO: check race conditions between Appsec enable/disable and WAF updates, the whole RC state management in general
49
+ function checkAsmDdFallback () {
50
+ if (!waf.wafManager) throw new Error('Cannot update disabled WAF')
51
+
52
+ try {
53
+ waf.wafManager.setAsmDdFallbackConfig()
54
+ } catch {
55
+ log.error('[ASM] Could not apply default ruleset back as fallback')
56
+ }
57
+ }
58
+
59
+ function updateConfig (product, configId, configPath, config) {
60
+ if (!waf.wafManager) throw new Error('Cannot update disabled WAF')
61
+
62
+ try {
63
+ if (product === 'ASM_DD') {
64
+ waf.wafManager.removeConfig(waf.wafManager.constructor.defaultWafConfigPath)
65
+ }
66
+
67
+ const updateSucceeded = waf.wafManager.updateConfig(configPath, config)
68
+ Reporter.reportWafConfigUpdate(product, configId, waf.wafManager.ddwaf.diagnostics, waf.wafManager.ddwafVersion)
69
+
70
+ if (!updateSucceeded) {
71
+ throw new WafUpdateError(waf.wafManager.ddwaf.diagnostics)
72
+ }
73
+ } catch (err) {
74
+ log.error('[ASM] Could not update config from RC')
75
+ throw err
76
+ }
77
+ }
78
+
79
+ function removeConfig (configPath) {
39
80
  if (!waf.wafManager) throw new Error('Cannot update disabled WAF')
40
81
 
41
82
  try {
42
- waf.wafManager.update(newRules)
83
+ waf.wafManager.removeConfig(configPath)
43
84
  } catch (err) {
44
- log.error('[ASM] Could not apply rules from remote config')
85
+ log.error('[ASM] Could not remove config from RC')
45
86
  throw err
46
87
  }
47
88
  }
@@ -135,7 +135,7 @@ class WAFContextWrapper {
135
135
  this.setUserIdCache(userId, result)
136
136
  }
137
137
 
138
- metrics.duration = result.totalRuntime / 1e3
138
+ metrics.duration = result.duration / 1e3
139
139
  metrics.blockTriggered = blockTriggered
140
140
  metrics.ruleTriggered = ruleTriggered
141
141
  metrics.wafTimeout = result.timeout
@@ -144,7 +144,7 @@ class WAFContextWrapper {
144
144
  Reporter.reportAttack(result.events)
145
145
  }
146
146
 
147
- Reporter.reportDerivatives(result.derivatives)
147
+ Reporter.reportAttributes(result.attributes)
148
148
 
149
149
  return result
150
150
  } catch (err) {
@@ -7,11 +7,14 @@ const WAFContextWrapper = require('./waf_context_wrapper')
7
7
  const contexts = new WeakMap()
8
8
 
9
9
  class WAFManager {
10
+ static get defaultWafConfigPath () { return 'datadog/00/ASM_DD/default/config' }
11
+
10
12
  constructor (rules, config) {
11
13
  this.config = config
12
14
  this.wafTimeout = config.wafTimeout
13
15
  this.ddwaf = this._loadDDWAF(rules)
14
16
  this.rulesVersion = this.ddwaf.diagnostics.ruleset_version
17
+ this.defaultRules = rules
15
18
 
16
19
  Reporter.reportWafInit(this.ddwafVersion, this.rulesVersion, this.ddwaf.diagnostics.rules, true)
17
20
  }
@@ -23,7 +26,7 @@ class WAFManager {
23
26
  this.ddwafVersion = DDWAF.version()
24
27
 
25
28
  const { obfuscatorKeyRegex, obfuscatorValueRegex } = this.config
26
- return new DDWAF(rules, { obfuscatorKeyRegex, obfuscatorValueRegex })
29
+ return new DDWAF(rules, WAFManager.defaultWafConfigPath, { obfuscatorKeyRegex, obfuscatorValueRegex })
27
30
  } catch (err) {
28
31
  this.ddwafVersion = this.ddwafVersion || 'unknown'
29
32
  Reporter.reportWafInit(this.ddwafVersion, 'unknown')
@@ -51,20 +54,27 @@ class WAFManager {
51
54
  return wafContext
52
55
  }
53
56
 
54
- update (newRules) {
55
- try {
56
- this.ddwaf.update(newRules)
57
+ setRulesVersion () {
58
+ if (this.ddwaf.diagnostics.ruleset_version) {
59
+ this.rulesVersion = this.ddwaf.diagnostics.ruleset_version
60
+ }
61
+ }
57
62
 
58
- if (this.ddwaf.diagnostics.ruleset_version) {
59
- this.rulesVersion = this.ddwaf.diagnostics.ruleset_version
60
- }
63
+ setAsmDdFallbackConfig () {
64
+ if (!this.ddwaf.configPaths.some(cp => cp.includes('ASM_DD'))) {
65
+ this.updateConfig(WAFManager.defaultWafConfigPath, this.defaultRules)
66
+ }
67
+ }
61
68
 
62
- Reporter.reportWafUpdate(this.ddwafVersion, this.rulesVersion, true)
63
- } catch (error) {
64
- Reporter.reportWafUpdate(this.ddwafVersion, 'unknown', false)
69
+ updateConfig (path, rules) {
70
+ const updateResult = this.ddwaf.createOrUpdateConfig(rules, path)
71
+ this.setRulesVersion()
72
+ return updateResult
73
+ }
65
74
 
66
- throw error
67
- }
75
+ removeConfig (path) {
76
+ this.ddwaf.removeConfig(path)
77
+ this.setRulesVersion()
68
78
  }
69
79
 
70
80
  destroy () {
@@ -62,7 +62,7 @@ class TestVisDynamicInstrumentation {
62
62
 
63
63
  log.debug('Starting Test Visibility - Dynamic Instrumentation client...')
64
64
 
65
- const rcChannel = new MessageChannel() // mock channel
65
+ const probeChannel = new MessageChannel() // mock channel
66
66
  const configChannel = new MessageChannel() // mock channel
67
67
 
68
68
  this.worker = new Worker(
@@ -84,14 +84,14 @@ class TestVisDynamicInstrumentation {
84
84
  workerData: {
85
85
  config: this._config.serialize(),
86
86
  parentThreadId,
87
- rcPort: rcChannel.port1,
87
+ probePort: probeChannel.port1,
88
88
  configPort: configChannel.port1,
89
89
  breakpointSetChannel: this.breakpointSetChannel.port1,
90
90
  breakpointHitChannel: this.breakpointHitChannel.port1,
91
91
  breakpointRemoveChannel: this.breakpointRemoveChannel.port1
92
92
  },
93
93
  transferList: [
94
- rcChannel.port1,
94
+ probeChannel.port1,
95
95
  configChannel.port1,
96
96
  this.breakpointSetChannel.port1,
97
97
  this.breakpointHitChannel.port1,
@@ -1,3 +1,5 @@
1
+ 'use strict'
2
+
1
3
  const request = require('../../exporters/common/request')
2
4
  const id = require('../../id')
3
5
  const log = require('../../log')
@@ -1,3 +1,5 @@
1
+ 'use strict'
2
+
1
3
  const fs = require('fs')
2
4
  const path = require('path')
3
5
 
@@ -287,7 +289,7 @@ function sendGitMetadata (url, { isEvpProxy, evpProxyPrefix }, configRepositoryU
287
289
  // Otherwise we unshallow and get commits to upload again
288
290
  log.debug('It is shallow clone, unshallowing...')
289
291
  if (!isFalse(getEnvironmentVariable('DD_CIVISIBILITY_GIT_UNSHALLOW_ENABLED'))) {
290
- unshallowRepository()
292
+ unshallowRepository(false)
291
293
  }
292
294
 
293
295
  // The latest commits change after unshallowing
@@ -1,3 +1,5 @@
1
+ 'use strict'
2
+
1
3
  const request = require('../../exporters/common/request')
2
4
  const log = require('../../log')
3
5
  const { getEnvironmentVariable } = require('../../config-helper')
@@ -1,3 +1,5 @@
1
+ 'use strict'
2
+
1
3
  const Plugin = require('../../plugins/plugin')
2
4
  const log = require('../../log')
3
5
  const { getEnvironmentVariable } = require('../../config-helper')
@@ -1,3 +1,5 @@
1
+ 'use strict'
2
+
1
3
  const request = require('../../exporters/common/request')
2
4
  const id = require('../../id')
3
5
  const log = require('../../log')
@@ -1,3 +1,5 @@
1
+ 'use strict'
2
+
1
3
  const telemetryMetrics = require('../telemetry/metrics')
2
4
 
3
5
  const ciVisibilityMetrics = telemetryMetrics.manager.namespace('civisibility')
@@ -1,3 +1,5 @@
1
+ 'use strict'
2
+
1
3
  const CiPlugin = require('../../plugins/ci_plugin')
2
4
  const {
3
5
  TEST_STATUS,
@@ -1,3 +1,5 @@
1
+ 'use strict'
2
+
1
3
  const request = require('../../exporters/common/request')
2
4
  const id = require('../../id')
3
5
  const { getEnvironmentVariable } = require('../../config-helper')
@@ -9,7 +11,9 @@ function getTestManagementTests ({
9
11
  isGzipCompatible,
10
12
  repositoryUrl,
11
13
  commitMessage,
12
- sha
14
+ sha,
15
+ commitHeadSha,
16
+ commitHeadMessage
13
17
  }, done) {
14
18
  const options = {
15
19
  path: '/api/v2/test/libraries/test-management/tests',
@@ -43,8 +47,8 @@ function getTestManagementTests ({
43
47
  type: 'ci_app_libraries_tests_request',
44
48
  attributes: {
45
49
  repository_url: repositoryUrl,
46
- commit_message: commitMessage,
47
- sha
50
+ commit_message: commitHeadMessage || commitMessage,
51
+ sha: commitHeadSha || sha
48
52
  }
49
53
  }
50
54
  })
@@ -16,7 +16,7 @@ const { updateConfig } = require('./telemetry')
16
16
  const telemetryMetrics = require('./telemetry/metrics')
17
17
  const { isInServerlessEnvironment, getIsGCPFunction, getIsAzureFunction } = require('./serverless')
18
18
  const {
19
- ORIGIN_KEY, GRPC_CLIENT_ERROR_STATUSES, GRPC_SERVER_ERROR_STATUSES, INSTRUMENTED_BY_SSI
19
+ ORIGIN_KEY, GRPC_CLIENT_ERROR_STATUSES, GRPC_SERVER_ERROR_STATUSES
20
20
  } = require('./constants')
21
21
  const { appendRules } = require('./payload-tagging/config')
22
22
  const { getEnvironmentVariable, getEnvironmentVariables } = require('./config-helper')
@@ -516,6 +516,7 @@ class Config {
516
516
  defaults['dogstatsd.port'] = '8125'
517
517
  defaults.dsmEnabled = false
518
518
  defaults['dynamicInstrumentation.enabled'] = false
519
+ defaults['dynamicInstrumentation.probeFile'] = undefined
519
520
  defaults['dynamicInstrumentation.redactedIdentifiers'] = []
520
521
  defaults['dynamicInstrumentation.redactionExcludedIdentifiers'] = []
521
522
  defaults['dynamicInstrumentation.uploadIntervalSeconds'] = 1
@@ -529,6 +530,9 @@ class Config {
529
530
  defaults['grpc.client.error.statuses'] = GRPC_CLIENT_ERROR_STATUSES
530
531
  defaults['grpc.server.error.statuses'] = GRPC_SERVER_ERROR_STATUSES
531
532
  defaults.headerTags = []
533
+ defaults['heapSnapshot.count'] = 0
534
+ defaults['heapSnapshot.destination'] = ''
535
+ defaults['heapSnapshot.interval'] = 3600
532
536
  defaults.hostname = '127.0.0.1'
533
537
  defaults['iast.dbRowsToTaint'] = 1
534
538
  defaults['iast.deduplicationEnabled'] = true
@@ -704,6 +708,7 @@ class Config {
704
708
  DD_DOGSTATSD_HOST,
705
709
  DD_DOGSTATSD_PORT,
706
710
  DD_DYNAMIC_INSTRUMENTATION_ENABLED,
711
+ DD_DYNAMIC_INSTRUMENTATION_PROBE_FILE,
707
712
  DD_DYNAMIC_INSTRUMENTATION_REDACTED_IDENTIFIERS,
708
713
  DD_DYNAMIC_INSTRUMENTATION_REDACTION_EXCLUDED_IDENTIFIERS,
709
714
  DD_DYNAMIC_INSTRUMENTATION_UPLOAD_INTERVAL_SECONDS,
@@ -713,6 +718,9 @@ class Config {
713
718
  DD_GRPC_CLIENT_ERROR_STATUSES,
714
719
  DD_GRPC_SERVER_ERROR_STATUSES,
715
720
  JEST_WORKER_ID,
721
+ DD_HEAP_SNAPSHOT_COUNT,
722
+ DD_HEAP_SNAPSHOT_DESTINATION,
723
+ DD_HEAP_SNAPSHOT_INTERVAL,
716
724
  DD_IAST_DB_ROWS_TO_TAINT,
717
725
  DD_IAST_DEDUPLICATION_ENABLED,
718
726
  DD_IAST_ENABLED,
@@ -877,6 +885,7 @@ class Config {
877
885
  this._setString(env, 'dogstatsd.port', DD_DOGSTATSD_PORT)
878
886
  this._setBoolean(env, 'dsmEnabled', DD_DATA_STREAMS_ENABLED)
879
887
  this._setBoolean(env, 'dynamicInstrumentation.enabled', DD_DYNAMIC_INSTRUMENTATION_ENABLED)
888
+ this._setString(env, 'dynamicInstrumentation.probeFile', DD_DYNAMIC_INSTRUMENTATION_PROBE_FILE)
880
889
  this._setArray(env, 'dynamicInstrumentation.redactedIdentifiers', DD_DYNAMIC_INSTRUMENTATION_REDACTED_IDENTIFIERS)
881
890
  this._setArray(
882
891
  env,
@@ -896,6 +905,9 @@ class Config {
896
905
  this._setIntegerRangeSet(env, 'grpc.client.error.statuses', DD_GRPC_CLIENT_ERROR_STATUSES)
897
906
  this._setIntegerRangeSet(env, 'grpc.server.error.statuses', DD_GRPC_SERVER_ERROR_STATUSES)
898
907
  this._setArray(env, 'headerTags', DD_TRACE_HEADER_TAGS)
908
+ env['heapSnapshot.count'] = maybeInt(DD_HEAP_SNAPSHOT_COUNT)
909
+ this._setString(env, 'heapSnapshot.destination', DD_HEAP_SNAPSHOT_DESTINATION)
910
+ env['heapSnapshot.interval'] = maybeInt(DD_HEAP_SNAPSHOT_INTERVAL)
899
911
  this._setString(env, 'hostname', DD_AGENT_HOST)
900
912
  env['iast.dbRowsToTaint'] = maybeInt(DD_IAST_DB_ROWS_TO_TAINT)
901
913
  this._setBoolean(env, 'iast.deduplicationEnabled', DD_IAST_DEDUPLICATION_ENABLED)
@@ -916,6 +928,7 @@ class Config {
916
928
  this._setString(env, 'iast.telemetryVerbosity', DD_IAST_TELEMETRY_VERBOSITY)
917
929
  this._setBoolean(env, 'iast.stackTrace.enabled', DD_IAST_STACK_TRACE_ENABLED)
918
930
  this._setArray(env, 'injectionEnabled', DD_INJECTION_ENABLED)
931
+ this._setString(env, 'instrumentationSource', DD_INJECTION_ENABLED ? 'ssi' : 'manual')
919
932
  this._setBoolean(env, 'injectForce', DD_INJECT_FORCE)
920
933
  this._setBoolean(env, 'isAzureFunction', getIsAzureFunction())
921
934
  this._setBoolean(env, 'isGCPFunction', getIsGCPFunction())
@@ -1098,6 +1111,7 @@ class Config {
1098
1111
  }
1099
1112
  this._setBoolean(opts, 'dsmEnabled', options.dsmEnabled)
1100
1113
  this._setBoolean(opts, 'dynamicInstrumentation.enabled', options.dynamicInstrumentation?.enabled)
1114
+ this._setString(opts, 'dynamicInstrumentation.probeFile', options.dynamicInstrumentation?.probeFile)
1101
1115
  this._setArray(
1102
1116
  opts,
1103
1117
  'dynamicInstrumentation.redactedIdentifiers',
@@ -1141,9 +1155,6 @@ class Config {
1141
1155
  opts['iast.securityControlsConfiguration'] = options.iast?.securityControlsConfiguration
1142
1156
  this._setBoolean(opts, 'iast.stackTrace.enabled', options.iast?.stackTrace?.enabled)
1143
1157
  this._setString(opts, 'iast.telemetryVerbosity', options.iast && options.iast.telemetryVerbosity)
1144
- if (options[INSTRUMENTED_BY_SSI]) {
1145
- this._setString(opts, 'instrumentationSource', options[INSTRUMENTED_BY_SSI])
1146
- }
1147
1158
  this._setBoolean(opts, 'isCiVisibility', options.isCiVisibility)
1148
1159
  this._setBoolean(opts, 'legacyBaggageEnabled', options.legacyBaggageEnabled)
1149
1160
  this._setBoolean(opts, 'llmobs.agentlessEnabled', options.llmobs?.agentlessEnabled)
@@ -1,3 +1,5 @@
1
+ 'use strict'
2
+
1
3
  const os = require('os')
2
4
  const fs = require('fs')
3
5
  const { getEnvironmentVariable } = require('../../dd-trace/src/config-helper')
@@ -53,6 +53,5 @@ module.exports = {
53
53
  SPAN_POINTER_DIRECTION: Object.freeze({
54
54
  UPSTREAM: 'u',
55
55
  DOWNSTREAM: 'd'
56
- }),
57
- INSTRUMENTED_BY_SSI: Symbol('_dd.instrumented.by.ssi')
56
+ })
58
57
  }
@@ -1,3 +1,5 @@
1
+ 'use strict'
2
+
1
3
  const DataStreamsContext = require('./context')
2
4
 
3
5
  class DataStreamsCheckpointer {
@@ -1,3 +1,5 @@
1
+ 'use strict'
2
+
1
3
  const { storage } = require('../../../datadog-core')
2
4
  const log = require('../log')
3
5
 
@@ -1,3 +1,5 @@
1
+ 'use strict'
2
+
1
3
  // encodes positive and negative numbers, using zig zag encoding to reduce the size of the variable length encoding.
2
4
  // uses high and low part to ensure those parts are under the limit for byte operations in javascript (32 bits)
3
5
  // maximum number possible to encode is MAX_SAFE_INTEGER/2 (using zig zag shifts the bits by 1 to the left)
@@ -1,3 +1,5 @@
1
+ 'use strict'
2
+
1
3
  const FNV_64_PRIME = BigInt('0x100000001B3')
2
4
  const FNV1_64_INIT = BigInt('0xCBF29CE484222325')
3
5
 
@@ -1,14 +1,15 @@
1
+ 'use strict'
2
+
1
3
  // encoding used here is sha256
2
4
  // other languages use FNV1
3
5
  // this inconsistency is ok because hashes do not need to be consistent across services
4
6
  const crypto = require('crypto')
5
7
  const { encodeVarint, decodeVarint } = require('./encoding')
6
- const LRUCache = require('lru-cache')
8
+ const { LRUCache } = require('lru-cache')
7
9
  const log = require('../log')
8
10
  const pick = require('../../../datadog-core/src/utils/src/pick')
9
11
 
10
- const options = { max: 500 }
11
- const cache = new LRUCache(options)
12
+ const cache = new LRUCache({ max: 500 })
12
13
 
13
14
  const CONTEXT_PROPAGATION_KEY = 'dd-pathway-ctx'
14
15
  const CONTEXT_PROPAGATION_KEY_BASE64 = 'dd-pathway-ctx-base64'
@@ -24,15 +25,16 @@ function computeHash (service, env, edgeTags, parentHash) {
24
25
  edgeTags.sort()
25
26
  const hashableEdgeTags = edgeTags.filter(item => item !== 'manual_checkpoint:true')
26
27
 
27
- const key = `${service}${env}` + hashableEdgeTags.join('') + parentHash.toString()
28
- if (cache.get(key)) {
29
- return cache.get(key)
28
+ const key = `${service}${env}${hashableEdgeTags.join('')}${parentHash}`
29
+ let value = cache.get(key)
30
+ if (value) {
31
+ return value
30
32
  }
31
33
  const currentHash = shaHash(`${service}${env}` + hashableEdgeTags.join(''))
32
34
  const buf = Buffer.concat([currentHash, parentHash], 16)
33
- const val = shaHash(buf.toString())
34
- cache.set(key, val)
35
- return val
35
+ value = shaHash(buf.toString())
36
+ cache.set(key, value)
37
+ return value
36
38
  }
37
39
 
38
40
  function encodePathwayContext (dataStreamsContext) {
@@ -1,3 +1,5 @@
1
+ 'use strict'
2
+
1
3
  const os = require('os')
2
4
  const pkg = require('../../../../package.json')
3
5
 
@@ -78,15 +80,14 @@ class StatsBucket {
78
80
  return this._backlogs
79
81
  }
80
82
 
81
- forCheckpoint (checkpoint) {
82
- const key = checkpoint.hash
83
- if (!this._checkpoints.has(key)) {
84
- this._checkpoints.set(
85
- key, new StatsPoint(checkpoint.hash, checkpoint.parentHash, checkpoint.edgeTags)
86
- )
83
+ forCheckpoint ({ hash, parentHash, edgeTags }) {
84
+ let checkpoint = this._checkpoints.get(hash)
85
+ if (!checkpoint) {
86
+ checkpoint = new StatsPoint(hash, parentHash, edgeTags)
87
+ this._checkpoints.set(hash, checkpoint)
87
88
  }
88
89
 
89
- return this._checkpoints.get(key)
90
+ return checkpoint
90
91
  }
91
92
 
92
93
  /**
@@ -1,3 +1,5 @@
1
+ 'use strict'
2
+
1
3
  class Schema {
2
4
  constructor (definition, id) {
3
5
  this.definition = definition