dd-trace 5.38.0 → 5.40.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 (97) hide show
  1. package/LICENSE-3rdparty.csv +1 -0
  2. package/index.d.ts +30 -21
  3. package/package.json +4 -2
  4. package/packages/datadog-instrumentations/src/apollo-server-core.js +1 -1
  5. package/packages/datadog-instrumentations/src/apollo-server.js +1 -1
  6. package/packages/datadog-instrumentations/src/express-session.js +41 -0
  7. package/packages/datadog-instrumentations/src/fetch.js +27 -6
  8. package/packages/datadog-instrumentations/src/helpers/fetch.js +6 -1
  9. package/packages/datadog-instrumentations/src/helpers/hooks.js +1 -0
  10. package/packages/datadog-instrumentations/src/jest.js +16 -10
  11. package/packages/datadog-instrumentations/src/mocha/main.js +2 -1
  12. package/packages/datadog-instrumentations/src/nyc.js +2 -1
  13. package/packages/datadog-instrumentations/src/vitest.js +4 -2
  14. package/packages/datadog-plugin-amqplib/src/consumer.js +1 -1
  15. package/packages/datadog-plugin-amqplib/src/producer.js +1 -2
  16. package/packages/datadog-plugin-avsc/src/schema_iterator.js +1 -1
  17. package/packages/datadog-plugin-aws-sdk/src/base.js +5 -1
  18. package/packages/datadog-plugin-aws-sdk/src/services/dynamodb.js +9 -8
  19. package/packages/datadog-plugin-aws-sdk/src/services/kinesis.js +1 -4
  20. package/packages/datadog-plugin-aws-sdk/src/services/sns.js +1 -2
  21. package/packages/datadog-plugin-aws-sdk/src/services/sqs.js +1 -2
  22. package/packages/datadog-plugin-google-cloud-pubsub/src/consumer.js +1 -1
  23. package/packages/datadog-plugin-google-cloud-pubsub/src/producer.js +1 -2
  24. package/packages/datadog-plugin-kafkajs/src/batch-consumer.js +1 -1
  25. package/packages/datadog-plugin-kafkajs/src/consumer.js +5 -2
  26. package/packages/datadog-plugin-kafkajs/src/producer.js +4 -3
  27. package/packages/datadog-plugin-mongodb-core/src/index.js +10 -13
  28. package/packages/datadog-plugin-protobufjs/src/schema_iterator.js +1 -1
  29. package/packages/datadog-plugin-rhea/src/consumer.js +1 -1
  30. package/packages/datadog-plugin-rhea/src/producer.js +1 -2
  31. package/packages/datadog-shimmer/src/shimmer.js +95 -95
  32. package/packages/dd-trace/src/appsec/addresses.js +1 -0
  33. package/packages/dd-trace/src/appsec/channels.js +1 -0
  34. package/packages/dd-trace/src/appsec/iast/analyzers/vulnerability-analyzer.js +1 -1
  35. package/packages/dd-trace/src/appsec/iast/iast-context.js +2 -2
  36. package/packages/dd-trace/src/appsec/iast/index.js +0 -1
  37. package/packages/dd-trace/src/appsec/iast/vulnerabilities-formatter/index.js +1 -2
  38. package/packages/dd-trace/src/appsec/iast/vulnerability-reporter.js +3 -5
  39. package/packages/dd-trace/src/appsec/index.js +23 -1
  40. package/packages/dd-trace/src/appsec/reporter.js +3 -8
  41. package/packages/dd-trace/src/appsec/rule_manager.js +1 -1
  42. package/packages/dd-trace/src/appsec/sdk/set_user.js +9 -5
  43. package/packages/dd-trace/src/appsec/sdk/track_event.js +2 -4
  44. package/packages/dd-trace/src/appsec/telemetry/common.js +24 -0
  45. package/packages/dd-trace/src/appsec/telemetry/index.js +126 -0
  46. package/packages/dd-trace/src/appsec/telemetry/rasp.js +35 -0
  47. package/packages/dd-trace/src/appsec/telemetry/user.js +24 -0
  48. package/packages/dd-trace/src/appsec/telemetry/waf.js +92 -0
  49. package/packages/dd-trace/src/appsec/user_tracking.js +2 -4
  50. package/packages/dd-trace/src/ci-visibility/dynamic-instrumentation/index.js +16 -4
  51. package/packages/dd-trace/src/config.js +31 -14
  52. package/packages/dd-trace/src/constants.js +1 -1
  53. package/packages/dd-trace/src/{data_streams.js → datastreams/checkpointer.js} +1 -1
  54. package/packages/dd-trace/src/{data_streams_context.js → datastreams/context.js} +2 -2
  55. package/packages/dd-trace/src/datastreams/index.js +104 -0
  56. package/packages/dd-trace/src/datastreams/manager.js +27 -0
  57. package/packages/dd-trace/src/datastreams/processor.js +1 -44
  58. package/packages/dd-trace/src/datastreams/size.js +53 -0
  59. package/packages/dd-trace/src/debugger/devtools_client/breakpoints.js +2 -2
  60. package/packages/dd-trace/src/debugger/devtools_client/snapshot/collector.js +1 -1
  61. package/packages/dd-trace/src/debugger/devtools_client/source-maps.js +22 -15
  62. package/packages/dd-trace/src/dogstatsd.js +23 -4
  63. package/packages/dd-trace/src/exporters/agent/index.js +2 -2
  64. package/packages/dd-trace/src/flare/index.js +3 -0
  65. package/packages/dd-trace/src/noop/dogstatsd.js +6 -0
  66. package/packages/dd-trace/src/opentelemetry/tracer.js +45 -1
  67. package/packages/dd-trace/src/opentracing/propagation/text_map.js +11 -47
  68. package/packages/dd-trace/src/opentracing/propagation/text_map_dsm.js +1 -1
  69. package/packages/dd-trace/src/opentracing/span.js +12 -2
  70. package/packages/dd-trace/src/payload-tagging/config/aws.json +8 -0
  71. package/packages/dd-trace/src/plugin_manager.js +4 -3
  72. package/packages/dd-trace/src/plugins/ci_plugin.js +2 -2
  73. package/packages/dd-trace/src/priority_sampler.js +5 -3
  74. package/packages/dd-trace/src/profiling/profiler.js +1 -1
  75. package/packages/dd-trace/src/profiling/profilers/wall.js +15 -4
  76. package/packages/dd-trace/src/proxy.js +41 -22
  77. package/packages/dd-trace/src/{appsec/remote_config → remote_config}/capabilities.js +1 -0
  78. package/packages/dd-trace/src/{appsec/remote_config → remote_config}/index.js +8 -5
  79. package/packages/dd-trace/src/{appsec/remote_config → remote_config}/manager.js +5 -5
  80. package/packages/dd-trace/src/runtime_metrics/index.js +34 -0
  81. package/packages/dd-trace/src/{runtime_metrics.js → runtime_metrics/runtime_metrics.js} +4 -4
  82. package/packages/dd-trace/src/serverless.js +10 -1
  83. package/packages/dd-trace/src/service-naming/index.js +12 -4
  84. package/packages/dd-trace/src/span_processor.js +7 -4
  85. package/packages/dd-trace/src/span_stats.js +1 -2
  86. package/packages/dd-trace/src/standalone/index.js +70 -0
  87. package/packages/dd-trace/src/standalone/product.js +24 -0
  88. package/packages/dd-trace/src/standalone/tracesource.js +22 -0
  89. package/packages/dd-trace/src/standalone/tracesource_priority_sampler.js +47 -0
  90. package/packages/dd-trace/src/telemetry/index.js +16 -387
  91. package/packages/dd-trace/src/telemetry/telemetry.js +394 -0
  92. package/packages/dd-trace/src/tracer.js +7 -15
  93. package/packages/dd-trace/src/appsec/standalone.js +0 -130
  94. package/packages/dd-trace/src/appsec/telemetry.js +0 -218
  95. package/packages/dd-trace/src/service-naming/schemas/index.js +0 -6
  96. /package/packages/dd-trace/src/{appsec/remote_config → remote_config}/apply_states.js +0 -0
  97. /package/packages/dd-trace/src/{appsec/remote_config → remote_config}/scheduler.js +0 -0
@@ -54,6 +54,7 @@ dev,eslint-plugin-import,MIT,Copyright 2015 Ben Mosher
54
54
  dev,eslint-plugin-mocha,MIT,Copyright 2014 Mathias Schreck
55
55
  dev,eslint-plugin-n,MIT,Copyright 2015 Toru Nagashima
56
56
  dev,eslint-plugin-promise,ISC,jden and other contributors
57
+ dev,eslint-plugin-unicorn,MIT,Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (https://sindresorhus.com)
57
58
  dev,express,MIT,Copyright 2009-2014 TJ Holowaychuk 2013-2014 Roman Shtylman 2014-2015 Douglas Christopher Wilson
58
59
  dev,get-port,MIT,Copyright Sindre Sorhus
59
60
  dev,glob,ISC,Copyright Isaac Z. Schlueter and Contributors
package/index.d.ts CHANGED
@@ -345,6 +345,12 @@ declare namespace tracer {
345
345
  * List of options available to the tracer.
346
346
  */
347
347
  export interface TracerOptions {
348
+ /**
349
+ * Used to disable APM Tracing when using standalone products
350
+ * @default true
351
+ */
352
+ apmTracingEnabled?: boolean
353
+
348
354
  /**
349
355
  * Whether to enable trace ID injection in log records to be able to correlate
350
356
  * traces with logs.
@@ -528,6 +534,9 @@ declare namespace tracer {
528
534
  appsec?: {
529
535
  /**
530
536
  * Configuration of Standalone ASM mode
537
+ * Deprecated in favor of `apmTracingEnabled`.
538
+ *
539
+ * @deprecated
531
540
  */
532
541
  standalone?: {
533
542
  /**
@@ -813,43 +822,43 @@ declare namespace tracer {
813
822
  export interface DogStatsD {
814
823
  /**
815
824
  * Increments a metric by the specified value, optionally specifying tags.
816
- * @param {string} stat The dot-separated metric name.
817
- * @param {number} value The amount to increment the stat by.
818
- * @param {[tag:string]:string|number} tags Tags to pass along, such as `{ foo: 'bar' }`. Values are combined with config.tags.
825
+ * @param stat The dot-separated metric name.
826
+ * @param value The amount to increment the stat by.
827
+ * @param tags Tags to pass along, such as `{ foo: 'bar' }`. Values are combined with config.tags.
819
828
  */
820
- increment(stat: string, value?: number, tags?: { [tag: string]: string|number }): void
829
+ increment(stat: string, value?: number, tags?: Record<string, string|number>): void
821
830
 
822
831
  /**
823
832
  * Decrements a metric by the specified value, optionally specifying tags.
824
- * @param {string} stat The dot-separated metric name.
825
- * @param {number} value The amount to decrement the stat by.
826
- * @param {[tag:string]:string|number} tags Tags to pass along, such as `{ foo: 'bar' }`. Values are combined with config.tags.
833
+ * @param stat The dot-separated metric name.
834
+ * @param value The amount to decrement the stat by.
835
+ * @param tags Tags to pass along, such as `{ foo: 'bar' }`. Values are combined with config.tags.
827
836
  */
828
- decrement(stat: string, value?: number, tags?: { [tag: string]: string|number }): void
837
+ decrement(stat: string, value?: number, tags?: Record<string, string|number>): void
829
838
 
830
839
  /**
831
840
  * Sets a distribution value, optionally specifying tags.
832
- * @param {string} stat The dot-separated metric name.
833
- * @param {number} value The amount to increment the stat by.
834
- * @param {[tag:string]:string|number} tags Tags to pass along, such as `{ foo: 'bar' }`. Values are combined with config.tags.
841
+ * @param stat The dot-separated metric name.
842
+ * @param value The amount to increment the stat by.
843
+ * @param tags Tags to pass along, such as `{ foo: 'bar' }`. Values are combined with config.tags.
835
844
  */
836
- distribution(stat: string, value?: number, tags?: { [tag: string]: string|number }): void
845
+ distribution(stat: string, value?: number, tags?: Record<string, string|number>): void
837
846
 
838
847
  /**
839
848
  * Sets a gauge value, optionally specifying tags.
840
- * @param {string} stat The dot-separated metric name.
841
- * @param {number} value The amount to increment the stat by.
842
- * @param {[tag:string]:string|number} tags Tags to pass along, such as `{ foo: 'bar' }`. Values are combined with config.tags.
849
+ * @param stat The dot-separated metric name.
850
+ * @param value The amount to increment the stat by.
851
+ * @param tags Tags to pass along, such as `{ foo: 'bar' }`. Values are combined with config.tags.
843
852
  */
844
- gauge(stat: string, value?: number, tags?: { [tag: string]: string|number }): void
853
+ gauge(stat: string, value?: number, tags?: Record<string, string|number>): void
845
854
 
846
855
  /**
847
856
  * Sets a histogram value, optionally specifying tags.
848
- * @param {string} stat The dot-separated metric name.
849
- * @param {number} value The amount to increment the stat by.
850
- * @param {[tag:string]:string|number} tags Tags to pass along, such as `{ foo: 'bar' }`. Values are combined with config.tags.
857
+ * @param stat The dot-separated metric name.
858
+ * @param value The amount to increment the stat by.
859
+ * @param tags Tags to pass along, such as `{ foo: 'bar' }`. Values are combined with config.tags.
851
860
  */
852
- histogram(stat: string, value?: number, tags?: { [tag: string]: string|number }): void
861
+ histogram(stat: string, value?: number, tags?: Record<string, string|number>): void
853
862
 
854
863
  /**
855
864
  * Forces any unsent metrics to be sent
@@ -871,7 +880,7 @@ declare namespace tracer {
871
880
 
872
881
  /**
873
882
  * Links a failed login event to the current trace.
874
- * @param {string} userId The user id of the attemped login.
883
+ * @param {string} userId The user id of the attempted login.
875
884
  * @param {boolean} exists If the user id exists.
876
885
  * @param {[key: string]: string} metadata Custom fields to link to the login failure event.
877
886
  *
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dd-trace",
3
- "version": "5.38.0",
3
+ "version": "5.40.0",
4
4
  "description": "Datadog APM tracing client for JavaScript",
5
5
  "main": "index.js",
6
6
  "typings": "index.d.ts",
@@ -14,6 +14,7 @@
14
14
  "type:test": "cd docs && yarn && yarn test",
15
15
  "lint": "node scripts/check_licenses.js && eslint . --max-warnings 0 && yarn audit",
16
16
  "lint:fix": "node scripts/check_licenses.js && eslint . --max-warnings 0 --fix && yarn audit",
17
+ "lint:inspect": "npx @eslint/config-inspector@latest",
17
18
  "release:proposal": "node scripts/release/proposal",
18
19
  "services": "node ./scripts/install_plugin_modules && node packages/dd-trace/test/setup/services",
19
20
  "test": "SERVICES=* yarn services && mocha --expose-gc 'packages/dd-trace/test/setup/node.js' 'packages/*/test/**/*.spec.js'",
@@ -23,7 +24,7 @@
23
24
  "test:appsec:plugins:ci": "yarn services && nyc --no-clean --include \"packages/dd-trace/src/appsec/**/*.js\" -- npm run test:appsec:plugins",
24
25
  "test:debugger": "mocha -r 'packages/dd-trace/test/setup/mocha.js' 'packages/dd-trace/test/debugger/**/*.spec.js'",
25
26
  "test:debugger:ci": "nyc --no-clean --include 'packages/dd-trace/src/debugger/**/*.js' -- npm run test:debugger",
26
- "test:trace:core": "tap packages/dd-trace/test/*.spec.js \"packages/dd-trace/test/{ci-visibility,datastreams,encode,exporters,opentelemetry,opentracing,plugins,service-naming,telemetry}/**/*.spec.js\"",
27
+ "test:trace:core": "tap packages/dd-trace/test/*.spec.js \"packages/dd-trace/test/{ci-visibility,datastreams,encode,exporters,opentelemetry,opentracing,plugins,service-naming,standalone,telemetry}/**/*.spec.js\"",
27
28
  "test:trace:core:ci": "npm run test:trace:core -- --coverage --nyc-arg=--include=\"packages/dd-trace/src/**/*.js\"",
28
29
  "test:instrumentations": "mocha -r 'packages/dd-trace/test/setup/mocha.js' 'packages/datadog-instrumentations/test/**/*.spec.js'",
29
30
  "test:instrumentations:ci": "nyc --no-clean --include 'packages/datadog-instrumentations/src/**/*.js' -- npm run test:instrumentations",
@@ -138,6 +139,7 @@
138
139
  "eslint-plugin-mocha": "^10.5.0",
139
140
  "eslint-plugin-n": "^17.15.1",
140
141
  "eslint-plugin-promise": "^7.2.1",
142
+ "eslint-plugin-unicorn": "^57.0.0",
141
143
  "express": "^4.21.2",
142
144
  "get-port": "^3.2.0",
143
145
  "glob": "^7.1.6",
@@ -10,7 +10,7 @@ addHook({ name: 'apollo-server-core', file: 'dist/runHttpQuery.js', versions: ['
10
10
  const HttpQueryError = runHttpQueryModule.HttpQueryError
11
11
 
12
12
  shimmer.wrap(runHttpQueryModule, 'runHttpQuery', function wrapRunHttpQuery (originalRunHttpQuery) {
13
- return async function runHttpQuery () {
13
+ return function runHttpQuery () {
14
14
  if (!requestChannel.start.hasSubscribers) {
15
15
  return originalRunHttpQuery.apply(this, arguments)
16
16
  }
@@ -12,7 +12,7 @@ const requestChannel = dc.tracingChannel('datadog:apollo:request')
12
12
  let HeaderMap
13
13
 
14
14
  function wrapExecuteHTTPGraphQLRequest (originalExecuteHTTPGraphQLRequest) {
15
- return async function executeHTTPGraphQLRequest () {
15
+ return function executeHTTPGraphQLRequest () {
16
16
  if (!HeaderMap || !requestChannel.start.hasSubscribers) {
17
17
  return originalExecuteHTTPGraphQLRequest.apply(this, arguments)
18
18
  }
@@ -0,0 +1,41 @@
1
+ 'use strict'
2
+
3
+ const shimmer = require('../../datadog-shimmer')
4
+ const { channel, addHook } = require('./helpers/instrument')
5
+
6
+ const sessionMiddlewareFinishCh = channel('datadog:express-session:middleware:finish')
7
+
8
+ function wrapSessionMiddleware (sessionMiddleware) {
9
+ return function wrappedSessionMiddleware (req, res, next) {
10
+ shimmer.wrap(arguments, 2, function wrapNext (next) {
11
+ return function wrappedNext () {
12
+ if (sessionMiddlewareFinishCh.hasSubscribers) {
13
+ const abortController = new AbortController()
14
+
15
+ sessionMiddlewareFinishCh.publish({ req, res, sessionId: req.sessionID, abortController })
16
+
17
+ if (abortController.signal.aborted) return
18
+ }
19
+
20
+ return next.apply(this, arguments)
21
+ }
22
+ })
23
+
24
+ return sessionMiddleware.apply(this, arguments)
25
+ }
26
+ }
27
+
28
+ function wrapSession (session) {
29
+ return function wrappedSession () {
30
+ const sessionMiddleware = session.apply(this, arguments)
31
+
32
+ return shimmer.wrapFunction(sessionMiddleware, wrapSessionMiddleware)
33
+ }
34
+ }
35
+
36
+ addHook({
37
+ name: 'express-session',
38
+ versions: ['>=1.5.0']
39
+ }, session => {
40
+ return shimmer.wrapFunction(session, wrapSession)
41
+ })
@@ -1,12 +1,33 @@
1
1
  'use strict'
2
2
 
3
- const shimmer = require('../../datadog-shimmer')
4
- const { tracingChannel } = require('dc-polyfill')
5
- const { createWrapFetch } = require('./helpers/fetch')
3
+ const { isInServerlessEnvironment } = require('../../dd-trace/src/serverless')
6
4
 
7
5
  if (globalThis.fetch) {
8
- const ch = tracingChannel('apm:fetch:request')
9
- const wrapFetch = createWrapFetch(globalThis.Request, ch)
6
+ const globalFetch = globalThis.fetch
10
7
 
11
- globalThis.fetch = shimmer.wrapFunction(fetch, fetch => wrapFetch(fetch))
8
+ let fetch = (input, init) => {
9
+ wrapRealFetch()
10
+
11
+ return fetch(input, init)
12
+ }
13
+
14
+ function wrapRealFetch () {
15
+ const { channel, tracingChannel } = require('dc-polyfill')
16
+ const { createWrapFetch } = require('./helpers/fetch')
17
+
18
+ const ch = tracingChannel('apm:fetch:request')
19
+ const wrapFetch = createWrapFetch(globalThis.Request, ch, () => {
20
+ channel('dd-trace:instrumentation:load').publish({ name: 'fetch' })
21
+ })
22
+
23
+ fetch = wrapFetch(globalFetch)
24
+ }
25
+
26
+ if (!isInServerlessEnvironment()) {
27
+ wrapRealFetch()
28
+ }
29
+
30
+ globalThis.fetch = function value (input, init) {
31
+ return fetch(input, init)
32
+ }
12
33
  }
@@ -1,10 +1,15 @@
1
1
  'use strict'
2
2
 
3
- exports.createWrapFetch = function createWrapFetch (Request, ch) {
3
+ exports.createWrapFetch = function createWrapFetch (Request, ch, onLoad) {
4
4
  return function wrapFetch (fetch) {
5
5
  if (typeof fetch !== 'function') return fetch
6
6
 
7
7
  return function (input, init) {
8
+ if (onLoad) {
9
+ onLoad()
10
+ onLoad = undefined
11
+ }
12
+
8
13
  if (!ch.start.hasSubscribers) return fetch.apply(this, arguments)
9
14
 
10
15
  if (input instanceof Request) {
@@ -47,6 +47,7 @@ module.exports = {
47
47
  elasticsearch: () => require('../elasticsearch'),
48
48
  express: () => require('../express'),
49
49
  'express-mongo-sanitize': () => require('../express-mongo-sanitize'),
50
+ 'express-session': () => require('../express-session'),
50
51
  fastify: () => require('../fastify'),
51
52
  'find-my-way': () => require('../find-my-way'),
52
53
  fs: () => require('../fs'),
@@ -147,10 +147,10 @@ function getWrappedEnvironment (BaseEnvironment, jestVersion) {
147
147
 
148
148
  if (this.isKnownTestsEnabled) {
149
149
  try {
150
- const hasKnownTests = !!knownTests.jest
150
+ const hasKnownTests = !!knownTests?.jest
151
151
  earlyFlakeDetectionNumRetries = this.testEnvironmentOptions._ddEarlyFlakeDetectionNumRetries
152
152
  this.knownTestsForThisSuite = hasKnownTests
153
- ? (knownTests.jest[this.testSuite] || [])
153
+ ? (knownTests?.jest[this.testSuite] || [])
154
154
  : this.getKnownTestsForSuite(this.testEnvironmentOptions._ddKnownTests)
155
155
  } catch (e) {
156
156
  // If there has been an error parsing the tests, we'll disable Early Flake Deteciton
@@ -170,7 +170,7 @@ function getWrappedEnvironment (BaseEnvironment, jestVersion) {
170
170
  try {
171
171
  const hasQuarantinedTests = !!quarantinedTests.jest
172
172
  this.quarantinedTestsForThisSuite = hasQuarantinedTests
173
- ? this.getQuarantinedTestsForSuite(quarantinedTests.jest.suites[this.testSuite].tests)
173
+ ? this.getQuarantinedTestsForSuite(quarantinedTests.jest.suites?.[this.testSuite]?.tests)
174
174
  : this.getQuarantinedTestsForSuite(this.testEnvironmentOptions._ddQuarantinedTests)
175
175
  } catch (e) {
176
176
  log.error('Error parsing quarantined tests', e)
@@ -209,11 +209,14 @@ function getWrappedEnvironment (BaseEnvironment, jestVersion) {
209
209
  return knownTestsForSuite
210
210
  }
211
211
 
212
- getQuarantinedTestsForSuite (quaratinedTests) {
212
+ getQuarantinedTestsForSuite (quarantined) {
213
213
  if (this.quarantinedTestsForThisSuite) {
214
214
  return this.quarantinedTestsForThisSuite
215
215
  }
216
- let quarantinedTestsForSuite = quaratinedTests
216
+ if (!quarantined) {
217
+ return []
218
+ }
219
+ let quarantinedTestsForSuite = quarantined
217
220
  // If jest is using workers, quarantined tests are serialized to json.
218
221
  // If jest runs in band, they are not.
219
222
  if (typeof quarantinedTestsForSuite === 'string') {
@@ -439,7 +442,8 @@ addHook({
439
442
  }, getTestEnvironment)
440
443
 
441
444
  function getWrappedScheduleTests (scheduleTests, frameworkVersion) {
442
- return async function (tests) {
445
+ // `scheduleTests` is an async function
446
+ return function (tests) {
443
447
  if (!isSuitesSkippingEnabled || hasFilteredSkippableSuites) {
444
448
  return scheduleTests.apply(this, arguments)
445
449
  }
@@ -741,7 +745,8 @@ function coverageReporterWrapper (coverageReporter) {
741
745
  * This calculation adds no value, so we'll skip it, as long as the user has not manually opted in to code coverage,
742
746
  * in which case we'll leave it.
743
747
  */
744
- shimmer.wrap(CoverageReporter.prototype, '_addUntestedFiles', addUntestedFiles => async function () {
748
+ // `_addUntestedFiles` is an async function
749
+ shimmer.wrap(CoverageReporter.prototype, '_addUntestedFiles', addUntestedFiles => function () {
745
750
  // If the user has added coverage manually, they're willing to pay the price of this execution, so
746
751
  // we will not skip it.
747
752
  if (isSuitesSkippingEnabled && !isUserCodeCoverageEnabled) {
@@ -898,7 +903,8 @@ addHook({
898
903
  }, transformPackage => {
899
904
  const originalCreateScriptTransformer = transformPackage.createScriptTransformer
900
905
 
901
- transformPackage.createScriptTransformer = async function (config) {
906
+ // `createScriptTransformer` is an async function
907
+ transformPackage.createScriptTransformer = function (config) {
902
908
  const { testEnvironmentOptions, ...restOfConfig } = config
903
909
  const {
904
910
  _ddTestModuleId,
@@ -948,7 +954,7 @@ addHook({
948
954
  if (isKnownTestsEnabled) {
949
955
  const projectSuites = testPaths.tests.map(test => getTestSuitePath(test.path, test.context.config.rootDir))
950
956
  const isFaulty =
951
- getIsFaultyEarlyFlakeDetection(projectSuites, knownTests.jest || {}, earlyFlakeDetectionFaultyThreshold)
957
+ getIsFaultyEarlyFlakeDetection(projectSuites, knownTests?.jest || {}, earlyFlakeDetectionFaultyThreshold)
952
958
  if (isFaulty) {
953
959
  log.error('Early flake detection is disabled because the number of new suites is too high.')
954
960
  isEarlyFlakeDetectionEnabled = false
@@ -1060,7 +1066,7 @@ addHook({
1060
1066
  }
1061
1067
  const [{ globalConfig, config, path: testSuiteAbsolutePath }] = args
1062
1068
  const testSuite = getTestSuitePath(testSuiteAbsolutePath, globalConfig.rootDir || process.cwd())
1063
- const suiteKnownTests = knownTests.jest?.[testSuite] || []
1069
+ const suiteKnownTests = knownTests?.jest?.[testSuite] || []
1064
1070
 
1065
1071
  const suiteQuarantinedTests = quarantinedTests.jest?.suites?.[testSuite]?.tests || {}
1066
1072
 
@@ -349,7 +349,8 @@ addHook({
349
349
  versions: ['>=5.2.0'],
350
350
  file: 'lib/cli/run-helpers.js'
351
351
  }, (run) => {
352
- shimmer.wrap(run, 'runMocha', runMocha => async function () {
352
+ // `runMocha` is an async function
353
+ shimmer.wrap(run, 'runMocha', runMocha => function () {
353
354
  if (!testStartCh.hasSubscribers) {
354
355
  return runMocha.apply(this, arguments)
355
356
  }
@@ -7,7 +7,8 @@ addHook({
7
7
  name: 'nyc',
8
8
  versions: ['>=17']
9
9
  }, (nycPackage) => {
10
- shimmer.wrap(nycPackage.prototype, 'wrap', wrap => async function () {
10
+ // `wrap` is an async function
11
+ shimmer.wrap(nycPackage.prototype, 'wrap', wrap => function () {
11
12
  // Only relevant if the config `all` is set to true
12
13
  try {
13
14
  if (JSON.parse(process.env.NYC_CONFIG).all) {
@@ -329,7 +329,8 @@ addHook({
329
329
  const { VitestTestRunner } = vitestPackage
330
330
 
331
331
  // `onBeforeRunTask` is run before any repetition or attempt is run
332
- shimmer.wrap(VitestTestRunner.prototype, 'onBeforeRunTask', onBeforeRunTask => async function (task) {
332
+ // `onBeforeRunTask` is an async function
333
+ shimmer.wrap(VitestTestRunner.prototype, 'onBeforeRunTask', onBeforeRunTask => function (task) {
333
334
  const testName = getTestName(task)
334
335
 
335
336
  const {
@@ -361,7 +362,8 @@ addHook({
361
362
  })
362
363
 
363
364
  // `onAfterRunTask` is run after all repetitions or attempts are run
364
- shimmer.wrap(VitestTestRunner.prototype, 'onAfterRunTask', onAfterRunTask => async function (task) {
365
+ // `onAfterRunTask` is an async function
366
+ shimmer.wrap(VitestTestRunner.prototype, 'onAfterRunTask', onAfterRunTask => function (task) {
365
367
  const { isEarlyFlakeDetectionEnabled, isQuarantinedTestsEnabled } = getProvidedContext()
366
368
 
367
369
  if (isEarlyFlakeDetectionEnabled && taskToStatuses.has(task)) {
@@ -2,7 +2,7 @@
2
2
 
3
3
  const { TEXT_MAP } = require('../../../ext/formats')
4
4
  const ConsumerPlugin = require('../../dd-trace/src/plugins/consumer')
5
- const { getAmqpMessageSize } = require('../../dd-trace/src/datastreams/processor')
5
+ const { getAmqpMessageSize } = require('../../dd-trace/src/datastreams')
6
6
  const { getResourceName } = require('./util')
7
7
 
8
8
  class AmqplibConsumerPlugin extends ConsumerPlugin {
@@ -3,8 +3,7 @@
3
3
  const { TEXT_MAP } = require('../../../ext/formats')
4
4
  const { CLIENT_PORT_KEY } = require('../../dd-trace/src/constants')
5
5
  const ProducerPlugin = require('../../dd-trace/src/plugins/producer')
6
- const { DsmPathwayCodec } = require('../../dd-trace/src/datastreams/pathway')
7
- const { getAmqpMessageSize } = require('../../dd-trace/src/datastreams/processor')
6
+ const { DsmPathwayCodec, getAmqpMessageSize } = require('../../dd-trace/src/datastreams')
8
7
  const { getResourceName } = require('./util')
9
8
 
10
9
  class AmqplibProducerPlugin extends ProducerPlugin {
@@ -10,7 +10,7 @@ const {
10
10
  const log = require('../../dd-trace/src/log')
11
11
  const {
12
12
  SchemaBuilder
13
- } = require('../../dd-trace/src/datastreams/schemas/schema_builder')
13
+ } = require('../../dd-trace/src/datastreams')
14
14
 
15
15
  class SchemaExtractor {
16
16
  constructor (schema) {
@@ -93,7 +93,11 @@ class BaseAwsSdkPlugin extends ClientPlugin {
93
93
  this.responseExtractDSMContext(operation, params, response.data ?? response, span)
94
94
  }
95
95
  this.addResponseTags(span, response)
96
- this.addSpanPointers(span, response)
96
+
97
+ if (this._tracerConfig?.trace?.aws?.addSpanPointers) {
98
+ this.addSpanPointers(span, response)
99
+ }
100
+
97
101
  this.finish(span, response, response.error)
98
102
  })
99
103
  }
@@ -8,6 +8,7 @@ const { extractPrimaryKeys, generatePointerHash } = require('../util')
8
8
  class DynamoDb extends BaseAwsSdkPlugin {
9
9
  static get id () { return 'dynamodb' }
10
10
  static get peerServicePrecursors () { return ['tablename'] }
11
+ static get isPayloadReporter () { return true }
11
12
 
12
13
  generateTags (params, operation, response) {
13
14
  const tags = {}
@@ -113,7 +114,7 @@ class DynamoDb extends BaseAwsSdkPlugin {
113
114
  }
114
115
 
115
116
  /**
116
- * Parses primary key config from the `DD_AWS_SDK_DYNAMODB_TABLE_PRIMARY_KEYS` env var.
117
+ * Parses primary key config from the `DD_TRACE_DYNAMODB_TABLE_PRIMARY_KEYS` env var.
117
118
  * Only runs when needed, and warns when missing or invalid config.
118
119
  * @returns {Object|undefined} Parsed config from env var or undefined if empty/missing/invalid config.
119
120
  */
@@ -123,9 +124,9 @@ class DynamoDb extends BaseAwsSdkPlugin {
123
124
  return this.dynamoPrimaryKeyConfig
124
125
  }
125
126
 
126
- const configStr = this._tracerConfig?.aws?.dynamoDb?.tablePrimaryKeys
127
+ const configStr = this._tracerConfig?.trace?.dynamoDb?.tablePrimaryKeys
127
128
  if (!configStr) {
128
- log.warn('Missing DD_AWS_SDK_DYNAMODB_TABLE_PRIMARY_KEYS env variable. ' +
129
+ log.warn('Missing DD_TRACE_DYNAMODB_TABLE_PRIMARY_KEYS env variable. ' +
129
130
  'Please add your table\'s primary keys under this env variable.')
130
131
  return
131
132
  }
@@ -138,14 +139,14 @@ class DynamoDb extends BaseAwsSdkPlugin {
138
139
  config[tableName] = new Set(primaryKeys)
139
140
  } else {
140
141
  log.warn(`Invalid primary key configuration for table: ${tableName}.` +
141
- 'Please fix the DD_AWS_SDK_DYNAMODB_TABLE_PRIMARY_KEYS env var.')
142
+ 'Please fix the DD_TRACE_DYNAMODB_TABLE_PRIMARY_KEYS env var.')
142
143
  }
143
144
  }
144
145
 
145
146
  this.dynamoPrimaryKeyConfig = config
146
147
  return config
147
148
  } catch (err) {
148
- log.warn('Failed to parse DD_AWS_SDK_DYNAMODB_TABLE_PRIMARY_KEYS:', err.message)
149
+ log.warn('Failed to parse DD_TRACE_DYNAMODB_TABLE_PRIMARY_KEYS:', err.message)
149
150
  }
150
151
  }
151
152
 
@@ -154,7 +155,7 @@ class DynamoDb extends BaseAwsSdkPlugin {
154
155
  * @param {string} tableName - Name of the DynamoDB table.
155
156
  * @param {Object} item - Complete PutItem item parameter to be put.
156
157
  * @param {Object.<string, Set<string>>} primaryKeyConfig - Mapping of table names to Sets of primary key names
157
- * loaded from DD_AWS_SDK_DYNAMODB_TABLE_PRIMARY_KEYS.
158
+ * loaded from DD_TRACE_DYNAMODB_TABLE_PRIMARY_KEYS.
158
159
  * @returns {string|undefined} Hash combining table name and primary key/value pairs, or undefined if unable.
159
160
  */
160
161
  static calculatePutItemHash (tableName, item, primaryKeyConfig) {
@@ -163,14 +164,14 @@ class DynamoDb extends BaseAwsSdkPlugin {
163
164
  return
164
165
  }
165
166
  if (!primaryKeyConfig) {
166
- log.warn('Missing DD_AWS_SDK_DYNAMODB_TABLE_PRIMARY_KEYS env variable')
167
+ log.warn('Missing DD_TRACE_DYNAMODB_TABLE_PRIMARY_KEYS env variable')
167
168
  return
168
169
  }
169
170
  const primaryKeySet = primaryKeyConfig[tableName]
170
171
  if (!primaryKeySet || !(primaryKeySet instanceof Set) || primaryKeySet.size === 0 || primaryKeySet.size > 2) {
171
172
  log.warn(
172
173
  `span pointers: failed to extract PutItem span pointer: table ${tableName} ` +
173
- 'not found in primary key names or the DD_AWS_SDK_DYNAMODB_TABLE_PRIMARY_KEYS env var was invalid.' +
174
+ 'not found in primary key names or the DD_TRACE_DYNAMODB_TABLE_PRIMARY_KEYS env var was invalid.' +
174
175
  'Please update the env var.'
175
176
  )
176
177
  return
@@ -1,8 +1,5 @@
1
1
  'use strict'
2
- const {
3
- getSizeOrZero
4
- } = require('../../../dd-trace/src/datastreams/processor')
5
- const { DsmPathwayCodec } = require('../../../dd-trace/src/datastreams/pathway')
2
+ const { DsmPathwayCodec, getSizeOrZero } = require('../../../dd-trace/src/datastreams')
6
3
  const log = require('../../../dd-trace/src/log')
7
4
  const BaseAwsSdkPlugin = require('../base')
8
5
  const { storage } = require('../../../datadog-core')
@@ -1,6 +1,5 @@
1
1
  'use strict'
2
- const { getHeadersSize } = require('../../../dd-trace/src/datastreams/processor')
3
- const { DsmPathwayCodec } = require('../../../dd-trace/src/datastreams/pathway')
2
+ const { DsmPathwayCodec, getHeadersSize } = require('../../../dd-trace/src/datastreams')
4
3
  const log = require('../../../dd-trace/src/log')
5
4
  const BaseAwsSdkPlugin = require('../base')
6
5
 
@@ -3,8 +3,7 @@
3
3
  const log = require('../../../dd-trace/src/log')
4
4
  const BaseAwsSdkPlugin = require('../base')
5
5
  const { storage } = require('../../../datadog-core')
6
- const { getHeadersSize } = require('../../../dd-trace/src/datastreams/processor')
7
- const { DsmPathwayCodec } = require('../../../dd-trace/src/datastreams/pathway')
6
+ const { DsmPathwayCodec, getHeadersSize } = require('../../../dd-trace/src/datastreams')
8
7
 
9
8
  class Sqs extends BaseAwsSdkPlugin {
10
9
  static get id () { return 'sqs' }
@@ -1,6 +1,6 @@
1
1
  'use strict'
2
2
 
3
- const { getMessageSize } = require('../../dd-trace/src/datastreams/processor')
3
+ const { getMessageSize } = require('../../dd-trace/src/datastreams')
4
4
  const ConsumerPlugin = require('../../dd-trace/src/plugins/consumer')
5
5
 
6
6
  class GoogleCloudPubsubConsumerPlugin extends ConsumerPlugin {
@@ -1,8 +1,7 @@
1
1
  'use strict'
2
2
 
3
3
  const ProducerPlugin = require('../../dd-trace/src/plugins/producer')
4
- const { DsmPathwayCodec } = require('../../dd-trace/src/datastreams/pathway')
5
- const { getHeadersSize } = require('../../dd-trace/src/datastreams/processor')
4
+ const { DsmPathwayCodec, getHeadersSize } = require('../../dd-trace/src/datastreams')
6
5
 
7
6
  class GoogleCloudPubsubProducerPlugin extends ProducerPlugin {
8
7
  static get id () { return 'google-cloud-pubsub' }
@@ -1,5 +1,5 @@
1
1
  const ConsumerPlugin = require('../../dd-trace/src/plugins/consumer')
2
- const { getMessageSize } = require('../../dd-trace/src/datastreams/processor')
2
+ const { getMessageSize } = require('../../dd-trace/src/datastreams')
3
3
 
4
4
  class KafkajsBatchConsumerPlugin extends ConsumerPlugin {
5
5
  static get id () { return 'kafkajs' }
@@ -1,12 +1,14 @@
1
1
  'use strict'
2
2
 
3
3
  const dc = require('dc-polyfill')
4
- const { getMessageSize } = require('../../dd-trace/src/datastreams/processor')
4
+ const { getMessageSize } = require('../../dd-trace/src/datastreams')
5
5
  const ConsumerPlugin = require('../../dd-trace/src/plugins/consumer')
6
6
 
7
7
  const afterStartCh = dc.channel('dd-trace:kafkajs:consumer:afterStart')
8
8
  const beforeFinishCh = dc.channel('dd-trace:kafkajs:consumer:beforeFinish')
9
9
 
10
+ const MESSAGING_DESTINATION_KEY = 'messaging.destination.name'
11
+
10
12
  class KafkajsConsumerPlugin extends ConsumerPlugin {
11
13
  static get id () { return 'kafkajs' }
12
14
  static get operation () { return 'consume' }
@@ -72,7 +74,8 @@ class KafkajsConsumerPlugin extends ConsumerPlugin {
72
74
  component: 'kafkajs',
73
75
  'kafka.topic': topic,
74
76
  'kafka.message.offset': message.offset,
75
- 'kafka.cluster_id': clusterId
77
+ 'kafka.cluster_id': clusterId,
78
+ [MESSAGING_DESTINATION_KEY]: topic
76
79
  },
77
80
  metrics: {
78
81
  'kafka.partition': partition
@@ -1,10 +1,10 @@
1
1
  'use strict'
2
2
 
3
3
  const ProducerPlugin = require('../../dd-trace/src/plugins/producer')
4
- const { DsmPathwayCodec } = require('../../dd-trace/src/datastreams/pathway')
5
- const { getMessageSize } = require('../../dd-trace/src/datastreams/processor')
4
+ const { DsmPathwayCodec, getMessageSize } = require('../../dd-trace/src/datastreams')
6
5
 
7
6
  const BOOTSTRAP_SERVERS_KEY = 'messaging.kafka.bootstrap.servers'
7
+ const MESSAGING_DESTINATION_KEY = 'messaging.destination.name'
8
8
 
9
9
  class KafkajsProducerPlugin extends ProducerPlugin {
10
10
  static get id () { return 'kafkajs' }
@@ -72,7 +72,8 @@ class KafkajsProducerPlugin extends ProducerPlugin {
72
72
  meta: {
73
73
  component: 'kafkajs',
74
74
  'kafka.topic': topic,
75
- 'kafka.cluster_id': clusterId
75
+ 'kafka.cluster_id': clusterId,
76
+ [MESSAGING_DESTINATION_KEY]: topic
76
77
  },
77
78
  metrics: {
78
79
  'kafka.batch_size': messages.length