dd-trace 6.0.0-pre-4df8c4d → 6.0.0-pre-d6f5ded

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 (99) hide show
  1. package/LICENSE-3rdparty.csv +2 -0
  2. package/index.d.ts +20 -0
  3. package/package.json +8 -5
  4. package/packages/datadog-instrumentations/src/aerospike.js +1 -1
  5. package/packages/datadog-instrumentations/src/apollo-server.js +1 -1
  6. package/packages/datadog-instrumentations/src/aws-sdk.js +4 -4
  7. package/packages/datadog-instrumentations/src/body-parser.js +4 -4
  8. package/packages/datadog-instrumentations/src/cassandra-driver.js +2 -2
  9. package/packages/datadog-instrumentations/src/child_process.js +2 -2
  10. package/packages/datadog-instrumentations/src/connect.js +4 -4
  11. package/packages/datadog-instrumentations/src/cookie-parser.js +4 -4
  12. package/packages/datadog-instrumentations/src/couchbase.js +12 -12
  13. package/packages/datadog-instrumentations/src/cucumber.js +9 -8
  14. package/packages/datadog-instrumentations/src/dns.js +10 -10
  15. package/packages/datadog-instrumentations/src/elasticsearch.js +4 -4
  16. package/packages/datadog-instrumentations/src/express-mongo-sanitize.js +3 -3
  17. package/packages/datadog-instrumentations/src/express.js +4 -4
  18. package/packages/datadog-instrumentations/src/fastify.js +6 -6
  19. package/packages/datadog-instrumentations/src/fetch.js +1 -1
  20. package/packages/datadog-instrumentations/src/find-my-way.js +2 -2
  21. package/packages/datadog-instrumentations/src/fs.js +2 -2
  22. package/packages/datadog-instrumentations/src/google-cloud-pubsub.js +2 -2
  23. package/packages/datadog-instrumentations/src/grpc/client.js +4 -6
  24. package/packages/datadog-instrumentations/src/grpc/server.js +2 -2
  25. package/packages/datadog-instrumentations/src/hapi.js +10 -13
  26. package/packages/datadog-instrumentations/src/http/client.js +3 -3
  27. package/packages/datadog-instrumentations/src/jest.js +6 -4
  28. package/packages/datadog-instrumentations/src/kafkajs.js +67 -31
  29. package/packages/datadog-instrumentations/src/knex.js +2 -2
  30. package/packages/datadog-instrumentations/src/koa.js +5 -5
  31. package/packages/datadog-instrumentations/src/ldapjs.js +1 -1
  32. package/packages/datadog-instrumentations/src/mariadb.js +8 -8
  33. package/packages/datadog-instrumentations/src/memcached.js +2 -2
  34. package/packages/datadog-instrumentations/src/microgateway-core.js +7 -5
  35. package/packages/datadog-instrumentations/src/mocha/common.js +1 -1
  36. package/packages/datadog-instrumentations/src/mocha/main.js +1 -0
  37. package/packages/datadog-instrumentations/src/mocha/utils.js +2 -3
  38. package/packages/datadog-instrumentations/src/mocha.js +4 -0
  39. package/packages/datadog-instrumentations/src/moleculer/server.js +2 -2
  40. package/packages/datadog-instrumentations/src/mongodb-core.js +7 -7
  41. package/packages/datadog-instrumentations/src/mongoose.js +5 -6
  42. package/packages/datadog-instrumentations/src/mysql.js +3 -3
  43. package/packages/datadog-instrumentations/src/mysql2.js +6 -6
  44. package/packages/datadog-instrumentations/src/net.js +2 -2
  45. package/packages/datadog-instrumentations/src/next.js +5 -5
  46. package/packages/datadog-instrumentations/src/openai.js +4 -2
  47. package/packages/datadog-instrumentations/src/oracledb.js +8 -8
  48. package/packages/datadog-instrumentations/src/passport-http.js +1 -1
  49. package/packages/datadog-instrumentations/src/passport-local.js +1 -1
  50. package/packages/datadog-instrumentations/src/passport-utils.js +1 -1
  51. package/packages/datadog-instrumentations/src/pg.js +1 -1
  52. package/packages/datadog-instrumentations/src/pino.js +4 -4
  53. package/packages/datadog-instrumentations/src/playwright.js +6 -4
  54. package/packages/datadog-instrumentations/src/redis.js +2 -2
  55. package/packages/datadog-instrumentations/src/restify.js +4 -4
  56. package/packages/datadog-instrumentations/src/rhea.js +4 -4
  57. package/packages/datadog-instrumentations/src/router.js +5 -5
  58. package/packages/datadog-instrumentations/src/sharedb.js +2 -2
  59. package/packages/datadog-instrumentations/src/vitest.js +4 -3
  60. package/packages/datadog-instrumentations/src/winston.js +2 -3
  61. package/packages/datadog-plugin-aws-sdk/src/base.js +33 -0
  62. package/packages/datadog-plugin-aws-sdk/src/services/sns.js +2 -0
  63. package/packages/datadog-plugin-cypress/src/cypress-plugin.js +20 -5
  64. package/packages/datadog-plugin-hapi/src/index.js +2 -2
  65. package/packages/datadog-plugin-jest/src/index.js +1 -0
  66. package/packages/datadog-plugin-kafkajs/src/batch-consumer.js +21 -0
  67. package/packages/datadog-plugin-kafkajs/src/index.js +3 -1
  68. package/packages/datadog-plugin-vitest/src/index.js +18 -1
  69. package/packages/datadog-shimmer/src/shimmer.js +144 -10
  70. package/packages/dd-trace/src/appsec/blocking.js +23 -17
  71. package/packages/dd-trace/src/appsec/graphql.js +3 -1
  72. package/packages/dd-trace/src/appsec/remote_config/index.js +8 -7
  73. package/packages/dd-trace/src/appsec/remote_config/manager.js +93 -52
  74. package/packages/dd-trace/src/appsec/rule_manager.js +8 -0
  75. package/packages/dd-trace/src/appsec/telemetry.js +3 -3
  76. package/packages/dd-trace/src/appsec/waf/waf_context_wrapper.js +5 -0
  77. package/packages/dd-trace/src/ci-visibility/exporters/agentless/writer.js +4 -0
  78. package/packages/dd-trace/src/ci-visibility/exporters/ci-visibility-exporter.js +15 -1
  79. package/packages/dd-trace/src/config.js +57 -9
  80. package/packages/dd-trace/src/constants.js +4 -1
  81. package/packages/dd-trace/src/encode/agentless-ci-visibility.js +29 -2
  82. package/packages/dd-trace/src/lambda/handler.js +1 -0
  83. package/packages/dd-trace/src/lambda/index.js +12 -1
  84. package/packages/dd-trace/src/opentracing/propagation/text_map.js +1 -6
  85. package/packages/dd-trace/src/payload-tagging/config/aws.json +30 -0
  86. package/packages/dd-trace/src/payload-tagging/config/index.js +30 -0
  87. package/packages/dd-trace/src/payload-tagging/index.js +93 -0
  88. package/packages/dd-trace/src/payload-tagging/tagging.js +83 -0
  89. package/packages/dd-trace/src/plugin_manager.js +11 -10
  90. package/packages/dd-trace/src/plugins/ci_plugin.js +18 -1
  91. package/packages/dd-trace/src/plugins/util/test.js +24 -4
  92. package/packages/dd-trace/src/profiler.js +15 -3
  93. package/packages/dd-trace/src/profiling/config.js +7 -0
  94. package/packages/dd-trace/src/profiling/exporter_cli.js +13 -1
  95. package/packages/dd-trace/src/profiling/exporters/agent.js +7 -1
  96. package/packages/dd-trace/src/profiling/ssi-heuristics.js +10 -2
  97. package/packages/dd-trace/src/proxy.js +4 -3
  98. package/packages/dd-trace/src/telemetry/index.js +24 -6
  99. package/packages/dd-trace/src/telemetry/logs/index.js +6 -1
@@ -14,6 +14,7 @@ require,import-in-the-middle,Apache license 2.0,Copyright 2021 Datadog Inc.
14
14
  require,int64-buffer,MIT,Copyright 2015-2016 Yusuke Kawasaki
15
15
  require,istanbul-lib-coverage,BSD-3-Clause,Copyright 2012-2015 Yahoo! Inc.
16
16
  require,jest-docblock,MIT,Copyright Meta Platforms, Inc. and affiliates.
17
+ require,jsonpath-plus,MIT,Copyright (c) 2011-2019 Stefan Goessner, Subbu Allamaraju, Mike Brevoort, Robert Krahn, Brett Zamir, Richard Schneider
17
18
  require,koalas,MIT,Copyright 2013-2017 Brian Woodward
18
19
  require,limiter,MIT,Copyright 2011 John Hurliman
19
20
  require,lodash.sortby,MIT,Copyright JS Foundation and other contributors
@@ -26,6 +27,7 @@ require,pprof-format,MIT,Copyright 2022 Stephen Belanger
26
27
  require,protobufjs,BSD-3-Clause,Copyright 2016 Daniel Wirtz
27
28
  require,tlhunter-sorted-set,MIT,Copyright (c) 2023 Datadog Inc.
28
29
  require,retry,MIT,Copyright 2011 Tim Koschützki Felix Geisendörfer
30
+ require,rfdc,MIT,Copyright 2019 David Mark Clements
29
31
  require,semver,ISC,Copyright Isaac Z. Schlueter and Contributors
30
32
  require,shell-quote,mit,Copyright (c) 2013 James Halliday
31
33
  dev,@types/node,MIT,Copyright Authors
package/index.d.ts CHANGED
@@ -729,6 +729,26 @@ declare namespace tracer {
729
729
  * The selection and priority order of context propagation injection and extraction mechanisms.
730
730
  */
731
731
  propagationStyle?: string[] | PropagationStyle
732
+
733
+ /**
734
+ * Cloud payload report as tags
735
+ */
736
+ cloudPayloadTagging?: {
737
+ /**
738
+ * Additional JSONPath queries to replace with `redacted` in request payloads
739
+ * Undefined or invalid JSONPath queries disable the feature for requests.
740
+ */
741
+ request?: string,
742
+ /**
743
+ * Additional JSONPath queries to replace with `redacted` in response payloads
744
+ * Undefined or invalid JSONPath queries disable the feature for responses.
745
+ */
746
+ response?: string,
747
+ /**
748
+ * Maximum depth of payload traversal for tags
749
+ */
750
+ maxDepth?: number
751
+ }
732
752
  }
733
753
 
734
754
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dd-trace",
3
- "version": "6.0.0-pre-4df8c4d",
3
+ "version": "6.0.0-pre-d6f5ded",
4
4
  "description": "Datadog APM tracing client for JavaScript",
5
5
  "main": "index.js",
6
6
  "typings": "index.d.ts",
@@ -13,6 +13,7 @@
13
13
  "type:doc": "cd docs && yarn && yarn build",
14
14
  "type:test": "cd docs && yarn && yarn test",
15
15
  "lint": "node scripts/check_licenses.js && eslint . && yarn audit --groups dependencies",
16
+ "lint-fix": "node scripts/check_licenses.js && eslint . --fix && yarn audit --groups dependencies",
16
17
  "services": "node ./scripts/install_plugin_modules && node packages/dd-trace/test/setup/services",
17
18
  "test": "SERVICES=* yarn services && mocha --expose-gc 'packages/dd-trace/test/setup/node.js' 'packages/*/test/**/*.spec.js'",
18
19
  "test:appsec": "mocha -r \"packages/dd-trace/test/setup/mocha.js\" --exclude \"packages/dd-trace/test/appsec/**/*.plugin.spec.js\" \"packages/dd-trace/test/appsec/**/*.spec.js\"",
@@ -72,7 +73,7 @@
72
73
  "node": ">=18"
73
74
  },
74
75
  "dependencies": {
75
- "@datadog/native-appsec": "8.0.1",
76
+ "@datadog/native-appsec": "8.1.1",
76
77
  "@datadog/native-iast-rewriter": "2.4.1",
77
78
  "@datadog/native-iast-taint-tracking": "3.1.0",
78
79
  "@datadog/native-metrics": "^2.0.0",
@@ -87,6 +88,7 @@
87
88
  "int64-buffer": "^0.1.9",
88
89
  "istanbul-lib-coverage": "3.2.0",
89
90
  "jest-docblock": "^29.7.0",
91
+ "jsonpath-plus": "^9.0.0",
90
92
  "koalas": "^1.0.2",
91
93
  "limiter": "1.1.5",
92
94
  "lodash.sortby": "^4.7.0",
@@ -94,10 +96,11 @@
94
96
  "module-details-from-path": "^1.0.3",
95
97
  "msgpack-lite": "^0.1.26",
96
98
  "opentracing": ">=0.12.1",
97
- "path-to-regexp": "^0.1.2",
99
+ "path-to-regexp": "^0.1.10",
98
100
  "pprof-format": "^2.1.0",
99
101
  "protobufjs": "^7.2.5",
100
102
  "retry": "^0.13.1",
103
+ "rfdc": "^1.3.1",
101
104
  "semver": "^7.5.4",
102
105
  "shell-quote": "^1.8.1",
103
106
  "tlhunter-sorted-set": "^0.1.0"
@@ -106,7 +109,7 @@
106
109
  "@types/node": "^16.18.103",
107
110
  "autocannon": "^4.5.2",
108
111
  "aws-sdk": "^2.1446.0",
109
- "axios": "^1.6.7",
112
+ "axios": "^1.7.4",
110
113
  "benchmark": "^2.1.4",
111
114
  "body-parser": "^1.20.2",
112
115
  "chai": "^4.3.7",
@@ -116,11 +119,11 @@
116
119
  "dotenv": "16.3.1",
117
120
  "esbuild": "0.16.12",
118
121
  "eslint": "^8.57.0",
119
- "eslint-config-standard": "^17.1.0",
120
122
  "eslint-plugin-import": "^2.29.1",
121
123
  "eslint-plugin-mocha": "^10.4.3",
122
124
  "eslint-plugin-n": "^16.6.2",
123
125
  "eslint-plugin-promise": "^6.4.0",
126
+ "eslint-config-standard": "^17.1.0",
124
127
  "express": "^4.18.2",
125
128
  "get-port": "^3.2.0",
126
129
  "glob": "^7.1.6",
@@ -43,5 +43,5 @@ addHook({
43
43
  versions: ['^3.16.2', '4', '5']
44
44
  },
45
45
  commandFactory => {
46
- return shimmer.wrap(commandFactory, wrapCreateCommand(commandFactory))
46
+ return shimmer.wrapFunction(commandFactory, f => wrapCreateCommand(f))
47
47
  })
@@ -55,7 +55,7 @@ function apolloExpress4Hook (express4) {
55
55
  return function expressMiddleware (server, options) {
56
56
  const originalMiddleware = originalExpressMiddleware.apply(this, arguments)
57
57
 
58
- return shimmer.wrap(originalMiddleware, function (req, res, next) {
58
+ return shimmer.wrapFunction(originalMiddleware, originalMiddleware => function (req, res, next) {
59
59
  if (!graphqlMiddlewareChannel.start.hasSubscribers) {
60
60
  return originalMiddleware.apply(this, arguments)
61
61
  }
@@ -75,7 +75,7 @@ function wrapSmithySend (send) {
75
75
  })
76
76
 
77
77
  if (typeof cb === 'function') {
78
- args[args.length - 1] = function (err, result) {
78
+ args[args.length - 1] = shimmer.wrapFunction(cb, cb => function (err, result) {
79
79
  const message = getMessage(request, err, result)
80
80
 
81
81
  completeChannel.publish(message)
@@ -89,7 +89,7 @@ function wrapSmithySend (send) {
89
89
  responseFinishChannel.publish(message.response.error)
90
90
  }
91
91
  })
92
- }
92
+ })
93
93
  } else { // always a promise
94
94
  return send.call(this, command, ...args)
95
95
  .then(
@@ -113,7 +113,7 @@ function wrapSmithySend (send) {
113
113
 
114
114
  function wrapCb (cb, serviceName, request, ar) {
115
115
  // eslint-disable-next-line n/handle-callback-err
116
- return function wrappedCb (err, response) {
116
+ return shimmer.wrapFunction(cb, cb => function wrappedCb (err, response) {
117
117
  const obj = { request, response }
118
118
  return ar.runInAsyncScope(() => {
119
119
  channel(`apm:aws:response:start:${serviceName}`).publish(obj)
@@ -141,7 +141,7 @@ function wrapCb (cb, serviceName, request, ar) {
141
141
  throw e
142
142
  }
143
143
  })
144
- }
144
+ })
145
145
  }
146
146
 
147
147
  function getMessage (request, error, result) {
@@ -6,7 +6,7 @@ const { channel, addHook, AsyncResource } = require('./helpers/instrument')
6
6
  const bodyParserReadCh = channel('datadog:body-parser:read:finish')
7
7
 
8
8
  function publishRequestBodyAndNext (req, res, next) {
9
- return function () {
9
+ return shimmer.wrapFunction(next, next => function () {
10
10
  if (bodyParserReadCh.hasSubscribers && req) {
11
11
  const abortController = new AbortController()
12
12
  const body = req.body
@@ -17,7 +17,7 @@ function publishRequestBodyAndNext (req, res, next) {
17
17
  }
18
18
 
19
19
  return next.apply(this, arguments)
20
- }
20
+ })
21
21
  }
22
22
 
23
23
  addHook({
@@ -25,7 +25,7 @@ addHook({
25
25
  file: 'lib/read.js',
26
26
  versions: ['>=1.4.0 <1.20.0']
27
27
  }, read => {
28
- return shimmer.wrap(read, function (req, res, next) {
28
+ return shimmer.wrapFunction(read, read => function (req, res, next) {
29
29
  const nextResource = new AsyncResource('bound-anonymous-fn')
30
30
  arguments[2] = nextResource.bind(publishRequestBodyAndNext(req, res, next))
31
31
  return read.apply(this, arguments)
@@ -37,7 +37,7 @@ addHook({
37
37
  file: 'lib/read.js',
38
38
  versions: ['>=1.20.0']
39
39
  }, read => {
40
- return shimmer.wrap(read, function (req, res, next) {
40
+ return shimmer.wrapFunction(read, read => function (req, res, next) {
41
41
  arguments[2] = publishRequestBodyAndNext(req, res, next)
42
42
  return read.apply(this, arguments)
43
43
  })
@@ -180,12 +180,12 @@ function finish (finishCh, errorCh, error) {
180
180
  }
181
181
 
182
182
  function wrapCallback (finishCh, errorCh, asyncResource, callback) {
183
- return asyncResource.bind(function (err) {
183
+ return shimmer.wrapFunction(callback, callback => asyncResource.bind(function (err) {
184
184
  finish(finishCh, errorCh, err)
185
185
  if (callback) {
186
186
  return callback.apply(this, arguments)
187
187
  }
188
- })
188
+ }))
189
189
  }
190
190
 
191
191
  function isRequestValid (exec, args, length) {
@@ -133,8 +133,8 @@ function wrapChildProcessAsyncMethod (shell = false) {
133
133
 
134
134
  if (childProcessMethod[util.promisify.custom]) {
135
135
  const wrapedChildProcessCustomPromisifyMethod =
136
- shimmer.wrap(childProcessMethod[util.promisify.custom],
137
- wrapChildProcessCustomPromisifyMethod(childProcessMethod[util.promisify.custom]), shell)
136
+ shimmer.wrapFunction(childProcessMethod[util.promisify.custom],
137
+ promisify => wrapChildProcessCustomPromisifyMethod(promisify, shell))
138
138
 
139
139
  // should do it in this way because the original property is readonly
140
140
  const descriptor = Object.getOwnPropertyDescriptor(childProcessMethod, util.promisify.custom)
@@ -59,7 +59,7 @@ function wrapLayerHandle (layer) {
59
59
 
60
60
  const original = layer.handle
61
61
 
62
- return shimmer.wrap(original, function () {
62
+ return shimmer.wrapFunction(original, original => function () {
63
63
  if (!enterChannel.hasSubscribers) return original.apply(this, arguments)
64
64
 
65
65
  const lastIndex = arguments.length - 1
@@ -90,7 +90,7 @@ function wrapLayerHandle (layer) {
90
90
  }
91
91
 
92
92
  function wrapNext (req, next) {
93
- return function (error) {
93
+ return shimmer.wrapFunction(next, next => function (error) {
94
94
  if (error) {
95
95
  errorChannel.publish({ req, error })
96
96
  }
@@ -99,11 +99,11 @@ function wrapNext (req, next) {
99
99
  finishChannel.publish({ req })
100
100
 
101
101
  next.apply(this, arguments)
102
- }
102
+ })
103
103
  }
104
104
 
105
105
  addHook({ name: 'connect', versions: ['>=3'] }, connect => {
106
- return shimmer.wrap(connect, wrapConnect(connect))
106
+ return shimmer.wrapFunction(connect, connect => wrapConnect(connect))
107
107
  })
108
108
 
109
109
  addHook({ name: 'connect', versions: ['2.2.2'] }, connect => {
@@ -6,7 +6,7 @@ const { channel, addHook } = require('./helpers/instrument')
6
6
  const cookieParserReadCh = channel('datadog:cookie-parser:read:finish')
7
7
 
8
8
  function publishRequestCookieAndNext (req, res, next) {
9
- return function cookieParserWrapper () {
9
+ return shimmer.wrapFunction(next, next => function cookieParserWrapper () {
10
10
  if (cookieParserReadCh.hasSubscribers && req) {
11
11
  const abortController = new AbortController()
12
12
 
@@ -18,17 +18,17 @@ function publishRequestCookieAndNext (req, res, next) {
18
18
  }
19
19
 
20
20
  return next.apply(this, arguments)
21
- }
21
+ })
22
22
  }
23
23
 
24
24
  addHook({
25
25
  name: 'cookie-parser',
26
26
  versions: ['>=1.0.0']
27
27
  }, cookieParser => {
28
- return shimmer.wrap(cookieParser, function () {
28
+ return shimmer.wrapFunction(cookieParser, cookieParser => function () {
29
29
  const cookieMiddleware = cookieParser.apply(this, arguments)
30
30
 
31
- return shimmer.wrap(cookieMiddleware, function (req, res, next) {
31
+ return shimmer.wrapFunction(cookieMiddleware, cookieMiddleware => function (req, res, next) {
32
32
  arguments[2] = publishRequestCookieAndNext(req, res, next)
33
33
  return cookieMiddleware.apply(this, arguments)
34
34
  })
@@ -37,7 +37,7 @@ function wrapMaybeInvoke (_maybeInvoke) {
37
37
 
38
38
  return _maybeInvoke.apply(this, arguments)
39
39
  }
40
- return shimmer.wrap(_maybeInvoke, wrapped)
40
+ return wrapped
41
41
  }
42
42
 
43
43
  function wrapQuery (query) {
@@ -51,7 +51,7 @@ function wrapQuery (query) {
51
51
  const res = query.apply(this, arguments)
52
52
  return res
53
53
  }
54
- return shimmer.wrap(query, wrapped)
54
+ return wrapped
55
55
  }
56
56
 
57
57
  function wrap (prefix, fn) {
@@ -76,13 +76,13 @@ function wrap (prefix, fn) {
76
76
 
77
77
  startCh.publish({ bucket: { name: this.name || this._name }, seedNodes: this._dd_hosts })
78
78
 
79
- arguments[callbackIndex] = asyncResource.bind(function (error, result) {
79
+ arguments[callbackIndex] = shimmer.wrapFunction(cb, cb => asyncResource.bind(function (error, result) {
80
80
  if (error) {
81
81
  errorCh.publish(error)
82
82
  }
83
83
  finishCh.publish(result)
84
84
  return cb.apply(this, arguments)
85
- })
85
+ }))
86
86
 
87
87
  try {
88
88
  return fn.apply(this, arguments)
@@ -94,7 +94,7 @@ function wrap (prefix, fn) {
94
94
  }
95
95
  })
96
96
  }
97
- return shimmer.wrap(fn, wrapped)
97
+ return wrapped
98
98
  }
99
99
 
100
100
  // semver >=3
@@ -118,13 +118,13 @@ function wrapCBandPromise (fn, name, startData, thisArg, args) {
118
118
  // v3 offers callback or promises event handling
119
119
  // NOTE: this does not work with v3.2.0-3.2.1 cluster.query, as there is a bug in the couchbase source code
120
120
  const cb = callbackResource.bind(args[cbIndex])
121
- args[cbIndex] = asyncResource.bind(function (error, result) {
121
+ args[cbIndex] = shimmer.wrapFunction(cb, cb => asyncResource.bind(function (error, result) {
122
122
  if (error) {
123
123
  errorCh.publish(error)
124
124
  }
125
125
  finishCh.publish({ result })
126
126
  return cb.apply(thisArg, arguments)
127
- })
127
+ }))
128
128
  }
129
129
  const res = fn.apply(thisArg, args)
130
130
 
@@ -166,8 +166,8 @@ addHook({ name: 'couchbase', file: 'lib/bucket.js', versions: ['^2.6.12'] }, Buc
166
166
  const finishCh = channel('apm:couchbase:query:finish')
167
167
  const errorCh = channel('apm:couchbase:query:error')
168
168
 
169
- Bucket.prototype._maybeInvoke = wrapMaybeInvoke(Bucket.prototype._maybeInvoke)
170
- Bucket.prototype.query = wrapQuery(Bucket.prototype.query)
169
+ shimmer.wrap(Bucket.prototype, '_maybeInvoke', maybeInvoke => wrapMaybeInvoke(maybeInvoke))
170
+ shimmer.wrap(Bucket.prototype, 'query', query => wrapQuery(query))
171
171
 
172
172
  shimmer.wrap(Bucket.prototype, '_n1qlReq', _n1qlReq => function (host, q, adhoc, emitter) {
173
173
  if (!startCh.hasSubscribers) {
@@ -203,15 +203,15 @@ addHook({ name: 'couchbase', file: 'lib/bucket.js', versions: ['^2.6.12'] }, Buc
203
203
  })
204
204
 
205
205
  wrapAllNames(['upsert', 'insert', 'replace', 'append', 'prepend'], name => {
206
- Bucket.prototype[name] = wrap(`apm:couchbase:${name}`, Bucket.prototype[name])
206
+ shimmer.wrap(Bucket.prototype, name, fn => wrap(`apm:couchbase:${name}`, fn))
207
207
  })
208
208
 
209
209
  return Bucket
210
210
  })
211
211
 
212
212
  addHook({ name: 'couchbase', file: 'lib/cluster.js', versions: ['^2.6.12'] }, Cluster => {
213
- Cluster.prototype._maybeInvoke = wrapMaybeInvoke(Cluster.prototype._maybeInvoke)
214
- Cluster.prototype.query = wrapQuery(Cluster.prototype.query)
213
+ shimmer.wrap(Cluster.prototype, '_maybeInvoke', maybeInvoke => wrapMaybeInvoke(maybeInvoke))
214
+ shimmer.wrap(Cluster.prototype, 'query', query => wrapQuery(query))
215
215
 
216
216
  shimmer.wrap(Cluster.prototype, 'openBucket', openBucket => {
217
217
  return function () {
@@ -1,7 +1,6 @@
1
1
  'use strict'
2
2
  const { createCoverageMap } = require('istanbul-lib-coverage')
3
3
 
4
- const { NUM_FAILED_TEST_RETRIES } = require('../../dd-trace/src/plugins/util/test')
5
4
  const { addHook, channel, AsyncResource } = require('./helpers/instrument')
6
5
  const shimmer = require('../../datadog-shimmer')
7
6
  const log = require('../../dd-trace/src/log')
@@ -66,6 +65,7 @@ let isSuitesSkippingEnabled = false
66
65
  let isEarlyFlakeDetectionEnabled = false
67
66
  let earlyFlakeDetectionNumRetries = 0
68
67
  let isFlakyTestRetriesEnabled = false
68
+ let numTestRetries = 0
69
69
  let knownTests = []
70
70
  let skippedSuites = []
71
71
  let isSuitesSkipped = false
@@ -188,7 +188,7 @@ function wrapRun (pl, isLatestVersion) {
188
188
  testStartCh.publish(testStartPayload)
189
189
  })
190
190
  try {
191
- this.eventBroadcaster.on('envelope', (testCase) => {
191
+ this.eventBroadcaster.on('envelope', shimmer.wrapFunction(null, () => (testCase) => {
192
192
  // Only supported from >=8.0.0
193
193
  if (testCase?.testCaseFinished) {
194
194
  const { testCaseFinished: { willBeRetried } } = testCase
@@ -206,7 +206,7 @@ function wrapRun (pl, isLatestVersion) {
206
206
  })
207
207
  }
208
208
  }
209
- })
209
+ }))
210
210
  let promise
211
211
 
212
212
  asyncResource.runInAsyncScope(() => {
@@ -307,6 +307,7 @@ function getWrappedStart (start, frameworkVersion, isParallel = false) {
307
307
  earlyFlakeDetectionNumRetries = configurationResponse.libraryConfig?.earlyFlakeDetectionNumRetries
308
308
  isSuitesSkippingEnabled = configurationResponse.libraryConfig?.isSuitesSkippingEnabled
309
309
  isFlakyTestRetriesEnabled = configurationResponse.libraryConfig?.isFlakyTestRetriesEnabled
310
+ numTestRetries = configurationResponse.libraryConfig?.flakyTestRetriesCount
310
311
 
311
312
  if (isEarlyFlakeDetectionEnabled) {
312
313
  const knownTestsResponse = await getChannelPromise(knownTestsCh)
@@ -344,8 +345,8 @@ function getWrappedStart (start, frameworkVersion, isParallel = false) {
344
345
  const processArgv = process.argv.slice(2).join(' ')
345
346
  const command = process.env.npm_lifecycle_script || `cucumber-js ${processArgv}`
346
347
 
347
- if (isFlakyTestRetriesEnabled && !this.options.retry) {
348
- this.options.retry = NUM_FAILED_TEST_RETRIES
348
+ if (isFlakyTestRetriesEnabled && !this.options.retry && numTestRetries > 0) {
349
+ this.options.retry = numTestRetries
349
350
  }
350
351
 
351
352
  sessionAsyncResource.runInAsyncScope(() => {
@@ -549,7 +550,7 @@ addHook({
549
550
  // Test start / finish for newer versions. The only hook executed in workers when in parallel mode
550
551
  addHook({
551
552
  name: '@cucumber/cucumber',
552
- versions: ['>=7.3.0'],
553
+ versions: ['>=7.3.0 <11.0.0'],
553
554
  file: 'lib/runtime/test_case_runner.js'
554
555
  }, testCaseHook)
555
556
 
@@ -558,7 +559,7 @@ addHook({
558
559
  // `getWrappedRunTest` generates suite start and finish events
559
560
  addHook({
560
561
  name: '@cucumber/cucumber',
561
- versions: ['>=7.3.0'],
562
+ versions: ['>=7.3.0 <11.0.0'],
562
563
  file: 'lib/runtime/index.js'
563
564
  }, (runtimePackage, frameworkVersion) => {
564
565
  shimmer.wrap(runtimePackage.default.prototype, 'runTestCase', runTestCase => getWrappedRunTest(runTestCase))
@@ -587,7 +588,7 @@ addHook({
587
588
  // `getWrappedParseWorkerMessage` generates suite finish events
588
589
  addHook({
589
590
  name: '@cucumber/cucumber',
590
- versions: ['>=8.0.0'],
591
+ versions: ['>=8.0.0 <11.0.0'],
591
592
  file: 'lib/runtime/parallel/coordinator.js'
592
593
  }, (coordinatorPackage, frameworkVersion) => {
593
594
  shimmer.wrap(coordinatorPackage.default.prototype, 'start', start => getWrappedStart(start, frameworkVersion, true))
@@ -21,16 +21,16 @@ const rrtypeMap = new WeakMap()
21
21
  const names = ['dns', 'node:dns']
22
22
 
23
23
  addHook({ name: names }, dns => {
24
- dns.lookup = wrap('apm:dns:lookup', dns.lookup, 2)
25
- dns.lookupService = wrap('apm:dns:lookup_service', dns.lookupService, 3)
26
- dns.resolve = wrap('apm:dns:resolve', dns.resolve, 2)
27
- dns.reverse = wrap('apm:dns:reverse', dns.reverse, 2)
24
+ shimmer.wrap(dns, 'lookup', fn => wrap('apm:dns:lookup', fn, 2))
25
+ shimmer.wrap(dns, 'lookupService', fn => wrap('apm:dns:lookup_service', fn, 2))
26
+ shimmer.wrap(dns, 'resolve', fn => wrap('apm:dns:resolve', fn, 2))
27
+ shimmer.wrap(dns, 'reverse', fn => wrap('apm:dns:reverse', fn, 2))
28
28
 
29
29
  patchResolveShorthands(dns)
30
30
 
31
31
  if (dns.Resolver) {
32
- dns.Resolver.prototype.resolve = wrap('apm:dns:resolve', dns.Resolver.prototype.resolve, 2)
33
- dns.Resolver.prototype.reverse = wrap('apm:dns:reverse', dns.Resolver.prototype.reverse, 2)
32
+ shimmer.wrap(dns.Resolver.prototype, 'resolve', fn => wrap('apm:dns:resolve', fn, 2))
33
+ shimmer.wrap(dns.Resolver.prototype, 'reverse', fn => wrap('apm:dns:reverse', fn, 2))
34
34
 
35
35
  patchResolveShorthands(dns.Resolver.prototype)
36
36
  }
@@ -43,7 +43,7 @@ function patchResolveShorthands (prototype) {
43
43
  .filter(method => !!prototype[method])
44
44
  .forEach(method => {
45
45
  rrtypeMap.set(prototype[method], rrtypes[method])
46
- prototype[method] = wrap('apm:dns:resolve', prototype[method], 2, rrtypes[method])
46
+ shimmer.wrap(prototype, method, fn => wrap('apm:dns:resolve', fn, 2, rrtypes[method]))
47
47
  })
48
48
  }
49
49
 
@@ -72,13 +72,13 @@ function wrap (prefix, fn, expectedArgs, rrtype) {
72
72
  return asyncResource.runInAsyncScope(() => {
73
73
  startCh.publish(startArgs)
74
74
 
75
- arguments[arguments.length - 1] = asyncResource.bind(function (error, result) {
75
+ arguments[arguments.length - 1] = shimmer.wrapFunction(cb, cb => asyncResource.bind(function (error, result) {
76
76
  if (error) {
77
77
  errorCh.publish(error)
78
78
  }
79
79
  finishCh.publish(result)
80
80
  cb.apply(this, arguments)
81
- })
81
+ }))
82
82
 
83
83
  try {
84
84
  return fn.apply(this, arguments)
@@ -92,5 +92,5 @@ function wrap (prefix, fn, expectedArgs, rrtype) {
92
92
  })
93
93
  }
94
94
 
95
- return shimmer.wrap(fn, wrapped)
95
+ return wrapped
96
96
  }
@@ -48,12 +48,12 @@ function createWrapSelect () {
48
48
  return function () {
49
49
  if (arguments.length === 1) {
50
50
  const cb = arguments[0]
51
- arguments[0] = function (err, connection) {
51
+ arguments[0] = shimmer.wrapFunction(cb, cb => function (err, connection) {
52
52
  if (connectCh.hasSubscribers && connection && connection.host) {
53
53
  connectCh.publish({ hostname: connection.host.host, port: connection.host.port })
54
54
  }
55
55
  cb(err, connection)
56
- }
56
+ })
57
57
  }
58
58
  return request.apply(this, arguments)
59
59
  }
@@ -86,10 +86,10 @@ function createWrapRequest (name) {
86
86
  if (typeof cb === 'function') {
87
87
  cb = parentResource.bind(cb)
88
88
 
89
- arguments[lastIndex] = asyncResource.bind(function (error) {
89
+ arguments[lastIndex] = shimmer.wrapFunction(cb, cb => asyncResource.bind(function (error) {
90
90
  finish(params, error)
91
91
  return cb.apply(null, arguments)
92
- })
92
+ }))
93
93
  return request.apply(this, arguments)
94
94
  } else {
95
95
  const promise = request.apply(this, arguments)
@@ -22,15 +22,15 @@ addHook({ name: 'express-mongo-sanitize', versions: ['>=1.0.0'] }, expressMongoS
22
22
  return sanitizedObject
23
23
  })
24
24
 
25
- return shimmer.wrap(expressMongoSanitize, function () {
25
+ return shimmer.wrapFunction(expressMongoSanitize, expressMongoSanitize => function () {
26
26
  const middleware = expressMongoSanitize.apply(this, arguments)
27
27
 
28
- return shimmer.wrap(middleware, function (req, res, next) {
28
+ return shimmer.wrapFunction(middleware, middleware => function (req, res, next) {
29
29
  if (!sanitizeMiddlewareFinished.hasSubscribers) {
30
30
  return middleware.apply(this, arguments)
31
31
  }
32
32
 
33
- const wrappedNext = shimmer.wrap(next, function () {
33
+ const wrappedNext = shimmer.wrapFunction(next, next => function () {
34
34
  sanitizeMiddlewareFinished.publish({
35
35
  sanitizedProperties: propertiesToSanitize,
36
36
  req
@@ -49,7 +49,7 @@ addHook({ name: 'express', versions: ['>=4'] }, express => {
49
49
  const queryParserReadCh = channel('datadog:query:read:finish')
50
50
 
51
51
  function publishQueryParsedAndNext (req, res, next) {
52
- return function () {
52
+ return shimmer.wrapFunction(next, next => function () {
53
53
  if (queryParserReadCh.hasSubscribers && req) {
54
54
  const abortController = new AbortController()
55
55
  const query = req.query
@@ -60,7 +60,7 @@ function publishQueryParsedAndNext (req, res, next) {
60
60
  }
61
61
 
62
62
  return next.apply(this, arguments)
63
- }
63
+ })
64
64
  }
65
65
 
66
66
  addHook({
@@ -68,10 +68,10 @@ addHook({
68
68
  versions: ['>=4'],
69
69
  file: 'lib/middleware/query.js'
70
70
  }, query => {
71
- return shimmer.wrap(query, function () {
71
+ return shimmer.wrapFunction(query, query => function () {
72
72
  const queryMiddleware = query.apply(this, arguments)
73
73
 
74
- return shimmer.wrap(queryMiddleware, function (req, res, next) {
74
+ return shimmer.wrapFunction(queryMiddleware, queryMiddleware => function (req, res, next) {
75
75
  arguments[2] = publishQueryParsedAndNext(req, res, next)
76
76
  return queryMiddleware.apply(this, arguments)
77
77
  })
@@ -34,12 +34,12 @@ function wrapFastify (fastify, hasParsingEvents) {
34
34
  }
35
35
 
36
36
  function wrapAddHook (addHook) {
37
- return function addHookWithTrace (name, fn) {
37
+ return shimmer.wrapFunction(addHook, addHook => function addHookWithTrace (name, fn) {
38
38
  fn = arguments[arguments.length - 1]
39
39
 
40
40
  if (typeof fn !== 'function') return addHook.apply(this, arguments)
41
41
 
42
- arguments[arguments.length - 1] = shimmer.wrap(fn, function (request, reply, done) {
42
+ arguments[arguments.length - 1] = shimmer.wrapFunction(fn, fn => function (request, reply, done) {
43
43
  const req = getReq(request)
44
44
 
45
45
  try {
@@ -78,7 +78,7 @@ function wrapAddHook (addHook) {
78
78
  })
79
79
 
80
80
  return addHook.apply(this, arguments)
81
- }
81
+ })
82
82
  }
83
83
 
84
84
  function onRequest (request, reply, done) {
@@ -151,7 +151,7 @@ function publishError (error, req) {
151
151
  }
152
152
 
153
153
  addHook({ name: 'fastify', versions: ['>=3'] }, fastify => {
154
- const wrapped = shimmer.wrap(fastify, wrapFastify(fastify, true))
154
+ const wrapped = shimmer.wrapFunction(fastify, fastify => wrapFastify(fastify, true))
155
155
 
156
156
  wrapped.fastify = wrapped
157
157
  wrapped.default = wrapped
@@ -160,9 +160,9 @@ addHook({ name: 'fastify', versions: ['>=3'] }, fastify => {
160
160
  })
161
161
 
162
162
  addHook({ name: 'fastify', versions: ['2'] }, fastify => {
163
- return shimmer.wrap(fastify, wrapFastify(fastify, true))
163
+ return shimmer.wrapFunction(fastify, fastify => wrapFastify(fastify, true))
164
164
  })
165
165
 
166
166
  addHook({ name: 'fastify', versions: ['1'] }, fastify => {
167
- return shimmer.wrap(fastify, wrapFastify(fastify, false))
167
+ return shimmer.wrapFunction(fastify, fastify => wrapFastify(fastify, false))
168
168
  })
@@ -8,5 +8,5 @@ if (globalThis.fetch) {
8
8
  const ch = tracingChannel('apm:fetch:request')
9
9
  const wrapFetch = createWrapFetch(globalThis.Request, ch)
10
10
 
11
- globalThis.fetch = shimmer.wrap(fetch, wrapFetch(fetch))
11
+ globalThis.fetch = shimmer.wrapFunction(fetch, fetch => wrapFetch(fetch))
12
12
  }
@@ -9,11 +9,11 @@ function wrapOn (on) {
9
9
  return function onWithTrace (method, path, opts) {
10
10
  const index = typeof opts === 'function' ? 2 : 3
11
11
  const handler = arguments[index]
12
- const wrapper = function (req) {
12
+ const wrapper = shimmer.wrapFunction(handler, handler => function (req) {
13
13
  routeChannel.publish({ req, route: path })
14
14
 
15
15
  return handler.apply(this, arguments)
16
- }
16
+ })
17
17
 
18
18
  if (typeof handler === 'function') {
19
19
  arguments[index] = wrapper