dd-trace 5.41.0 → 5.42.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 (63) hide show
  1. package/LICENSE-3rdparty.csv +1 -0
  2. package/index.d.ts +8 -1
  3. package/package.json +6 -3
  4. package/packages/datadog-esbuild/index.js +3 -1
  5. package/packages/datadog-instrumentations/src/cucumber.js +37 -29
  6. package/packages/datadog-instrumentations/src/fetch.js +1 -1
  7. package/packages/datadog-instrumentations/src/google-cloud-vertexai.js +102 -0
  8. package/packages/datadog-instrumentations/src/{check_require_cache.js → helpers/check-require-cache.js} +2 -2
  9. package/packages/datadog-instrumentations/src/helpers/hooks.js +2 -2
  10. package/packages/datadog-instrumentations/src/helpers/register.js +4 -1
  11. package/packages/datadog-instrumentations/src/jest.js +72 -49
  12. package/packages/datadog-instrumentations/src/langchain.js +29 -10
  13. package/packages/datadog-instrumentations/src/mocha/main.js +53 -34
  14. package/packages/datadog-instrumentations/src/mocha/utils.js +34 -24
  15. package/packages/datadog-instrumentations/src/mocha/worker.js +7 -8
  16. package/packages/datadog-instrumentations/src/openai.js +1 -1
  17. package/packages/datadog-instrumentations/src/playwright.js +37 -30
  18. package/packages/datadog-instrumentations/src/vitest.js +64 -29
  19. package/packages/datadog-plugin-cucumber/src/index.js +13 -4
  20. package/packages/datadog-plugin-cypress/src/cypress-plugin.js +41 -35
  21. package/packages/datadog-plugin-cypress/src/plugin.js +10 -0
  22. package/packages/datadog-plugin-google-cloud-vertexai/src/index.js +195 -0
  23. package/packages/datadog-plugin-jest/src/index.js +18 -6
  24. package/packages/datadog-plugin-langchain/src/handlers/embedding.js +4 -1
  25. package/packages/datadog-plugin-mocha/src/index.js +13 -4
  26. package/packages/datadog-plugin-playwright/src/index.js +19 -5
  27. package/packages/datadog-plugin-vitest/src/index.js +41 -17
  28. package/packages/dd-trace/src/appsec/api_security_sampler.js +7 -3
  29. package/packages/dd-trace/src/appsec/blocking.js +23 -16
  30. package/packages/dd-trace/src/appsec/graphql.js +13 -6
  31. package/packages/dd-trace/src/appsec/rasp/utils.js +0 -1
  32. package/packages/dd-trace/src/appsec/reporter.js +35 -0
  33. package/packages/dd-trace/src/appsec/sdk/user_blocking.js +1 -3
  34. package/packages/dd-trace/src/appsec/telemetry/index.js +5 -1
  35. package/packages/dd-trace/src/appsec/telemetry/rasp.js +16 -1
  36. package/packages/dd-trace/src/appsec/telemetry/waf.js +16 -1
  37. package/packages/dd-trace/src/appsec/waf/waf_context_wrapper.js +43 -13
  38. package/packages/dd-trace/src/ci-visibility/exporters/agentless/writer.js +2 -2
  39. package/packages/dd-trace/src/ci-visibility/exporters/ci-visibility-exporter.js +15 -14
  40. package/packages/dd-trace/src/ci-visibility/requests/get-library-configuration.js +1 -2
  41. package/packages/dd-trace/src/ci-visibility/telemetry.js +2 -1
  42. package/packages/dd-trace/src/ci-visibility/{quarantined-tests/get-quarantined-tests.js → test-management/get-test-management-tests.js} +5 -5
  43. package/packages/dd-trace/src/config.js +11 -1
  44. package/packages/dd-trace/src/dogstatsd.js +137 -28
  45. package/packages/dd-trace/src/encode/agentless-ci-visibility.js +9 -2
  46. package/packages/dd-trace/src/lambda/runtime/patch.js +5 -3
  47. package/packages/dd-trace/src/lambda/runtime/ritm.js +13 -18
  48. package/packages/dd-trace/src/llmobs/plugins/openai.js +27 -2
  49. package/packages/dd-trace/src/opentracing/span.js +3 -0
  50. package/packages/dd-trace/src/plugin_manager.js +0 -4
  51. package/packages/dd-trace/src/plugins/ci_plugin.js +38 -10
  52. package/packages/dd-trace/src/plugins/index.js +2 -0
  53. package/packages/dd-trace/src/plugins/util/git.js +7 -3
  54. package/packages/dd-trace/src/plugins/util/test.js +10 -0
  55. package/packages/dd-trace/src/plugins/util/web.js +5 -2
  56. package/packages/dd-trace/src/priority_sampler.js +116 -15
  57. package/packages/dd-trace/src/runtime_metrics/runtime_metrics.js +15 -80
  58. package/packages/dd-trace/src/sampler.js +9 -0
  59. package/packages/dd-trace/src/standalone/product.js +6 -2
  60. package/packages/dd-trace/src/startup-log.js +2 -1
  61. package/packages/dd-trace/src/telemetry/metrics.js +0 -8
  62. package/packages/dd-trace/src/tracer.js +1 -1
  63. /package/packages/datadog-instrumentations/src/{utils/src → helpers}/extract-package-and-module-path.js +0 -0
@@ -4,7 +4,7 @@
4
4
 
5
5
  const v8 = require('v8')
6
6
  const os = require('os')
7
- const { DogStatsDClient } = require('../dogstatsd')
7
+ const { DogStatsDClient, MetricsAggregationClient } = require('../dogstatsd')
8
8
  const log = require('../log')
9
9
  const Histogram = require('../histogram')
10
10
  const { performance, PerformanceObserver } = require('perf_hooks')
@@ -25,9 +25,6 @@ let interval
25
25
  let client
26
26
  let time
27
27
  let cpuUsage
28
- let gauges
29
- let counters
30
- let histograms
31
28
  let elu
32
29
 
33
30
  reset()
@@ -49,7 +46,7 @@ const runtimeMetrics = module.exports = {
49
46
  nativeMetrics = null
50
47
  }
51
48
 
52
- client = new DogStatsDClient(clientConfig)
49
+ client = new MetricsAggregationClient(new DogStatsDClient(clientConfig))
53
50
 
54
51
  time = process.hrtime()
55
52
 
@@ -98,50 +95,27 @@ const runtimeMetrics = module.exports = {
98
95
  },
99
96
 
100
97
  boolean (name, value, tag) {
101
- this.gauge(name, value ? 1 : 0, tag)
98
+ client && client.boolean(name, value, tag)
102
99
  },
103
100
 
104
101
  histogram (name, value, tag) {
105
- if (!client) return
106
-
107
- histograms[name] = histograms[name] || new Map()
108
-
109
- if (!histograms[name].has(tag)) {
110
- histograms[name].set(tag, new Histogram())
111
- }
112
-
113
- histograms[name].get(tag).record(value)
102
+ client && client.histogram(name, value, tag)
114
103
  },
115
104
 
116
105
  count (name, count, tag, monotonic = false) {
117
- if (!client) return
118
- if (typeof tag === 'boolean') {
119
- monotonic = tag
120
- tag = undefined
121
- }
122
-
123
- const map = monotonic ? counters : gauges
124
-
125
- map[name] = map[name] || new Map()
126
-
127
- const value = map[name].get(tag) || 0
128
-
129
- map[name].set(tag, value + count)
106
+ client && client.count(name, count, tag, monotonic)
130
107
  },
131
108
 
132
109
  gauge (name, value, tag) {
133
- if (!client) return
134
-
135
- gauges[name] = gauges[name] || new Map()
136
- gauges[name].set(tag, value)
110
+ client && client.gauge(name, value, tag)
137
111
  },
138
112
 
139
113
  increment (name, tag, monotonic) {
140
- this.count(name, 1, tag, monotonic)
114
+ client && client.increment(name, 1, tag, monotonic)
141
115
  },
142
116
 
143
117
  decrement (name, tag) {
144
- this.count(name, -1, tag)
118
+ client && client.decrement(name, 1, tag)
145
119
  }
146
120
  }
147
121
 
@@ -150,9 +124,6 @@ function reset () {
150
124
  client = null
151
125
  time = null
152
126
  cpuUsage = null
153
- gauges = {}
154
- counters = {}
155
- histograms = {}
156
127
  nativeMetrics = null
157
128
  gcObserver && gcObserver.disconnect()
158
129
  gcObserver = null
@@ -246,33 +217,6 @@ function captureGCMetrics () {
246
217
  gcProfiler.start()
247
218
  }
248
219
 
249
- function captureGauges () {
250
- Object.keys(gauges).forEach(name => {
251
- gauges[name].forEach((value, tag) => {
252
- client.gauge(name, value, tag && [tag])
253
- })
254
- })
255
- }
256
-
257
- function captureCounters () {
258
- Object.keys(counters).forEach(name => {
259
- counters[name].forEach((value, tag) => {
260
- client.increment(name, value, tag && [tag])
261
- })
262
- })
263
-
264
- counters = {}
265
- }
266
-
267
- function captureHistograms () {
268
- Object.keys(histograms).forEach(name => {
269
- histograms[name].forEach((stats, tag) => {
270
- histogram(name, stats, tag && [tag])
271
- stats.reset()
272
- })
273
- })
274
- }
275
-
276
220
  /**
277
221
  * Gathers and reports Event Loop Utilization (ELU) since last run
278
222
  *
@@ -295,9 +239,6 @@ function captureCommonMetrics () {
295
239
  captureMemoryUsage()
296
240
  captureProcess()
297
241
  captureHeapStats()
298
- captureGauges()
299
- captureCounters()
300
- captureHistograms()
301
242
  captureELU()
302
243
  captureGCMetrics()
303
244
  }
@@ -339,21 +280,15 @@ function captureNativeMetrics () {
339
280
  }
340
281
 
341
282
  function histogram (name, stats, tags) {
342
- tags = [].concat(tags)
283
+ tags = tags ? [].concat(tags) : []
343
284
 
344
- // Stats can contain garbage data when a value was never recorded.
345
- if (stats.count === 0) {
346
- stats = { max: 0, min: 0, sum: 0, avg: 0, median: 0, p95: 0, count: 0 }
285
+ if (tags.length > 0) {
286
+ for (const tag of tags) {
287
+ client.histogram(name, stats, tag)
288
+ }
289
+ } else {
290
+ client.histogram(name, stats)
347
291
  }
348
-
349
- client.gauge(`${name}.min`, stats.min, tags)
350
- client.gauge(`${name}.max`, stats.max, tags)
351
- client.increment(`${name}.sum`, stats.sum, tags)
352
- client.increment(`${name}.total`, stats.sum, tags)
353
- client.gauge(`${name}.avg`, stats.avg, tags)
354
- client.increment(`${name}.count`, stats.count, tags)
355
- client.gauge(`${name}.median`, stats.median, tags)
356
- client.gauge(`${name}.95percentile`, stats.p95, tags)
357
292
  }
358
293
 
359
294
  function startGCObserver () {
@@ -1,14 +1,23 @@
1
1
  'use strict'
2
2
 
3
3
  class Sampler {
4
+ /**
5
+ * @param rate {number}
6
+ */
4
7
  constructor (rate) {
5
8
  this._rate = rate
6
9
  }
7
10
 
11
+ /**
12
+ * @returns {number}
13
+ */
8
14
  rate () {
9
15
  return this._rate
10
16
  }
11
17
 
18
+ /**
19
+ * @returns {boolean}
20
+ */
12
21
  isSampled () {
13
22
  return this._rate === 1 || Math.random() < this._rate
14
23
  }
@@ -13,12 +13,16 @@ function getProductRateLimiter (config) {
13
13
  return dropAll
14
14
  }
15
15
 
16
- module.exports = {
16
+ const PRODUCTS = {
17
17
  APM: { id: 1 << 0 },
18
18
  ASM: { id: 1 << 1, mechanism: SAMPLING_MECHANISM_APPSEC },
19
19
  DSM: { id: 1 << 2 },
20
20
  DJM: { id: 1 << 3 },
21
- DBM: { id: 1 << 4 },
21
+ DBM: { id: 1 << 4 }
22
+ }
23
+
24
+ module.exports = {
25
+ ...PRODUCTS,
22
26
 
23
27
  getProductRateLimiter
24
28
  }
@@ -86,7 +86,8 @@ function tracerInfo () {
86
86
 
87
87
  out.log_injection_enabled = !!config.logInjection
88
88
  out.runtime_metrics_enabled = !!config.runtimeMetrics
89
- out.profiling_enabled = !!(config.profiling || {}).enabled
89
+ const profilingEnabled = config.profiling?.enabled
90
+ out.profiling_enabled = profilingEnabled === 'true' || profilingEnabled === 'auto'
90
91
  Object.assign(out, getIntegrationsAndAnalytics())
91
92
 
92
93
  out.appsec_enabled = !!config.appsec.enabled
@@ -27,19 +27,11 @@ function hasPoints (metric) {
27
27
  return metric.points.length > 0
28
28
  }
29
29
 
30
- let versionTag
31
-
32
30
  class Metric {
33
31
  constructor (namespace, metric, common, tags) {
34
32
  this.namespace = namespace.toString()
35
33
  this.metric = common ? metric : `nodejs.${metric}`
36
34
  this.tags = tagArray(tags)
37
- if (common) {
38
- if (versionTag === undefined) {
39
- versionTag = `version:${process.version}`
40
- }
41
- this.tags.push(versionTag)
42
- }
43
35
  this.common = common
44
36
 
45
37
  this.points = []
@@ -7,7 +7,7 @@ const { isError } = require('./util')
7
7
  const { setStartupLogConfig } = require('./startup-log')
8
8
  const { ERROR_MESSAGE, ERROR_TYPE, ERROR_STACK } = require('../../dd-trace/src/constants')
9
9
  const { DataStreamsCheckpointer, DataStreamsManager, DataStreamsProcessor } = require('./datastreams')
10
- const { flushStartupLogs } = require('../../datadog-instrumentations/src/check_require_cache')
10
+ const { flushStartupLogs } = require('../../datadog-instrumentations/src/helpers/check-require-cache')
11
11
  const log = require('./log/writer')
12
12
 
13
13
  const SPAN_TYPE = tags.SPAN_TYPE