dd-trace 4.18.0 → 4.23.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 (137) hide show
  1. package/LICENSE-3rdparty.csv +3 -2
  2. package/README.md +3 -3
  3. package/ext/kinds.d.ts +1 -0
  4. package/ext/kinds.js +2 -1
  5. package/ext/tags.d.ts +2 -1
  6. package/ext/tags.js +6 -1
  7. package/index.d.ts +29 -0
  8. package/package.json +12 -11
  9. package/packages/datadog-core/src/storage/async_resource.js +1 -1
  10. package/packages/datadog-esbuild/index.js +1 -20
  11. package/packages/datadog-instrumentations/src/aerospike.js +47 -0
  12. package/packages/datadog-instrumentations/src/apollo-server-core.js +41 -0
  13. package/packages/datadog-instrumentations/src/apollo-server.js +83 -0
  14. package/packages/datadog-instrumentations/src/child-process.js +4 -5
  15. package/packages/datadog-instrumentations/src/couchbase.js +5 -4
  16. package/packages/datadog-instrumentations/src/crypto.js +2 -1
  17. package/packages/datadog-instrumentations/src/dns.js +2 -1
  18. package/packages/datadog-instrumentations/src/graphql.js +18 -4
  19. package/packages/datadog-instrumentations/src/helpers/bundler-register.js +1 -2
  20. package/packages/datadog-instrumentations/src/helpers/hooks.js +10 -2
  21. package/packages/datadog-instrumentations/src/helpers/instrument.js +9 -4
  22. package/packages/datadog-instrumentations/src/helpers/register.js +19 -3
  23. package/packages/datadog-instrumentations/src/http/client.js +12 -2
  24. package/packages/datadog-instrumentations/src/http/server.js +7 -4
  25. package/packages/datadog-instrumentations/src/http2/client.js +3 -1
  26. package/packages/datadog-instrumentations/src/http2/server.js +3 -1
  27. package/packages/datadog-instrumentations/src/jest.js +12 -6
  28. package/packages/datadog-instrumentations/src/kafkajs.js +27 -0
  29. package/packages/datadog-instrumentations/src/net.js +10 -2
  30. package/packages/datadog-instrumentations/src/next.js +18 -6
  31. package/packages/datadog-instrumentations/src/restify.js +14 -1
  32. package/packages/datadog-instrumentations/src/rhea.js +15 -9
  33. package/packages/datadog-plugin-aerospike/src/index.js +113 -0
  34. package/packages/datadog-plugin-cucumber/src/index.js +34 -2
  35. package/packages/datadog-plugin-cypress/src/plugin.js +60 -8
  36. package/packages/datadog-plugin-graphql/src/resolve.js +26 -18
  37. package/packages/datadog-plugin-http/src/client.js +19 -2
  38. package/packages/datadog-plugin-jest/src/index.js +38 -4
  39. package/packages/datadog-plugin-kafkajs/src/consumer.js +59 -6
  40. package/packages/datadog-plugin-kafkajs/src/producer.js +64 -6
  41. package/packages/datadog-plugin-mocha/src/index.js +32 -1
  42. package/packages/datadog-plugin-next/src/index.js +40 -14
  43. package/packages/datadog-plugin-playwright/src/index.js +17 -1
  44. package/packages/dd-trace/src/appsec/activation.js +29 -0
  45. package/packages/dd-trace/src/appsec/addresses.js +3 -1
  46. package/packages/dd-trace/src/appsec/api_security_sampler.js +48 -0
  47. package/packages/dd-trace/src/appsec/blocked_templates.js +4 -1
  48. package/packages/dd-trace/src/appsec/blocking.js +95 -43
  49. package/packages/dd-trace/src/appsec/channels.js +5 -2
  50. package/packages/dd-trace/src/appsec/graphql.js +146 -0
  51. package/packages/dd-trace/src/appsec/iast/analyzers/analyzers.js +1 -0
  52. package/packages/dd-trace/src/appsec/iast/analyzers/header-injection-analyzer.js +105 -0
  53. package/packages/dd-trace/src/appsec/iast/iast-log.js +1 -1
  54. package/packages/dd-trace/src/appsec/iast/iast-plugin.js +1 -1
  55. package/packages/dd-trace/src/appsec/iast/index.js +1 -1
  56. package/packages/dd-trace/src/appsec/iast/path-line.js +1 -1
  57. package/packages/dd-trace/src/appsec/iast/taint-tracking/rewriter.js +1 -1
  58. package/packages/dd-trace/src/appsec/iast/vulnerabilities-formatter/constants.js +7 -0
  59. package/packages/dd-trace/src/appsec/iast/vulnerabilities-formatter/evidence-redaction/sensitive-analyzers/command-sensitive-analyzer.js +12 -19
  60. package/packages/dd-trace/src/appsec/iast/vulnerabilities-formatter/evidence-redaction/sensitive-analyzers/header-sensitive-analyzer.js +20 -0
  61. package/packages/dd-trace/src/appsec/iast/vulnerabilities-formatter/evidence-redaction/sensitive-analyzers/json-sensitive-analyzer.js +6 -10
  62. package/packages/dd-trace/src/appsec/iast/vulnerabilities-formatter/evidence-redaction/sensitive-analyzers/ldap-sensitive-analyzer.js +18 -25
  63. package/packages/dd-trace/src/appsec/iast/vulnerabilities-formatter/evidence-redaction/sensitive-analyzers/sql-sensitive-analyzer.js +79 -85
  64. package/packages/dd-trace/src/appsec/iast/vulnerabilities-formatter/evidence-redaction/sensitive-analyzers/url-sensitive-analyzer.js +27 -36
  65. package/packages/dd-trace/src/appsec/iast/vulnerabilities-formatter/evidence-redaction/sensitive-handler.js +14 -11
  66. package/packages/dd-trace/src/appsec/iast/vulnerabilities.js +1 -0
  67. package/packages/dd-trace/src/appsec/index.js +33 -32
  68. package/packages/dd-trace/src/appsec/recommended.json +1737 -120
  69. package/packages/dd-trace/src/appsec/remote_config/capabilities.js +6 -1
  70. package/packages/dd-trace/src/appsec/remote_config/index.js +40 -15
  71. package/packages/dd-trace/src/appsec/reporter.js +50 -34
  72. package/packages/dd-trace/src/appsec/rule_manager.js +9 -6
  73. package/packages/dd-trace/src/appsec/sdk/user_blocking.js +1 -1
  74. package/packages/dd-trace/src/appsec/waf/waf_context_wrapper.js +28 -13
  75. package/packages/dd-trace/src/appsec/waf/waf_manager.js +0 -1
  76. package/packages/dd-trace/src/ci-visibility/exporters/agentless/coverage-writer.js +30 -1
  77. package/packages/dd-trace/src/ci-visibility/exporters/agentless/writer.js +30 -1
  78. package/packages/dd-trace/src/ci-visibility/exporters/ci-visibility-exporter.js +17 -1
  79. package/packages/dd-trace/src/ci-visibility/exporters/git/git_metadata.js +110 -59
  80. package/packages/dd-trace/src/ci-visibility/intelligent-test-runner/get-itr-configuration.js +40 -7
  81. package/packages/dd-trace/src/ci-visibility/intelligent-test-runner/get-skippable-suites.js +26 -1
  82. package/packages/dd-trace/src/ci-visibility/telemetry.js +130 -0
  83. package/packages/dd-trace/src/config.js +145 -63
  84. package/packages/dd-trace/src/datastreams/processor.js +166 -26
  85. package/packages/dd-trace/src/encode/agentless-ci-visibility.js +14 -1
  86. package/packages/dd-trace/src/encode/coverage-ci-visibility.js +14 -0
  87. package/packages/dd-trace/src/exporters/common/agent-info-exporter.js +4 -0
  88. package/packages/dd-trace/src/exporters/common/form-data.js +4 -0
  89. package/packages/dd-trace/src/format.js +6 -1
  90. package/packages/dd-trace/src/id.js +12 -0
  91. package/packages/dd-trace/src/iitm.js +1 -1
  92. package/packages/dd-trace/src/log/channels.js +1 -1
  93. package/packages/dd-trace/src/noop/proxy.js +4 -0
  94. package/packages/dd-trace/src/opentelemetry/span.js +95 -2
  95. package/packages/dd-trace/src/opentelemetry/tracer.js +9 -10
  96. package/packages/dd-trace/src/opentracing/propagation/text_map.js +14 -5
  97. package/packages/dd-trace/src/opentracing/span.js +6 -0
  98. package/packages/dd-trace/src/opentracing/span_context.js +5 -2
  99. package/packages/dd-trace/src/opentracing/tracer.js +2 -2
  100. package/packages/dd-trace/src/plugin_manager.js +1 -1
  101. package/packages/dd-trace/src/plugins/ci_plugin.js +46 -9
  102. package/packages/dd-trace/src/plugins/database.js +1 -1
  103. package/packages/dd-trace/src/plugins/index.js +6 -0
  104. package/packages/dd-trace/src/plugins/plugin.js +1 -1
  105. package/packages/dd-trace/src/plugins/util/ci.js +6 -19
  106. package/packages/dd-trace/src/plugins/util/exec.js +23 -2
  107. package/packages/dd-trace/src/plugins/util/git.js +98 -22
  108. package/packages/dd-trace/src/plugins/util/ip_extractor.js +7 -6
  109. package/packages/dd-trace/src/plugins/util/test.js +3 -2
  110. package/packages/dd-trace/src/plugins/util/url.js +26 -0
  111. package/packages/dd-trace/src/plugins/util/user-provided-git.js +4 -16
  112. package/packages/dd-trace/src/priority_sampler.js +30 -38
  113. package/packages/dd-trace/src/profiler.js +5 -3
  114. package/packages/dd-trace/src/profiling/config.js +26 -2
  115. package/packages/dd-trace/src/profiling/exporters/agent.js +1 -0
  116. package/packages/dd-trace/src/profiling/profiler.js +17 -10
  117. package/packages/dd-trace/src/profiling/profilers/events.js +264 -0
  118. package/packages/dd-trace/src/profiling/profilers/shared.js +39 -0
  119. package/packages/dd-trace/src/profiling/profilers/space.js +2 -1
  120. package/packages/dd-trace/src/profiling/profilers/wall.js +121 -58
  121. package/packages/dd-trace/src/proxy.js +25 -1
  122. package/packages/dd-trace/src/ritm.js +1 -1
  123. package/packages/dd-trace/src/sampling_rule.js +130 -0
  124. package/packages/dd-trace/src/service-naming/schemas/v0/storage.js +5 -0
  125. package/packages/dd-trace/src/service-naming/schemas/v1/storage.js +4 -0
  126. package/packages/dd-trace/src/span_processor.js +4 -0
  127. package/packages/dd-trace/src/span_sampler.js +6 -64
  128. package/packages/dd-trace/src/spanleak.js +98 -0
  129. package/packages/dd-trace/src/startup-log.js +7 -1
  130. package/packages/dd-trace/src/telemetry/dependencies.js +56 -10
  131. package/packages/dd-trace/src/telemetry/index.js +171 -41
  132. package/packages/dd-trace/src/telemetry/logs/index.js +2 -2
  133. package/packages/dd-trace/src/telemetry/send-data.js +47 -5
  134. package/packages/dd-trace/src/tracer.js +8 -2
  135. package/scripts/install_plugin_modules.js +11 -3
  136. package/packages/diagnostics_channel/index.js +0 -3
  137. package/packages/diagnostics_channel/src/index.js +0 -121
@@ -8,7 +8,7 @@ require,@datadog/sketches-js,Apache license 2.0,Copyright 2020 Datadog Inc.
8
8
  require,@opentelemetry/api,Apache license 2.0,Copyright OpenTelemetry Authors
9
9
  require,@opentelemetry/core,Apache license 2.0,Copyright OpenTelemetry Authors
10
10
  require,crypto-randomuuid,MIT,Copyright 2021 Node.js Foundation and contributors
11
- require,diagnostics_channel,MIT,Copyright 2021 Simon D.
11
+ require,dc-polyfill,MIT,Copyright 2023 Datadog Inc.
12
12
  require,ignore,MIT,Copyright 2013 Kael Zhang and contributors
13
13
  require,import-in-the-middle,Apache license 2.0,Copyright 2021 Datadog Inc.
14
14
  require,int64-buffer,MIT,Copyright 2015-2016 Yusuke Kawasaki
@@ -28,7 +28,9 @@ require,msgpack-lite,MIT,Copyright 2015 Yusuke Kawasaki
28
28
  require,node-abort-controller,MIT,Copyright (c) 2019 Steve Faulkner
29
29
  require,opentracing,MIT,Copyright 2016 Resonance Labs Inc
30
30
  require,path-to-regexp,MIT,Copyright 2014 Blake Embrey
31
+ require,pprof-format,MIT,Copyright 2022 Stephen Belanger
31
32
  require,protobufjs,BSD-3-Clause,Copyright 2016 Daniel Wirtz
33
+ require,tlhunter-sorted-set,MIT,Copyright (c) 2023 Datadog Inc.
32
34
  require,retry,MIT,Copyright 2011 Tim Koschützki Felix Geisendörfer
33
35
  require,semver,ISC,Copyright Isaac Z. Schlueter and Contributors
34
36
  dev,@types/node,MIT,Copyright Authors
@@ -62,7 +64,6 @@ dev,mocha,MIT,Copyright 2011-2018 JS Foundation and contributors https://js.foun
62
64
  dev,multer,MIT,Copyright 2014 Hage Yaapa
63
65
  dev,nock,MIT,Copyright 2017 Pedro Teixeira and other contributors
64
66
  dev,nyc,ISC,Copyright 2015 Contributors
65
- dev,pprof-format,MIT,Copyright 2022 Stephen Belanger
66
67
  dev,proxyquire,MIT,Copyright 2013 Thorsten Lorenz
67
68
  dev,rimraf,ISC,Copyright Isaac Z. Schlueter and Contributors
68
69
  dev,sinon,BSD-3-Clause,Copyright 2010-2017 Christian Johansen
package/README.md CHANGED
@@ -202,11 +202,11 @@ To get around this, one can treat all third party modules, or at least third par
202
202
 
203
203
  For these reasons it's necessary to have custom-built bundler plugins. Such plugins are able to instruct the bundler on how to behave, injecting intermediary code and otherwise intercepting the "translated" `require()` calls. The result is that many more packages are then included in the bundled JavaScript file. Some applications can have 100% of modules bundled, however native modules still need to remain external to the bundle.
204
204
 
205
- ### Esbuild Support
205
+ ### ESBuild Support
206
206
 
207
- This library provides experimental esbuild support in the form of an esbuild plugin, and currently requires at least Node.js v16.17 or v18.7. To use the plugin, make sure you have `dd-trace@3+` installed, and then require the `dd-trace/esbuild` module when building your bundle.
207
+ This library provides experimental ESBuild support in the form of an ESBuild plugin. Require the `dd-trace/esbuild` module when building your bundle to enable the plugin.
208
208
 
209
- Here's an example of how one might use `dd-trace` with esbuild:
209
+ Here's an example of how one might use `dd-trace` with ESBuild:
210
210
 
211
211
  ```javascript
212
212
  const ddPlugin = require('dd-trace/esbuild')
package/ext/kinds.d.ts CHANGED
@@ -3,6 +3,7 @@ declare const kinds: {
3
3
  CLIENT: 'client'
4
4
  PRODUCER: 'producer'
5
5
  CONSUMER: 'consumer'
6
+ INTERNAL: 'internal'
6
7
  }
7
8
 
8
9
  export = kinds
package/ext/kinds.js CHANGED
@@ -4,5 +4,6 @@ module.exports = {
4
4
  SERVER: 'server',
5
5
  CLIENT: 'client',
6
6
  PRODUCER: 'producer',
7
- CONSUMER: 'consumer'
7
+ CONSUMER: 'consumer',
8
+ INTERNAL: 'internal'
8
9
  }
package/ext/tags.d.ts CHANGED
@@ -17,7 +17,8 @@ declare const tags: {
17
17
  HTTP_REQUEST_HEADERS: 'http.request.headers'
18
18
  HTTP_RESPONSE_HEADERS: 'http.response.headers'
19
19
  HTTP_USERAGENT: 'http.useragent',
20
- HTTP_CLIENT_IP: 'http.client_ip'
20
+ HTTP_CLIENT_IP: 'http.client_ip',
21
+ PATHWAY_HASH: 'pathway.hash'
21
22
  }
22
23
 
23
24
  export = tags
package/ext/tags.js CHANGED
@@ -22,7 +22,12 @@ const tags = {
22
22
  HTTP_REQUEST_HEADERS: 'http.request.headers',
23
23
  HTTP_RESPONSE_HEADERS: 'http.response.headers',
24
24
  HTTP_USERAGENT: 'http.useragent',
25
- HTTP_CLIENT_IP: 'http.client_ip'
25
+ HTTP_CLIENT_IP: 'http.client_ip',
26
+
27
+ // Messaging
28
+
29
+ // DSM Specific
30
+ PATHWAY_HASH: 'pathway.hash'
26
31
  }
27
32
 
28
33
  // Deprecated
package/index.d.ts CHANGED
@@ -567,6 +567,11 @@ export declare interface TracerOptions {
567
567
  */
568
568
  blockedTemplateJson?: string,
569
569
 
570
+ /**
571
+ * Specifies a path to a custom blocking template json file for graphql requests
572
+ */
573
+ blockedTemplateGraphql?: string,
574
+
570
575
  /**
571
576
  * Controls the automated user event tracking configuration
572
577
  */
@@ -578,6 +583,22 @@ export declare interface TracerOptions {
578
583
  * @default 'safe'
579
584
  */
580
585
  mode?: 'safe' | 'extended' | 'disabled'
586
+ },
587
+
588
+ /**
589
+ * Configuration for Api Security sampling
590
+ */
591
+ apiSecurity?: {
592
+ /** Whether to enable Api Security.
593
+ * @default false
594
+ */
595
+ enabled?: boolean,
596
+
597
+ /** Controls the request sampling rate (between 0 and 1) in which Api Security is triggered.
598
+ * The value will be coerced back if it's outside of the 0-1 range.
599
+ * @default 0.1
600
+ */
601
+ requestSampling?: number
581
602
  }
582
603
  };
583
604
 
@@ -927,6 +948,14 @@ declare namespace plugins {
927
948
  * @default code => code < 500
928
949
  */
929
950
  validateStatus?: (code: number) => boolean;
951
+
952
+ /**
953
+ * Enable injection of tracing headers into requests signed with AWS IAM headers.
954
+ * Disable this if you get AWS signature errors (HTTP 403).
955
+ *
956
+ * @default false
957
+ */
958
+ enablePropagationWithAmazonHeaders?: boolean;
930
959
  }
931
960
 
932
961
  /** @hidden */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dd-trace",
3
- "version": "4.18.0",
3
+ "version": "4.23.0",
4
4
  "description": "Datadog APM tracing client for JavaScript",
5
5
  "main": "index.js",
6
6
  "typings": "index.d.ts",
@@ -19,7 +19,7 @@
19
19
  "test:appsec:ci": "nyc --no-clean --include \"packages/dd-trace/src/appsec/**/*.js\" --exclude \"packages/dd-trace/test/appsec/**/*.plugin.spec.js\" -- npm run test:appsec",
20
20
  "test:appsec:plugins": "mocha --colors --exit -r \"packages/dd-trace/test/setup/mocha.js\" \"packages/dd-trace/test/appsec/**/*.@($(echo $PLUGINS)).plugin.spec.js\"",
21
21
  "test:appsec:plugins:ci": "yarn services && nyc --no-clean --include \"packages/dd-trace/src/appsec/**/*.js\" -- npm run test:appsec:plugins",
22
- "test:trace:core": "tap packages/dd-trace/test/*.spec.js \"packages/dd-trace/test/{ci-visibility,encode,exporters,opentelemetry,opentracing,plugins,service-naming,telemetry}/**/*.spec.js\"",
22
+ "test:trace:core": "tap packages/dd-trace/test/*.spec.js \"packages/dd-trace/test/{ci-visibility,datastreams,encode,exporters,opentelemetry,opentracing,plugins,service-naming,telemetry}/**/*.spec.js\"",
23
23
  "test:trace:core:ci": "npm run test:trace:core -- --coverage --nyc-arg=--include=\"packages/dd-trace/src/**/*.js\"",
24
24
  "test:instrumentations": "mocha --colors -r 'packages/dd-trace/test/setup/mocha.js' 'packages/datadog-instrumentations/test/**/*.spec.js'",
25
25
  "test:instrumentations:ci": "nyc --no-clean --include 'packages/datadog-instrumentations/src/**/*.js' -- npm run test:instrumentations",
@@ -68,18 +68,18 @@
68
68
  "node": ">=16"
69
69
  },
70
70
  "dependencies": {
71
- "@datadog/native-appsec": "^4.0.0",
72
- "@datadog/native-iast-rewriter": "2.2.1",
73
- "@datadog/native-iast-taint-tracking": "1.6.3",
71
+ "@datadog/native-appsec": "6.0.0",
72
+ "@datadog/native-iast-rewriter": "2.2.2",
73
+ "@datadog/native-iast-taint-tracking": "1.6.4",
74
74
  "@datadog/native-metrics": "^2.0.0",
75
- "@datadog/pprof": "4.0.1",
75
+ "@datadog/pprof": "4.1.0",
76
76
  "@datadog/sketches-js": "^2.1.0",
77
77
  "@opentelemetry/api": "^1.0.0",
78
78
  "@opentelemetry/core": "^1.14.0",
79
79
  "crypto-randomuuid": "^1.0.0",
80
- "diagnostics_channel": "^1.1.0",
80
+ "dc-polyfill": "^0.1.2",
81
81
  "ignore": "^5.2.4",
82
- "import-in-the-middle": "^1.4.2",
82
+ "import-in-the-middle": "^1.7.1",
83
83
  "int64-buffer": "^0.1.9",
84
84
  "ipaddr.js": "^2.1.0",
85
85
  "istanbul-lib-coverage": "3.2.0",
@@ -97,9 +97,11 @@
97
97
  "node-abort-controller": "^3.1.1",
98
98
  "opentracing": ">=0.12.1",
99
99
  "path-to-regexp": "^0.1.2",
100
- "protobufjs": "^7.2.4",
100
+ "pprof-format": "^2.0.7",
101
+ "protobufjs": "^7.2.5",
101
102
  "retry": "^0.13.1",
102
- "semver": "^7.5.4"
103
+ "semver": "^7.5.4",
104
+ "tlhunter-sorted-set": "^0.1.0"
103
105
  },
104
106
  "devDependencies": {
105
107
  "@types/node": ">=16",
@@ -133,7 +135,6 @@
133
135
  "multer": "^1.4.5-lts.1",
134
136
  "nock": "^11.3.3",
135
137
  "nyc": "^15.1.0",
136
- "pprof-format": "^2.0.7",
137
138
  "proxyquire": "^1.8.0",
138
139
  "rimraf": "^3.0.0",
139
140
  "sinon": "^15.2.0",
@@ -1,7 +1,7 @@
1
1
  'use strict'
2
2
 
3
3
  const { createHook, executionAsyncResource } = require('async_hooks')
4
- const { channel } = require('../../../diagnostics_channel')
4
+ const { channel } = require('dc-polyfill')
5
5
 
6
6
  const beforeCh = channel('dd-trace:storage:before')
7
7
  const afterCh = channel('dd-trace:storage:after')
@@ -5,8 +5,6 @@
5
5
  const instrumentations = require('../datadog-instrumentations/src/helpers/instrumentations.js')
6
6
  const hooks = require('../datadog-instrumentations/src/helpers/hooks.js')
7
7
 
8
- warnIfUnsupported()
9
-
10
8
  for (const hook of Object.values(hooks)) {
11
9
  hook()
12
10
  }
@@ -144,7 +142,7 @@ module.exports.setup = function (build) {
144
142
  ${fileCode}
145
143
  })(...arguments);
146
144
  {
147
- const dc = require('diagnostics_channel');
145
+ const dc = require('dc-polyfill');
148
146
  const ch = dc.channel('${CHANNEL}');
149
147
  const mod = module.exports
150
148
  const payload = {
@@ -167,23 +165,6 @@ module.exports.setup = function (build) {
167
165
  })
168
166
  }
169
167
 
170
- // Currently esbuild support requires Node.js >=v16.17 or >=v18.7
171
- // Better yet it would support Node >=v14.17 or >=v16
172
- // Of course, the most ideal would be to support all versions of Node that dd-trace supports.
173
- // Version constraints based on Node's diagnostics_channel support
174
- function warnIfUnsupported () {
175
- const [major, minor] = process.versions.node.split('.').map(Number)
176
- if (
177
- major < 16 ||
178
- (major === 16 && minor < 17) ||
179
- (major === 18 && minor < 7)) {
180
- console.error('WARNING: Esbuild support isn\'t available for older versions of Node.js.')
181
- console.error(`Expected: Node.js >=v16.17 or >=v18.7. Actual: Node.js = ${process.version}.`)
182
- console.error('This application may build properly with this version of Node.js, but unless a')
183
- console.error('more recent version is used at runtime, third party packages won\'t be instrumented.')
184
- }
185
- }
186
-
187
168
  // @see https://github.com/nodejs/node/issues/47000
188
169
  function dotFriendlyResolve (path, directory) {
189
170
  if (path === '.') {
@@ -0,0 +1,47 @@
1
+ 'use strict'
2
+
3
+ const {
4
+ addHook
5
+ } = require('./helpers/instrument')
6
+ const shimmer = require('../../datadog-shimmer')
7
+
8
+ const tracingChannel = require('dc-polyfill').tracingChannel
9
+ const ch = tracingChannel('apm:aerospike:command')
10
+
11
+ function wrapCreateCommand (createCommand) {
12
+ if (typeof createCommand !== 'function') return createCommand
13
+
14
+ return function commandWithTrace () {
15
+ const CommandClass = createCommand.apply(this, arguments)
16
+
17
+ if (!CommandClass) return CommandClass
18
+
19
+ shimmer.wrap(CommandClass.prototype, 'process', wrapProcess)
20
+
21
+ return CommandClass
22
+ }
23
+ }
24
+
25
+ function wrapProcess (process) {
26
+ return function (...args) {
27
+ const cb = args[0]
28
+ if (typeof cb !== 'function') return process.apply(this, args)
29
+
30
+ const ctx = {
31
+ commandName: this.constructor.name,
32
+ commandArgs: this.args,
33
+ clientConfig: this.client.config
34
+ }
35
+
36
+ return ch.traceCallback(process, -1, ctx, this, ...args)
37
+ }
38
+ }
39
+
40
+ addHook({
41
+ name: 'aerospike',
42
+ file: 'lib/commands/command.js',
43
+ versions: ['^3.16.2', '4', '5']
44
+ },
45
+ commandFactory => {
46
+ return shimmer.wrap(commandFactory, wrapCreateCommand(commandFactory))
47
+ })
@@ -0,0 +1,41 @@
1
+ 'use strict'
2
+
3
+ const { AbortController } = require('node-abort-controller')
4
+ const { addHook } = require('./helpers/instrument')
5
+ const shimmer = require('../../datadog-shimmer')
6
+ const dc = require('dc-polyfill')
7
+
8
+ const requestChannel = dc.tracingChannel('datadog:apollo-server-core:request')
9
+
10
+ addHook({ name: 'apollo-server-core', file: 'dist/runHttpQuery.js', versions: ['>3.0.0'] }, runHttpQueryModule => {
11
+ const HttpQueryError = runHttpQueryModule.HttpQueryError
12
+
13
+ shimmer.wrap(runHttpQueryModule, 'runHttpQuery', function wrapRunHttpQuery (originalRunHttpQuery) {
14
+ return async function runHttpQuery () {
15
+ if (!requestChannel.start.hasSubscribers) {
16
+ return originalRunHttpQuery.apply(this, arguments)
17
+ }
18
+
19
+ const abortController = new AbortController()
20
+ const abortData = {}
21
+
22
+ const runHttpQueryResult = requestChannel.tracePromise(
23
+ originalRunHttpQuery,
24
+ { abortController, abortData },
25
+ this,
26
+ ...arguments)
27
+
28
+ const abortPromise = new Promise((resolve, reject) => {
29
+ abortController.signal.addEventListener('abort', (event) => {
30
+ // runHttpQuery callbacks are writing the response on resolve/reject.
31
+ // We should return blocking data in the apollo-server-core HttpQueryError object
32
+ reject(new HttpQueryError(abortData.statusCode, abortData.message, true, abortData.headers))
33
+ }, { once: true })
34
+ })
35
+
36
+ return Promise.race([runHttpQueryResult, abortPromise])
37
+ }
38
+ })
39
+
40
+ return runHttpQueryModule
41
+ })
@@ -0,0 +1,83 @@
1
+ 'use strict'
2
+
3
+ const { AbortController } = require('node-abort-controller')
4
+ const dc = require('dc-polyfill')
5
+
6
+ const { addHook } = require('./helpers/instrument')
7
+ const shimmer = require('../../datadog-shimmer')
8
+
9
+ const graphqlMiddlewareChannel = dc.tracingChannel('datadog:apollo:middleware')
10
+
11
+ const requestChannel = dc.tracingChannel('datadog:apollo:request')
12
+
13
+ let HeaderMap
14
+
15
+ function wrapExecuteHTTPGraphQLRequest (originalExecuteHTTPGraphQLRequest) {
16
+ return async function executeHTTPGraphQLRequest () {
17
+ if (!HeaderMap || !requestChannel.start.hasSubscribers) {
18
+ return originalExecuteHTTPGraphQLRequest.apply(this, arguments)
19
+ }
20
+
21
+ const abortController = new AbortController()
22
+ const abortData = {}
23
+
24
+ const graphqlResponseData = requestChannel.tracePromise(
25
+ originalExecuteHTTPGraphQLRequest,
26
+ { abortController, abortData },
27
+ this,
28
+ ...arguments)
29
+
30
+ const abortPromise = new Promise((resolve, reject) => {
31
+ abortController.signal.addEventListener('abort', (event) => {
32
+ // This method is expected to return response data
33
+ // with headers, status and body
34
+ const headers = new HeaderMap()
35
+ Object.keys(abortData.headers).forEach(key => {
36
+ headers.set(key, abortData.headers[key])
37
+ })
38
+
39
+ resolve({
40
+ headers: headers,
41
+ status: abortData.statusCode,
42
+ body: {
43
+ kind: 'complete',
44
+ string: abortData.message
45
+ }
46
+ })
47
+ }, { once: true })
48
+ })
49
+
50
+ return Promise.race([abortPromise, graphqlResponseData])
51
+ }
52
+ }
53
+
54
+ function apolloExpress4Hook (express4) {
55
+ shimmer.wrap(express4, 'expressMiddleware', function wrapExpressMiddleware (originalExpressMiddleware) {
56
+ return function expressMiddleware (server, options) {
57
+ const originalMiddleware = originalExpressMiddleware.apply(this, arguments)
58
+
59
+ return shimmer.wrap(originalMiddleware, function (req, res, next) {
60
+ if (!graphqlMiddlewareChannel.start.hasSubscribers) {
61
+ return originalMiddleware.apply(this, arguments)
62
+ }
63
+
64
+ return graphqlMiddlewareChannel.traceSync(originalMiddleware, { req }, this, ...arguments)
65
+ })
66
+ }
67
+ })
68
+ return express4
69
+ }
70
+
71
+ function apolloHeaderMapHook (headerMap) {
72
+ HeaderMap = headerMap.HeaderMap
73
+ return headerMap
74
+ }
75
+
76
+ function apolloServerHook (apolloServer) {
77
+ shimmer.wrap(apolloServer.ApolloServer.prototype, 'executeHTTPGraphQLRequest', wrapExecuteHTTPGraphQLRequest)
78
+ return apolloServer
79
+ }
80
+
81
+ addHook({ name: '@apollo/server', file: 'dist/cjs/ApolloServer.js', versions: ['>=4.0.0'] }, apolloServerHook)
82
+ addHook({ name: '@apollo/server', file: 'dist/cjs/express4/index.js', versions: ['>=4.0.0'] }, apolloExpress4Hook)
83
+ addHook({ name: '@apollo/server', file: 'dist/cjs/utils/HeaderMap.js', versions: ['>=4.0.0'] }, apolloHeaderMapHook)
@@ -9,11 +9,10 @@ const shimmer = require('../../datadog-shimmer')
9
9
  const childProcessChannel = channel('datadog:child_process:execution:start')
10
10
  const execMethods = ['exec', 'execFile', 'fork', 'spawn', 'execFileSync', 'execSync', 'spawnSync']
11
11
  const names = ['child_process', 'node:child_process']
12
- names.forEach(name => {
13
- addHook({ name }, childProcess => {
14
- shimmer.massWrap(childProcess, execMethods, wrapChildProcessMethod())
15
- return childProcess
16
- })
12
+
13
+ addHook({ name: names }, childProcess => {
14
+ shimmer.massWrap(childProcess, execMethods, wrapChildProcessMethod())
15
+ return childProcess
17
16
  })
18
17
 
19
18
  function wrapChildProcessMethod () {
@@ -252,9 +252,10 @@ addHook({ name: 'couchbase', file: 'lib/cluster.js', versions: ['^3.0.7', '^3.1.
252
252
  return Cluster
253
253
  })
254
254
 
255
- // semver >=3.2.0
255
+ // semver >=3.2.2
256
+ // NOTE: <3.2.2 segfaults on cluster.close() https://issues.couchbase.com/browse/JSCBC-936
256
257
 
257
- addHook({ name: 'couchbase', file: 'dist/collection.js', versions: ['>=3.2.0'] }, collection => {
258
+ addHook({ name: 'couchbase', file: 'dist/collection.js', versions: ['>=3.2.2'] }, collection => {
258
259
  const Collection = collection.Collection
259
260
 
260
261
  wrapAllNames(['upsert', 'insert', 'replace'], name => {
@@ -264,7 +265,7 @@ addHook({ name: 'couchbase', file: 'dist/collection.js', versions: ['>=3.2.0'] }
264
265
  return collection
265
266
  })
266
267
 
267
- addHook({ name: 'couchbase', file: 'dist/bucket.js', versions: ['>=3.2.0'] }, bucket => {
268
+ addHook({ name: 'couchbase', file: 'dist/bucket.js', versions: ['>=3.2.2'] }, bucket => {
268
269
  const Bucket = bucket.Bucket
269
270
  shimmer.wrap(Bucket.prototype, 'collection', getCollection => {
270
271
  return function () {
@@ -278,7 +279,7 @@ addHook({ name: 'couchbase', file: 'dist/bucket.js', versions: ['>=3.2.0'] }, bu
278
279
  return bucket
279
280
  })
280
281
 
281
- addHook({ name: 'couchbase', file: 'dist/cluster.js', versions: ['3.2.0 - 3.2.1', '>=3.2.2'] }, (cluster) => {
282
+ addHook({ name: 'couchbase', file: 'dist/cluster.js', versions: ['>=3.2.2'] }, (cluster) => {
282
283
  const Cluster = cluster.Cluster
283
284
 
284
285
  shimmer.wrap(Cluster.prototype, 'query', wrapV3Query)
@@ -11,8 +11,9 @@ const cryptoCipherCh = channel('datadog:crypto:cipher:start')
11
11
 
12
12
  const hashMethods = ['createHash', 'createHmac', 'createSign', 'createVerify', 'sign', 'verify']
13
13
  const cipherMethods = ['createCipheriv', 'createDecipheriv']
14
+ const names = ['crypto', 'node:crypto']
14
15
 
15
- addHook({ name: 'crypto' }, crypto => {
16
+ addHook({ name: names }, crypto => {
16
17
  shimmer.massWrap(crypto, hashMethods, wrapCryptoMethod(cryptoHashCh))
17
18
  shimmer.massWrap(crypto, cipherMethods, wrapCryptoMethod(cryptoCipherCh))
18
19
  return crypto
@@ -18,8 +18,9 @@ const rrtypes = {
18
18
  }
19
19
 
20
20
  const rrtypeMap = new WeakMap()
21
+ const names = ['dns', 'node:dns']
21
22
 
22
- addHook({ name: 'dns' }, dns => {
23
+ addHook({ name: names }, dns => {
23
24
  dns.lookup = wrap('apm:dns:lookup', dns.lookup, 2)
24
25
  dns.lookupService = wrap('apm:dns:lookup_service', dns.lookupService, 3)
25
26
  dns.resolve = wrap('apm:dns:resolve', dns.resolve, 2)
@@ -1,5 +1,7 @@
1
1
  'use strict'
2
2
 
3
+ const { AbortController } = require('node-abort-controller')
4
+
3
5
  const {
4
6
  addHook,
5
7
  channel,
@@ -37,6 +39,13 @@ const validateStartCh = channel('apm:graphql:validate:start')
37
39
  const validateFinishCh = channel('apm:graphql:validate:finish')
38
40
  const validateErrorCh = channel('apm:graphql:validate:error')
39
41
 
42
+ class AbortError extends Error {
43
+ constructor (message) {
44
+ super(message)
45
+ this.name = 'AbortError'
46
+ }
47
+ }
48
+
40
49
  function getOperation (document, operationName) {
41
50
  if (!document || !Array.isArray(document.definitions)) {
42
51
  return
@@ -175,11 +184,11 @@ function wrapExecute (execute) {
175
184
  docSource: documentSources.get(document)
176
185
  })
177
186
 
178
- const context = { source, asyncResource, fields: {} }
187
+ const context = { source, asyncResource, fields: {}, abortController: new AbortController() }
179
188
 
180
189
  contexts.set(contextValue, context)
181
190
 
182
- return callInAsyncScope(exe, asyncResource, this, arguments, (err, res) => {
191
+ return callInAsyncScope(exe, asyncResource, this, arguments, context.abortController, (err, res) => {
183
192
  if (finishResolveCh.hasSubscribers) finishResolvers(context)
184
193
 
185
194
  const error = err || (res && res.errors && res.errors[0])
@@ -207,7 +216,7 @@ function wrapResolve (resolve) {
207
216
 
208
217
  const field = assertField(context, info, args)
209
218
 
210
- return callInAsyncScope(resolve, field.asyncResource, this, arguments, (err) => {
219
+ return callInAsyncScope(resolve, field.asyncResource, this, arguments, context.abortController, (err) => {
211
220
  updateFieldCh.publish({ field, info, err })
212
221
  })
213
222
  }
@@ -217,10 +226,15 @@ function wrapResolve (resolve) {
217
226
  return resolveAsync
218
227
  }
219
228
 
220
- function callInAsyncScope (fn, aR, thisArg, args, cb) {
229
+ function callInAsyncScope (fn, aR, thisArg, args, abortController, cb) {
221
230
  cb = cb || (() => {})
222
231
 
223
232
  return aR.runInAsyncScope(() => {
233
+ if (abortController?.signal.aborted) {
234
+ cb(null, null)
235
+ throw new AbortError('Aborted')
236
+ }
237
+
224
238
  try {
225
239
  const result = fn.apply(thisArg, args)
226
240
  if (result && typeof result.then === 'function') {
@@ -1,7 +1,6 @@
1
1
  'use strict'
2
2
 
3
- // eslint-disable-next-line n/no-restricted-require
4
- const dc = require('diagnostics_channel')
3
+ const dc = require('dc-polyfill')
5
4
 
6
5
  const {
7
6
  filename,
@@ -1,6 +1,8 @@
1
1
  'use strict'
2
2
 
3
3
  module.exports = {
4
+ '@apollo/server': () => require('../apollo-server'),
5
+ 'apollo-server-core': () => require('../apollo-server-core'),
4
6
  '@aws-sdk/smithy-client': () => require('../aws-sdk'),
5
7
  '@cucumber/cucumber': () => require('../cucumber'),
6
8
  '@playwright/test': () => require('../playwright'),
@@ -20,6 +22,7 @@ module.exports = {
20
22
  '@opentelemetry/sdk-trace-node': () => require('../otel-sdk-trace'),
21
23
  '@redis/client': () => require('../redis'),
22
24
  '@smithy/smithy-client': () => require('../aws-sdk'),
25
+ 'aerospike': () => require('../aerospike'),
23
26
  'amqp10': () => require('../amqp10'),
24
27
  'amqplib': () => require('../amqplib'),
25
28
  'aws-sdk': () => require('../aws-sdk'),
@@ -28,7 +31,6 @@ module.exports = {
28
31
  'bunyan': () => require('../bunyan'),
29
32
  'cassandra-driver': () => require('../cassandra-driver'),
30
33
  'child_process': () => require('../child-process'),
31
- 'node:child_process': () => require('../child-process'),
32
34
  'connect': () => require('../connect'),
33
35
  'cookie': () => require('../cookie'),
34
36
  'cookie-parser': () => require('../cookie-parser'),
@@ -42,7 +44,6 @@ module.exports = {
42
44
  'fastify': () => require('../fastify'),
43
45
  'find-my-way': () => require('../find-my-way'),
44
46
  'fs': () => require('../fs'),
45
- 'node:fs': () => require('../fs'),
46
47
  'generic-pool': () => require('../generic-pool'),
47
48
  'graphql': () => require('../graphql'),
48
49
  'grpc': () => require('../grpc'),
@@ -76,6 +77,13 @@ module.exports = {
76
77
  'mysql2': () => require('../mysql2'),
77
78
  'net': () => require('../net'),
78
79
  'next': () => require('../next'),
80
+ 'node:child_process': () => require('../child-process'),
81
+ 'node:crypto': () => require('../crypto'),
82
+ 'node:dns': () => require('../dns'),
83
+ 'node:http': () => require('../http'),
84
+ 'node:http2': () => require('../http2'),
85
+ 'node:https': () => require('../http'),
86
+ 'node:net': () => require('../net'),
79
87
  'oracledb': () => require('../oracledb'),
80
88
  'openai': () => require('../openai'),
81
89
  'paperplane': () => require('../paperplane'),
@@ -1,6 +1,6 @@
1
1
  'use strict'
2
2
 
3
- const dc = require('../../../diagnostics_channel')
3
+ const dc = require('dc-polyfill')
4
4
  const semver = require('semver')
5
5
  const instrumentations = require('./instrumentations')
6
6
  const { AsyncResource } = require('async_hooks')
@@ -21,11 +21,16 @@ exports.channel = function (name) {
21
21
  * @param Function hook
22
22
  */
23
23
  exports.addHook = function addHook ({ name, versions, file }, hook) {
24
- if (!instrumentations[name]) {
25
- instrumentations[name] = []
24
+ if (typeof name === 'string') {
25
+ name = [name]
26
26
  }
27
27
 
28
- instrumentations[name].push({ name, versions, file, hook })
28
+ for (const val of name) {
29
+ if (!instrumentations[val]) {
30
+ instrumentations[val] = []
31
+ }
32
+ instrumentations[val].push({ name: val, versions, file, hook })
33
+ }
29
34
  }
30
35
 
31
36
  // AsyncResource.bind exists and binds `this` properly only from 17.8.0 and up.