dd-trace 5.21.0 → 5.22.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 (84) hide show
  1. package/package.json +3 -3
  2. package/packages/datadog-instrumentations/src/aerospike.js +1 -1
  3. package/packages/datadog-instrumentations/src/apollo-server.js +1 -1
  4. package/packages/datadog-instrumentations/src/aws-sdk.js +4 -4
  5. package/packages/datadog-instrumentations/src/body-parser.js +4 -4
  6. package/packages/datadog-instrumentations/src/cassandra-driver.js +2 -2
  7. package/packages/datadog-instrumentations/src/child_process.js +2 -2
  8. package/packages/datadog-instrumentations/src/connect.js +4 -4
  9. package/packages/datadog-instrumentations/src/cookie-parser.js +4 -4
  10. package/packages/datadog-instrumentations/src/couchbase.js +12 -12
  11. package/packages/datadog-instrumentations/src/cucumber.js +6 -5
  12. package/packages/datadog-instrumentations/src/dns.js +10 -10
  13. package/packages/datadog-instrumentations/src/elasticsearch.js +4 -4
  14. package/packages/datadog-instrumentations/src/express-mongo-sanitize.js +3 -3
  15. package/packages/datadog-instrumentations/src/express.js +4 -4
  16. package/packages/datadog-instrumentations/src/fastify.js +6 -6
  17. package/packages/datadog-instrumentations/src/fetch.js +1 -1
  18. package/packages/datadog-instrumentations/src/find-my-way.js +2 -2
  19. package/packages/datadog-instrumentations/src/fs.js +2 -2
  20. package/packages/datadog-instrumentations/src/google-cloud-pubsub.js +2 -2
  21. package/packages/datadog-instrumentations/src/grpc/client.js +4 -6
  22. package/packages/datadog-instrumentations/src/grpc/server.js +2 -2
  23. package/packages/datadog-instrumentations/src/hapi.js +10 -13
  24. package/packages/datadog-instrumentations/src/helpers/register.js +1 -1
  25. package/packages/datadog-instrumentations/src/http/client.js +3 -3
  26. package/packages/datadog-instrumentations/src/jest.js +5 -4
  27. package/packages/datadog-instrumentations/src/knex.js +2 -2
  28. package/packages/datadog-instrumentations/src/koa.js +5 -5
  29. package/packages/datadog-instrumentations/src/ldapjs.js +1 -1
  30. package/packages/datadog-instrumentations/src/mariadb.js +8 -8
  31. package/packages/datadog-instrumentations/src/memcached.js +2 -2
  32. package/packages/datadog-instrumentations/src/microgateway-core.js +4 -4
  33. package/packages/datadog-instrumentations/src/mocha/common.js +1 -1
  34. package/packages/datadog-instrumentations/src/mocha/main.js +1 -0
  35. package/packages/datadog-instrumentations/src/mocha/utils.js +2 -3
  36. package/packages/datadog-instrumentations/src/mocha.js +4 -0
  37. package/packages/datadog-instrumentations/src/moleculer/server.js +2 -2
  38. package/packages/datadog-instrumentations/src/mongodb-core.js +7 -7
  39. package/packages/datadog-instrumentations/src/mongoose.js +5 -6
  40. package/packages/datadog-instrumentations/src/mysql.js +3 -3
  41. package/packages/datadog-instrumentations/src/mysql2.js +6 -6
  42. package/packages/datadog-instrumentations/src/net.js +2 -2
  43. package/packages/datadog-instrumentations/src/next.js +5 -5
  44. package/packages/datadog-instrumentations/src/openai.js +58 -69
  45. package/packages/datadog-instrumentations/src/oracledb.js +8 -8
  46. package/packages/datadog-instrumentations/src/passport-http.js +1 -1
  47. package/packages/datadog-instrumentations/src/passport-local.js +1 -1
  48. package/packages/datadog-instrumentations/src/passport-utils.js +1 -1
  49. package/packages/datadog-instrumentations/src/pg.js +1 -1
  50. package/packages/datadog-instrumentations/src/pino.js +4 -4
  51. package/packages/datadog-instrumentations/src/playwright.js +6 -4
  52. package/packages/datadog-instrumentations/src/redis.js +2 -2
  53. package/packages/datadog-instrumentations/src/restify.js +4 -4
  54. package/packages/datadog-instrumentations/src/rhea.js +4 -4
  55. package/packages/datadog-instrumentations/src/router.js +5 -5
  56. package/packages/datadog-instrumentations/src/sharedb.js +2 -2
  57. package/packages/datadog-instrumentations/src/vitest.js +4 -3
  58. package/packages/datadog-instrumentations/src/winston.js +2 -3
  59. package/packages/datadog-plugin-cypress/src/cypress-plugin.js +5 -6
  60. package/packages/datadog-plugin-hapi/src/index.js +2 -2
  61. package/packages/datadog-plugin-jest/src/index.js +1 -0
  62. package/packages/datadog-plugin-openai/src/index.js +58 -47
  63. package/packages/datadog-shimmer/src/shimmer.js +144 -10
  64. package/packages/dd-trace/src/appsec/blocking.js +23 -17
  65. package/packages/dd-trace/src/appsec/graphql.js +3 -1
  66. package/packages/dd-trace/src/appsec/iast/iast-log.js +2 -1
  67. package/packages/dd-trace/src/appsec/remote_config/manager.js +4 -1
  68. package/packages/dd-trace/src/appsec/rule_manager.js +8 -0
  69. package/packages/dd-trace/src/appsec/telemetry.js +3 -3
  70. package/packages/dd-trace/src/ci-visibility/exporters/ci-visibility-exporter.js +2 -1
  71. package/packages/dd-trace/src/config.js +40 -31
  72. package/packages/dd-trace/src/lambda/handler.js +1 -0
  73. package/packages/dd-trace/src/lambda/index.js +12 -1
  74. package/packages/dd-trace/src/opentracing/propagation/text_map.js +1 -6
  75. package/packages/dd-trace/src/plugins/util/test.js +1 -5
  76. package/packages/dd-trace/src/profiler.js +15 -5
  77. package/packages/dd-trace/src/profiling/config.js +2 -4
  78. package/packages/dd-trace/src/profiling/exporter_cli.js +13 -1
  79. package/packages/dd-trace/src/profiling/exporters/agent.js +7 -1
  80. package/packages/dd-trace/src/profiling/profiler.js +0 -9
  81. package/packages/dd-trace/src/profiling/ssi-heuristics.js +49 -58
  82. package/packages/dd-trace/src/proxy.js +21 -21
  83. package/packages/dd-trace/src/telemetry/index.js +23 -6
  84. package/packages/dd-trace/src/telemetry/logs/index.js +20 -0
@@ -1,14 +1,10 @@
1
1
  'use strict'
2
2
 
3
- const {
4
- channel,
5
- addHook
6
- } = require('./helpers/instrument')
3
+ const { addHook } = require('./helpers/instrument')
7
4
  const shimmer = require('../../datadog-shimmer')
8
5
 
9
- const startCh = channel('apm:openai:request:start')
10
- const finishCh = channel('apm:openai:request:finish')
11
- const errorCh = channel('apm:openai:request:error')
6
+ const tracingChannel = require('dc-polyfill').tracingChannel
7
+ const ch = tracingChannel('apm:openai:request')
12
8
 
13
9
  const V4_PACKAGE_SHIMS = [
14
10
  {
@@ -110,33 +106,18 @@ addHook({ name: 'openai', file: 'dist/api.js', versions: ['>=3.0.0 <4'] }, expor
110
106
 
111
107
  for (const methodName of methodNames) {
112
108
  shimmer.wrap(exports.OpenAIApi.prototype, methodName, fn => function () {
113
- if (!startCh.hasSubscribers) {
109
+ if (!ch.start.hasSubscribers) {
114
110
  return fn.apply(this, arguments)
115
111
  }
116
112
 
117
- startCh.publish({
113
+ const ctx = {
118
114
  methodName,
119
115
  args: arguments,
120
116
  basePath: this.basePath,
121
117
  apiKey: this.configuration.apiKey
122
- })
123
-
124
- return fn.apply(this, arguments)
125
- .then((response) => {
126
- finish({
127
- headers: response.headers,
128
- body: response.data,
129
- path: response.request.path,
130
- method: response.request.method
131
- })
132
-
133
- return response
134
- })
135
- .catch(error => {
136
- finish(undefined, error)
118
+ }
137
119
 
138
- throw error
139
- })
120
+ return ch.tracePromise(fn, ctx, this, ...arguments)
140
121
  })
141
122
  }
142
123
 
@@ -213,7 +194,7 @@ function convertBufferstoObjects (chunks = []) {
213
194
  * the chunks, and let the combined content be the final response.
214
195
  * This way, spans look the same as when not streamed.
215
196
  */
216
- function wrapStreamIterator (response, options, n) {
197
+ function wrapStreamIterator (response, options, n, ctx) {
217
198
  let processChunksAsBuffers = false
218
199
  let chunks = []
219
200
  return function (itr) {
@@ -253,11 +234,13 @@ function wrapStreamIterator (response, options, n) {
253
234
  }
254
235
  }
255
236
 
256
- finish({
237
+ finish(ctx, {
257
238
  headers: response.headers,
258
- body,
259
- path: response.url,
260
- method: options.method
239
+ data: body,
240
+ request: {
241
+ path: response.url,
242
+ method: options.method
243
+ }
261
244
  })
262
245
  }
263
246
 
@@ -281,7 +264,7 @@ for (const shim of V4_PACKAGE_SHIMS) {
281
264
 
282
265
  for (const methodName of methods) {
283
266
  shimmer.wrap(targetPrototype, methodName, methodFn => function () {
284
- if (!startCh.hasSubscribers) {
267
+ if (!ch.start.hasSubscribers) {
285
268
  return methodFn.apply(this, arguments)
286
269
  }
287
270
 
@@ -303,66 +286,72 @@ for (const shim of V4_PACKAGE_SHIMS) {
303
286
 
304
287
  const client = this._client || this.client
305
288
 
306
- startCh.publish({
289
+ const ctx = {
307
290
  methodName: `${baseResource}.${methodName}`,
308
291
  args: arguments,
309
292
  basePath: client.baseURL,
310
293
  apiKey: client.apiKey
311
- })
294
+ }
312
295
 
313
- const apiProm = methodFn.apply(this, arguments)
296
+ return ch.start.runStores(ctx, () => {
297
+ const apiProm = methodFn.apply(this, arguments)
314
298
 
315
- // wrapping `parse` avoids problematic wrapping of `then` when trying to call
316
- // `withResponse` in userland code after. This way, we can return the whole `APIPromise`
317
- shimmer.wrap(apiProm, 'parse', origApiPromParse => function () {
318
- return origApiPromParse.apply(this, arguments)
299
+ // wrapping `parse` avoids problematic wrapping of `then` when trying to call
300
+ // `withResponse` in userland code after. This way, we can return the whole `APIPromise`
301
+ shimmer.wrap(apiProm, 'parse', origApiPromParse => function () {
302
+ return origApiPromParse.apply(this, arguments)
319
303
  // the original response is wrapped in a promise, so we need to unwrap it
320
- .then(body => Promise.all([this.responsePromise, body]))
321
- .then(([{ response, options }, body]) => {
322
- if (stream) {
323
- if (body.iterator) {
324
- shimmer.wrap(body, 'iterator', wrapStreamIterator(response, options, n))
304
+ .then(body => Promise.all([this.responsePromise, body]))
305
+ .then(([{ response, options }, body]) => {
306
+ if (stream) {
307
+ if (body.iterator) {
308
+ shimmer.wrap(body, 'iterator', wrapStreamIterator(response, options, n, ctx))
309
+ } else {
310
+ shimmer.wrap(
311
+ body.response.body, Symbol.asyncIterator, wrapStreamIterator(response, options, n, ctx)
312
+ )
313
+ }
325
314
  } else {
326
- shimmer.wrap(
327
- body.response.body, Symbol.asyncIterator, wrapStreamIterator(response, options, n)
328
- )
315
+ finish(ctx, {
316
+ headers: response.headers,
317
+ data: body,
318
+ request: {
319
+ path: response.url,
320
+ method: options.method
321
+ }
322
+ })
329
323
  }
330
- } else {
331
- finish({
332
- headers: response.headers,
333
- body,
334
- path: response.url,
335
- method: options.method
336
- })
337
- }
338
324
 
339
- return body
340
- })
341
- .catch(error => {
342
- finish(undefined, error)
325
+ return body
326
+ })
327
+ .catch(error => {
328
+ finish(ctx, undefined, error)
343
329
 
344
- throw error
345
- })
346
- .finally(() => {
330
+ throw error
331
+ })
332
+ .finally(() => {
347
333
  // maybe we don't want to unwrap here in case the promise is re-used?
348
334
  // other hand: we want to avoid resource leakage
349
- shimmer.unwrap(apiProm, 'parse')
350
- })
351
- })
335
+ shimmer.unwrap(apiProm, 'parse')
336
+ })
337
+ })
352
338
 
353
- return apiProm
339
+ return apiProm
340
+ })
354
341
  })
355
342
  }
356
343
  return exports
357
344
  })
358
345
  }
359
346
 
360
- function finish (response, error) {
347
+ function finish (ctx, response, error) {
361
348
  if (error) {
362
- errorCh.publish({ error })
349
+ ctx.error = error
350
+ ch.error.publish(ctx)
363
351
  }
364
352
 
365
- finishCh.publish(response)
353
+ ctx.result = response
354
+ ch.asyncEnd.publish(ctx)
366
355
  }
367
356
 
368
357
  function getOption (args, option, defaultValue) {
@@ -31,10 +31,10 @@ addHook({ name: 'oracledb', versions: ['>=5'] }, oracledb => {
31
31
  if (arguments.length && typeof arguments[arguments.length - 1] === 'function') {
32
32
  const cb = arguments[arguments.length - 1]
33
33
  const outerAr = new AsyncResource('apm:oracledb:outer-scope')
34
- arguments[arguments.length - 1] = function wrappedCb (err, result) {
34
+ arguments[arguments.length - 1] = shimmer.wrapFunction(cb, cb => function wrappedCb (err, result) {
35
35
  finish(err)
36
36
  return outerAr.runInAsyncScope(() => cb.apply(this, arguments))
37
- }
37
+ })
38
38
  }
39
39
 
40
40
  return new AsyncResource('apm:oracledb:inner-scope').runInAsyncScope(() => {
@@ -67,12 +67,12 @@ addHook({ name: 'oracledb', versions: ['>=5'] }, oracledb => {
67
67
  shimmer.wrap(oracledb, 'getConnection', getConnection => {
68
68
  return function wrappedGetConnection (connAttrs, callback) {
69
69
  if (callback) {
70
- arguments[1] = (err, connection) => {
70
+ arguments[1] = shimmer.wrapFunction(callback, callback => (err, connection) => {
71
71
  if (connection) {
72
72
  connectionAttributes.set(connection, connAttrs)
73
73
  }
74
74
  callback(err, connection)
75
- }
75
+ })
76
76
 
77
77
  getConnection.apply(this, arguments)
78
78
  } else {
@@ -86,12 +86,12 @@ addHook({ name: 'oracledb', versions: ['>=5'] }, oracledb => {
86
86
  shimmer.wrap(oracledb, 'createPool', createPool => {
87
87
  return function wrappedCreatePool (poolAttrs, callback) {
88
88
  if (callback) {
89
- arguments[1] = (err, pool) => {
89
+ arguments[1] = shimmer.wrapFunction(callback, callback => (err, pool) => {
90
90
  if (pool) {
91
91
  poolAttributes.set(pool, poolAttrs)
92
92
  }
93
93
  callback(err, pool)
94
- }
94
+ })
95
95
 
96
96
  createPool.apply(this, arguments)
97
97
  } else {
@@ -109,12 +109,12 @@ addHook({ name: 'oracledb', versions: ['>=5'] }, oracledb => {
109
109
  callback = arguments[arguments.length - 1]
110
110
  }
111
111
  if (callback) {
112
- arguments[arguments.length - 1] = (err, connection) => {
112
+ arguments[arguments.length - 1] = shimmer.wrapFunction(callback, callback => (err, connection) => {
113
113
  if (connection) {
114
114
  connectionAttributes.set(connection, poolAttributes.get(this))
115
115
  }
116
116
  callback(err, connection)
117
- }
117
+ })
118
118
  getConnection.apply(this, arguments)
119
119
  } else {
120
120
  return getConnection.apply(this, arguments).then((connection) => {
@@ -9,7 +9,7 @@ addHook({
9
9
  file: 'lib/passport-http/strategies/basic.js',
10
10
  versions: ['>=0.3.0']
11
11
  }, BasicStrategy => {
12
- return shimmer.wrap(BasicStrategy, function () {
12
+ return shimmer.wrapFunction(BasicStrategy, BasicStrategy => function () {
13
13
  const type = 'http'
14
14
 
15
15
  if (typeof arguments[0] === 'function') {
@@ -9,7 +9,7 @@ addHook({
9
9
  file: 'lib/strategy.js',
10
10
  versions: ['>=1.0.0']
11
11
  }, Strategy => {
12
- return shimmer.wrap(Strategy, function () {
12
+ return shimmer.wrapFunction(Strategy, Strategy => function () {
13
13
  const type = 'local'
14
14
 
15
15
  if (typeof arguments[0] === 'function') {
@@ -11,7 +11,7 @@ function wrapVerifiedAndPublish (username, password, verified, type) {
11
11
  }
12
12
 
13
13
  // eslint-disable-next-line n/handle-callback-err
14
- return shimmer.wrap(verified, function (err, user, info) {
14
+ return shimmer.wrapFunction(verified, verified => function (err, user, info) {
15
15
  const credentials = { type, username }
16
16
  passportVerifyChannel.publish({ credentials, user })
17
17
  return verified.apply(this, arguments)
@@ -122,7 +122,7 @@ function wrapPoolQuery (query) {
122
122
 
123
123
  const cb = arguments[arguments.length - 1]
124
124
  if (typeof cb === 'function') {
125
- arguments[arguments.length - 1] = shimmer.wrap(cb, function () {
125
+ arguments[arguments.length - 1] = shimmer.wrapFunction(cb, cb => function () {
126
126
  finish()
127
127
  return cb.apply(this, arguments)
128
128
  })
@@ -76,19 +76,19 @@ function wrapPrettyFactory (prettyFactory) {
76
76
  addHook({ name: 'pino', versions: ['2 - 3', '4', '>=5 <5.14.0'] }, pino => {
77
77
  const asJsonSym = (pino.symbols && pino.symbols.asJsonSym) || 'asJson'
78
78
 
79
- return shimmer.wrap(pino, wrapPino(asJsonSym, wrapAsJson, pino))
79
+ return shimmer.wrapFunction(pino, pino => wrapPino(asJsonSym, wrapAsJson, pino))
80
80
  })
81
81
 
82
82
  addHook({ name: 'pino', versions: ['>=5.14.0 <6.8.0'] }, pino => {
83
83
  const mixinSym = pino.symbols.mixinSym
84
84
 
85
- return shimmer.wrap(pino, wrapPino(mixinSym, wrapMixin, pino))
85
+ return shimmer.wrapFunction(pino, pino => wrapPino(mixinSym, wrapMixin, pino))
86
86
  })
87
87
 
88
88
  addHook({ name: 'pino', versions: ['>=6.8.0'] }, pino => {
89
89
  const mixinSym = pino.symbols.mixinSym
90
90
 
91
- const wrapped = shimmer.wrap(pino, wrapPino(mixinSym, wrapMixin, pino))
91
+ const wrapped = shimmer.wrapFunction(pino, pino => wrapPino(mixinSym, wrapMixin, pino))
92
92
  wrapped.pino = wrapped
93
93
  wrapped.default = wrapped
94
94
 
@@ -101,5 +101,5 @@ addHook({ name: 'pino-pretty', file: 'lib/utils.js', versions: ['>=3'] }, utils
101
101
  })
102
102
 
103
103
  addHook({ name: 'pino-pretty', versions: ['1 - 2'] }, prettyFactory => {
104
- return shimmer.wrap(prettyFactory, wrapPrettyFactory(prettyFactory))
104
+ return shimmer.wrapFunction(prettyFactory, wrapPrettyFactory)
105
105
  })
@@ -2,7 +2,7 @@ const semver = require('semver')
2
2
 
3
3
  const { addHook, channel, AsyncResource } = require('./helpers/instrument')
4
4
  const shimmer = require('../../datadog-shimmer')
5
- const { parseAnnotations, getTestSuitePath, NUM_FAILED_TEST_RETRIES } = require('../../dd-trace/src/plugins/util/test')
5
+ const { parseAnnotations, getTestSuitePath } = require('../../dd-trace/src/plugins/util/test')
6
6
  const log = require('../../dd-trace/src/log')
7
7
 
8
8
  const testStartCh = channel('ci:playwright:test:start')
@@ -36,8 +36,9 @@ const STATUS_TO_TEST_STATUS = {
36
36
 
37
37
  let remainingTestsByFile = {}
38
38
  let isEarlyFlakeDetectionEnabled = false
39
- let isFlakyTestRetriesEnabled = false
40
39
  let earlyFlakeDetectionNumRetries = 0
40
+ let isFlakyTestRetriesEnabled = false
41
+ let flakyTestRetriesCount = 0
41
42
  let knownTests = {}
42
43
  let rootDir = ''
43
44
  const MINIMUM_SUPPORTED_VERSION_EFD = '1.38.0'
@@ -407,6 +408,7 @@ function runnerHook (runnerExport, playwrightVersion) {
407
408
  isEarlyFlakeDetectionEnabled = libraryConfig.isEarlyFlakeDetectionEnabled
408
409
  earlyFlakeDetectionNumRetries = libraryConfig.earlyFlakeDetectionNumRetries
409
410
  isFlakyTestRetriesEnabled = libraryConfig.isFlakyTestRetriesEnabled
411
+ flakyTestRetriesCount = libraryConfig.flakyTestRetriesCount
410
412
  }
411
413
  } catch (e) {
412
414
  isEarlyFlakeDetectionEnabled = false
@@ -429,10 +431,10 @@ function runnerHook (runnerExport, playwrightVersion) {
429
431
 
430
432
  const projects = getProjectsFromRunner(this)
431
433
 
432
- if (isFlakyTestRetriesEnabled) {
434
+ if (isFlakyTestRetriesEnabled && flakyTestRetriesCount > 0) {
433
435
  projects.forEach(project => {
434
436
  if (project.retries === 0) { // Only if it hasn't been set by the user
435
- project.retries = NUM_FAILED_TEST_RETRIES
437
+ project.retries = flakyTestRetriesCount
436
438
  }
437
439
  })
438
440
  }
@@ -156,12 +156,12 @@ function start (client, command, args, url = {}) {
156
156
  }
157
157
 
158
158
  function wrapCallback (finishCh, errorCh, callback) {
159
- return function (err) {
159
+ return shimmer.wrapFunction(callback, callback => function (err) {
160
160
  finish(finishCh, errorCh, err)
161
161
  if (callback) {
162
162
  return callback.apply(this, arguments)
163
163
  }
164
- }
164
+ })
165
165
  }
166
166
 
167
167
  function finish (finishCh, errorCh, error) {
@@ -40,7 +40,7 @@ function wrapMiddleware (middleware) {
40
40
  function wrapFn (fn) {
41
41
  if (Array.isArray(fn)) return wrapMiddleware(fn)
42
42
 
43
- return function (req, res, next) {
43
+ return shimmer.wrapFunction(fn, fn => function (req, res, next) {
44
44
  if (typeof next === 'function') {
45
45
  arguments[2] = wrapNext(req, next)
46
46
  }
@@ -72,16 +72,16 @@ function wrapFn (fn) {
72
72
  } finally {
73
73
  exitChannel.publish({ req })
74
74
  }
75
- }
75
+ })
76
76
  }
77
77
 
78
78
  function wrapNext (req, next) {
79
- return function () {
79
+ return shimmer.wrapFunction(next, next => function () {
80
80
  nextChannel.publish({ req })
81
81
  finishChannel.publish({ req })
82
82
 
83
83
  next.apply(this, arguments)
84
- }
84
+ })
85
85
  }
86
86
 
87
87
  addHook({ name: 'restify', versions: ['>=3'], file: 'lib/server.js' }, Server => {
@@ -153,11 +153,11 @@ function wrapDeliveryUpdate (obj, update) {
153
153
  const asyncResource = context.asyncResource
154
154
  if (obj && asyncResource) {
155
155
  const cb = asyncResource.bind(update)
156
- return AsyncResource.bind(function wrappedUpdate (settled, stateData) {
156
+ return shimmer.wrapFunction(cb, cb => AsyncResource.bind(function wrappedUpdate (settled, stateData) {
157
157
  const state = getStateFromData(stateData)
158
158
  dispatchReceiveCh.publish({ state })
159
159
  return cb.apply(this, arguments)
160
- })
160
+ }))
161
161
  }
162
162
  return function wrappedUpdate (settled, stateData) {
163
163
  return update.apply(this, arguments)
@@ -178,7 +178,7 @@ function patchCircularBuffer (proto, Session) {
178
178
  }
179
179
  if (CircularBuffer && !patched.has(CircularBuffer.prototype)) {
180
180
  shimmer.wrap(CircularBuffer.prototype, 'pop_if', popIf => function (fn) {
181
- arguments[0] = AsyncResource.bind(function (entry) {
181
+ arguments[0] = shimmer.wrapFunction(fn, fn => AsyncResource.bind(function (entry) {
182
182
  const context = contexts.get(entry)
183
183
  const asyncResource = context && context.asyncResource
184
184
 
@@ -198,7 +198,7 @@ function patchCircularBuffer (proto, Session) {
198
198
  }
199
199
 
200
200
  return shouldPop
201
- })
201
+ }))
202
202
  return popIf.apply(this, arguments)
203
203
  })
204
204
  patched.add(CircularBuffer.prototype)
@@ -18,7 +18,7 @@ function createWrapRouterMethod (name) {
18
18
  function wrapLayerHandle (layer, original) {
19
19
  original._name = original._name || layer.name
20
20
 
21
- const handle = shimmer.wrap(original, function () {
21
+ const handle = shimmer.wrapFunction(original, original => function () {
22
22
  if (!enterChannel.hasSubscribers) return original.apply(this, arguments)
23
23
 
24
24
  const matchers = layerMatchers.get(layer)
@@ -89,7 +89,7 @@ function createWrapRouterMethod (name) {
89
89
  }
90
90
 
91
91
  function wrapNext (req, next) {
92
- return function (error) {
92
+ return shimmer.wrapFunction(next, next => function (error) {
93
93
  if (error && error !== 'route' && error !== 'router') {
94
94
  errorChannel.publish({ req, error })
95
95
  }
@@ -98,7 +98,7 @@ function createWrapRouterMethod (name) {
98
98
  finishChannel.publish({ req })
99
99
 
100
100
  next.apply(this, arguments)
101
- }
101
+ })
102
102
  }
103
103
 
104
104
  function extractMatchers (fn) {
@@ -151,7 +151,7 @@ function createWrapRouterMethod (name) {
151
151
  }
152
152
 
153
153
  function wrapMethod (original) {
154
- return function methodWithTrace (fn) {
154
+ return shimmer.wrapFunction(original, original => function methodWithTrace (fn) {
155
155
  const offset = this.stack ? [].concat(this.stack).length : 0
156
156
  const router = original.apply(this, arguments)
157
157
 
@@ -162,7 +162,7 @@ function createWrapRouterMethod (name) {
162
162
  wrapStack(this.stack, offset, extractMatchers(fn))
163
163
 
164
164
  return router
165
- }
165
+ })
166
166
  }
167
167
 
168
168
  return wrapMethod
@@ -48,14 +48,14 @@ addHook({ name: 'sharedb', versions: ['>=1'], file: 'lib/agent.js' }, Agent => {
48
48
 
49
49
  callback = callbackResource.bind(callback)
50
50
 
51
- arguments[1] = asyncResource.bind(function (error, res) {
51
+ arguments[1] = shimmer.wrapFunction(callback, callback => asyncResource.bind(function (error, res) {
52
52
  if (error) {
53
53
  errorCh.publish(error)
54
54
  }
55
55
  finishCh.publish({ request, res })
56
56
 
57
57
  return callback.apply(this, arguments)
58
- })
58
+ }))
59
59
 
60
60
  try {
61
61
  return origHandleMessageFn.apply(this, arguments)
@@ -1,6 +1,5 @@
1
1
  const { addHook, channel, AsyncResource } = require('./helpers/instrument')
2
2
  const shimmer = require('../../datadog-shimmer')
3
- const { NUM_FAILED_TEST_RETRIES } = require('../../dd-trace/src/plugins/util/test')
4
3
 
5
4
  // test hooks
6
5
  const testStartCh = channel('ci:vitest:test:start')
@@ -108,17 +107,19 @@ function getSortWrapper (sort) {
108
107
  // So we will use the sort from BaseSequencer. This means that a custom sequencer
109
108
  // will not work. This will be a known limitation.
110
109
  let isFlakyTestRetriesEnabled = false
110
+ let flakyTestRetriesCount = 0
111
111
 
112
112
  try {
113
113
  const { err, libraryConfig } = await getChannelPromise(libraryConfigurationCh)
114
114
  if (!err) {
115
115
  isFlakyTestRetriesEnabled = libraryConfig.isFlakyTestRetriesEnabled
116
+ flakyTestRetriesCount = libraryConfig.flakyTestRetriesCount
116
117
  }
117
118
  } catch (e) {
118
119
  isFlakyTestRetriesEnabled = false
119
120
  }
120
- if (isFlakyTestRetriesEnabled && !this.ctx.config.retry) {
121
- this.ctx.config.retry = NUM_FAILED_TEST_RETRIES
121
+ if (isFlakyTestRetriesEnabled && !this.ctx.config.retry && flakyTestRetriesCount > 0) {
122
+ this.ctx.config.retry = flakyTestRetriesCount
122
123
  }
123
124
 
124
125
  let testCodeCoverageLinesTotal
@@ -42,13 +42,12 @@ function wrapMethod (method, logCh) {
42
42
 
43
43
  if (patched.has(transport) || typeof transport.log !== 'function') continue
44
44
 
45
- const log = transport.log
46
- transport.log = function wrappedLog (level, msg, meta, callback) {
45
+ shimmer.wrap(transport, 'log', log => function wrappedLog (level, msg, meta, callback) {
47
46
  const payload = { message: meta || {} }
48
47
  logCh.publish(payload)
49
48
  arguments[2] = payload.message
50
49
  log.apply(this, arguments)
51
- }
50
+ })
52
51
  patched.add(transport)
53
52
  }
54
53
  }
@@ -28,8 +28,7 @@ const {
28
28
  TEST_SOURCE_FILE,
29
29
  TEST_IS_NEW,
30
30
  TEST_IS_RETRY,
31
- TEST_EARLY_FLAKE_ENABLED,
32
- NUM_FAILED_TEST_RETRIES
31
+ TEST_EARLY_FLAKE_ENABLED
33
32
  } = require('../../dd-trace/src/plugins/util/test')
34
33
  const { isMarkedAsUnskippable } = require('../../datadog-plugin-jest/src/util')
35
34
  const { ORIGIN_KEY, COMPONENT } = require('../../dd-trace/src/constants')
@@ -229,16 +228,16 @@ class CypressPlugin {
229
228
  isCodeCoverageEnabled,
230
229
  isEarlyFlakeDetectionEnabled,
231
230
  earlyFlakeDetectionNumRetries,
232
- isFlakyTestRetriesEnabled
231
+ isFlakyTestRetriesEnabled,
232
+ flakyTestRetriesCount
233
233
  }
234
234
  } = libraryConfigurationResponse
235
235
  this.isSuitesSkippingEnabled = isSuitesSkippingEnabled
236
236
  this.isCodeCoverageEnabled = isCodeCoverageEnabled
237
237
  this.isEarlyFlakeDetectionEnabled = isEarlyFlakeDetectionEnabled
238
238
  this.earlyFlakeDetectionNumRetries = earlyFlakeDetectionNumRetries
239
- this.isFlakyTestRetriesEnabled = isFlakyTestRetriesEnabled
240
- if (this.isFlakyTestRetriesEnabled) {
241
- this.cypressConfig.retries.runMode = NUM_FAILED_TEST_RETRIES
239
+ if (isFlakyTestRetriesEnabled) {
240
+ this.cypressConfig.retries.runMode = flakyTestRetriesCount
242
241
  }
243
242
  }
244
243
  return this.cypressConfig
@@ -32,8 +32,8 @@ class HapiPlugin extends RouterPlugin {
32
32
  }
33
33
  })
34
34
 
35
- this.addSub('apm:hapi:extension:enter', ({ req }) => {
36
- this.enter(this._requestSpans.get(req))
35
+ this.addBind('apm:hapi:extension:start', ({ req }) => {
36
+ return this._requestSpans.get(req)
37
37
  })
38
38
  }
39
39
  }
@@ -154,6 +154,7 @@ class JestPlugin extends CiPlugin {
154
154
  config._ddEarlyFlakeDetectionNumRetries = this.libraryConfig?.earlyFlakeDetectionNumRetries ?? 0
155
155
  config._ddRepositoryRoot = this.repositoryRoot
156
156
  config._ddIsFlakyTestRetriesEnabled = this.libraryConfig?.isFlakyTestRetriesEnabled ?? false
157
+ config._ddFlakyTestRetriesCount = this.libraryConfig?.flakyTestRetriesCount
157
158
  })
158
159
  })
159
160