dd-trace 4.18.0 → 5.6.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 (209) hide show
  1. package/CONTRIBUTING.md +98 -0
  2. package/LICENSE-3rdparty.csv +4 -5
  3. package/MIGRATING.md +15 -0
  4. package/README.md +20 -140
  5. package/ci/cypress/after-run.js +1 -0
  6. package/ci/cypress/after-spec.js +1 -0
  7. package/ci/init.js +1 -4
  8. package/ext/kinds.d.ts +1 -0
  9. package/ext/kinds.js +2 -1
  10. package/ext/tags.d.ts +2 -1
  11. package/ext/tags.js +6 -1
  12. package/index.d.ts +1523 -1460
  13. package/package.json +19 -19
  14. package/packages/datadog-core/src/storage/async_resource.js +1 -1
  15. package/packages/datadog-core/src/utils/src/get.js +11 -0
  16. package/packages/datadog-core/src/utils/src/has.js +14 -0
  17. package/packages/datadog-core/src/utils/src/kebabcase.js +16 -0
  18. package/packages/datadog-core/src/utils/src/pick.js +11 -0
  19. package/packages/datadog-core/src/utils/src/set.js +16 -0
  20. package/packages/datadog-core/src/utils/src/uniq.js +5 -0
  21. package/packages/datadog-esbuild/index.js +1 -20
  22. package/packages/datadog-instrumentations/src/aerospike.js +47 -0
  23. package/packages/datadog-instrumentations/src/amqplib.js +2 -2
  24. package/packages/datadog-instrumentations/src/apollo-server-core.js +41 -0
  25. package/packages/datadog-instrumentations/src/apollo-server.js +83 -0
  26. package/packages/datadog-instrumentations/src/child_process.js +150 -0
  27. package/packages/datadog-instrumentations/src/couchbase.js +5 -4
  28. package/packages/datadog-instrumentations/src/crypto.js +2 -1
  29. package/packages/datadog-instrumentations/src/cucumber.js +163 -46
  30. package/packages/datadog-instrumentations/src/dns.js +2 -1
  31. package/packages/datadog-instrumentations/src/express.js +20 -0
  32. package/packages/datadog-instrumentations/src/graphql.js +18 -4
  33. package/packages/datadog-instrumentations/src/grpc/client.js +56 -36
  34. package/packages/datadog-instrumentations/src/grpc/server.js +3 -1
  35. package/packages/datadog-instrumentations/src/helpers/bundler-register.js +1 -2
  36. package/packages/datadog-instrumentations/src/helpers/hooks.js +12 -3
  37. package/packages/datadog-instrumentations/src/helpers/instrument.js +9 -4
  38. package/packages/datadog-instrumentations/src/helpers/register.js +19 -3
  39. package/packages/datadog-instrumentations/src/http/client.js +12 -2
  40. package/packages/datadog-instrumentations/src/http/server.js +7 -4
  41. package/packages/datadog-instrumentations/src/http2/client.js +3 -1
  42. package/packages/datadog-instrumentations/src/http2/server.js +3 -1
  43. package/packages/datadog-instrumentations/src/jest.js +239 -52
  44. package/packages/datadog-instrumentations/src/kafkajs.js +27 -0
  45. package/packages/datadog-instrumentations/src/mocha.js +154 -18
  46. package/packages/datadog-instrumentations/src/mongodb-core.js +34 -3
  47. package/packages/datadog-instrumentations/src/mongoose.js +23 -10
  48. package/packages/datadog-instrumentations/src/mquery.js +65 -0
  49. package/packages/datadog-instrumentations/src/net.js +10 -2
  50. package/packages/datadog-instrumentations/src/next.js +35 -9
  51. package/packages/datadog-instrumentations/src/playwright.js +110 -16
  52. package/packages/datadog-instrumentations/src/restify.js +14 -1
  53. package/packages/datadog-instrumentations/src/rhea.js +15 -9
  54. package/packages/datadog-plugin-aerospike/src/index.js +113 -0
  55. package/packages/datadog-plugin-amqplib/src/consumer.js +14 -1
  56. package/packages/datadog-plugin-amqplib/src/producer.js +13 -1
  57. package/packages/datadog-plugin-aws-sdk/src/base.js +3 -2
  58. package/packages/datadog-plugin-aws-sdk/src/services/kinesis.js +163 -27
  59. package/packages/datadog-plugin-aws-sdk/src/services/sns.js +46 -8
  60. package/packages/datadog-plugin-aws-sdk/src/services/sqs.js +129 -22
  61. package/packages/datadog-plugin-child_process/src/index.js +91 -0
  62. package/packages/datadog-plugin-child_process/src/scrub-cmd-params.js +125 -0
  63. package/packages/datadog-plugin-cucumber/src/index.js +70 -13
  64. package/packages/datadog-plugin-cypress/src/after-run.js +3 -0
  65. package/packages/datadog-plugin-cypress/src/after-spec.js +3 -0
  66. package/packages/datadog-plugin-cypress/src/cypress-plugin.js +625 -0
  67. package/packages/datadog-plugin-cypress/src/plugin.js +6 -454
  68. package/packages/datadog-plugin-cypress/src/support.js +50 -3
  69. package/packages/datadog-plugin-google-cloud-pubsub/src/consumer.js +2 -0
  70. package/packages/datadog-plugin-graphql/src/index.js +1 -6
  71. package/packages/datadog-plugin-graphql/src/resolve.js +28 -18
  72. package/packages/datadog-plugin-grpc/src/client.js +16 -2
  73. package/packages/datadog-plugin-grpc/src/util.js +1 -1
  74. package/packages/datadog-plugin-http/src/client.js +19 -2
  75. package/packages/datadog-plugin-jest/src/index.js +118 -12
  76. package/packages/datadog-plugin-jest/src/util.js +38 -16
  77. package/packages/datadog-plugin-kafkajs/src/consumer.js +76 -6
  78. package/packages/datadog-plugin-kafkajs/src/producer.js +64 -8
  79. package/packages/datadog-plugin-mocha/src/index.js +87 -17
  80. package/packages/datadog-plugin-next/src/index.js +40 -14
  81. package/packages/datadog-plugin-playwright/src/index.js +71 -8
  82. package/packages/datadog-plugin-rhea/src/consumer.js +16 -1
  83. package/packages/datadog-plugin-rhea/src/producer.js +10 -0
  84. package/packages/dd-trace/src/appsec/activation.js +29 -0
  85. package/packages/dd-trace/src/appsec/addresses.js +5 -1
  86. package/packages/dd-trace/src/appsec/api_security_sampler.js +61 -0
  87. package/packages/dd-trace/src/appsec/blocked_templates.js +4 -1
  88. package/packages/dd-trace/src/appsec/blocking.js +95 -43
  89. package/packages/dd-trace/src/appsec/channels.js +7 -3
  90. package/packages/dd-trace/src/appsec/graphql.js +146 -0
  91. package/packages/dd-trace/src/appsec/iast/analyzers/analyzers.js +2 -0
  92. package/packages/dd-trace/src/appsec/iast/analyzers/command-injection-analyzer.js +1 -1
  93. package/packages/dd-trace/src/appsec/iast/analyzers/header-injection-analyzer.js +105 -0
  94. package/packages/dd-trace/src/appsec/iast/analyzers/nosql-injection-mongodb-analyzer.js +22 -17
  95. package/packages/dd-trace/src/appsec/iast/analyzers/sql-injection-analyzer.js +7 -28
  96. package/packages/dd-trace/src/appsec/iast/analyzers/vulnerability-analyzer.js +10 -6
  97. package/packages/dd-trace/src/appsec/iast/analyzers/weak-randomness-analyzer.js +19 -0
  98. package/packages/dd-trace/src/appsec/iast/context/context-plugin.js +90 -0
  99. package/packages/dd-trace/src/appsec/iast/context/kafka-ctx-plugin.js +14 -0
  100. package/packages/dd-trace/src/appsec/iast/iast-log.js +1 -1
  101. package/packages/dd-trace/src/appsec/iast/iast-plugin.js +13 -2
  102. package/packages/dd-trace/src/appsec/iast/index.js +15 -5
  103. package/packages/dd-trace/src/appsec/iast/overhead-controller.js +1 -1
  104. package/packages/dd-trace/src/appsec/iast/path-line.js +1 -1
  105. package/packages/dd-trace/src/appsec/iast/taint-tracking/csi-methods.js +2 -0
  106. package/packages/dd-trace/src/appsec/iast/taint-tracking/index.js +10 -0
  107. package/packages/dd-trace/src/appsec/iast/taint-tracking/operations-taint-object.js +53 -0
  108. package/packages/dd-trace/src/appsec/iast/taint-tracking/operations.js +10 -46
  109. package/packages/dd-trace/src/appsec/iast/taint-tracking/plugin.js +13 -9
  110. package/packages/dd-trace/src/appsec/iast/taint-tracking/plugins/kafka.js +47 -0
  111. package/packages/dd-trace/src/appsec/iast/taint-tracking/rewriter.js +19 -6
  112. package/packages/dd-trace/src/appsec/iast/taint-tracking/source-types.js +3 -1
  113. package/packages/dd-trace/src/appsec/iast/taint-tracking/taint-tracking-impl.js +41 -3
  114. package/packages/dd-trace/src/appsec/iast/vulnerabilities-formatter/constants.js +7 -0
  115. package/packages/dd-trace/src/appsec/iast/vulnerabilities-formatter/evidence-redaction/sensitive-analyzers/command-sensitive-analyzer.js +12 -19
  116. package/packages/dd-trace/src/appsec/iast/vulnerabilities-formatter/evidence-redaction/sensitive-analyzers/header-sensitive-analyzer.js +20 -0
  117. package/packages/dd-trace/src/appsec/iast/vulnerabilities-formatter/evidence-redaction/sensitive-analyzers/json-sensitive-analyzer.js +6 -10
  118. package/packages/dd-trace/src/appsec/iast/vulnerabilities-formatter/evidence-redaction/sensitive-analyzers/ldap-sensitive-analyzer.js +18 -25
  119. package/packages/dd-trace/src/appsec/iast/vulnerabilities-formatter/evidence-redaction/sensitive-analyzers/sql-sensitive-analyzer.js +79 -85
  120. package/packages/dd-trace/src/appsec/iast/vulnerabilities-formatter/evidence-redaction/sensitive-analyzers/url-sensitive-analyzer.js +27 -36
  121. package/packages/dd-trace/src/appsec/iast/vulnerabilities-formatter/evidence-redaction/sensitive-handler.js +14 -11
  122. package/packages/dd-trace/src/appsec/iast/vulnerabilities-formatter/utils.js +1 -1
  123. package/packages/dd-trace/src/appsec/iast/vulnerabilities.js +2 -0
  124. package/packages/dd-trace/src/appsec/index.js +49 -33
  125. package/packages/dd-trace/src/appsec/recommended.json +1763 -106
  126. package/packages/dd-trace/src/appsec/remote_config/capabilities.js +7 -1
  127. package/packages/dd-trace/src/appsec/remote_config/index.js +42 -16
  128. package/packages/dd-trace/src/appsec/remote_config/manager.js +9 -8
  129. package/packages/dd-trace/src/appsec/reporter.js +51 -34
  130. package/packages/dd-trace/src/appsec/rule_manager.js +11 -8
  131. package/packages/dd-trace/src/appsec/sdk/user_blocking.js +1 -1
  132. package/packages/dd-trace/src/appsec/waf/waf_context_wrapper.js +28 -13
  133. package/packages/dd-trace/src/appsec/waf/waf_manager.js +0 -1
  134. package/packages/dd-trace/src/ci-visibility/{intelligent-test-runner/get-itr-configuration.js → early-flake-detection/get-known-tests.js} +17 -22
  135. package/packages/dd-trace/src/ci-visibility/exporters/agent-proxy/index.js +25 -6
  136. package/packages/dd-trace/src/ci-visibility/exporters/agentless/coverage-writer.js +30 -1
  137. package/packages/dd-trace/src/ci-visibility/exporters/agentless/index.js +2 -0
  138. package/packages/dd-trace/src/ci-visibility/exporters/agentless/writer.js +30 -1
  139. package/packages/dd-trace/src/ci-visibility/exporters/ci-visibility-exporter.js +95 -37
  140. package/packages/dd-trace/src/ci-visibility/exporters/git/git_metadata.js +134 -61
  141. package/packages/dd-trace/src/ci-visibility/intelligent-test-runner/get-skippable-suites.js +37 -4
  142. package/packages/dd-trace/src/ci-visibility/requests/get-library-configuration.js +131 -0
  143. package/packages/dd-trace/src/ci-visibility/telemetry.js +130 -0
  144. package/packages/dd-trace/src/config.js +561 -470
  145. package/packages/dd-trace/src/data_streams_context.js +1 -1
  146. package/packages/dd-trace/src/datastreams/pathway.js +58 -1
  147. package/packages/dd-trace/src/datastreams/processor.js +196 -27
  148. package/packages/dd-trace/src/datastreams/writer.js +11 -5
  149. package/packages/dd-trace/src/dogstatsd.js +3 -5
  150. package/packages/dd-trace/src/encode/agentless-ci-visibility.js +44 -6
  151. package/packages/dd-trace/src/encode/coverage-ci-visibility.js +14 -0
  152. package/packages/dd-trace/src/exporters/common/agent-info-exporter.js +4 -0
  153. package/packages/dd-trace/src/exporters/common/form-data.js +4 -0
  154. package/packages/dd-trace/src/exporters/common/request.js +21 -3
  155. package/packages/dd-trace/src/format.js +30 -2
  156. package/packages/dd-trace/src/id.js +12 -0
  157. package/packages/dd-trace/src/iitm.js +1 -1
  158. package/packages/dd-trace/src/log/channels.js +1 -1
  159. package/packages/dd-trace/src/noop/proxy.js +4 -0
  160. package/packages/dd-trace/src/noop/span.js +1 -0
  161. package/packages/dd-trace/src/opentelemetry/span.js +104 -4
  162. package/packages/dd-trace/src/opentelemetry/tracer.js +9 -10
  163. package/packages/dd-trace/src/opentracing/propagation/text_map.js +16 -7
  164. package/packages/dd-trace/src/opentracing/span.js +48 -4
  165. package/packages/dd-trace/src/opentracing/span_context.js +15 -6
  166. package/packages/dd-trace/src/opentracing/tracer.js +4 -3
  167. package/packages/dd-trace/src/plugin_manager.js +1 -1
  168. package/packages/dd-trace/src/plugins/ci_plugin.js +78 -19
  169. package/packages/dd-trace/src/plugins/database.js +1 -1
  170. package/packages/dd-trace/src/plugins/index.js +7 -0
  171. package/packages/dd-trace/src/plugins/plugin.js +1 -1
  172. package/packages/dd-trace/src/plugins/util/ci.js +6 -19
  173. package/packages/dd-trace/src/plugins/util/git.js +104 -22
  174. package/packages/dd-trace/src/plugins/util/ip_extractor.js +7 -6
  175. package/packages/dd-trace/src/plugins/util/test.js +60 -10
  176. package/packages/dd-trace/src/plugins/util/url.js +26 -0
  177. package/packages/dd-trace/src/plugins/util/user-provided-git.js +4 -16
  178. package/packages/dd-trace/src/plugins/util/web.js +1 -1
  179. package/packages/dd-trace/src/priority_sampler.js +30 -38
  180. package/packages/dd-trace/src/profiler.js +5 -3
  181. package/packages/dd-trace/src/profiling/config.js +77 -24
  182. package/packages/dd-trace/src/profiling/exporters/agent.js +77 -31
  183. package/packages/dd-trace/src/profiling/exporters/file.js +2 -1
  184. package/packages/dd-trace/src/profiling/profiler.js +33 -22
  185. package/packages/dd-trace/src/profiling/profilers/events.js +270 -0
  186. package/packages/dd-trace/src/profiling/profilers/shared.js +45 -0
  187. package/packages/dd-trace/src/profiling/profilers/space.js +18 -2
  188. package/packages/dd-trace/src/profiling/profilers/wall.js +146 -70
  189. package/packages/dd-trace/src/proxy.js +56 -24
  190. package/packages/dd-trace/src/ritm.js +1 -1
  191. package/packages/dd-trace/src/sampling_rule.js +130 -0
  192. package/packages/dd-trace/src/service-naming/schemas/v0/storage.js +5 -0
  193. package/packages/dd-trace/src/service-naming/schemas/v1/storage.js +4 -0
  194. package/packages/dd-trace/src/span_processor.js +9 -1
  195. package/packages/dd-trace/src/span_sampler.js +6 -64
  196. package/packages/dd-trace/src/spanleak.js +98 -0
  197. package/packages/dd-trace/src/startup-log.js +7 -1
  198. package/packages/dd-trace/src/telemetry/dependencies.js +56 -10
  199. package/packages/dd-trace/src/telemetry/index.js +182 -53
  200. package/packages/dd-trace/src/telemetry/logs/index.js +2 -2
  201. package/packages/dd-trace/src/telemetry/send-data.js +65 -7
  202. package/packages/dd-trace/src/tracer.js +12 -5
  203. package/register.js +4 -0
  204. package/scripts/install_plugin_modules.js +11 -3
  205. package/scripts/st.js +105 -0
  206. package/packages/datadog-instrumentations/src/child-process.js +0 -30
  207. package/packages/dd-trace/src/plugins/util/exec.js +0 -13
  208. package/packages/diagnostics_channel/index.js +0 -3
  209. package/packages/diagnostics_channel/src/index.js +0 -121
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dd-trace",
3
- "version": "4.18.0",
3
+ "version": "5.6.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",
@@ -36,6 +36,7 @@
36
36
  "test:integration:cucumber": "mocha --colors --timeout 30000 \"integration-tests/cucumber/*.spec.js\"",
37
37
  "test:integration:cypress": "mocha --colors --timeout 30000 \"integration-tests/cypress/*.spec.js\"",
38
38
  "test:integration:playwright": "mocha --colors --timeout 30000 \"integration-tests/playwright/*.spec.js\"",
39
+ "test:integration:profiler": "mocha --colors --timeout 90000 \"integration-tests/profiler/*.spec.js\"",
39
40
  "test:integration:serverless": "mocha --colors --timeout 30000 \"integration-tests/serverless/*.spec.js\"",
40
41
  "test:integration:plugins": "mocha --colors --exit -r \"packages/dd-trace/test/setup/mocha.js\" \"packages/datadog-plugin-@($(echo $PLUGINS))/test/integration-test/**/*.spec.js\"",
41
42
  "test:unit:plugins": "mocha --colors --exit -r \"packages/dd-trace/test/setup/mocha.js\" \"packages/datadog-instrumentations/test/@($(echo $PLUGINS)).spec.js\" \"packages/datadog-plugin-@($(echo $PLUGINS))/test/**/*.spec.js\" --exclude \"packages/datadog-plugin-@($(echo $PLUGINS))/test/integration-test/**/*.spec.js\"",
@@ -65,31 +66,28 @@
65
66
  },
66
67
  "homepage": "https://github.com/DataDog/dd-trace-js#readme",
67
68
  "engines": {
68
- "node": ">=16"
69
+ "node": ">=18"
69
70
  },
70
71
  "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",
72
+ "@datadog/native-appsec": "7.1.0",
73
+ "@datadog/native-iast-rewriter": "2.2.3",
74
+ "@datadog/native-iast-taint-tracking": "1.7.0",
74
75
  "@datadog/native-metrics": "^2.0.0",
75
- "@datadog/pprof": "4.0.1",
76
+ "@datadog/pprof": "5.1.0",
76
77
  "@datadog/sketches-js": "^2.1.0",
77
78
  "@opentelemetry/api": "^1.0.0",
78
79
  "@opentelemetry/core": "^1.14.0",
79
80
  "crypto-randomuuid": "^1.0.0",
80
- "diagnostics_channel": "^1.1.0",
81
+ "dc-polyfill": "^0.1.4",
81
82
  "ignore": "^5.2.4",
82
- "import-in-the-middle": "^1.4.2",
83
+ "import-in-the-middle": "^1.7.3",
83
84
  "int64-buffer": "^0.1.9",
84
85
  "ipaddr.js": "^2.1.0",
85
86
  "istanbul-lib-coverage": "3.2.0",
86
87
  "jest-docblock": "^29.7.0",
87
88
  "koalas": "^1.0.2",
88
- "limiter": "^1.1.4",
89
- "lodash.kebabcase": "^4.1.1",
90
- "lodash.pick": "^4.4.0",
89
+ "limiter": "1.1.5",
91
90
  "lodash.sortby": "^4.7.0",
92
- "lodash.uniq": "^4.5.0",
93
91
  "lru-cache": "^7.14.0",
94
92
  "methods": "^1.1.2",
95
93
  "module-details-from-path": "^1.0.3",
@@ -97,15 +95,18 @@
97
95
  "node-abort-controller": "^3.1.1",
98
96
  "opentracing": ">=0.12.1",
99
97
  "path-to-regexp": "^0.1.2",
100
- "protobufjs": "^7.2.4",
98
+ "pprof-format": "^2.0.7",
99
+ "protobufjs": "^7.2.5",
101
100
  "retry": "^0.13.1",
102
- "semver": "^7.5.4"
101
+ "semver": "^7.5.4",
102
+ "shell-quote": "^1.8.1",
103
+ "tlhunter-sorted-set": "^0.1.0"
103
104
  },
104
105
  "devDependencies": {
105
- "@types/node": ">=16",
106
+ "@types/node": ">=18",
106
107
  "autocannon": "^4.5.2",
107
108
  "aws-sdk": "^2.1446.0",
108
- "axios": "^0.21.2",
109
+ "axios": "^1.6.7",
109
110
  "benchmark": "^2.1.4",
110
111
  "body-parser": "^1.20.2",
111
112
  "chai": "^4.3.7",
@@ -129,11 +130,10 @@
129
130
  "jszip": "^3.5.0",
130
131
  "knex": "^2.4.2",
131
132
  "mkdirp": "^3.0.1",
132
- "mocha": "8",
133
+ "mocha": "^9",
133
134
  "multer": "^1.4.5-lts.1",
134
135
  "nock": "^11.3.3",
135
136
  "nyc": "^15.1.0",
136
- "pprof-format": "^2.0.7",
137
137
  "proxyquire": "^1.8.0",
138
138
  "rimraf": "^3.0.0",
139
139
  "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')
@@ -0,0 +1,11 @@
1
+ 'use strict'
2
+
3
+ module.exports = (object, path) => {
4
+ const pathArr = path.split('.')
5
+ let val = object
6
+ for (const p of pathArr) {
7
+ if (val === undefined) return val
8
+ val = val[p]
9
+ }
10
+ return val
11
+ }
@@ -0,0 +1,14 @@
1
+ 'use strict'
2
+
3
+ module.exports = (object, path) => {
4
+ const pathArr = path.split('.')
5
+ let property = object
6
+ for (const n of pathArr) {
7
+ if (property.hasOwnProperty(n)) {
8
+ property = property[n]
9
+ } else {
10
+ return false
11
+ }
12
+ }
13
+ return true
14
+ }
@@ -0,0 +1,16 @@
1
+ 'use strict'
2
+
3
+ module.exports = str => {
4
+ if (typeof str !== 'string') {
5
+ throw new TypeError('Expected a string')
6
+ }
7
+
8
+ return str
9
+ .trim()
10
+ .replace(/([a-z])([A-Z])/g, '$1-$2')
11
+ .replace(/\s+/g, '-')
12
+ .replace(/^-+|-+$/g, '')
13
+ .replace(/_/g, '-')
14
+ .replace(/-{2,}/g, '-')
15
+ .toLowerCase()
16
+ }
@@ -0,0 +1,11 @@
1
+ 'use strict'
2
+
3
+ module.exports = (object, props) => {
4
+ const result = {}
5
+ props.forEach(prop => {
6
+ if (prop in object) {
7
+ result[prop] = object[prop]
8
+ }
9
+ })
10
+ return result
11
+ }
@@ -0,0 +1,16 @@
1
+ 'use strict'
2
+
3
+ module.exports = (object, path, value) => {
4
+ const pathArr = path.split('.')
5
+ let property = object
6
+ let i
7
+ for (i = 0; i < pathArr.length - 1; i++) {
8
+ const n = pathArr[i]
9
+ if (property.hasOwnProperty(n)) {
10
+ property = property[n]
11
+ } else {
12
+ property[n] = property = {}
13
+ }
14
+ }
15
+ property[pathArr[i]] = value
16
+ }
@@ -0,0 +1,5 @@
1
+ 'use strict'
2
+
3
+ module.exports = function (arr) {
4
+ return [...new Set(arr)]
5
+ }
@@ -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
+ })
@@ -5,7 +5,7 @@ const {
5
5
  addHook,
6
6
  AsyncResource
7
7
  } = require('./helpers/instrument')
8
- const kebabCase = require('lodash.kebabcase')
8
+ const kebabCase = require('../../datadog-core/src/utils/src/kebabcase')
9
9
  const shimmer = require('../../datadog-shimmer')
10
10
 
11
11
  const startCh = channel('apm:amqplib:command:start')
@@ -28,7 +28,7 @@ addHook({ name: 'amqplib', file: 'lib/channel.js', versions: ['>=0.5'] }, channe
28
28
  })
29
29
 
30
30
  shimmer.wrap(channel.Channel.prototype, 'sendMessage', sendMessage => function (fields) {
31
- return instrument(sendMessage, this, arguments, 'basic.publish', fields)
31
+ return instrument(sendMessage, this, arguments, 'basic.publish', fields, arguments[2])
32
32
  })
33
33
 
34
34
  shimmer.wrap(channel.BaseChannel.prototype, 'dispatchMessage', dispatchMessage => function (fields, message) {
@@ -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)
@@ -0,0 +1,150 @@
1
+ 'use strict'
2
+
3
+ const util = require('util')
4
+
5
+ const {
6
+ addHook,
7
+ AsyncResource
8
+ } = require('./helpers/instrument')
9
+ const shimmer = require('../../datadog-shimmer')
10
+ const dc = require('dc-polyfill')
11
+
12
+ const childProcessChannel = dc.tracingChannel('datadog:child_process:execution')
13
+
14
+ // ignored exec method because it calls to execFile directly
15
+ const execAsyncMethods = ['execFile', 'spawn']
16
+ const execSyncMethods = ['execFileSync', 'spawnSync']
17
+
18
+ const names = ['child_process', 'node:child_process']
19
+
20
+ // child_process and node:child_process returns the same object instance, we only want to add hooks once
21
+ let patched = false
22
+ names.forEach(name => {
23
+ addHook({ name }, childProcess => {
24
+ if (!patched) {
25
+ patched = true
26
+ shimmer.massWrap(childProcess, execAsyncMethods, wrapChildProcessAsyncMethod())
27
+ shimmer.massWrap(childProcess, execSyncMethods, wrapChildProcessSyncMethod())
28
+ shimmer.wrap(childProcess, 'execSync', wrapChildProcessSyncMethod(true))
29
+ }
30
+
31
+ return childProcess
32
+ })
33
+ })
34
+
35
+ function normalizeArgs (args, shell) {
36
+ const childProcessInfo = {
37
+ command: args[0]
38
+ }
39
+
40
+ if (Array.isArray(args[1])) {
41
+ childProcessInfo.command = childProcessInfo.command + ' ' + args[1].join(' ')
42
+ if (args[2] != null && typeof args[2] === 'object') {
43
+ childProcessInfo.options = args[2]
44
+ }
45
+ } else if (args[1] != null && typeof args[1] === 'object') {
46
+ childProcessInfo.options = args[1]
47
+ }
48
+ childProcessInfo.shell = shell ||
49
+ childProcessInfo.options?.shell === true ||
50
+ typeof childProcessInfo.options?.shell === 'string'
51
+
52
+ return childProcessInfo
53
+ }
54
+
55
+ function wrapChildProcessSyncMethod (shell = false) {
56
+ return function wrapMethod (childProcessMethod) {
57
+ return function () {
58
+ if (!childProcessChannel.start.hasSubscribers || arguments.length === 0) {
59
+ return childProcessMethod.apply(this, arguments)
60
+ }
61
+
62
+ const childProcessInfo = normalizeArgs(arguments, shell)
63
+
64
+ return childProcessChannel.traceSync(
65
+ childProcessMethod,
66
+ {
67
+ command: childProcessInfo.command,
68
+ shell: childProcessInfo.shell
69
+ },
70
+ this,
71
+ ...arguments)
72
+ }
73
+ }
74
+ }
75
+
76
+ function wrapChildProcessCustomPromisifyMethod (customPromisifyMethod, shell) {
77
+ return function () {
78
+ if (!childProcessChannel.start.hasSubscribers || arguments.length === 0) {
79
+ return customPromisifyMethod.apply(this, arguments)
80
+ }
81
+
82
+ const childProcessInfo = normalizeArgs(arguments, shell)
83
+
84
+ return childProcessChannel.tracePromise(
85
+ customPromisifyMethod,
86
+ {
87
+ command: childProcessInfo.command,
88
+ shell: childProcessInfo.shell
89
+ },
90
+ this,
91
+ ...arguments)
92
+ }
93
+ }
94
+
95
+ function wrapChildProcessAsyncMethod (shell = false) {
96
+ return function wrapMethod (childProcessMethod) {
97
+ function wrappedChildProcessMethod () {
98
+ if (!childProcessChannel.start.hasSubscribers || arguments.length === 0) {
99
+ return childProcessMethod.apply(this, arguments)
100
+ }
101
+
102
+ const childProcessInfo = normalizeArgs(arguments, shell)
103
+
104
+ const innerResource = new AsyncResource('bound-anonymous-fn')
105
+ return innerResource.runInAsyncScope(() => {
106
+ childProcessChannel.start.publish({ command: childProcessInfo.command, shell: childProcessInfo.shell })
107
+
108
+ const childProcess = childProcessMethod.apply(this, arguments)
109
+ if (childProcess) {
110
+ let errorExecuted = false
111
+
112
+ childProcess.on('error', (e) => {
113
+ errorExecuted = true
114
+ childProcessChannel.error.publish(e)
115
+ })
116
+
117
+ childProcess.on('close', (code) => {
118
+ code = code || 0
119
+ if (!errorExecuted && code !== 0) {
120
+ childProcessChannel.error.publish()
121
+ }
122
+ childProcessChannel.asyncEnd.publish({
123
+ command: childProcessInfo.command,
124
+ shell: childProcessInfo.shell,
125
+ result: code
126
+ })
127
+ })
128
+ }
129
+
130
+ return childProcess
131
+ })
132
+ }
133
+
134
+ if (childProcessMethod[util.promisify.custom]) {
135
+ const wrapedChildProcessCustomPromisifyMethod =
136
+ shimmer.wrap(childProcessMethod[util.promisify.custom],
137
+ wrapChildProcessCustomPromisifyMethod(childProcessMethod[util.promisify.custom]), shell)
138
+
139
+ // should do it in this way because the original property is readonly
140
+ const descriptor = Object.getOwnPropertyDescriptor(childProcessMethod, util.promisify.custom)
141
+ Object.defineProperty(wrappedChildProcessMethod,
142
+ util.promisify.custom,
143
+ {
144
+ ...descriptor,
145
+ value: wrapedChildProcessCustomPromisifyMethod
146
+ })
147
+ }
148
+ return wrappedChildProcessMethod
149
+ }
150
+ }
@@ -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