dd-trace 5.28.0 → 5.29.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 (144) hide show
  1. package/LICENSE-3rdparty.csv +8 -2
  2. package/ci/init.js +16 -0
  3. package/index.d.ts +31 -13
  4. package/init.js +4 -68
  5. package/loader-hook.mjs +4 -0
  6. package/package.json +16 -11
  7. package/packages/datadog-core/src/storage.js +39 -2
  8. package/packages/datadog-instrumentations/src/aerospike.js +1 -1
  9. package/packages/datadog-instrumentations/src/cucumber.js +29 -3
  10. package/packages/datadog-instrumentations/src/express.js +38 -4
  11. package/packages/datadog-instrumentations/src/helpers/bundler-register.js +3 -3
  12. package/packages/datadog-instrumentations/src/helpers/hooks.js +0 -1
  13. package/packages/datadog-instrumentations/src/helpers/register.js +3 -4
  14. package/packages/datadog-instrumentations/src/http/client.js +1 -1
  15. package/packages/datadog-instrumentations/src/jest.js +27 -8
  16. package/packages/datadog-instrumentations/src/mocha/utils.js +2 -1
  17. package/packages/datadog-instrumentations/src/mysql2.js +13 -8
  18. package/packages/datadog-instrumentations/src/next.js +7 -4
  19. package/packages/datadog-instrumentations/src/passport-http.js +2 -14
  20. package/packages/datadog-instrumentations/src/passport-local.js +2 -14
  21. package/packages/datadog-instrumentations/src/passport-utils.js +43 -19
  22. package/packages/datadog-instrumentations/src/pg.js +6 -6
  23. package/packages/datadog-instrumentations/src/playwright.js +17 -4
  24. package/packages/datadog-instrumentations/src/router.js +97 -1
  25. package/packages/datadog-instrumentations/src/sequelize.js +9 -4
  26. package/packages/datadog-instrumentations/src/url.js +4 -0
  27. package/packages/datadog-instrumentations/src/vitest.js +27 -2
  28. package/packages/datadog-plugin-avsc/src/schema_iterator.js +8 -3
  29. package/packages/datadog-plugin-aws-sdk/src/services/dynamodb.js +154 -0
  30. package/packages/datadog-plugin-aws-sdk/src/services/eventbridge.js +1 -1
  31. package/packages/datadog-plugin-aws-sdk/src/services/kinesis.js +1 -1
  32. package/packages/datadog-plugin-aws-sdk/src/services/lambda.js +1 -1
  33. package/packages/datadog-plugin-aws-sdk/src/services/s3.js +1 -1
  34. package/packages/datadog-plugin-aws-sdk/src/services/sqs.js +1 -1
  35. package/packages/datadog-plugin-aws-sdk/src/util.js +92 -0
  36. package/packages/datadog-plugin-child_process/src/scrub-cmd-params.js +1 -1
  37. package/packages/datadog-plugin-cucumber/src/index.js +39 -4
  38. package/packages/datadog-plugin-cypress/src/cypress-plugin.js +3 -3
  39. package/packages/datadog-plugin-grpc/src/client.js +2 -2
  40. package/packages/datadog-plugin-grpc/src/util.js +1 -1
  41. package/packages/datadog-plugin-jest/src/index.js +39 -4
  42. package/packages/datadog-plugin-mocha/src/index.js +36 -2
  43. package/packages/datadog-plugin-oracledb/src/index.js +1 -1
  44. package/packages/datadog-plugin-vitest/src/index.js +34 -2
  45. package/packages/datadog-shimmer/src/shimmer.js +8 -4
  46. package/packages/dd-trace/src/appsec/addresses.js +3 -0
  47. package/packages/dd-trace/src/appsec/blocked_templates.js +1 -1
  48. package/packages/dd-trace/src/appsec/channels.js +1 -0
  49. package/packages/dd-trace/src/appsec/iast/analyzers/code-injection-analyzer.js +4 -0
  50. package/packages/dd-trace/src/appsec/iast/analyzers/hardcoded-password-rules.js +1 -1
  51. package/packages/dd-trace/src/appsec/iast/analyzers/hardcoded-secret-rules.js +1 -1
  52. package/packages/dd-trace/src/appsec/iast/analyzers/hardcoded-secrets-rules.js +1 -1
  53. package/packages/dd-trace/src/appsec/iast/analyzers/injection-analyzer.js +10 -3
  54. package/packages/dd-trace/src/appsec/iast/analyzers/sql-injection-analyzer.js +4 -0
  55. package/packages/dd-trace/src/appsec/iast/analyzers/template-injection-analyzer.js +4 -0
  56. package/packages/dd-trace/src/appsec/iast/iast-plugin.js +6 -19
  57. package/packages/dd-trace/src/appsec/iast/taint-tracking/index.js +3 -3
  58. package/packages/dd-trace/src/appsec/iast/taint-tracking/plugin.js +64 -3
  59. package/packages/dd-trace/src/appsec/iast/taint-tracking/source-types.js +2 -1
  60. package/packages/dd-trace/src/appsec/iast/vulnerabilities-formatter/evidence-redaction/sensitive-regex.js +2 -2
  61. package/packages/dd-trace/src/appsec/iast/vulnerabilities-formatter/utils.js +1 -1
  62. package/packages/dd-trace/src/appsec/iast/vulnerability-reporter.js +32 -37
  63. package/packages/dd-trace/src/appsec/index.js +16 -10
  64. package/packages/dd-trace/src/appsec/remote_config/capabilities.js +1 -0
  65. package/packages/dd-trace/src/appsec/remote_config/index.js +25 -1
  66. package/packages/dd-trace/src/appsec/reporter.js +3 -1
  67. package/packages/dd-trace/src/appsec/sdk/track_event.js +32 -19
  68. package/packages/dd-trace/src/appsec/telemetry.js +10 -0
  69. package/packages/dd-trace/src/appsec/user_tracking.js +168 -0
  70. package/packages/dd-trace/src/azure_metadata.js +4 -4
  71. package/packages/dd-trace/src/ci-visibility/dynamic-instrumentation/index.js +5 -4
  72. package/packages/dd-trace/src/ci-visibility/dynamic-instrumentation/worker/index.js +39 -3
  73. package/packages/dd-trace/src/ci-visibility/exporters/agentless/coverage-writer.js +1 -1
  74. package/packages/dd-trace/src/ci-visibility/exporters/agentless/di-logs-writer.js +1 -1
  75. package/packages/dd-trace/src/ci-visibility/exporters/agentless/index.js +1 -1
  76. package/packages/dd-trace/src/ci-visibility/exporters/agentless/writer.js +1 -1
  77. package/packages/dd-trace/src/ci-visibility/exporters/ci-visibility-exporter.js +29 -9
  78. package/packages/dd-trace/src/ci-visibility/requests/get-library-configuration.js +4 -2
  79. package/packages/dd-trace/src/config.js +24 -32
  80. package/packages/dd-trace/src/constants.js +1 -0
  81. package/packages/dd-trace/src/crashtracking/crashtracker.js +3 -2
  82. package/packages/dd-trace/src/datastreams/processor.js +4 -6
  83. package/packages/dd-trace/src/datastreams/writer.js +6 -5
  84. package/packages/dd-trace/src/debugger/devtools_client/breakpoints.js +80 -0
  85. package/packages/dd-trace/src/debugger/devtools_client/config.js +3 -1
  86. package/packages/dd-trace/src/debugger/devtools_client/defaults.js +6 -0
  87. package/packages/dd-trace/src/debugger/devtools_client/index.js +63 -8
  88. package/packages/dd-trace/src/debugger/devtools_client/remote_config.js +10 -67
  89. package/packages/dd-trace/src/debugger/devtools_client/send.js +2 -1
  90. package/packages/dd-trace/src/debugger/devtools_client/state.js +1 -1
  91. package/packages/dd-trace/src/debugger/devtools_client/status.js +4 -4
  92. package/packages/dd-trace/src/debugger/index.js +14 -10
  93. package/packages/dd-trace/src/dogstatsd.js +2 -2
  94. package/packages/dd-trace/src/encode/0.4.js +23 -78
  95. package/packages/dd-trace/src/encode/agentless-ci-visibility.js +0 -32
  96. package/packages/dd-trace/src/encode/coverage-ci-visibility.js +1 -2
  97. package/packages/dd-trace/src/encode/span-stats.js +0 -30
  98. package/packages/dd-trace/src/exporters/agent/writer.js +3 -3
  99. package/packages/dd-trace/src/exporters/common/request.js +1 -1
  100. package/packages/dd-trace/src/exporters/span-stats/writer.js +1 -1
  101. package/packages/dd-trace/src/flare/index.js +1 -1
  102. package/packages/dd-trace/src/guardrails/index.js +64 -0
  103. package/packages/dd-trace/src/guardrails/log.js +32 -0
  104. package/packages/dd-trace/src/guardrails/telemetry.js +78 -0
  105. package/packages/dd-trace/src/guardrails/util.js +10 -0
  106. package/packages/dd-trace/src/lambda/runtime/ritm.js +2 -2
  107. package/packages/dd-trace/src/llmobs/storage.js +2 -3
  108. package/packages/dd-trace/src/llmobs/writers/base.js +2 -2
  109. package/packages/dd-trace/src/{encode → msgpack}/chunk.js +8 -5
  110. package/packages/dd-trace/src/msgpack/encoder.js +309 -0
  111. package/packages/dd-trace/src/msgpack/index.js +6 -0
  112. package/packages/dd-trace/src/opentelemetry/context_manager.js +2 -2
  113. package/packages/dd-trace/src/opentracing/propagation/text_map.js +12 -9
  114. package/packages/dd-trace/src/opentracing/span.js +1 -1
  115. package/packages/dd-trace/src/opentracing/tracer.js +2 -2
  116. package/packages/dd-trace/src/plugin_manager.js +4 -2
  117. package/packages/dd-trace/src/plugins/ci_plugin.js +47 -4
  118. package/packages/dd-trace/src/plugins/plugin.js +1 -1
  119. package/packages/dd-trace/src/plugins/tracing.js +1 -1
  120. package/packages/dd-trace/src/plugins/util/git.js +7 -7
  121. package/packages/dd-trace/src/plugins/util/test.js +36 -3
  122. package/packages/dd-trace/src/plugins/util/web.js +2 -2
  123. package/packages/dd-trace/src/profiling/config.js +3 -0
  124. package/packages/dd-trace/src/profiling/exporters/agent.js +9 -68
  125. package/packages/dd-trace/src/profiling/exporters/event_serializer.js +76 -0
  126. package/packages/dd-trace/src/profiling/exporters/file.js +8 -4
  127. package/packages/dd-trace/src/profiling/profiler.js +62 -10
  128. package/packages/dd-trace/src/profiling/profilers/event_plugins/event.js +22 -12
  129. package/packages/dd-trace/src/profiling/profilers/events.js +47 -8
  130. package/packages/dd-trace/src/profiling/profilers/wall.js +2 -17
  131. package/packages/dd-trace/src/profiling/webspan-utils.js +23 -0
  132. package/packages/dd-trace/src/proxy.js +7 -2
  133. package/packages/dd-trace/src/runtime_metrics.js +107 -4
  134. package/packages/dd-trace/src/serverless.js +1 -1
  135. package/packages/dd-trace/src/span_processor.js +10 -10
  136. package/packages/dd-trace/src/tagger.js +1 -1
  137. package/packages/dd-trace/src/telemetry/index.js +1 -0
  138. package/packages/dd-trace/src/telemetry/logs/index.js +2 -2
  139. package/packages/dd-trace/src/telemetry/logs/log-collector.js +10 -2
  140. package/packages/dd-trace/src/telemetry/send-data.js +2 -2
  141. package/packages/dd-trace/src/util.js +5 -16
  142. package/packages/datadog-instrumentations/src/qs.js +0 -24
  143. package/packages/dd-trace/src/appsec/passport.js +0 -110
  144. package/packages/dd-trace/src/telemetry/init-telemetry.js +0 -75
@@ -13,7 +13,6 @@ require,crypto-randomuuid,MIT,Copyright 2021 Node.js Foundation and contributors
13
13
  require,dc-polyfill,MIT,Copyright 2023 Datadog Inc.
14
14
  require,ignore,MIT,Copyright 2013 Kael Zhang and contributors
15
15
  require,import-in-the-middle,Apache license 2.0,Copyright 2021 Datadog Inc.
16
- require,int64-buffer,MIT,Copyright 2015-2016 Yusuke Kawasaki
17
16
  require,istanbul-lib-coverage,BSD-3-Clause,Copyright 2012-2015 Yahoo! Inc.
18
17
  require,jest-docblock,MIT,Copyright Meta Platforms, Inc. and affiliates.
19
18
  require,koalas,MIT,Copyright 2013-2017 Brian Woodward
@@ -21,7 +20,6 @@ require,limiter,MIT,Copyright 2011 John Hurliman
21
20
  require,lodash.sortby,MIT,Copyright JS Foundation and other contributors
22
21
  require,lru-cache,ISC,Copyright (c) 2010-2022 Isaac Z. Schlueter and Contributors
23
22
  require,module-details-from-path,MIT,Copyright 2016 Thomas Watson Steen
24
- require,msgpack-lite,MIT,Copyright 2015 Yusuke Kawasaki
25
23
  require,opentracing,MIT,Copyright 2016 Resonance Labs Inc
26
24
  require,path-to-regexp,MIT,Copyright 2014 Blake Embrey
27
25
  require,pprof-format,MIT,Copyright 2022 Stephen Belanger
@@ -31,8 +29,12 @@ require,retry,MIT,Copyright 2011 Tim Koschützki Felix Geisendörfer
31
29
  require,rfdc,MIT,Copyright 2019 David Mark Clements
32
30
  require,semver,ISC,Copyright Isaac Z. Schlueter and Contributors
33
31
  require,shell-quote,mit,Copyright (c) 2013 James Halliday
32
+ require,source-map,BSD-3-Clause,Copyright (c) 2009-2011, Mozilla Foundation and contributors
34
33
  dev,@apollo/server,MIT,Copyright (c) 2016-2020 Apollo Graph, Inc. (Formerly Meteor Development Group, Inc.)
35
34
  dev,@types/node,MIT,Copyright Authors
35
+ dev,@eslint/eslintrc,MIT,Copyright OpenJS Foundation and other contributors, <www.openjsf.org>
36
+ dev,@eslint/js,MIT,Copyright OpenJS Foundation and other contributors, <www.openjsf.org>
37
+ dev,@stylistic/eslint-plugin-js,MIT,Copyright OpenJS Foundation and other contributors, <www.openjsf.org>
36
38
  dev,autocannon,MIT,Copyright 2016 Matteo Collina
37
39
  dev,aws-sdk,Apache 2.0,Copyright 2012-2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
38
40
  dev,axios,MIT,Copyright 2014-present Matt Zabriskie
@@ -53,11 +55,14 @@ dev,eslint-plugin-promise,ISC,jden and other contributors
53
55
  dev,express,MIT,Copyright 2009-2014 TJ Holowaychuk 2013-2014 Roman Shtylman 2014-2015 Douglas Christopher Wilson
54
56
  dev,get-port,MIT,Copyright Sindre Sorhus
55
57
  dev,glob,ISC,Copyright Isaac Z. Schlueter and Contributors
58
+ dev,globals,MIT,Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (https://sindresorhus.com)
56
59
  dev,graphql,MIT,Copyright 2015 Facebook Inc.
60
+ dev,int64-buffer,MIT,Copyright 2015-2016 Yusuke Kawasaki
57
61
  dev,jszip,MIT,Copyright 2015-2016 Stuart Knightley and contributors
58
62
  dev,knex,MIT,Copyright (c) 2013-present Tim Griesser
59
63
  dev,mkdirp,MIT,Copyright 2010 James Halliday
60
64
  dev,mocha,MIT,Copyright 2011-2018 JS Foundation and contributors https://js.foundation
65
+ dev,msgpack-lite,MIT,Copyright 2015 Yusuke Kawasaki
61
66
  dev,multer,MIT,Copyright 2014 Hage Yaapa
62
67
  dev,nock,MIT,Copyright 2017 Pedro Teixeira and other contributors
63
68
  dev,nyc,ISC,Copyright 2015 Contributors
@@ -67,6 +72,7 @@ dev,sinon,BSD-3-Clause,Copyright 2010-2017 Christian Johansen
67
72
  dev,sinon-chai,WTFPL and BSD-2-Clause,Copyright 2004 Sam Hocevar 2012–2017 Domenic Denicola
68
73
  dev,tap,ISC,Copyright 2011-2022 Isaac Z. Schlueter and Contributors
69
74
  dev,tiktoken,MIT,Copyright (c) 2022 OpenAI, Shantanu Jain
75
+ dev,yaml,ISC,Copyright Eemeli Aro <eemeli@gmail.com>
70
76
  file,aws-lambda-nodejs-runtime-interface-client,Apache 2.0,Copyright 2019 Amazon.com Inc. or its affiliates. All Rights Reserved.
71
77
  file,profile.proto,Apache license 2.0,Copyright 2016 Google Inc.
72
78
  file,is-git-url,MIT,Copyright (c) 2017 Jon Schlinkert.
package/ci/init.js CHANGED
@@ -1,11 +1,22 @@
1
1
  /* eslint-disable no-console */
2
2
  const tracer = require('../packages/dd-trace')
3
3
  const { isTrue } = require('../packages/dd-trace/src/util')
4
+ const log = require('../packages/dd-trace/src/log')
4
5
 
5
6
  const isJestWorker = !!process.env.JEST_WORKER_ID
6
7
  const isCucumberWorker = !!process.env.CUCUMBER_WORKER_ID
7
8
  const isMochaWorker = !!process.env.MOCHA_WORKER_ID
8
9
 
10
+ const packageManagers = [
11
+ 'npm',
12
+ 'yarn',
13
+ 'pnpm'
14
+ ]
15
+
16
+ const isPackageManager = () => {
17
+ return packageManagers.some(packageManager => process.argv[1]?.includes(`bin/${packageManager}`))
18
+ }
19
+
9
20
  const options = {
10
21
  startupLogs: false,
11
22
  isCiVisibility: true,
@@ -14,6 +25,11 @@ const options = {
14
25
 
15
26
  let shouldInit = true
16
27
 
28
+ if (isPackageManager()) {
29
+ log.debug('dd-trace is not initialized in a package manager.')
30
+ shouldInit = false
31
+ }
32
+
17
33
  const isAgentlessEnabled = isTrue(process.env.DD_CIVISIBILITY_AGENTLESS_ENABLED)
18
34
 
19
35
  if (isAgentlessEnabled) {
package/index.d.ts CHANGED
@@ -655,12 +655,24 @@ declare namespace tracer {
655
655
  */
656
656
  eventTracking?: {
657
657
  /**
658
- * Controls the automated user event tracking mode. Possible values are disabled, safe and extended.
659
- * On safe mode, any detected Personally Identifiable Information (PII) about the user will be redacted from the event.
660
- * On extended mode, no redaction will take place.
661
- * @default 'safe'
658
+ * Controls the automated user tracking mode for user IDs and logins collections. Possible values:
659
+ * * 'anonymous': will hash user IDs and user logins before collecting them
660
+ * * 'anon': alias for 'anonymous'
661
+ * * 'safe': deprecated alias for 'anonymous'
662
+ *
663
+ * * 'identification': will collect user IDs and logins without redaction
664
+ * * 'ident': alias for 'identification'
665
+ * * 'extended': deprecated alias for 'identification'
666
+ *
667
+ * * 'disabled': will not collect user IDs and logins
668
+ *
669
+ * Unknown values will be considered as 'disabled'
670
+ * @default 'identification'
662
671
  */
663
- mode?: 'safe' | 'extended' | 'disabled'
672
+ mode?:
673
+ 'anonymous' | 'anon' | 'safe' |
674
+ 'identification' | 'ident' | 'extended' |
675
+ 'disabled'
664
676
  },
665
677
  /**
666
678
  * Configuration for Api Security
@@ -752,7 +764,7 @@ declare namespace tracer {
752
764
  */
753
765
  maxDepth?: number
754
766
  }
755
-
767
+
756
768
  /**
757
769
  * Configuration enabling LLM Observability. Enablement is superceded by the DD_LLMOBS_ENABLED environment variable.
758
770
  */
@@ -2191,6 +2203,12 @@ declare namespace tracer {
2191
2203
  */
2192
2204
  cookieFilterPattern?: string,
2193
2205
 
2206
+ /**
2207
+ * Defines the number of rows to taint in data coming from databases
2208
+ * @default 1
2209
+ */
2210
+ dbRowsToTaint?: number,
2211
+
2194
2212
  /**
2195
2213
  * Whether to enable vulnerability deduplication
2196
2214
  */
@@ -2235,7 +2253,7 @@ declare namespace tracer {
2235
2253
  * Disable LLM Observability tracing.
2236
2254
  */
2237
2255
  disable (): void,
2238
-
2256
+
2239
2257
  /**
2240
2258
  * Instruments a function by automatically creating a span activated on its
2241
2259
  * scope.
@@ -2277,10 +2295,10 @@ declare namespace tracer {
2277
2295
  /**
2278
2296
  * Decorate a function in a javascript runtime that supports function decorators.
2279
2297
  * Note that this is **not** supported in the Node.js runtime, but is in TypeScript.
2280
- *
2298
+ *
2281
2299
  * In TypeScript, this decorator is only supported in contexts where general TypeScript
2282
2300
  * function decorators are supported.
2283
- *
2301
+ *
2284
2302
  * @param options Optional LLM Observability span options.
2285
2303
  */
2286
2304
  decorate (options: llmobs.LLMObsNamelessSpanOptions): any
@@ -2297,7 +2315,7 @@ declare namespace tracer {
2297
2315
  /**
2298
2316
  * Sets inputs, outputs, tags, metadata, and metrics as provided for a given LLM Observability span.
2299
2317
  * Note that with the exception of tags, this method will override any existing values for the provided fields.
2300
- *
2318
+ *
2301
2319
  * For example:
2302
2320
  * ```javascript
2303
2321
  * llmobs.trace({ kind: 'llm', name: 'myLLM', modelName: 'gpt-4o', modelProvider: 'openai' }, () => {
@@ -2310,7 +2328,7 @@ declare namespace tracer {
2310
2328
  * })
2311
2329
  * })
2312
2330
  * ```
2313
- *
2331
+ *
2314
2332
  * @param span The span to annotate (defaults to the current LLM Observability span if not provided)
2315
2333
  * @param options An object containing the inputs, outputs, tags, metadata, and metrics to set on the span.
2316
2334
  */
@@ -2486,14 +2504,14 @@ declare namespace tracer {
2486
2504
  * LLM Observability span kind. One of `agent`, `workflow`, `task`, `tool`, `retrieval`, `embedding`, or `llm`.
2487
2505
  */
2488
2506
  kind: llmobs.spanKind,
2489
-
2507
+
2490
2508
  /**
2491
2509
  * The ID of the underlying user session. Required for tracking sessions.
2492
2510
  */
2493
2511
  sessionId?: string,
2494
2512
 
2495
2513
  /**
2496
- * The name of the ML application that the agent is orchestrating.
2514
+ * The name of the ML application that the agent is orchestrating.
2497
2515
  * If not provided, the default value will be set to mlApp provided during initalization, or `DD_LLMOBS_ML_APP`.
2498
2516
  */
2499
2517
  mlApp?: string,
package/init.js CHANGED
@@ -2,72 +2,8 @@
2
2
 
3
3
  /* eslint-disable no-var */
4
4
 
5
- var nodeVersion = require('./version')
6
- var NODE_MAJOR = nodeVersion.NODE_MAJOR
7
- var NODE_MINOR = nodeVersion.NODE_MINOR
5
+ var guard = require('./packages/dd-trace/src/guardrails')
8
6
 
9
- // We use several things that are not supported by older versions of Node:
10
- // - AsyncLocalStorage
11
- // - The `semver` module
12
- // - dc-polyfill
13
- // - Mocha (for testing)
14
- // and probably others.
15
- // TODO: Remove all these dependencies so that we can report telemetry.
16
- if ((NODE_MAJOR === 12 && NODE_MINOR >= 17) || NODE_MAJOR > 12) {
17
- var path = require('path')
18
- var Module = require('module')
19
- var semver = require('semver')
20
- var log = require('./packages/dd-trace/src/log')
21
- var isTrue = require('./packages/dd-trace/src/util').isTrue
22
- var telemetry = require('./packages/dd-trace/src/telemetry/init-telemetry')
23
-
24
- var initBailout = false
25
- var clobberBailout = false
26
- var forced = isTrue(process.env.DD_INJECT_FORCE)
27
-
28
- if (process.env.DD_INJECTION_ENABLED) {
29
- // If we're running via single-step install, and we're not in the app's
30
- // node_modules, then we should not initialize the tracer. This prevents
31
- // single-step-installed tracer from clobbering the manually-installed tracer.
32
- var resolvedInApp
33
- var entrypoint = process.argv[1]
34
- try {
35
- resolvedInApp = Module.createRequire(entrypoint).resolve('dd-trace')
36
- } catch (e) {
37
- // Ignore. If we can't resolve the module, we assume it's not in the app.
38
- }
39
- if (resolvedInApp) {
40
- var ourselves = path.join(__dirname, 'index.js')
41
- if (ourselves !== resolvedInApp) {
42
- clobberBailout = true
43
- }
44
- }
45
-
46
- // If we're running via single-step install, and the runtime doesn't match
47
- // the engines field in package.json, then we should not initialize the tracer.
48
- if (!clobberBailout) {
49
- var engines = require('./package.json').engines
50
- var version = process.versions.node
51
- if (!semver.satisfies(version, engines.node)) {
52
- initBailout = true
53
- telemetry([
54
- { name: 'abort', tags: ['reason:incompatible_runtime'] },
55
- { name: 'abort.runtime', tags: [] }
56
- ])
57
- log.info('Aborting application instrumentation due to incompatible_runtime.')
58
- log.info('Found incompatible runtime nodejs ' + version + ', Supported runtimes: nodejs ' + engines.node + '.')
59
- if (forced) {
60
- log.info('DD_INJECT_FORCE enabled, allowing unsupported runtimes and continuing.')
61
- }
62
- }
63
- }
64
- }
65
-
66
- if (!clobberBailout && (!initBailout || forced)) {
67
- var tracer = require('.')
68
- tracer.init()
69
- module.exports = tracer
70
- telemetry('complete', ['injection_forced:' + (forced && initBailout ? 'true' : 'false')])
71
- log.info('Application instrumentation bootstrapping complete')
72
- }
73
- }
7
+ module.exports = guard(function () {
8
+ return require('.').init()
9
+ })
package/loader-hook.mjs CHANGED
@@ -1 +1,5 @@
1
+ // TODO(bengl): Not sure why `import/export` fails on this line, but it's just
2
+ // a passthrough to another module so it should be fine. Disabling for now.
3
+
4
+ // eslint-disable-next-line import/export
1
5
  export * from 'import-in-the-middle/hook.mjs'
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dd-trace",
3
- "version": "5.28.0",
3
+ "version": "5.29.0",
4
4
  "description": "Datadog APM tracing client for JavaScript",
5
5
  "main": "index.js",
6
6
  "typings": "index.d.ts",
@@ -8,7 +8,6 @@
8
8
  "env": "bash ./plugin-env",
9
9
  "preinstall": "node scripts/preinstall.js",
10
10
  "bench": "node benchmark",
11
- "bench:profiler": "node benchmark/profiler",
12
11
  "bench:e2e": "SERVICES=mongo yarn services && cd benchmark/e2e && node benchmark-run.js --duration=30",
13
12
  "bench:e2e:ci-visibility": "node benchmark/e2e-ci/benchmark-run.js",
14
13
  "type:doc": "cd docs && yarn && yarn build",
@@ -82,11 +81,11 @@
82
81
  "node": ">=18"
83
82
  },
84
83
  "dependencies": {
85
- "@datadog/libdatadog": "^0.2.2",
84
+ "@datadog/libdatadog": "^0.3.0",
86
85
  "@datadog/native-appsec": "8.3.0",
87
- "@datadog/native-iast-rewriter": "2.5.0",
86
+ "@datadog/native-iast-rewriter": "2.6.1",
88
87
  "@datadog/native-iast-taint-tracking": "3.2.0",
89
- "@datadog/native-metrics": "^3.0.1",
88
+ "@datadog/native-metrics": "^3.1.0",
90
89
  "@datadog/pprof": "5.4.1",
91
90
  "@datadog/sketches-js": "^2.1.0",
92
91
  "@isaacs/ttlcache": "^1.4.1",
@@ -96,7 +95,6 @@
96
95
  "dc-polyfill": "^0.1.4",
97
96
  "ignore": "^5.2.4",
98
97
  "import-in-the-middle": "1.11.2",
99
- "int64-buffer": "^0.1.9",
100
98
  "istanbul-lib-coverage": "3.2.0",
101
99
  "jest-docblock": "^29.7.0",
102
100
  "koalas": "^1.0.2",
@@ -104,20 +102,23 @@
104
102
  "lodash.sortby": "^4.7.0",
105
103
  "lru-cache": "^7.14.0",
106
104
  "module-details-from-path": "^1.0.3",
107
- "msgpack-lite": "^0.1.26",
108
105
  "opentracing": ">=0.12.1",
109
- "path-to-regexp": "^0.1.10",
106
+ "path-to-regexp": "^0.1.12",
110
107
  "pprof-format": "^2.1.0",
111
108
  "protobufjs": "^7.2.5",
112
109
  "retry": "^0.13.1",
113
110
  "rfdc": "^1.3.1",
114
111
  "semver": "^7.5.4",
115
112
  "shell-quote": "^1.8.1",
113
+ "source-map": "^0.7.4",
116
114
  "tlhunter-sorted-set": "^0.1.0"
117
115
  },
118
116
  "devDependencies": {
119
117
  "@apollo/server": "^4.11.0",
120
- "@types/node": "^16.18.103",
118
+ "@eslint/eslintrc": "^3.1.0",
119
+ "@eslint/js": "^9.11.1",
120
+ "@stylistic/eslint-plugin-js": "^2.8.0",
121
+ "@types/node": "^16.0.0",
121
122
  "autocannon": "^4.5.2",
122
123
  "aws-sdk": "^2.1446.0",
123
124
  "axios": "^1.7.4",
@@ -135,14 +136,17 @@
135
136
  "eslint-plugin-mocha": "^10.4.3",
136
137
  "eslint-plugin-n": "^16.6.2",
137
138
  "eslint-plugin-promise": "^6.4.0",
138
- "express": "^4.18.2",
139
+ "express": "^4.21.2",
139
140
  "get-port": "^3.2.0",
140
141
  "glob": "^7.1.6",
142
+ "globals": "^15.10.0",
141
143
  "graphql": "0.13.2",
144
+ "int64-buffer": "^0.1.9",
142
145
  "jszip": "^3.5.0",
143
146
  "knex": "^2.4.2",
144
147
  "mkdirp": "^3.0.1",
145
148
  "mocha": "^9",
149
+ "msgpack-lite": "^0.1.26",
146
150
  "multer": "^1.4.5-lts.1",
147
151
  "nock": "^11.3.3",
148
152
  "nyc": "^15.1.0",
@@ -151,6 +155,7 @@
151
155
  "sinon": "^16.1.3",
152
156
  "sinon-chai": "^3.7.0",
153
157
  "tap": "^16.3.7",
154
- "tiktoken": "^1.0.15"
158
+ "tiktoken": "^1.0.15",
159
+ "yaml": "^2.5.0"
155
160
  }
156
161
  }
@@ -2,12 +2,47 @@
2
2
 
3
3
  const { AsyncLocalStorage } = require('async_hooks')
4
4
 
5
+ class DatadogStorage {
6
+ constructor () {
7
+ this._storage = new AsyncLocalStorage()
8
+ }
9
+
10
+ disable () {
11
+ this._storage.disable()
12
+ }
13
+
14
+ enterWith (store) {
15
+ const handle = {}
16
+ stores.set(handle, store)
17
+ this._storage.enterWith(handle)
18
+ }
19
+
20
+ exit (callback, ...args) {
21
+ this._storage.exit(callback, ...args)
22
+ }
23
+
24
+ getStore () {
25
+ const handle = this._storage.getStore()
26
+ return stores.get(handle)
27
+ }
28
+
29
+ run (store, fn, ...args) {
30
+ const prior = this._storage.getStore()
31
+ this.enterWith(store)
32
+ try {
33
+ return Reflect.apply(fn, null, args)
34
+ } finally {
35
+ this._storage.enterWith(prior)
36
+ }
37
+ }
38
+ }
39
+
5
40
  const storages = Object.create(null)
6
- const legacyStorage = new AsyncLocalStorage()
41
+ const legacyStorage = new DatadogStorage()
7
42
 
8
43
  const storage = function (namespace) {
9
44
  if (!storages[namespace]) {
10
- storages[namespace] = new AsyncLocalStorage()
45
+ storages[namespace] = new DatadogStorage()
11
46
  }
12
47
  return storages[namespace]
13
48
  }
@@ -18,4 +53,6 @@ storage.exit = legacyStorage.exit.bind(legacyStorage)
18
53
  storage.getStore = legacyStorage.getStore.bind(legacyStorage)
19
54
  storage.run = legacyStorage.run.bind(legacyStorage)
20
55
 
56
+ const stores = new WeakMap()
57
+
21
58
  module.exports = storage
@@ -40,7 +40,7 @@ function wrapProcess (process) {
40
40
  addHook({
41
41
  name: 'aerospike',
42
42
  file: 'lib/commands/command.js',
43
- versions: ['^3.16.2', '4', '5']
43
+ versions: ['4', '5']
44
44
  },
45
45
  commandFactory => {
46
46
  return shimmer.wrapFunction(commandFactory, f => wrapCreateCommand(f))
@@ -126,6 +126,20 @@ function getTestStatusFromRetries (testStatuses) {
126
126
  return 'pass'
127
127
  }
128
128
 
129
+ function getErrorFromCucumberResult (cucumberResult) {
130
+ if (!cucumberResult.message) {
131
+ return
132
+ }
133
+
134
+ const [message] = cucumberResult.message.split('\n')
135
+ const error = new Error(message)
136
+ if (cucumberResult.exception) {
137
+ error.type = cucumberResult.exception.type
138
+ }
139
+ error.stack = cucumberResult.message
140
+ return error
141
+ }
142
+
129
143
  function getChannelPromise (channelToPublishTo) {
130
144
  return new Promise(resolve => {
131
145
  sessionAsyncResource.runInAsyncScope(() => {
@@ -230,9 +244,19 @@ function wrapRun (pl, isLatestVersion) {
230
244
  if (testCase?.testCaseFinished) {
231
245
  const { testCaseFinished: { willBeRetried } } = testCase
232
246
  if (willBeRetried) { // test case failed and will be retried
247
+ let error
248
+ try {
249
+ const cucumberResult = this.getWorstStepResult()
250
+ error = getErrorFromCucumberResult(cucumberResult)
251
+ } catch (e) {
252
+ // ignore error
253
+ }
254
+
233
255
  const failedAttemptAsyncResource = numAttemptToAsyncResource.get(numAttempt)
256
+ const isRetry = numAttempt++ > 0
234
257
  failedAttemptAsyncResource.runInAsyncScope(() => {
235
- testRetryCh.publish(numAttempt++ > 0) // the current span will be finished and a new one will be created
258
+ // the current span will be finished and a new one will be created
259
+ testRetryCh.publish({ isRetry, error })
236
260
  })
237
261
 
238
262
  const newAsyncResource = new AsyncResource('bound-anonymous-fn')
@@ -251,7 +275,7 @@ function wrapRun (pl, isLatestVersion) {
251
275
  })
252
276
  promise.finally(() => {
253
277
  const result = this.getWorstStepResult()
254
- const { status, skipReason, errorMessage } = isLatestVersion
278
+ const { status, skipReason } = isLatestVersion
255
279
  ? getStatusFromResultLatest(result)
256
280
  : getStatusFromResult(result)
257
281
 
@@ -270,8 +294,10 @@ function wrapRun (pl, isLatestVersion) {
270
294
  }
271
295
  const attemptAsyncResource = numAttemptToAsyncResource.get(numAttempt)
272
296
 
297
+ const error = getErrorFromCucumberResult(result)
298
+
273
299
  attemptAsyncResource.runInAsyncScope(() => {
274
- testFinishCh.publish({ status, skipReason, errorMessage, isNew, isEfdRetry, isFlakyRetry: numAttempt > 0 })
300
+ testFinishCh.publish({ status, skipReason, error, isNew, isEfdRetry, isFlakyRetry: numAttempt > 0 })
275
301
  })
276
302
  })
277
303
  return promise
@@ -59,8 +59,6 @@ function wrapResponseRender (render) {
59
59
 
60
60
  addHook({ name: 'express', versions: ['>=4'] }, express => {
61
61
  shimmer.wrap(express.application, 'handle', wrapHandle)
62
- shimmer.wrap(express.Router, 'use', wrapRouterMethod)
63
- shimmer.wrap(express.Router, 'route', wrapRouterMethod)
64
62
 
65
63
  shimmer.wrap(express.response, 'json', wrapResponseJson)
66
64
  shimmer.wrap(express.response, 'jsonp', wrapResponseJson)
@@ -69,6 +67,20 @@ addHook({ name: 'express', versions: ['>=4'] }, express => {
69
67
  return express
70
68
  })
71
69
 
70
+ addHook({ name: 'express', versions: ['4'] }, express => {
71
+ shimmer.wrap(express.Router, 'use', wrapRouterMethod)
72
+ shimmer.wrap(express.Router, 'route', wrapRouterMethod)
73
+
74
+ return express
75
+ })
76
+
77
+ addHook({ name: 'express', versions: ['>=5.0.0'] }, express => {
78
+ shimmer.wrap(express.Router.prototype, 'use', wrapRouterMethod)
79
+ shimmer.wrap(express.Router.prototype, 'route', wrapRouterMethod)
80
+
81
+ return express
82
+ })
83
+
72
84
  const queryParserReadCh = channel('datadog:query:read:finish')
73
85
 
74
86
  function publishQueryParsedAndNext (req, res, next) {
@@ -88,7 +100,7 @@ function publishQueryParsedAndNext (req, res, next) {
88
100
 
89
101
  addHook({
90
102
  name: 'express',
91
- versions: ['>=4'],
103
+ versions: ['4'],
92
104
  file: 'lib/middleware/query.js'
93
105
  }, query => {
94
106
  return shimmer.wrapFunction(query, query => function () {
@@ -129,7 +141,29 @@ addHook({ name: 'express', versions: ['>=4.0.0 <4.3.0'] }, express => {
129
141
  return express
130
142
  })
131
143
 
132
- addHook({ name: 'express', versions: ['>=4.3.0'] }, express => {
144
+ addHook({ name: 'express', versions: ['>=4.3.0 <5.0.0'] }, express => {
133
145
  shimmer.wrap(express.Router, 'process_params', wrapProcessParamsMethod(2))
134
146
  return express
135
147
  })
148
+
149
+ const queryReadCh = channel('datadog:express:query:finish')
150
+
151
+ addHook({ name: 'express', file: ['lib/request.js'], versions: ['>=5.0.0'] }, request => {
152
+ const requestDescriptor = Object.getOwnPropertyDescriptor(request, 'query')
153
+
154
+ shimmer.wrap(requestDescriptor, 'get', function (originalGet) {
155
+ return function wrappedGet () {
156
+ const query = originalGet.apply(this, arguments)
157
+
158
+ if (queryReadCh.hasSubscribers && query) {
159
+ queryReadCh.publish({ query })
160
+ }
161
+
162
+ return query
163
+ }
164
+ })
165
+
166
+ Object.defineProperty(request, 'query', requestDescriptor)
167
+
168
+ return request
169
+ })
@@ -30,12 +30,12 @@ dc.subscribe(CHANNEL, (payload) => {
30
30
  try {
31
31
  hooks[payload.package]()
32
32
  } catch (err) {
33
- log.error(`esbuild-wrapped ${payload.package} missing in list of hooks`)
33
+ log.error('esbuild-wrapped %s missing in list of hooks', payload.package)
34
34
  throw err
35
35
  }
36
36
 
37
37
  if (!instrumentations[payload.package]) {
38
- log.error(`esbuild-wrapped ${payload.package} missing in list of instrumentations`)
38
+ log.error('esbuild-wrapped %s missing in list of instrumentations', payload.package)
39
39
  return
40
40
  }
41
41
 
@@ -47,7 +47,7 @@ dc.subscribe(CHANNEL, (payload) => {
47
47
  loadChannel.publish({ name, version: payload.version, file })
48
48
  payload.module = hook(payload.module, payload.version)
49
49
  } catch (e) {
50
- log.error(e)
50
+ log.error('Error executing bundler hook', e)
51
51
  }
52
52
  }
53
53
  })
@@ -111,7 +111,6 @@ module.exports = {
111
111
  protobufjs: () => require('../protobufjs'),
112
112
  pug: () => require('../pug'),
113
113
  q: () => require('../q'),
114
- qs: () => require('../qs'),
115
114
  redis: () => require('../redis'),
116
115
  restify: () => require('../restify'),
117
116
  rhea: () => require('../rhea'),
@@ -7,7 +7,7 @@ const Hook = require('./hook')
7
7
  const requirePackageJson = require('../../../dd-trace/src/require-package-json')
8
8
  const log = require('../../../dd-trace/src/log')
9
9
  const checkRequireCache = require('../check_require_cache')
10
- const telemetry = require('../../../dd-trace/src/telemetry/init-telemetry')
10
+ const telemetry = require('../../../dd-trace/src/guardrails/telemetry')
11
11
 
12
12
  const {
13
13
  DD_TRACE_DISABLED_INSTRUMENTATIONS = '',
@@ -103,8 +103,7 @@ for (const packageName of names) {
103
103
  try {
104
104
  version = version || getVersion(moduleBaseDir)
105
105
  } catch (e) {
106
- log.error(`Error getting version for "${name}": ${e.message}`)
107
- log.error(e)
106
+ log.error('Error getting version for "%s": %s', name, e.message, e)
108
107
  continue
109
108
  }
110
109
  if (typeof namesAndSuccesses[`${name}@${version}`] === 'undefined') {
@@ -146,7 +145,7 @@ for (const packageName of names) {
146
145
  `integration:${name}`,
147
146
  `integration_version:${version}`
148
147
  ])
149
- log.info(`Found incompatible integration version: ${nameVersion}`)
148
+ log.info('Found incompatible integration version: %s', nameVersion)
150
149
  seenCombo.add(nameVersion)
151
150
  }
152
151
  }
@@ -39,7 +39,7 @@ function patch (http, methodName) {
39
39
  try {
40
40
  args = normalizeArgs.apply(null, arguments)
41
41
  } catch (e) {
42
- log.error(e)
42
+ log.error('Error normalising http req arguments', e)
43
43
  return request.apply(this, arguments)
44
44
  }
45
45