dd-trace 5.56.0 → 5.57.1

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 (134) hide show
  1. package/index.d.ts +44 -2
  2. package/init.js +4 -1
  3. package/package.json +20 -20
  4. package/packages/datadog-esbuild/index.js +22 -0
  5. package/packages/datadog-instrumentations/src/cassandra-driver.js +43 -60
  6. package/packages/datadog-instrumentations/src/confluentinc-kafka-javascript.js +12 -12
  7. package/packages/datadog-instrumentations/src/cucumber.js +4 -6
  8. package/packages/datadog-instrumentations/src/elasticsearch.js +16 -19
  9. package/packages/datadog-instrumentations/src/fastify.js +91 -9
  10. package/packages/datadog-instrumentations/src/helpers/bundler-register.js +20 -5
  11. package/packages/datadog-instrumentations/src/helpers/check-require-cache.js +2 -2
  12. package/packages/datadog-instrumentations/src/helpers/hooks.js +1 -0
  13. package/packages/datadog-instrumentations/src/helpers/register.js +17 -5
  14. package/packages/datadog-instrumentations/src/ioredis.js +8 -13
  15. package/packages/datadog-instrumentations/src/iovalkey.js +10 -14
  16. package/packages/datadog-instrumentations/src/jest.js +28 -6
  17. package/packages/datadog-instrumentations/src/memcached.js +17 -24
  18. package/packages/datadog-instrumentations/src/mocha/main.js +7 -6
  19. package/packages/datadog-instrumentations/src/moleculer/client.js +9 -10
  20. package/packages/datadog-instrumentations/src/moleculer/server.js +12 -13
  21. package/packages/datadog-instrumentations/src/openai.js +30 -2
  22. package/packages/datadog-instrumentations/src/playwright.js +4 -1
  23. package/packages/datadog-instrumentations/src/prisma.js +116 -0
  24. package/packages/datadog-instrumentations/src/redis.js +32 -43
  25. package/packages/datadog-instrumentations/src/router.js +1 -1
  26. package/packages/datadog-instrumentations/src/sharedb.js +10 -16
  27. package/packages/datadog-instrumentations/src/vitest.js +4 -4
  28. package/packages/datadog-plugin-aws-sdk/src/base.js +6 -1
  29. package/packages/datadog-plugin-aws-sdk/src/services/dynamodb.js +9 -4
  30. package/packages/datadog-plugin-aws-sdk/src/services/kinesis.js +3 -2
  31. package/packages/datadog-plugin-aws-sdk/src/services/sqs.js +2 -1
  32. package/packages/datadog-plugin-aws-sdk/src/util.js +2 -2
  33. package/packages/datadog-plugin-bunyan/src/index.js +2 -2
  34. package/packages/datadog-plugin-cassandra-driver/src/index.js +6 -2
  35. package/packages/datadog-plugin-confluentinc-kafka-javascript/src/batch-consumer.js +1 -1
  36. package/packages/datadog-plugin-confluentinc-kafka-javascript/src/consumer.js +1 -1
  37. package/packages/datadog-plugin-confluentinc-kafka-javascript/src/index.js +1 -1
  38. package/packages/datadog-plugin-confluentinc-kafka-javascript/src/producer.js +1 -1
  39. package/packages/datadog-plugin-cucumber/src/index.js +4 -2
  40. package/packages/datadog-plugin-cypress/src/cypress-plugin.js +9 -5
  41. package/packages/datadog-plugin-elasticsearch/src/index.js +12 -4
  42. package/packages/datadog-plugin-http/src/client.js +1 -0
  43. package/packages/datadog-plugin-http/src/server.js +2 -1
  44. package/packages/datadog-plugin-http2/src/client.js +1 -0
  45. package/packages/datadog-plugin-http2/src/server.js +1 -0
  46. package/packages/datadog-plugin-jest/src/index.js +4 -3
  47. package/packages/datadog-plugin-memcached/src/index.js +6 -2
  48. package/packages/datadog-plugin-mocha/src/index.js +3 -2
  49. package/packages/datadog-plugin-moleculer/src/client.js +15 -9
  50. package/packages/datadog-plugin-moleculer/src/server.js +9 -5
  51. package/packages/datadog-plugin-next/src/index.js +2 -1
  52. package/packages/datadog-plugin-openai/src/tracing.js +127 -80
  53. package/packages/datadog-plugin-pino/src/index.js +2 -2
  54. package/packages/datadog-plugin-prisma/src/client.js +62 -0
  55. package/packages/datadog-plugin-prisma/src/engine.js +81 -0
  56. package/packages/datadog-plugin-prisma/src/index.js +22 -0
  57. package/packages/datadog-plugin-protobufjs/src/schema_iterator.js +1 -1
  58. package/packages/datadog-plugin-redis/src/index.js +9 -3
  59. package/packages/datadog-plugin-router/src/index.js +1 -0
  60. package/packages/datadog-plugin-sharedb/src/index.js +13 -5
  61. package/packages/datadog-plugin-winston/src/index.js +2 -2
  62. package/packages/dd-trace/src/appsec/channels.js +26 -21
  63. package/packages/dd-trace/src/appsec/iast/analyzers/unvalidated-redirect-analyzer.js +13 -20
  64. package/packages/dd-trace/src/appsec/iast/taint-tracking/source-types.js +0 -1
  65. package/packages/dd-trace/src/appsec/index.js +16 -1
  66. package/packages/dd-trace/src/appsec/rasp/utils.js +0 -5
  67. package/packages/dd-trace/src/ci-visibility/dynamic-instrumentation/worker/index.js +3 -3
  68. package/packages/dd-trace/src/ci-visibility/early-flake-detection/get-known-tests.js +1 -1
  69. package/packages/dd-trace/src/ci-visibility/exporters/agentless/coverage-writer.js +1 -1
  70. package/packages/dd-trace/src/ci-visibility/exporters/agentless/di-logs-writer.js +1 -1
  71. package/packages/dd-trace/src/ci-visibility/exporters/agentless/writer.js +2 -2
  72. package/packages/dd-trace/src/ci-visibility/exporters/git/git_metadata.js +6 -6
  73. package/packages/dd-trace/src/ci-visibility/intelligent-test-runner/get-skippable-suites.js +2 -3
  74. package/packages/dd-trace/src/ci-visibility/requests/get-library-configuration.js +3 -3
  75. package/packages/dd-trace/src/config.js +286 -270
  76. package/packages/dd-trace/src/constants.js +2 -1
  77. package/packages/dd-trace/src/crashtracking/crashtracker.js +12 -14
  78. package/packages/dd-trace/src/datastreams/context.js +1 -1
  79. package/packages/dd-trace/src/datastreams/processor.js +1 -1
  80. package/packages/dd-trace/src/datastreams/writer.js +3 -3
  81. package/packages/dd-trace/src/debugger/devtools_client/breakpoints.js +6 -3
  82. package/packages/dd-trace/src/debugger/devtools_client/condition.js +1 -1
  83. package/packages/dd-trace/src/debugger/devtools_client/index.js +2 -3
  84. package/packages/dd-trace/src/debugger/devtools_client/state.js +7 -4
  85. package/packages/dd-trace/src/dogstatsd.js +3 -3
  86. package/packages/dd-trace/src/exporters/agent/index.js +10 -5
  87. package/packages/dd-trace/src/exporters/agent/writer.js +1 -1
  88. package/packages/dd-trace/src/exporters/common/agent-info-exporter.js +2 -2
  89. package/packages/dd-trace/src/exporters/log/index.js +1 -1
  90. package/packages/dd-trace/src/exporters/span-stats/writer.js +2 -2
  91. package/packages/dd-trace/src/guardrails/index.js +3 -1
  92. package/packages/dd-trace/src/guardrails/telemetry.js +1 -1
  93. package/packages/dd-trace/src/llmobs/index.js +11 -5
  94. package/packages/dd-trace/src/llmobs/plugins/base.js +2 -2
  95. package/packages/dd-trace/src/llmobs/plugins/langchain/index.js +1 -1
  96. package/packages/dd-trace/src/llmobs/tagger.js +13 -13
  97. package/packages/dd-trace/src/llmobs/writers/base.js +2 -2
  98. package/packages/dd-trace/src/llmobs/writers/spans.js +2 -2
  99. package/packages/dd-trace/src/opentelemetry/tracer.js +1 -1
  100. package/packages/dd-trace/src/opentracing/propagation/text_map.js +4 -4
  101. package/packages/dd-trace/src/opentracing/span.js +1 -0
  102. package/packages/dd-trace/src/plugin_manager.js +3 -3
  103. package/packages/dd-trace/src/plugins/cache.js +2 -2
  104. package/packages/dd-trace/src/plugins/ci_plugin.js +11 -7
  105. package/packages/dd-trace/src/plugins/database.js +3 -1
  106. package/packages/dd-trace/src/plugins/index.js +1 -0
  107. package/packages/dd-trace/src/plugins/log_plugin.js +5 -1
  108. package/packages/dd-trace/src/plugins/outbound.js +8 -6
  109. package/packages/dd-trace/src/plugins/structured_log_plugin.js +9 -0
  110. package/packages/dd-trace/src/plugins/tracing.js +1 -1
  111. package/packages/dd-trace/src/plugins/util/ci.js +83 -30
  112. package/packages/dd-trace/src/plugins/util/git.js +1 -0
  113. package/packages/dd-trace/src/plugins/util/inferred_proxy.js +3 -2
  114. package/packages/dd-trace/src/plugins/util/ip_extractor.js +1 -0
  115. package/packages/dd-trace/src/plugins/util/tags.js +4 -1
  116. package/packages/dd-trace/src/plugins/util/test.js +80 -10
  117. package/packages/dd-trace/src/plugins/util/web.js +1 -0
  118. package/packages/dd-trace/src/profiler.js +0 -2
  119. package/packages/dd-trace/src/profiling/exporter_cli.js +1 -3
  120. package/packages/dd-trace/src/profiling/ssi-heuristics.js +18 -126
  121. package/packages/dd-trace/src/proxy.js +12 -27
  122. package/packages/dd-trace/src/runtime_metrics/index.js +1 -1
  123. package/packages/dd-trace/src/runtime_metrics/runtime_metrics.js +14 -45
  124. package/packages/dd-trace/src/service-naming/schemas/v0/messaging.js +2 -2
  125. package/packages/dd-trace/src/service-naming/schemas/v0/storage.js +4 -0
  126. package/packages/dd-trace/src/service-naming/schemas/v1/messaging.js +2 -2
  127. package/packages/dd-trace/src/service-naming/schemas/v1/storage.js +4 -0
  128. package/packages/dd-trace/src/supported-configurations.json +12 -3
  129. package/packages/dd-trace/src/telemetry/telemetry.js +5 -1
  130. package/packages/dd-trace/src/tracer.js +11 -0
  131. package/packages/dd-trace/src/tracer_metadata.js +25 -0
  132. package/packages/dd-trace/src/util.js +11 -4
  133. package/version.js +3 -1
  134. package/packages/dd-trace/src/profiling/ssi-telemetry-mock-profiler.js +0 -30
package/index.d.ts CHANGED
@@ -212,6 +212,7 @@ interface Plugins {
212
212
  "playwright": tracer.plugins.playwright;
213
213
  "pg": tracer.plugins.pg;
214
214
  "pino": tracer.plugins.pino;
215
+ "prisma": tracer.plugins.prisma;
215
216
  "protobufjs": tracer.plugins.protobufjs;
216
217
  "redis": tracer.plugins.redis;
217
218
  "restify": tracer.plugins.restify;
@@ -483,10 +484,14 @@ declare namespace tracer {
483
484
  flushMinSpans?: number;
484
485
 
485
486
  /**
486
- * Whether to enable runtime metrics.
487
+ * Whether to enable runtime metrics, or an object specifying whether to enable specific metric types.
487
488
  * @default false
488
489
  */
489
- runtimeMetrics?: boolean
490
+ runtimeMetrics?: boolean | {
491
+ enabled?: boolean,
492
+ gc?: boolean,
493
+ eventLoop?: boolean
494
+ }
490
495
 
491
496
  /**
492
497
  * Custom function for DNS lookups when sending requests to the agent.
@@ -1271,6 +1276,15 @@ declare namespace tracer {
1271
1276
  meta?: boolean;
1272
1277
  }
1273
1278
 
1279
+ /** @hidden */
1280
+ interface Prisma extends Instrumentation {}
1281
+
1282
+ /** @hidden */
1283
+ interface PrismaClient extends Prisma {}
1284
+
1285
+ /** @hidden */
1286
+ interface PrismaEngine extends Prisma {}
1287
+
1274
1288
  /**
1275
1289
  * This plugin automatically instruments the
1276
1290
  * [aerospike](https://github.com/aerospike/aerospike-client-nodejs) for module versions >= v3.16.2.
@@ -1820,6 +1834,13 @@ declare namespace tracer {
1820
1834
  * [mongodb-core](https://github.com/mongodb-js/mongodb-core) module.
1821
1835
  */
1822
1836
  interface mongodb_core extends Instrumentation {
1837
+ /**
1838
+ * Whether to enable mongo heartbeats spans.
1839
+ *
1840
+ * @default true
1841
+ */
1842
+ heartbeatEnabled?: boolean;
1843
+
1823
1844
  /**
1824
1845
  * Whether to include the query contents in the resource name.
1825
1846
  */
@@ -1918,6 +1939,10 @@ declare namespace tracer {
1918
1939
  * The database monitoring propagation mode to be used for this plugin.
1919
1940
  */
1920
1941
  dbmPropagationMode?: string;
1942
+ /**
1943
+ * Appends the SQL comment propagation to the query string. Prepends the comment if `false`. For long query strings, the appended propagation comment might be truncated, causing loss of correlation between the query and trace.
1944
+ */
1945
+ appendComment?: boolean;
1921
1946
  }
1922
1947
 
1923
1948
  /**
@@ -1927,6 +1952,23 @@ declare namespace tracer {
1927
1952
  * on the tracer.
1928
1953
  */
1929
1954
  interface pino extends Integration {}
1955
+
1956
+ /**
1957
+ * This plugin automatically instruments the
1958
+ * [@prisma/client](https://www.prisma.io/docs/orm/prisma-client) module.
1959
+ */
1960
+ interface prisma extends PrismaClient, PrismaEngine {
1961
+ /**
1962
+ * Configuration for prisma client.
1963
+ */
1964
+ client?: PrismaClient | boolean,
1965
+
1966
+ /**
1967
+ * Configuration for Prisma engine.
1968
+ */
1969
+ engine?: PrismaEngine | boolean
1970
+ }
1971
+
1930
1972
  /**
1931
1973
  * This plugin automatically patches the [protobufjs](https://protobufjs.github.io/protobuf.js/)
1932
1974
  * to collect protobuf message schemas when Datastreams Monitoring is enabled.
package/init.js CHANGED
@@ -5,5 +5,8 @@
5
5
  var guard = require('./packages/dd-trace/src/guardrails')
6
6
 
7
7
  module.exports = guard(function () {
8
- return require('.').init()
8
+ var INSTRUMENTED_BY_SSI = require('./packages/dd-trace/src/constants').INSTRUMENTED_BY_SSI
9
+ var obj = {}
10
+ obj[INSTRUMENTED_BY_SSI] = 'ssi'
11
+ return require('.').init(obj)
9
12
  })
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dd-trace",
3
- "version": "5.56.0",
3
+ "version": "5.57.1",
4
4
  "description": "Datadog APM tracing client for JavaScript",
5
5
  "main": "index.js",
6
6
  "typings": "index.d.ts",
@@ -8,7 +8,7 @@
8
8
  "env": "bash ./plugin-env",
9
9
  "preinstall": "node scripts/preinstall.js",
10
10
  "bench": "node benchmark/index.js",
11
- "bench:e2e:ci-visibility": "node benchmark/e2e-ci/benchmark-run.js",
11
+ "bench:e2e:test-optimization": "node benchmark/e2e-test-optimization/benchmark-run.js",
12
12
  "dependencies:dedupe": "yarn-deduplicate yarn.lock",
13
13
  "type:doc": "cd docs && yarn && yarn build",
14
14
  "type:test": "cd docs && yarn && yarn test",
@@ -84,24 +84,24 @@
84
84
  "node": ">=18"
85
85
  },
86
86
  "dependencies": {
87
- "@datadog/libdatadog": "^0.6.0",
87
+ "@datadog/libdatadog": "0.7.0",
88
88
  "@datadog/native-appsec": "8.5.2",
89
89
  "@datadog/native-iast-taint-tracking": "4.0.0",
90
- "@datadog/native-metrics": "^3.1.1",
91
- "@datadog/pprof": "5.8.2",
92
- "@datadog/sketches-js": "^2.1.1",
90
+ "@datadog/native-metrics": "3.1.1",
91
+ "@datadog/pprof": "5.9.0",
92
+ "@datadog/sketches-js": "2.1.1",
93
93
  "@datadog/wasm-js-rewriter": "4.0.1",
94
94
  "@isaacs/ttlcache": "^1.4.1",
95
- "@opentelemetry/api": ">=1.0.0 <1.9.0",
95
+ "@opentelemetry/api": "1.8.0",
96
96
  "@opentelemetry/core": "^1.14.0",
97
97
  "crypto-randomuuid": "^1.0.0",
98
- "dc-polyfill": "0.1.9",
98
+ "dc-polyfill": "^0.1.9",
99
99
  "ignore": "^5.2.4",
100
- "import-in-the-middle": "1.14.0",
101
- "istanbul-lib-coverage": "3.2.2",
100
+ "import-in-the-middle": "^1.14.2",
101
+ "istanbul-lib-coverage": "^3.2.2",
102
102
  "jest-docblock": "^29.7.0",
103
103
  "koalas": "^1.0.2",
104
- "limiter": "1.1.5",
104
+ "limiter": "^1.1.5",
105
105
  "lodash.sortby": "^4.7.0",
106
106
  "lru-cache": "^7.18.3",
107
107
  "module-details-from-path": "^1.0.4",
@@ -119,30 +119,30 @@
119
119
  "ttl-set": "^1.0.0"
120
120
  },
121
121
  "devDependencies": {
122
- "@babel/helpers": "^7.27.3",
122
+ "@babel/helpers": "^7.27.6",
123
123
  "@eslint/eslintrc": "^3.3.1",
124
- "@eslint/js": "^9.27.0",
124
+ "@eslint/js": "^9.29.0",
125
125
  "@msgpack/msgpack": "^3.1.2",
126
- "@stylistic/eslint-plugin": "^4.4.0",
126
+ "@stylistic/eslint-plugin": "^5.0.0",
127
127
  "@types/node": "^18.19.106",
128
- "axios": "^1.9.0",
128
+ "axios": "^1.10.0",
129
129
  "benchmark": "^2.1.4",
130
130
  "body-parser": "^2.2.0",
131
131
  "chai": "^4.5.0",
132
- "eslint": "^9.27.0",
132
+ "eslint": "^9.29.0",
133
133
  "eslint-config-standard": "^17.1.0",
134
- "eslint-plugin-import": "^2.31.0",
134
+ "eslint-plugin-import": "^2.32.0",
135
135
  "eslint-plugin-mocha": "^10.5.0",
136
- "eslint-plugin-n": "^17.18.0",
136
+ "eslint-plugin-n": "^17.20.0",
137
137
  "eslint-plugin-promise": "^7.2.1",
138
138
  "eslint-plugin-unicorn": "^57.0.0",
139
139
  "express": "^4.21.2",
140
140
  "get-port": "^5.1.1",
141
141
  "glob": "^7.2.3",
142
142
  "globals": "^15.15.0",
143
- "graphql": "0.13.2",
143
+ "graphql": "*",
144
144
  "jszip": "^3.10.1",
145
- "mocha": "^10.8.2",
145
+ "mocha": "^11.6.0",
146
146
  "multer": "^2.0.1",
147
147
  "nock": "^11.9.1",
148
148
  "nyc": "^15.1.0",
@@ -53,8 +53,30 @@ for (const pkg of INSTRUMENTED) {
53
53
 
54
54
  module.exports.name = 'datadog-esbuild'
55
55
 
56
+ function isESMBuild (build) {
57
+ // check toLowerCase? to be safe if unexpected object is there instead of a string
58
+ const format = build.initialOptions.format?.toLowerCase?.()
59
+ const outputFile = build.initialOptions.outfile?.toLowerCase?.()
60
+ const outExtension = build.initialOptions.outExtension?.['.js']
61
+ return format === 'esm' || outputFile?.endsWith('.mjs') || outExtension === '.mjs'
62
+ }
63
+
56
64
  module.exports.setup = function (build) {
57
65
  const externalModules = new Set(build.initialOptions.external || [])
66
+ if (isESMBuild(build)) {
67
+ build.initialOptions.banner ??= {}
68
+ build.initialOptions.banner.js ??= ''
69
+ if (!build.initialOptions.banner.js.includes('import { createRequire as $dd_createRequire } from \'module\'')) {
70
+ build.initialOptions.banner.js = `import { createRequire as $dd_createRequire } from 'module';
71
+ import { fileURLToPath as $dd_fileURLToPath } from 'url';
72
+ import { dirname as $dd_dirname } from 'path';
73
+ globalThis.require ??= $dd_createRequire(import.meta.url);
74
+ globalThis.__filename ??= $dd_fileURLToPath(import.meta.url);
75
+ globalThis.__dirname ??= $dd_dirname(globalThis.__filename);
76
+ ${build.initialOptions.banner.js}`
77
+ }
78
+ }
79
+
58
80
  build.onResolve({ filter: /.*/ }, args => {
59
81
  if (externalModules.has(args.path)) {
60
82
  // Internal Node.js packages will still be instrumented via require()
@@ -2,8 +2,7 @@
2
2
 
3
3
  const {
4
4
  channel,
5
- addHook,
6
- AsyncResource
5
+ addHook
7
6
  } = require('./helpers/instrument')
8
7
  const shimmer = require('../../datadog-shimmer')
9
8
 
@@ -12,36 +11,33 @@ const finishCh = channel('apm:cassandra-driver:query:finish')
12
11
  const errorCh = channel('apm:cassandra-driver:query:error')
13
12
  const connectCh = channel('apm:cassandra-driver:query:connect')
14
13
 
14
+ let startCtx = {}
15
+
15
16
  addHook({ name: 'cassandra-driver', versions: ['>=3.0.0'] }, cassandra => {
16
17
  shimmer.wrap(cassandra.Client.prototype, 'batch', batch => function (queries, options, callback) {
17
18
  if (!startCh.hasSubscribers) {
18
19
  return batch.apply(this, arguments)
19
20
  }
20
- const callbackResource = new AsyncResource('bound-anonymous-fn')
21
- const asyncResource = new AsyncResource('bound-anonymous-fn')
22
21
  const lastIndex = arguments.length - 1
23
- let cb = arguments[lastIndex]
22
+ const cb = arguments[lastIndex]
24
23
 
25
- if (typeof cb === 'function') {
26
- cb = callbackResource.bind(cb)
27
- arguments[lastIndex] = wrapCallback(finishCh, errorCh, asyncResource, cb)
28
- }
24
+ startCtx = { keyspace: this.keyspace, query: queries, contactPoints: this.options && this.options.contactPoints }
25
+ return startCh.runStores(startCtx, () => {
26
+ if (typeof cb === 'function') {
27
+ arguments[lastIndex] = wrapCallback(finishCh, errorCh, startCtx, cb)
28
+ }
29
29
 
30
- return asyncResource.runInAsyncScope(() => {
31
- const contactPoints = this.options && this.options.contactPoints
32
- startCh.publish({ keyspace: this.keyspace, query: queries, contactPoints })
33
30
  try {
34
31
  const res = batch.apply(this, arguments)
35
32
  if (typeof res === 'function' || !res) {
36
- return wrapCallback(finishCh, errorCh, asyncResource, res)
33
+ return wrapCallback(finishCh, errorCh, startCtx, res)
37
34
  }
38
- const promiseAsyncResource = new AsyncResource('bound-anonymous-fn')
39
35
  return res.then(
40
- promiseAsyncResource.bind(() => finish(finishCh, errorCh)),
41
- promiseAsyncResource.bind(err => finish(finishCh, errorCh, err))
36
+ () => finish(finishCh, errorCh, startCtx),
37
+ err => finish(finishCh, errorCh, startCtx, err)
42
38
  )
43
39
  } catch (e) {
44
- finish(finishCh, errorCh, e)
40
+ finish(finishCh, errorCh, startCtx, e)
45
41
  throw e
46
42
  }
47
43
  })
@@ -54,17 +50,13 @@ addHook({ name: 'cassandra-driver', versions: ['>=4.4'] }, cassandra => {
54
50
  if (!startCh.hasSubscribers) {
55
51
  return _execute.apply(this, arguments)
56
52
  }
57
- const asyncResource = new AsyncResource('bound-anonymous-fn')
58
- return asyncResource.runInAsyncScope(() => {
59
- const contactPoints = this.options && this.options.contactPoints
60
- startCh.publish({ keyspace: this.keyspace, query, contactPoints })
53
+ startCtx = { keyspace: this.keyspace, query, contactPoints: this.options && this.options.contactPoints }
54
+ return startCh.runStores(startCtx, () => {
61
55
  const promise = _execute.apply(this, arguments)
62
56
 
63
- const promiseAsyncResource = new AsyncResource('bound-anonymous-fn')
64
-
65
57
  promise.then(
66
- promiseAsyncResource.bind(() => finish(finishCh, errorCh)),
67
- promiseAsyncResource.bind(err => finish(finishCh, errorCh, err))
58
+ () => finish(finishCh, errorCh, startCtx),
59
+ err => finish(finishCh, errorCh, startCtx, err)
68
60
  )
69
61
  return promise
70
62
  })
@@ -82,29 +74,23 @@ addHook({ name: 'cassandra-driver', versions: ['3 - 4.3'] }, cassandra => {
82
74
  if (!startCh.hasSubscribers) {
83
75
  return _innerExecute.apply(this, arguments)
84
76
  }
85
- const callbackResource = new AsyncResource('bound-anonymous-fn')
86
- const asyncResource = new AsyncResource('bound-anonymous-fn')
87
-
88
77
  if (!isValid(arguments)) {
89
78
  return _innerExecute.apply(this, arguments)
90
79
  }
91
80
 
92
- return asyncResource.runInAsyncScope(() => {
93
- const contactPoints = this.options && this.options.contactPoints
94
- startCh.publish({ keyspace: this.keyspace, query, contactPoints })
95
-
81
+ startCtx = { keyspace: this.keyspace, query, contactPoints: this.options && this.options.contactPoints }
82
+ return startCh.runStores(startCtx, () => {
96
83
  const lastIndex = arguments.length - 1
97
- let cb = arguments[lastIndex]
84
+ const cb = arguments[lastIndex]
98
85
 
99
86
  if (typeof cb === 'function') {
100
- cb = callbackResource.bind(cb)
101
- arguments[lastIndex] = wrapCallback(finishCh, errorCh, asyncResource, cb)
87
+ arguments[lastIndex] = wrapCallback(finishCh, errorCh, startCtx, cb)
102
88
  }
103
89
 
104
90
  try {
105
91
  return _innerExecute.apply(this, arguments)
106
92
  } catch (e) {
107
- finish(finishCh, errorCh, e)
93
+ finish(finishCh, errorCh, startCtx, e)
108
94
  throw e
109
95
  }
110
96
  })
@@ -118,7 +104,8 @@ addHook({ name: 'cassandra-driver', versions: ['>=3.3'], file: 'lib/request-exec
118
104
  if (!startCh.hasSubscribers) {
119
105
  return _sendOnConnection.apply(this, arguments)
120
106
  }
121
- connectCh.publish({ hostname: this._connection.address, port: this._connection.port })
107
+ startCtx = { hostname: this._connection.address, port: this._connection.port, ...startCtx }
108
+ connectCh.publish(startCtx)
122
109
  return _sendOnConnection.apply(this, arguments)
123
110
  })
124
111
  return RequestExecution
@@ -129,19 +116,16 @@ addHook({ name: 'cassandra-driver', versions: ['3.3 - 4.3'], file: 'lib/request-
129
116
  if (!startCh.hasSubscribers) {
130
117
  return getHostCallback.apply(this, arguments)
131
118
  }
132
- const asyncResource = new AsyncResource('bound-anonymous-fn')
133
119
  const execution = this
134
120
 
135
121
  if (!isRequestValid(this, arguments, 1)) {
136
122
  return start.apply(this, arguments)
137
123
  }
138
124
 
139
- getHostCallback = asyncResource.bind(getHostCallback)
140
-
141
- arguments[0] = AsyncResource.bind(function () {
142
- connectCh.publish({ hostname: execution._connection.address, port: execution._connection.port })
143
- return getHostCallback.apply(this, arguments)
144
- })
125
+ arguments[0] = function () {
126
+ startCtx = { hostname: execution._connection.address, port: execution._connection.port, ...startCtx }
127
+ return connectCh.runStores(startCtx, getHostCallback, this, ...arguments)
128
+ }
145
129
 
146
130
  return start.apply(this, arguments)
147
131
  })
@@ -158,34 +142,33 @@ addHook({ name: 'cassandra-driver', versions: ['3 - 3.2'], file: 'lib/request-ha
158
142
  if (!isRequestValid(this, arguments, 3)) {
159
143
  return send.apply(this, arguments)
160
144
  }
161
- const asyncResource = new AsyncResource('bound-anonymous-fn')
162
-
163
- callback = asyncResource.bind(callback)
164
145
 
165
- arguments[2] = AsyncResource.bind(function () {
166
- connectCh.publish({ hostname: handler.connection.address, port: handler.connection.port })
167
- return callback.apply(this, arguments)
168
- })
146
+ arguments[2] = function () {
147
+ startCtx = { hostname: handler.connection.address, port: handler.connection.port, ...startCtx }
148
+ return connectCh.runStores(startCtx, callback, this, ...arguments)
149
+ }
169
150
 
170
151
  return send.apply(this, arguments)
171
152
  })
172
153
  return RequestHandler
173
154
  })
174
155
 
175
- function finish (finishCh, errorCh, error) {
156
+ function finish (finishCh, errorCh, ctx, error) {
176
157
  if (error) {
177
- errorCh.publish(error)
158
+ ctx.error = error
159
+ errorCh.publish(ctx)
178
160
  }
179
- finishCh.publish()
161
+ finishCh.runStores(ctx, () => {})
180
162
  }
181
163
 
182
- function wrapCallback (finishCh, errorCh, asyncResource, callback) {
183
- return shimmer.wrapFunction(callback, callback => asyncResource.bind(function (err) {
184
- finish(finishCh, errorCh, err)
185
- if (callback) {
186
- return callback.apply(this, arguments)
164
+ function wrapCallback (finishCh, errorCh, ctx, callback) {
165
+ return shimmer.wrapFunction(callback, callback => function (err) {
166
+ if (err) {
167
+ ctx.error = err
168
+ errorCh.publish(ctx)
187
169
  }
188
- }))
170
+ return finishCh.runStores(ctx, callback, this, ...arguments)
171
+ })
189
172
  }
190
173
 
191
174
  function isRequestValid (exec, args, length) {
@@ -10,20 +10,20 @@ const log = require('../../dd-trace/src/log')
10
10
 
11
11
  // Create channels for Confluent Kafka JavaScript
12
12
  const channels = {
13
- producerStart: channel('apm:@confluentinc/kafka-javascript:produce:start'),
14
- producerFinish: channel('apm:@confluentinc/kafka-javascript:produce:finish'),
15
- producerError: channel('apm:@confluentinc/kafka-javascript:produce:error'),
16
- producerCommit: channel('apm:@confluentinc/kafka-javascript:produce:commit'),
17
- consumerStart: channel('apm:@confluentinc/kafka-javascript:consume:start'),
18
- consumerFinish: channel('apm:@confluentinc/kafka-javascript:consume:finish'),
19
- consumerError: channel('apm:@confluentinc/kafka-javascript:consume:error'),
20
- consumerCommit: channel('apm:@confluentinc/kafka-javascript:consume:commit'),
13
+ producerStart: channel('apm:confluentinc-kafka-javascript:produce:start'),
14
+ producerFinish: channel('apm:confluentinc-kafka-javascript:produce:finish'),
15
+ producerError: channel('apm:confluentinc-kafka-javascript:produce:error'),
16
+ producerCommit: channel('apm:confluentinc-kafka-javascript:produce:commit'),
17
+ consumerStart: channel('apm:confluentinc-kafka-javascript:consume:start'),
18
+ consumerFinish: channel('apm:confluentinc-kafka-javascript:consume:finish'),
19
+ consumerError: channel('apm:confluentinc-kafka-javascript:consume:error'),
20
+ consumerCommit: channel('apm:confluentinc-kafka-javascript:consume:commit'),
21
21
 
22
22
  // batch operations
23
- batchConsumerStart: channel('apm:@confluentinc/kafka-javascript:consume-batch:start'),
24
- batchConsumerFinish: channel('apm:@confluentinc/kafka-javascript:consume-batch:finish'),
25
- batchConsumerError: channel('apm:@confluentinc/kafka-javascript:consume-batch:error'),
26
- batchConsumerCommit: channel('apm:@confluentinc/kafka-javascript:consume-batch:commit')
23
+ batchConsumerStart: channel('apm:confluentinc-kafka-javascript:consume-batch:start'),
24
+ batchConsumerFinish: channel('apm:confluentinc-kafka-javascript:consume-batch:finish'),
25
+ batchConsumerError: channel('apm:confluentinc-kafka-javascript:consume-batch:error'),
26
+ batchConsumerCommit: channel('apm:confluentinc-kafka-javascript:consume-batch:commit')
27
27
  }
28
28
 
29
29
  const disabledHeaderWeakSet = new WeakSet()
@@ -157,9 +157,9 @@ function getErrorFromCucumberResult (cucumberResult) {
157
157
  return error
158
158
  }
159
159
 
160
- function getChannelPromise (channelToPublishTo, isParallel = false) {
160
+ function getChannelPromise (channelToPublishTo, isParallel = false, frameworkVersion = null) {
161
161
  return new Promise(resolve => {
162
- channelToPublishTo.publish({ onDone: resolve, isParallel })
162
+ channelToPublishTo.publish({ onDone: resolve, isParallel, frameworkVersion })
163
163
  })
164
164
  }
165
165
 
@@ -451,7 +451,7 @@ function getWrappedStart (start, frameworkVersion, isParallel = false, isCoordin
451
451
  }
452
452
  let errorSkippableRequest
453
453
 
454
- const configurationResponse = await getChannelPromise(libraryConfigurationCh, isParallel)
454
+ const configurationResponse = await getChannelPromise(libraryConfigurationCh, isParallel, frameworkVersion)
455
455
 
456
456
  isEarlyFlakeDetectionEnabled = configurationResponse.libraryConfig?.isEarlyFlakeDetectionEnabled
457
457
  earlyFlakeDetectionNumRetries = configurationResponse.libraryConfig?.earlyFlakeDetectionNumRetries
@@ -490,9 +490,7 @@ function getWrappedStart (start, frameworkVersion, isParallel = false, isCoordin
490
490
 
491
491
  isSuitesSkipped = picklesToRun.length !== oldPickles.length
492
492
 
493
- log.debug(
494
- () => `${picklesToRun.length} out of ${oldPickles.length} suites are going to run.`
495
- )
493
+ log.debug('%s out of %s suites are going to run.', picklesToRun.length, oldPickles.length)
496
494
 
497
495
  if (isCoordinator) {
498
496
  this.sourcedPickles = picklesToRun
@@ -2,8 +2,7 @@
2
2
 
3
3
  const {
4
4
  channel,
5
- addHook,
6
- AsyncResource
5
+ addHook
7
6
  } = require('./helpers/instrument')
8
7
  const shimmer = require('../../datadog-shimmer')
9
8
 
@@ -73,33 +72,30 @@ function createWrapRequest (name) {
73
72
 
74
73
  if (!params) return request.apply(this, arguments)
75
74
 
76
- const parentResource = new AsyncResource('bound-anonymous-fn')
77
- const asyncResource = new AsyncResource('bound-anonymous-fn')
78
-
79
- return asyncResource.runInAsyncScope(() => {
80
- startCh.publish({ params })
81
-
75
+ const ctx = { params }
76
+ return startCh.runStores(ctx, () => {
82
77
  try {
83
78
  const lastIndex = arguments.length - 1
84
79
  cb = arguments[lastIndex]
85
80
 
86
81
  if (typeof cb === 'function') {
87
- cb = parentResource.bind(cb)
88
-
89
- arguments[lastIndex] = shimmer.wrapFunction(cb, cb => asyncResource.bind(function (error) {
90
- finish(params, error)
91
- return cb.apply(null, arguments)
92
- }))
82
+ arguments[lastIndex] = shimmer.wrapFunction(cb, cb => function (error) {
83
+ if (error) {
84
+ ctx.error = error
85
+ errorCh.publish(ctx)
86
+ }
87
+ return finishCh.runStores(ctx, cb, null, ...arguments)
88
+ })
93
89
  return request.apply(this, arguments)
94
90
  }
95
91
  const promise = request.apply(this, arguments)
96
92
  if (promise && typeof promise.then === 'function') {
97
- const onResolve = asyncResource.bind(() => finish(params))
98
- const onReject = asyncResource.bind(e => finish(params, e))
93
+ const onResolve = () => finish(ctx)
94
+ const onReject = e => finish(ctx, e)
99
95
 
100
96
  promise.then(onResolve, onReject)
101
97
  } else {
102
- finish(params)
98
+ finish(ctx)
103
99
  }
104
100
  return promise
105
101
  } catch (err) {
@@ -112,11 +108,12 @@ function createWrapRequest (name) {
112
108
  }
113
109
  }
114
110
 
115
- function finish (params, error) {
111
+ function finish (ctx, error) {
116
112
  if (error) {
113
+ ctx.error = error
117
114
  errorCh.publish(error)
118
115
  }
119
- finishCh.publish({ params })
116
+ return finishCh.runStores(ctx, () => {})
120
117
  }
121
118
  }
122
119