dd-trace 5.54.0 → 5.55.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 (178) hide show
  1. package/ci/cypress/plugin.js +8 -0
  2. package/ci/cypress/polyfills.js +23 -0
  3. package/ci/init.js +8 -7
  4. package/initialize.mjs +2 -2
  5. package/package.json +6 -6
  6. package/packages/datadog-code-origin/index.js +22 -4
  7. package/packages/datadog-core/src/utils/src/kebabcase.js +3 -3
  8. package/packages/datadog-instrumentations/src/cassandra-driver.js +5 -6
  9. package/packages/datadog-instrumentations/src/confluentinc-kafka-javascript.js +2 -3
  10. package/packages/datadog-instrumentations/src/cookie-parser.js +1 -1
  11. package/packages/datadog-instrumentations/src/couchbase.js +3 -6
  12. package/packages/datadog-instrumentations/src/cucumber.js +21 -28
  13. package/packages/datadog-instrumentations/src/dns.js +4 -4
  14. package/packages/datadog-instrumentations/src/elasticsearch.js +9 -10
  15. package/packages/datadog-instrumentations/src/fastify.js +7 -9
  16. package/packages/datadog-instrumentations/src/google-cloud-pubsub.js +14 -16
  17. package/packages/datadog-instrumentations/src/hapi.js +10 -11
  18. package/packages/datadog-instrumentations/src/helpers/fetch.js +4 -5
  19. package/packages/datadog-instrumentations/src/helpers/hook.js +1 -2
  20. package/packages/datadog-instrumentations/src/helpers/register.js +6 -5
  21. package/packages/datadog-instrumentations/src/jest.js +67 -98
  22. package/packages/datadog-instrumentations/src/koa.js +2 -3
  23. package/packages/datadog-instrumentations/src/mariadb.js +11 -4
  24. package/packages/datadog-instrumentations/src/mocha/main.js +79 -75
  25. package/packages/datadog-instrumentations/src/mocha.js +3 -1
  26. package/packages/datadog-instrumentations/src/mysql.js +11 -2
  27. package/packages/datadog-instrumentations/src/nyc.js +2 -1
  28. package/packages/datadog-instrumentations/src/openai.js +2 -2
  29. package/packages/datadog-instrumentations/src/otel-sdk-trace.js +4 -3
  30. package/packages/datadog-instrumentations/src/pg.js +2 -3
  31. package/packages/datadog-instrumentations/src/playwright.js +19 -22
  32. package/packages/datadog-instrumentations/src/protobufjs.js +3 -4
  33. package/packages/datadog-instrumentations/src/redis.js +1 -1
  34. package/packages/datadog-instrumentations/src/restify.js +9 -13
  35. package/packages/datadog-instrumentations/src/router.js +12 -11
  36. package/packages/datadog-instrumentations/src/tedious.js +1 -2
  37. package/packages/datadog-instrumentations/src/vitest.js +15 -29
  38. package/packages/datadog-plugin-avsc/src/schema_iterator.js +12 -12
  39. package/packages/datadog-plugin-aws-sdk/src/base.js +12 -8
  40. package/packages/datadog-plugin-aws-sdk/src/services/cloudwatchlogs.js +3 -5
  41. package/packages/datadog-plugin-aws-sdk/src/services/dynamodb.js +12 -20
  42. package/packages/datadog-plugin-aws-sdk/src/services/kinesis.js +4 -5
  43. package/packages/datadog-plugin-aws-sdk/src/services/lambda.js +3 -5
  44. package/packages/datadog-plugin-aws-sdk/src/services/redshift.js +3 -5
  45. package/packages/datadog-plugin-aws-sdk/src/services/s3.js +3 -5
  46. package/packages/datadog-plugin-aws-sdk/src/services/sns.js +1 -2
  47. package/packages/datadog-plugin-aws-sdk/src/services/sqs.js +7 -10
  48. package/packages/datadog-plugin-cucumber/src/index.js +3 -2
  49. package/packages/datadog-plugin-cypress/src/cypress-plugin.js +2 -1
  50. package/packages/datadog-plugin-dd-trace-api/src/index.js +2 -1
  51. package/packages/datadog-plugin-elasticsearch/src/index.js +1 -1
  52. package/packages/datadog-plugin-google-cloud-vertexai/src/tracing.js +1 -1
  53. package/packages/datadog-plugin-graphql/src/index.js +3 -2
  54. package/packages/datadog-plugin-graphql/src/resolve.js +17 -10
  55. package/packages/datadog-plugin-http/src/client.js +5 -6
  56. package/packages/datadog-plugin-http2/src/client.js +7 -8
  57. package/packages/datadog-plugin-jest/src/index.js +3 -2
  58. package/packages/datadog-plugin-mocha/src/index.js +6 -1
  59. package/packages/datadog-plugin-mongodb-core/src/index.js +2 -1
  60. package/packages/datadog-plugin-mysql/src/index.js +11 -0
  61. package/packages/datadog-plugin-next/src/index.js +1 -1
  62. package/packages/datadog-plugin-openai/src/tracing.js +2 -4
  63. package/packages/datadog-plugin-playwright/src/index.js +3 -2
  64. package/packages/datadog-plugin-protobufjs/src/schema_iterator.js +8 -9
  65. package/packages/datadog-plugin-redis/src/index.js +1 -3
  66. package/packages/datadog-plugin-vitest/src/index.js +5 -4
  67. package/packages/dd-trace/src/appsec/iast/analyzers/analyzers.js +0 -1
  68. package/packages/dd-trace/src/appsec/iast/analyzers/hardcoded-password-rules.js +0 -1
  69. package/packages/dd-trace/src/appsec/iast/analyzers/hardcoded-secret-rules.js +0 -1
  70. package/packages/dd-trace/src/appsec/iast/analyzers/hardcoded-secrets-rules.js +0 -1
  71. package/packages/dd-trace/src/appsec/iast/analyzers/missing-header-analyzer.js +1 -2
  72. package/packages/dd-trace/src/appsec/iast/security-controls/index.js +11 -12
  73. package/packages/dd-trace/src/appsec/iast/taint-tracking/plugin.js +1 -1
  74. package/packages/dd-trace/src/appsec/iast/taint-tracking/rewriter.js +2 -1
  75. package/packages/dd-trace/src/appsec/iast/telemetry/span-tags.js +1 -1
  76. package/packages/dd-trace/src/appsec/iast/telemetry/verbosity.js +1 -2
  77. package/packages/dd-trace/src/appsec/iast/vulnerabilities-formatter/evidence-redaction/range-utils.js +10 -11
  78. package/packages/dd-trace/src/appsec/iast/vulnerabilities-formatter/evidence-redaction/sensitive-handler.js +0 -4
  79. package/packages/dd-trace/src/appsec/iast/vulnerabilities.js +0 -1
  80. package/packages/dd-trace/src/appsec/index.js +4 -4
  81. package/packages/dd-trace/src/appsec/reporter.js +5 -7
  82. package/packages/dd-trace/src/appsec/sdk/set_user.js +2 -2
  83. package/packages/dd-trace/src/appsec/sdk/track_event.js +3 -3
  84. package/packages/dd-trace/src/appsec/telemetry/index.js +31 -1
  85. package/packages/dd-trace/src/appsec/waf/waf_context_wrapper.js +6 -2
  86. package/packages/dd-trace/src/azure_metadata.js +8 -3
  87. package/packages/dd-trace/src/ci-visibility/dynamic-instrumentation/index.js +8 -7
  88. package/packages/dd-trace/src/ci-visibility/early-flake-detection/get-known-tests.js +2 -1
  89. package/packages/dd-trace/src/ci-visibility/exporters/agentless/coverage-writer.js +2 -1
  90. package/packages/dd-trace/src/ci-visibility/exporters/agentless/di-logs-writer.js +2 -1
  91. package/packages/dd-trace/src/ci-visibility/exporters/agentless/writer.js +2 -1
  92. package/packages/dd-trace/src/ci-visibility/exporters/git/git_metadata.js +4 -3
  93. package/packages/dd-trace/src/ci-visibility/exporters/test-worker/index.js +7 -6
  94. package/packages/dd-trace/src/ci-visibility/intelligent-test-runner/get-skippable-suites.js +2 -1
  95. package/packages/dd-trace/src/ci-visibility/log-submission/log-submission-plugin.js +4 -3
  96. package/packages/dd-trace/src/ci-visibility/requests/get-library-configuration.js +4 -3
  97. package/packages/dd-trace/src/ci-visibility/test-management/get-test-management-tests.js +2 -1
  98. package/packages/dd-trace/src/config-helper.js +89 -0
  99. package/packages/dd-trace/src/config.js +77 -78
  100. package/packages/dd-trace/src/config_stable.js +7 -4
  101. package/packages/dd-trace/src/datastreams/fnv.js +1 -1
  102. package/packages/dd-trace/src/datastreams/schemas/schema_builder.js +6 -6
  103. package/packages/dd-trace/src/debugger/devtools_client/breakpoints.js +1 -2
  104. package/packages/dd-trace/src/debugger/devtools_client/condition.js +1 -2
  105. package/packages/dd-trace/src/debugger/devtools_client/index.js +2 -1
  106. package/packages/dd-trace/src/debugger/devtools_client/send.js +3 -2
  107. package/packages/dd-trace/src/debugger/devtools_client/snapshot/collector.js +1 -2
  108. package/packages/dd-trace/src/debugger/devtools_client/snapshot/processor.js +3 -4
  109. package/packages/dd-trace/src/debugger/devtools_client/snapshot/redaction.js +1 -1
  110. package/packages/dd-trace/src/debugger/index.js +1 -0
  111. package/packages/dd-trace/src/dogstatsd.js +2 -2
  112. package/packages/dd-trace/src/encode/0.4.js +5 -2
  113. package/packages/dd-trace/src/encode/0.5.js +3 -5
  114. package/packages/dd-trace/src/encode/agentless-ci-visibility.js +5 -5
  115. package/packages/dd-trace/src/exporter.js +2 -1
  116. package/packages/dd-trace/src/exporters/common/docker.js +3 -2
  117. package/packages/dd-trace/src/exporters/common/request.js +4 -1
  118. package/packages/dd-trace/src/exporters/common/util.js +3 -1
  119. package/packages/dd-trace/src/id.js +3 -3
  120. package/packages/dd-trace/src/index.js +4 -3
  121. package/packages/dd-trace/src/lambda/handler.js +2 -1
  122. package/packages/dd-trace/src/lambda/index.js +2 -1
  123. package/packages/dd-trace/src/lambda/runtime/patch.js +3 -2
  124. package/packages/dd-trace/src/lambda/runtime/ritm.js +3 -2
  125. package/packages/dd-trace/src/llmobs/constants/tags.js +1 -0
  126. package/packages/dd-trace/src/llmobs/index.js +21 -5
  127. package/packages/dd-trace/src/llmobs/noop.js +18 -20
  128. package/packages/dd-trace/src/llmobs/plugins/langchain/handlers/index.js +11 -13
  129. package/packages/dd-trace/src/llmobs/plugins/openai.js +1 -2
  130. package/packages/dd-trace/src/llmobs/sdk.js +2 -1
  131. package/packages/dd-trace/src/llmobs/span_processor.js +1 -1
  132. package/packages/dd-trace/src/llmobs/tagger.js +19 -6
  133. package/packages/dd-trace/src/llmobs/writers/base.js +1 -1
  134. package/packages/dd-trace/src/log/index.js +5 -4
  135. package/packages/dd-trace/src/log/writer.js +1 -2
  136. package/packages/dd-trace/src/msgpack/encoder.js +3 -3
  137. package/packages/dd-trace/src/noop/span.js +1 -1
  138. package/packages/dd-trace/src/opentelemetry/tracer.js +1 -1
  139. package/packages/dd-trace/src/opentracing/propagation/log.js +4 -5
  140. package/packages/dd-trace/src/opentracing/propagation/text_map.js +17 -18
  141. package/packages/dd-trace/src/opentracing/span.js +7 -6
  142. package/packages/dd-trace/src/payload-tagging/config/index.js +17 -21
  143. package/packages/dd-trace/src/plugin_manager.js +4 -3
  144. package/packages/dd-trace/src/plugins/ci_plugin.js +25 -1
  145. package/packages/dd-trace/src/plugins/plugin.js +1 -1
  146. package/packages/dd-trace/src/plugins/util/ci.js +7 -7
  147. package/packages/dd-trace/src/plugins/util/git.js +1 -1
  148. package/packages/dd-trace/src/plugins/util/llm.js +2 -2
  149. package/packages/dd-trace/src/plugins/util/stacktrace.js +8 -1
  150. package/packages/dd-trace/src/plugins/util/test.js +4 -3
  151. package/packages/dd-trace/src/plugins/util/user-provided-git.js +2 -1
  152. package/packages/dd-trace/src/plugins/util/web.js +3 -4
  153. package/packages/dd-trace/src/priority_sampler.js +46 -35
  154. package/packages/dd-trace/src/profiling/config.js +12 -32
  155. package/packages/dd-trace/src/profiling/exporter_cli.js +20 -20
  156. package/packages/dd-trace/src/profiling/exporters/agent.js +1 -1
  157. package/packages/dd-trace/src/profiling/exporters/event_serializer.js +2 -1
  158. package/packages/dd-trace/src/profiling/index.js +2 -1
  159. package/packages/dd-trace/src/profiling/profiler.js +7 -4
  160. package/packages/dd-trace/src/profiling/ssi-telemetry-mock-profiler.js +3 -1
  161. package/packages/dd-trace/src/profiling/tagger.js +22 -12
  162. package/packages/dd-trace/src/proxy.js +2 -1
  163. package/packages/dd-trace/src/ritm.js +4 -4
  164. package/packages/dd-trace/src/runtime_metrics/runtime_metrics.js +3 -2
  165. package/packages/dd-trace/src/sampler.js +10 -2
  166. package/packages/dd-trace/src/serverless.js +11 -4
  167. package/packages/dd-trace/src/span_processor.js +2 -1
  168. package/packages/dd-trace/src/standalone/tracesource.js +1 -2
  169. package/packages/dd-trace/src/standalone/tracesource_priority_sampler.js +1 -2
  170. package/packages/dd-trace/src/startup-log.js +5 -17
  171. package/packages/dd-trace/src/supported-configurations.json +439 -0
  172. package/packages/dd-trace/src/telemetry/dependencies.js +62 -57
  173. package/packages/dd-trace/src/telemetry/send-data.js +7 -6
  174. package/packages/dd-trace/src/telemetry/telemetry.js +12 -25
  175. package/packages/dd-trace/src/tracer.js +3 -7
  176. package/packages/dd-trace/src/util.js +0 -5
  177. package/packages/dd-trace/src/appsec/iast/analyzers/header-injection-analyzer.js +0 -120
  178. package/packages/dd-trace/src/appsec/iast/vulnerabilities-formatter/evidence-redaction/sensitive-analyzers/header-sensitive-analyzer.js +0 -20
@@ -1,3 +1,11 @@
1
+ const { NODE_MAJOR } = require('../../version')
2
+
3
+ // These polyfills are here because cypress@6.7.0, which we still support for v5, runs its plugin code
4
+ // with Node.js@12.
5
+ if (NODE_MAJOR < 18) {
6
+ require('./polyfills')
7
+ }
8
+
1
9
  require('../init')
2
10
 
3
11
  module.exports = require('../../packages/datadog-plugin-cypress/src/plugin')
@@ -0,0 +1,23 @@
1
+ if (!Object.hasOwn) {
2
+ Object.defineProperty(Object, 'hasOwn', {
3
+ // eslint-disable-next-line prefer-object-has-own
4
+ value: (obj, prop) => Object.prototype.hasOwnProperty.call(obj, prop),
5
+ writable: true,
6
+ configurable: true,
7
+ })
8
+ }
9
+
10
+ if (!Array.prototype.at) {
11
+ // eslint-disable-next-line no-extend-native
12
+ Object.defineProperty(Array.prototype, 'at', {
13
+ value: function (n) {
14
+ const len = this.length
15
+ if (len === 0) return
16
+ let index = Math.trunc(n)
17
+ if (index < 0) index += len
18
+ return (index < 0 || index >= len) ? undefined : this[index]
19
+ },
20
+ writable: true,
21
+ configurable: true
22
+ })
23
+ }
package/ci/init.js CHANGED
@@ -2,12 +2,13 @@
2
2
  const tracer = require('../packages/dd-trace')
3
3
  const { isTrue, isFalse } = require('../packages/dd-trace/src/util')
4
4
  const log = require('../packages/dd-trace/src/log')
5
+ const { getEnvironmentVariable } = require('../packages/dd-trace/src/config-helper')
5
6
 
6
- const isJestWorker = !!process.env.JEST_WORKER_ID
7
- const isCucumberWorker = !!process.env.CUCUMBER_WORKER_ID
8
- const isMochaWorker = !!process.env.MOCHA_WORKER_ID
7
+ const isJestWorker = !!getEnvironmentVariable('JEST_WORKER_ID')
8
+ const isCucumberWorker = !!getEnvironmentVariable('CUCUMBER_WORKER_ID')
9
+ const isMochaWorker = !!getEnvironmentVariable('MOCHA_WORKER_ID')
9
10
 
10
- const isPlaywrightWorker = !!process.env.DD_PLAYWRIGHT_WORKER
11
+ const isPlaywrightWorker = !!getEnvironmentVariable('DD_PLAYWRIGHT_WORKER')
11
12
 
12
13
  const packageManagers = [
13
14
  'npm',
@@ -25,17 +26,17 @@ const options = {
25
26
  flushInterval: isJestWorker ? 0 : 5000
26
27
  }
27
28
 
28
- let shouldInit = !isFalse(process.env.DD_CIVISIBILITY_ENABLED)
29
+ let shouldInit = !isFalse(getEnvironmentVariable('DD_CIVISIBILITY_ENABLED'))
29
30
 
30
31
  if (isPackageManager()) {
31
32
  log.debug('dd-trace is not initialized in a package manager.')
32
33
  shouldInit = false
33
34
  }
34
35
 
35
- const isAgentlessEnabled = isTrue(process.env.DD_CIVISIBILITY_AGENTLESS_ENABLED)
36
+ const isAgentlessEnabled = isTrue(getEnvironmentVariable('DD_CIVISIBILITY_AGENTLESS_ENABLED'))
36
37
 
37
38
  if (isAgentlessEnabled) {
38
- if (process.env.DATADOG_API_KEY || process.env.DD_API_KEY) {
39
+ if (getEnvironmentVariable('DD_API_KEY')) {
39
40
  options.experimental = {
40
41
  exporter: 'datadog'
41
42
  }
package/initialize.mjs CHANGED
@@ -17,7 +17,7 @@ import { fileURLToPath } from 'node:url'
17
17
  import {
18
18
  load as origLoad,
19
19
  resolve as origResolve,
20
- getSource as origGetSource
20
+ getSource as origGetSource,
21
21
  } from 'import-in-the-middle/hook.mjs'
22
22
 
23
23
  let hasInsertedInit = false
@@ -31,7 +31,7 @@ ${result.source}`
31
31
  return result
32
32
  }
33
33
 
34
- const [NODE_MAJOR, NODE_MINOR] = process.versions.node.split('.').map(x => +x)
34
+ const [NODE_MAJOR, NODE_MINOR] = process.versions.node.split('.').map(Number)
35
35
 
36
36
  const brokenLoaders = NODE_MAJOR === 18 && NODE_MINOR === 0
37
37
  const iitmExclusions = [/langsmith/, /openai\/_shims/, /openai\/resources\/chat\/completions\/messages/]
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dd-trace",
3
- "version": "5.54.0",
3
+ "version": "5.55.0",
4
4
  "description": "Datadog APM tracing client for JavaScript",
5
5
  "main": "index.js",
6
6
  "typings": "index.d.ts",
@@ -26,8 +26,8 @@
26
26
  "test:debugger:ci": "nyc --no-clean --include 'packages/dd-trace/src/debugger/**/*.js' -- npm run test:debugger",
27
27
  "test:trace:core": "tap packages/dd-trace/test/*.spec.js \"packages/dd-trace/test/{ci-visibility,datastreams,encode,exporters,opentelemetry,opentracing,plugins,service-naming,standalone,telemetry}/**/*.spec.js\"",
28
28
  "test:trace:core:ci": "npm run test:trace:core -- --coverage --nyc-arg=--include=\"packages/dd-trace/src/**/*.js\"",
29
- "test:instrumentations": "mocha -r 'packages/dd-trace/test/setup/mocha.js' 'packages/datadog-instrumentations/test/**/*.spec.js'",
30
- "test:instrumentations:ci": "nyc --no-clean --include 'packages/datadog-instrumentations/src/**/*.js' -- npm run test:instrumentations",
29
+ "test:instrumentations": "mocha -r 'packages/dd-trace/test/setup/mocha.js' \"packages/datadog-instrumentations/test/@($(echo $PLUGINS)).spec.js\"",
30
+ "test:instrumentations:ci": "yarn services && nyc --no-clean --include \"packages/datadog-instrumentations/src/@($(echo $PLUGINS)).js\" --include \"packages/datadog-instrumentations/src/@($(echo $PLUGINS))/**/*.js\" -- npm run test:instrumentations",
31
31
  "test:instrumentations:misc": "mocha -r 'packages/dd-trace/test/setup/mocha.js' 'packages/datadog-instrumentations/test/*/**/*.spec.js'",
32
32
  "test:instrumentations:misc:ci": "nyc --no-clean --include 'packages/datadog-instrumentations/src/**/*.js' -- npm run test:instrumentations:misc",
33
33
  "test:core": "tap \"packages/datadog-core/test/**/*.spec.js\"",
@@ -38,8 +38,8 @@
38
38
  "test:llmobs:sdk:ci": "nyc --no-clean --include \"packages/dd-trace/src/llmobs/**/*.js\" -- npm run test:llmobs:sdk",
39
39
  "test:llmobs:plugins": "mocha -r \"packages/dd-trace/test/setup/mocha.js\" \"packages/dd-trace/test/llmobs/plugins/@($(echo $PLUGINS))/*.spec.js\"",
40
40
  "test:llmobs:plugins:ci": "yarn services && nyc --no-clean --include \"packages/dd-trace/src/llmobs/**/*.js\" -- npm run test:llmobs:plugins",
41
- "test:plugins": "mocha -r \"packages/dd-trace/test/setup/mocha.js\" \"packages/datadog-instrumentations/test/@($(echo $PLUGINS)).spec.js\" \"packages/datadog-plugin-@($(echo $PLUGINS))/test/**/*.spec.js\"",
42
- "test:plugins:ci": "yarn services && nyc --no-clean --include \"packages/datadog-instrumentations/src/@($(echo $PLUGINS)).js\" --include \"packages/datadog-instrumentations/src/@($(echo $PLUGINS))/**/*.js\" --include \"packages/datadog-plugin-@($(echo $PLUGINS))/src/**/*.js\" -- npm run test:plugins",
41
+ "test:plugins": "mocha -r \"packages/dd-trace/test/setup/mocha.js\" \"packages/datadog-plugin-@($(echo $PLUGINS))/test/**/*.spec.js\"",
42
+ "test:plugins:ci": "yarn services && nyc --no-clean --include \"packages/datadog-plugin-@($(echo $PLUGINS))/src/**/*.js\" -- npm run test:plugins",
43
43
  "test:plugins:upstream": "node ./packages/dd-trace/test/plugins/suite.js",
44
44
  "test:profiler": "tap \"packages/dd-trace/test/profiling/**/*.spec.js\"",
45
45
  "test:profiler:ci": "npm run test:profiler -- --coverage --nyc-arg=--include=\"packages/dd-trace/src/profiling/**/*.js\"",
@@ -143,7 +143,7 @@
143
143
  "graphql": "0.13.2",
144
144
  "jszip": "^3.10.1",
145
145
  "mocha": "^10.8.2",
146
- "multer": "^2.0.0",
146
+ "multer": "^2.0.1",
147
147
  "nock": "^11.9.1",
148
148
  "nyc": "^15.1.0",
149
149
  "proxyquire": "^1.8.0",
@@ -2,22 +2,40 @@
2
2
 
3
3
  const { getUserLandFrames } = require('../dd-trace/src/plugins/util/stacktrace')
4
4
 
5
- const limit = Number(process.env._DD_CODE_ORIGIN_MAX_USER_FRAMES) || 8
5
+ const ENTRY_SPAN_STACK_FRAMES_LIMIT = 1
6
+ const EXIT_SPAN_STACK_FRAMES_LIMIT = Number(process.env._DD_CODE_ORIGIN_FOR_SPANS_EXIT_SPAN_MAX_USER_FRAMES) || 8
6
7
 
7
8
  module.exports = {
8
9
  entryTags,
9
10
  exitTags
10
11
  }
11
12
 
13
+ /**
14
+ * @param {Function} topOfStackFunc - A function present in the current stack, above which no stack frames should be
15
+ * collected.
16
+ * @returns {Record<string, string>}
17
+ */
12
18
  function entryTags (topOfStackFunc) {
13
- return tag('entry', topOfStackFunc)
19
+ return tag('entry', topOfStackFunc, ENTRY_SPAN_STACK_FRAMES_LIMIT)
14
20
  }
15
21
 
22
+ /**
23
+ * @param {Function} topOfStackFunc - A function present in the current stack, above which no stack frames should be
24
+ * collected.
25
+ * @returns {Record<string, string>}
26
+ */
16
27
  function exitTags (topOfStackFunc) {
17
- return tag('exit', topOfStackFunc)
28
+ return tag('exit', topOfStackFunc, EXIT_SPAN_STACK_FRAMES_LIMIT)
18
29
  }
19
30
 
20
- function tag (type, topOfStackFunc) {
31
+ /**
32
+ * @param {'entry'|'exit'} type - The type of code origin.
33
+ * @param {Function} topOfStackFunc - A function present in the current stack, above which no stack frames should be
34
+ * collected.
35
+ * @param {number} limit - The maximum number of stack frames to include in the tags.
36
+ * @returns {Record<string, string>}
37
+ */
38
+ function tag (type, topOfStackFunc, limit) {
21
39
  const frames = getUserLandFrames(topOfStackFunc, limit)
22
40
  const tags = {
23
41
  '_dd.code_origin.type': type
@@ -7,8 +7,8 @@ module.exports = function kebabcase (str) {
7
7
 
8
8
  return str
9
9
  .trim()
10
- .replace(/([a-z])([A-Z])/g, '$1-$2') // Convert camelCase to kebab-case
11
- .replace(/[\s_]+/g, '-') // Replace spaces and underscores with a single dash
12
- .replace(/^-+|-+$/g, '') // Trim leading and trailing dashes
10
+ .replaceAll(/([a-z])([A-Z])/g, '$1-$2') // Convert camelCase to kebab-case
11
+ .replaceAll(/[\s_]+/g, '-') // Replace spaces and underscores with a single dash
12
+ .replaceAll(/^-+|-+$/g, '') // Trim leading and trailing dashes
13
13
  .toLowerCase()
14
14
  }
@@ -34,13 +34,12 @@ addHook({ name: 'cassandra-driver', versions: ['>=3.0.0'] }, cassandra => {
34
34
  const res = batch.apply(this, arguments)
35
35
  if (typeof res === 'function' || !res) {
36
36
  return wrapCallback(finishCh, errorCh, asyncResource, res)
37
- } else {
38
- const promiseAsyncResource = new AsyncResource('bound-anonymous-fn')
39
- return res.then(
40
- promiseAsyncResource.bind(() => finish(finishCh, errorCh)),
41
- promiseAsyncResource.bind(err => finish(finishCh, errorCh, err))
42
- )
43
37
  }
38
+ const promiseAsyncResource = new AsyncResource('bound-anonymous-fn')
39
+ return res.then(
40
+ promiseAsyncResource.bind(() => finish(finishCh, errorCh)),
41
+ promiseAsyncResource.bind(err => finish(finishCh, errorCh, err))
42
+ )
44
43
  } catch (e) {
45
44
  finish(finishCh, errorCh, e)
46
45
  throw e
@@ -379,10 +379,9 @@ function wrapKafkaCallback (callback, { startCh, commitCh, finishCh, errorCh },
379
379
  finishCh.publish(ctx)
380
380
  throw err
381
381
  })
382
- } else {
383
- finishCh.publish(ctx)
384
- return result
385
382
  }
383
+ finishCh.publish(ctx)
384
+ return result
386
385
  } catch (error) {
387
386
  ctx.error = error
388
387
  errorCh.publish(ctx)
@@ -10,7 +10,7 @@ function publishRequestCookieAndNext (req, res, next) {
10
10
  if (cookieParserReadCh.hasSubscribers && req) {
11
11
  const abortController = new AbortController()
12
12
 
13
- const mergedCookies = Object.assign({}, req.cookies, req.signedCookies)
13
+ const mergedCookies = { ...req.cookies, ...req.signedCookies }
14
14
 
15
15
  cookieParserReadCh.publish({ req, res, abortController, cookies: mergedCookies })
16
16
 
@@ -43,14 +43,11 @@ function wrapMaybeInvoke (_maybeInvoke) {
43
43
 
44
44
  function wrapQuery (query) {
45
45
  const wrapped = function (q, params, callback) {
46
- callback = AsyncResource.bind(arguments[arguments.length - 1])
47
-
48
- if (typeof callback === 'function') {
49
- arguments[arguments.length - 1] = callback
46
+ if (typeof arguments[arguments.length - 1] === 'function') {
47
+ arguments[arguments.length - 1] = AsyncResource.bind(arguments[arguments.length - 1])
50
48
  }
51
49
 
52
- const res = query.apply(this, arguments)
53
- return res
50
+ return query.apply(this, arguments)
54
51
  }
55
52
  return wrapped
56
53
  }
@@ -1,9 +1,10 @@
1
1
  'use strict'
2
2
  const { createCoverageMap } = require('istanbul-lib-coverage')
3
3
 
4
- const { addHook, channel, AsyncResource } = require('./helpers/instrument')
4
+ const { addHook, channel } = require('./helpers/instrument')
5
5
  const shimmer = require('../../datadog-shimmer')
6
6
  const log = require('../../dd-trace/src/log')
7
+ const { getEnvironmentVariable } = require('../../dd-trace/src/config-helper')
7
8
 
8
9
  const testStartCh = channel('ci:cucumber:test:start')
9
10
  const testRetryCh = channel('ci:cucumber:test:retry')
@@ -63,8 +64,6 @@ let eventDataCollector = null
63
64
  let pickleByFile = {}
64
65
  const pickleResultByFile = {}
65
66
 
66
- const sessionAsyncResource = new AsyncResource('bound-anonymous-fn')
67
-
68
67
  let skippableSuites = []
69
68
  let itrCorrelationId = ''
70
69
  let isForcedToRun = false
@@ -160,9 +159,7 @@ function getErrorFromCucumberResult (cucumberResult) {
160
159
 
161
160
  function getChannelPromise (channelToPublishTo, isParallel = false) {
162
161
  return new Promise(resolve => {
163
- sessionAsyncResource.runInAsyncScope(() => {
164
- channelToPublishTo.publish({ onDone: resolve, isParallel })
165
- })
162
+ channelToPublishTo.publish({ onDone: resolve, isParallel })
166
163
  })
167
164
  }
168
165
 
@@ -247,7 +244,7 @@ function wrapRun (pl, isLatestVersion) {
247
244
  testName: this.pickle.name,
248
245
  testFileAbsolutePath,
249
246
  testSourceLine,
250
- isParallel: !!process.env.CUCUMBER_WORKER_ID
247
+ isParallel: !!getEnvironmentVariable('CUCUMBER_WORKER_ID')
251
248
  }
252
249
  const ctx = testStartPayload
253
250
  numAttemptToCtx.set(numAttempt, ctx)
@@ -540,15 +537,13 @@ function getWrappedStart (start, frameworkVersion, isParallel = false, isCoordin
540
537
  }
541
538
 
542
539
  const processArgv = process.argv.slice(2).join(' ')
543
- const command = process.env.npm_lifecycle_script || `cucumber-js ${processArgv}`
540
+ const command = getEnvironmentVariable('npm_lifecycle_script') || `cucumber-js ${processArgv}`
544
541
 
545
542
  if (isFlakyTestRetriesEnabled && !options.retry && numTestRetries > 0) {
546
543
  options.retry = numTestRetries
547
544
  }
548
545
 
549
- sessionAsyncResource.runInAsyncScope(() => {
550
- sessionStartCh.publish({ command, frameworkVersion })
551
- })
546
+ sessionStartCh.publish({ command, frameworkVersion })
552
547
 
553
548
  if (!errorSkippableRequest && skippedSuites.length) {
554
549
  itrSkippedSuitesCh.publish({ skippedSuites, frameworkVersion })
@@ -576,19 +571,17 @@ function getWrappedStart (start, frameworkVersion, isParallel = false, isCoordin
576
571
  global.__coverage__ = fromCoverageMapToCoverage(originalCoverageMap)
577
572
  }
578
573
 
579
- sessionAsyncResource.runInAsyncScope(() => {
580
- sessionFinishCh.publish({
581
- status: success ? 'pass' : 'fail',
582
- isSuitesSkipped,
583
- testCodeCoverageLinesTotal,
584
- numSkippedSuites: skippedSuites.length,
585
- hasUnskippableSuites: isUnskippable,
586
- hasForcedToRunSuites: isForcedToRun,
587
- isEarlyFlakeDetectionEnabled,
588
- isEarlyFlakeDetectionFaulty,
589
- isTestManagementTestsEnabled,
590
- isParallel
591
- })
574
+ sessionFinishCh.publish({
575
+ status: success ? 'pass' : 'fail',
576
+ isSuitesSkipped,
577
+ testCodeCoverageLinesTotal,
578
+ numSkippedSuites: skippedSuites.length,
579
+ hasUnskippableSuites: isUnskippable,
580
+ hasForcedToRunSuites: isForcedToRun,
581
+ isEarlyFlakeDetectionEnabled,
582
+ isEarlyFlakeDetectionFaulty,
583
+ isTestManagementTestsEnabled,
584
+ isParallel
592
585
  })
593
586
  eventDataCollector = null
594
587
  return success
@@ -676,6 +669,7 @@ function getWrappedRunTestCase (runTestCaseFunction, isNewerCucumberVersion = fa
676
669
  if (isAttemptToFix && lastTestStatus !== 'skip') {
677
670
  for (let retryIndex = 0; retryIndex < testManagementAttemptToFixRetries; retryIndex++) {
678
671
  numRetriesByPickleId.set(pickle.id, retryIndex + 1)
672
+ // eslint-disable-next-line no-await-in-loop
679
673
  runTestCaseResult = await runTestCaseFunction.apply(this, arguments)
680
674
  }
681
675
  }
@@ -684,6 +678,7 @@ function getWrappedRunTestCase (runTestCaseFunction, isNewerCucumberVersion = fa
684
678
  if (isEarlyFlakeDetectionEnabled && lastTestStatus !== 'skip' && (isNew || isModified)) {
685
679
  for (let retryIndex = 0; retryIndex < earlyFlakeDetectionNumRetries; retryIndex++) {
686
680
  numRetriesByPickleId.set(pickle.id, retryIndex + 1)
681
+ // eslint-disable-next-line no-await-in-loop
687
682
  runTestCaseResult = await runTestCaseFunction.apply(this, arguments)
688
683
  }
689
684
  }
@@ -758,9 +753,7 @@ function getWrappedParseWorkerMessage (parseWorkerMessageFunction, isNewVersion)
758
753
  if (Array.isArray(message)) {
759
754
  const [messageCode, payload] = message
760
755
  if (messageCode === CUCUMBER_WORKER_TRACE_PAYLOAD_CODE) {
761
- sessionAsyncResource.runInAsyncScope(() => {
762
- workerReportTraceCh.publish(payload)
763
- })
756
+ workerReportTraceCh.publish(payload)
764
757
  return
765
758
  }
766
759
  }
@@ -932,7 +925,7 @@ addHook({
932
925
  shimmer.wrap(
933
926
  workerPackage.Worker.prototype,
934
927
  'runTestCase',
935
- runTestCase => getWrappedRunTestCase(runTestCase, true, !!process.env.CUCUMBER_WORKER_ID)
928
+ runTestCase => getWrappedRunTestCase(runTestCase, true, !!getEnvironmentVariable('CUCUMBER_WORKER_ID'))
936
929
  )
937
930
  return workerPackage
938
931
  })
@@ -39,12 +39,12 @@ addHook({ name: names }, dns => {
39
39
  })
40
40
 
41
41
  function patchResolveShorthands (prototype) {
42
- Object.keys(rrtypes)
43
- .filter(method => !!prototype[method])
44
- .forEach(method => {
42
+ for (const method of Object.keys(rrtypes)) {
43
+ if (prototype[method]) {
45
44
  rrtypeMap.set(prototype[method], rrtypes[method])
46
45
  shimmer.wrap(prototype, method, fn => wrap('apm:dns:resolve', fn, 2, rrtypes[method]))
47
- })
46
+ }
47
+ }
48
48
  }
49
49
 
50
50
  function wrap (prefix, fn, expectedArgs, rrtype) {
@@ -91,18 +91,17 @@ function createWrapRequest (name) {
91
91
  return cb.apply(null, arguments)
92
92
  }))
93
93
  return request.apply(this, arguments)
94
+ }
95
+ const promise = request.apply(this, arguments)
96
+ if (promise && typeof promise.then === 'function') {
97
+ const onResolve = asyncResource.bind(() => finish(params))
98
+ const onReject = asyncResource.bind(e => finish(params, e))
99
+
100
+ promise.then(onResolve, onReject)
94
101
  } else {
95
- const promise = request.apply(this, arguments)
96
- if (promise && typeof promise.then === 'function') {
97
- const onResolve = asyncResource.bind(() => finish(params))
98
- const onReject = asyncResource.bind(e => finish(params, e))
99
-
100
- promise.then(onResolve, onReject)
101
- } else {
102
- finish(params)
103
- }
104
- return promise
102
+ finish(params)
105
103
  }
104
+ return promise
106
105
  } catch (err) {
107
106
  err.stack // trigger getting the stack at the original throwing point
108
107
  errorCh.publish(err)
@@ -59,21 +59,19 @@ function wrapAddHook (addHook) {
59
59
  return parsingResource.runInAsyncScope(() => {
60
60
  return done.apply(this, arguments)
61
61
  })
62
- } else {
63
- return done.apply(this, arguments)
64
62
  }
63
+ return done.apply(this, arguments)
65
64
  }
66
65
 
67
66
  return fn.apply(this, arguments)
68
- } else {
69
- const promise = fn.apply(this, arguments)
70
-
71
- if (promise && typeof promise.catch === 'function') {
72
- return promise.catch(err => publishError(err, req))
73
- }
67
+ }
68
+ const promise = fn.apply(this, arguments)
74
69
 
75
- return promise
70
+ if (promise && typeof promise.catch === 'function') {
71
+ return promise.catch(err => publishError(err, req))
76
72
  }
73
+
74
+ return promise
77
75
  } catch (e) {
78
76
  throw publishError(e, req)
79
77
  }
@@ -79,21 +79,20 @@ function wrapMethod (method) {
79
79
  })
80
80
 
81
81
  return method.apply(this, arguments)
82
- } else {
83
- return method.apply(this, arguments)
84
- .then(
85
- response => {
86
- requestFinishCh.publish(ctx)
87
- return response
88
- },
89
- error => {
90
- ctx.error = error
91
- requestErrorCh.publish(ctx)
92
- requestFinishCh.publish(ctx)
93
- throw error
94
- }
95
- )
96
82
  }
83
+ return method.apply(this, arguments)
84
+ .then(
85
+ response => {
86
+ requestFinishCh.publish(ctx)
87
+ return response
88
+ },
89
+ error => {
90
+ ctx.error = error
91
+ requestErrorCh.publish(ctx)
92
+ requestFinishCh.publish(ctx)
93
+ throw error
94
+ }
95
+ )
97
96
  })
98
97
  }
99
98
  }
@@ -133,9 +132,8 @@ addHook({ name: '@google-cloud/pubsub', versions: ['>=1.2'], file: 'build/src/le
133
132
  if (receiveStartCh.hasSubscribers) {
134
133
  ctx.message = message
135
134
  return receiveStartCh.runStores(ctx, dispense, this, ...arguments)
136
- } else {
137
- return dispense.apply(this, arguments)
138
135
  }
136
+ return dispense.apply(this, arguments)
139
137
  })
140
138
 
141
139
  shimmer.wrap(LeaseManager.prototype, 'remove', remove => function (message) {
@@ -42,7 +42,10 @@ function wrapExt (ext) {
42
42
  if (events !== null && typeof events === 'object') {
43
43
  arguments[0] = wrapEvents(events)
44
44
  } else {
45
- arguments[1] = wrapExtension(method)
45
+ // The method should never be an array. The check is done as a safe guard
46
+ // during a refactoring where it was unclear if this would be possible or
47
+ // not.
48
+ arguments[1] = Array.isArray(method) ? method.map(wrapHandler) : [wrapHandler(method)]
46
49
  }
47
50
 
48
51
  return ext.apply(this, arguments)
@@ -75,17 +78,13 @@ function wrapRebuild (rebuild) {
75
78
  }
76
79
  }
77
80
 
78
- function wrapExtension (method) {
79
- return [].concat(method).map(wrapHandler)
80
- }
81
+ function wrapEvents (events, flat = false) {
82
+ const eventsArray = Array.isArray(events) ? events : [events]
81
83
 
82
- function wrapEvents (events) {
83
- return [].concat(events).map(event => {
84
- if (!event || !event.method) return event
84
+ return eventsArray.map(event => {
85
+ if (!event?.method) return event
85
86
 
86
- return Object.assign({}, event, {
87
- method: wrapExtension(event.method)
88
- })
87
+ return { ...event, method: wrapHandler(event.method) }
89
88
  })
90
89
  }
91
90
 
@@ -93,7 +92,7 @@ function wrapHandler (handler) {
93
92
  if (typeof handler !== 'function') return handler
94
93
 
95
94
  return shimmer.wrapFunction(handler, handler => function (request, h) {
96
- const req = request && request.raw && request.raw.req
95
+ const req = request?.raw?.req
97
96
 
98
97
  if (!req) return handler.apply(this, arguments)
99
98
 
@@ -16,12 +16,11 @@ exports.createWrapFetch = function createWrapFetch (Request, ch, onLoad) {
16
16
  const ctx = { req: input }
17
17
 
18
18
  return ch.tracePromise(() => fetch.call(this, input, init), ctx)
19
- } else {
20
- const req = new Request(input, init)
21
- const ctx = { req }
22
-
23
- return ch.tracePromise(() => fetch.call(this, req), ctx)
24
19
  }
20
+ const req = new Request(input, init)
21
+ const ctx = { req }
22
+
23
+ return ch.tracePromise(() => fetch.call(this, req), ctx)
25
24
  }
26
25
  }
27
26
  }
@@ -41,9 +41,8 @@ function Hook (modules, hookOptions, onrequire) {
41
41
  if (moduleExports && moduleExports.default) {
42
42
  moduleExports.default = safeHook(moduleExports.default, moduleName, moduleBaseDir)
43
43
  return moduleExports
44
- } else {
45
- return safeHook(moduleExports, moduleName, moduleBaseDir)
46
44
  }
45
+ return safeHook(moduleExports, moduleName, moduleBaseDir)
47
46
  })
48
47
  }
49
48
 
@@ -9,11 +9,14 @@ const log = require('../../../dd-trace/src/log')
9
9
  const checkRequireCache = require('./check-require-cache')
10
10
  const telemetry = require('../../../dd-trace/src/guardrails/telemetry')
11
11
  const { isInServerlessEnvironment } = require('../../../dd-trace/src/serverless')
12
+ const { getEnvironmentVariables } = require('../../../dd-trace/src/config-helper')
13
+
14
+ const envs = getEnvironmentVariables()
12
15
 
13
16
  const {
14
17
  DD_TRACE_DISABLED_INSTRUMENTATIONS = '',
15
18
  DD_TRACE_DEBUG = ''
16
- } = process.env
19
+ } = envs
17
20
 
18
21
  const hooks = require('./hooks')
19
22
  const instrumentations = require('./instrumentations')
@@ -24,7 +27,7 @@ const disabledInstrumentations = new Set(
24
27
  )
25
28
 
26
29
  // Check for DD_TRACE_<INTEGRATION>_ENABLED environment variables
27
- for (const [key, value] of Object.entries(process.env)) {
30
+ for (const [key, value] of Object.entries(envs)) {
28
31
  const match = key.match(/^DD_TRACE_(.+)_ENABLED$/)
29
32
  if (match && (value?.toLowerCase() === 'false' || value === '0')) {
30
33
  const integration = match[1].toLowerCase()
@@ -96,9 +99,7 @@ for (const packageName of names) {
96
99
  // That way it would also not be duplicated. The actual name being used has to be identified else wise.
97
100
  // Maybe it is also not important to know what name was actually used?
98
101
  hook[HOOK_SYMBOL] ??= new WeakSet()
99
- let matchesFile = false
100
-
101
- matchesFile = moduleName === fullFilename
102
+ let matchesFile = moduleName === fullFilename
102
103
 
103
104
  if (fullFilePattern) {
104
105
  // Some libraries include a hash in their filenames when installed,