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
@@ -1,9 +1,14 @@
1
+
1
2
  const request = require('../exporters/common/request')
3
+ const log = require('../log')
4
+ const { isTrue } = require('../util')
5
+
6
+ let agentTelemetry = true
2
7
 
3
8
  function getHeaders (config, application, reqType) {
4
9
  const headers = {
5
10
  'content-type': 'application/json',
6
- 'dd-telemetry-api-version': 'v1',
11
+ 'dd-telemetry-api-version': 'v2',
7
12
  'dd-telemetry-request-type': reqType,
8
13
  'dd-client-library-language': application.language_name,
9
14
  'dd-client-library-version': application.tracer_version
@@ -12,9 +17,19 @@ function getHeaders (config, application, reqType) {
12
17
  if (debug) {
13
18
  headers['dd-telemetry-debug-enabled'] = 'true'
14
19
  }
20
+ if (config.apiKey) {
21
+ headers['dd-api-key'] = config.apiKey
22
+ }
15
23
  return headers
16
24
  }
17
25
 
26
+ function getAgentlessTelemetryEndpoint (site) {
27
+ if (site === 'datad0g.com') { // staging
28
+ return 'https://all-http-intake.logs.datad0g.com'
29
+ }
30
+ return `https://instrumentation-telemetry-intake.${site}`
31
+ }
32
+
18
33
  let seqId = 0
19
34
 
20
35
  function getPayload (payload) {
@@ -28,23 +43,39 @@ function getPayload (payload) {
28
43
  }
29
44
  }
30
45
 
31
- function sendData (config, application, host, reqType, payload = {}) {
46
+ function sendData (config, application, host, reqType, payload = {}, cb = () => {}) {
32
47
  const {
33
48
  hostname,
34
49
  port,
35
- url
50
+ isCiVisibility
36
51
  } = config
37
52
 
53
+ let url = config.url
54
+
55
+ const isCiVisibilityAgentlessMode = isCiVisibility && isTrue(process.env.DD_CIVISIBILITY_AGENTLESS_ENABLED)
56
+
57
+ if (isCiVisibilityAgentlessMode) {
58
+ try {
59
+ url = url || new URL(getAgentlessTelemetryEndpoint(config.site))
60
+ } catch (err) {
61
+ log.error(err)
62
+ // No point to do the request if the URL is invalid
63
+ return cb(err, { payload, reqType })
64
+ }
65
+ }
66
+
38
67
  const options = {
39
68
  url,
40
69
  hostname,
41
70
  port,
42
71
  method: 'POST',
43
- path: '/telemetry/proxy/api/v2/apmtelemetry',
72
+ path: isCiVisibilityAgentlessMode ? '/api/v2/apmtelemetry' : '/telemetry/proxy/api/v2/apmtelemetry',
44
73
  headers: getHeaders(config, application, reqType)
45
74
  }
75
+
46
76
  const data = JSON.stringify({
47
- api_version: 'v1',
77
+ api_version: 'v2',
78
+ naming_schema_version: config.spanAttributeSchema ? config.spanAttributeSchema : '',
48
79
  request_type: reqType,
49
80
  tracer_time: Math.floor(Date.now() / 1000),
50
81
  runtime_id: config.tags['runtime-id'],
@@ -54,8 +85,35 @@ function sendData (config, application, host, reqType, payload = {}) {
54
85
  host
55
86
  })
56
87
 
57
- request(data, options, () => {
58
- // ignore errors
88
+ request(data, options, (error) => {
89
+ if (error && process.env.DD_API_KEY && config.site) {
90
+ if (agentTelemetry) {
91
+ log.warn('Agent telemetry failed, started agentless telemetry')
92
+ agentTelemetry = false
93
+ }
94
+ // figure out which data center to send to
95
+ const backendUrl = getAgentlessTelemetryEndpoint(config.site)
96
+ const backendHeader = { ...options.headers, 'DD-API-KEY': process.env.DD_API_KEY }
97
+ const backendOptions = {
98
+ ...options,
99
+ url: backendUrl,
100
+ headers: backendHeader,
101
+ path: '/api/v2/apmtelemetry'
102
+ }
103
+ if (backendUrl) {
104
+ request(data, backendOptions, (error) => { log.error(error) })
105
+ } else {
106
+ log.error('Invalid Telemetry URL')
107
+ }
108
+ }
109
+
110
+ if (!error && !agentTelemetry) {
111
+ agentTelemetry = true
112
+ log.info('Started agent telemetry')
113
+ }
114
+
115
+ // call the callback function so that we can track the error and payload
116
+ cb(error, { payload, reqType })
59
117
  })
60
118
  }
61
119
 
@@ -8,7 +8,7 @@ const { isError } = require('./util')
8
8
  const { setStartupLogConfig } = require('./startup-log')
9
9
  const { ERROR_MESSAGE, ERROR_TYPE, ERROR_STACK } = require('../../dd-trace/src/constants')
10
10
  const { DataStreamsProcessor } = require('./datastreams/processor')
11
- const { decodePathwayContext } = require('./datastreams/pathway')
11
+ const { DsmPathwayCodec } = require('./datastreams/pathway')
12
12
  const { DD_MAJOR } = require('../../../version')
13
13
  const DataStreamsContext = require('./data_streams_context')
14
14
 
@@ -31,19 +31,25 @@ class DatadogTracer extends Tracer {
31
31
 
32
32
  // todo[piochelepiotr] These two methods are not related to the tracer, but to data streams monitoring.
33
33
  // They should be moved outside of the tracer in the future.
34
- setCheckpoint (edgeTags) {
35
- const ctx = this._dataStreamsProcessor.setCheckpoint(edgeTags, DataStreamsContext.getDataStreamsContext())
34
+ setCheckpoint (edgeTags, span, payloadSize = 0) {
35
+ const ctx = this._dataStreamsProcessor.setCheckpoint(
36
+ edgeTags, span, DataStreamsContext.getDataStreamsContext(), payloadSize
37
+ )
36
38
  DataStreamsContext.setDataStreamsContext(ctx)
37
39
  return ctx
38
40
  }
39
41
 
40
- decodeDataStreamsContext (data) {
41
- const ctx = decodePathwayContext(data)
42
+ decodeDataStreamsContext (carrier) {
43
+ const ctx = DsmPathwayCodec.decode(carrier)
42
44
  // we erase the previous context everytime we decode a new one
43
45
  DataStreamsContext.setDataStreamsContext(ctx)
44
46
  return ctx
45
47
  }
46
48
 
49
+ setOffset (offsetData) {
50
+ return this._dataStreamsProcessor.setOffset(offsetData)
51
+ }
52
+
47
53
  trace (name, options, fn) {
48
54
  options = Object.assign({
49
55
  childOf: this.scope().active()
@@ -129,6 +135,7 @@ class DatadogTracer extends Tracer {
129
135
 
130
136
  setUrl (url) {
131
137
  this._exporter.setUrl(url)
138
+ this._dataStreamsProcessor.setUrl(url)
132
139
  }
133
140
 
134
141
  scope () {
package/register.js ADDED
@@ -0,0 +1,4 @@
1
+ const { register } = require('node:module')
2
+ const { pathToFileURL } = require('node:url')
3
+
4
+ register('./loader-hook.mjs', pathToFileURL(__filename))
@@ -80,7 +80,9 @@ async function assertVersions () {
80
80
  }
81
81
 
82
82
  async function assertInstrumentation (instrumentation, external) {
83
- const versions = [].concat(instrumentation.versions || [])
83
+ const versions = process.env.PACKAGE_VERSION_RANGE ? [process.env.PACKAGE_VERSION_RANGE]
84
+ : [].concat(instrumentation.versions || [])
85
+
84
86
  for (const version of versions) {
85
87
  if (version) {
86
88
  await assertModules(instrumentation.name, semver.coerce(version).version, external)
@@ -130,8 +132,14 @@ async function assertPackage (name, version, dependency, external) {
130
132
  }
131
133
 
132
134
  if (!external) {
133
- pkg.workspaces = {
134
- nohoist: ['**/**']
135
+ if (name === 'aerospike') {
136
+ pkg.installConfig = {
137
+ 'hoistingLimits': 'workspaces'
138
+ }
139
+ } else {
140
+ pkg.workspaces = {
141
+ nohoist: ['**/**']
142
+ }
135
143
  }
136
144
  }
137
145
  fs.writeFileSync(filename(name, version, 'package.json'), JSON.stringify(pkg, null, 2) + '\n')
package/scripts/st.js ADDED
@@ -0,0 +1,105 @@
1
+ #!/usr/bin/env node
2
+ /* eslint-disable no-console, no-fallthrough */
3
+ 'use strict'
4
+
5
+ const path = require('path')
6
+ const { writeFileSync } = require('fs')
7
+ const { execSync } = require('child_process')
8
+
9
+ const ddtracePath = path.join(__dirname, '..')
10
+ const defaultTestPath = process.env.DD_ST_PATH || path.join(ddtracePath, '..', 'system-tests')
11
+
12
+ const { buildAll, npm, testDir, testArgs } = parseArgs()
13
+
14
+ const binariesPath = path.join(testDir, 'binaries')
15
+
16
+ if (npm) {
17
+ console.log('Using NPM package:', npm)
18
+
19
+ writeFileSync(path.join(binariesPath, 'nodejs-load-from-npm'), npm)
20
+ } else {
21
+ console.log('Using local repo')
22
+
23
+ const packName = execSync(`npm pack ${ddtracePath}`, {
24
+ cwd: binariesPath,
25
+ stdio: [null, null, 'inherit'],
26
+ encoding: 'utf8'
27
+ }).slice(0, -1) // remove trailing newline
28
+
29
+ writeFileSync(path.join(binariesPath, 'nodejs-load-from-npm'), `/binaries/${packName}`)
30
+ }
31
+
32
+ try {
33
+ execSync(`./build.sh ${buildAll ? '' : '-i weblog'} && ./run.sh ${testArgs}`, {
34
+ cwd: testDir,
35
+ stdio: [null, 'inherit', 'inherit']
36
+ })
37
+ } catch (err) {
38
+ process.exit(err.status || 1)
39
+ }
40
+
41
+ function parseArgs () {
42
+ const args = {
43
+ buildAll: false,
44
+ npm: null,
45
+ testDir: defaultTestPath,
46
+ testArgs: ''
47
+ }
48
+
49
+ for (let i = 2; i < process.argv.length; i++) {
50
+ switch (process.argv[i]) {
51
+ case '-b':
52
+ case '--build-all':
53
+ args.buildAll = true
54
+ break
55
+
56
+ case '-h':
57
+ case '--help':
58
+ helpAndExit()
59
+ break
60
+
61
+ case '-n':
62
+ case '--npm': {
63
+ const arg = process.argv[i + 1]
64
+ if (!arg || arg[0] === '-') {
65
+ args.npm = 'dd-trace'
66
+ } else {
67
+ args.npm = arg
68
+ i++
69
+ }
70
+ break
71
+ }
72
+
73
+ case '-t':
74
+ case '--test-dir': {
75
+ const arg = process.argv[++i]
76
+ if (!arg || arg[0] === '-') helpAndExit()
77
+ args.testDir = arg
78
+ break
79
+ }
80
+
81
+ case '--':
82
+ args.testArgs = process.argv.slice(i + 1).join(' ')
83
+ return args
84
+
85
+ default:
86
+ console.log('Unknown option:', process.argv[i], '\n')
87
+ helpAndExit()
88
+ }
89
+ }
90
+
91
+ return args
92
+ }
93
+
94
+ function helpAndExit () {
95
+ console.log('Usage: node st.js [options...] [-- test-args]')
96
+ console.log('Options:')
97
+ console.log(' -b, --build-all Rebuild all images (default: only build weblog)')
98
+ console.log(' -h, --help Print this message')
99
+ console.log(' -n, --npm [package] Build a remote package instead of the local repo (default: "dd-trace")')
100
+ console.log(' Can be a package name (e.g. "dd-trace@4.2.0") or a git URL (e.g.')
101
+ console.log(' "git+https://github.com/DataDog/dd-trace-js.git#mybranch")')
102
+ console.log(' -t, --test-dir <path> Specify the system-tests directory (default: "dd-trace/../system-tests/")')
103
+ console.log(' -- <test-args> Passed to system-tests run.sh (e.g. "-- SCENARIO_NAME tests/path_to_test.py")')
104
+ process.exit()
105
+ }
@@ -1,30 +0,0 @@
1
- 'use strict'
2
-
3
- const {
4
- channel,
5
- addHook
6
- } = require('./helpers/instrument')
7
- const shimmer = require('../../datadog-shimmer')
8
-
9
- const childProcessChannel = channel('datadog:child_process:execution:start')
10
- const execMethods = ['exec', 'execFile', 'fork', 'spawn', 'execFileSync', 'execSync', 'spawnSync']
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
- })
17
- })
18
-
19
- function wrapChildProcessMethod () {
20
- function wrapMethod (childProcessMethod) {
21
- return function () {
22
- if (childProcessChannel.hasSubscribers && arguments.length > 0) {
23
- const command = arguments[0]
24
- childProcessChannel.publish({ command })
25
- }
26
- return childProcessMethod.apply(this, arguments)
27
- }
28
- }
29
- return wrapMethod
30
- }
@@ -1,13 +0,0 @@
1
- const cp = require('child_process')
2
- const log = require('../../log')
3
-
4
- const sanitizedExec = (cmd, flags, options = { stdio: 'pipe' }) => {
5
- try {
6
- return cp.execFileSync(cmd, flags, options).toString().replace(/(\r\n|\n|\r)/gm, '')
7
- } catch (e) {
8
- log.error(e)
9
- return ''
10
- }
11
- }
12
-
13
- module.exports = { sanitizedExec }
@@ -1,3 +0,0 @@
1
- 'use strict'
2
-
3
- module.exports = require('./src')
@@ -1,121 +0,0 @@
1
- 'use strict'
2
-
3
- const {
4
- Channel,
5
- channel
6
- } = require('diagnostics_channel') // eslint-disable-line n/no-restricted-require
7
-
8
- const [major, minor] = process.versions.node.split('.')
9
- const channels = new WeakSet()
10
-
11
- // Our own DC with a limited subset of functionality stable across Node versions.
12
- // TODO: Move the rest of the polyfill here.
13
- // TODO: Switch to using global subscribe/unsubscribe/hasSubscribers.
14
- const dc = { channel }
15
-
16
- // Prevent going to 0 subscribers to avoid bug in Node.
17
- // See https://github.com/nodejs/node/pull/47520
18
- if (major === '19' && minor === '9') {
19
- dc.channel = function () {
20
- const ch = channel.apply(this, arguments)
21
-
22
- if (!channels.has(ch)) {
23
- const subscribe = ch.subscribe
24
- const unsubscribe = ch.unsubscribe
25
-
26
- ch.subscribe = function () {
27
- delete ch.subscribe
28
- delete ch.unsubscribe
29
-
30
- const result = subscribe.apply(this, arguments)
31
-
32
- this.subscribe(() => {}) // Keep it active forever.
33
-
34
- return result
35
- }
36
-
37
- if (ch.unsubscribe === Channel.prototype.unsubscribe) {
38
- // Needed because another subscriber could have subscribed to something
39
- // that we unsubscribe to before the library is loaded.
40
- ch.unsubscribe = function () {
41
- delete ch.subscribe
42
- delete ch.unsubscribe
43
-
44
- this.subscribe(() => {}) // Keep it active forever.
45
-
46
- return unsubscribe.apply(this, arguments)
47
- }
48
- }
49
-
50
- channels.add(ch)
51
- }
52
-
53
- return ch
54
- }
55
- }
56
-
57
- if (!Channel.prototype.runStores) {
58
- const ActiveChannelPrototype = getActiveChannelPrototype()
59
-
60
- Channel.prototype.bindStore = ActiveChannelPrototype.bindStore = function (store, transform) {
61
- if (!this._stores) {
62
- this._stores = new Map()
63
- }
64
- this._stores.set(store, transform)
65
- }
66
-
67
- Channel.prototype.unbindStore = ActiveChannelPrototype.unbindStore = function (store) {
68
- if (!this._stores) return
69
- this._stores.delete(store)
70
- }
71
-
72
- Channel.prototype.runStores = ActiveChannelPrototype.runStores = function (data, fn, thisArg, ...args) {
73
- if (!this._stores) return Reflect.apply(fn, thisArg, args)
74
-
75
- let run = () => {
76
- this.publish(data)
77
- return Reflect.apply(fn, thisArg, args)
78
- }
79
-
80
- for (const entry of this._stores.entries()) {
81
- const store = entry[0]
82
- const transform = entry[1]
83
- run = wrapStoreRun(store, data, run, transform)
84
- }
85
-
86
- return run()
87
- }
88
- }
89
-
90
- function defaultTransform (data) {
91
- return data
92
- }
93
-
94
- function wrapStoreRun (store, data, next, transform = defaultTransform) {
95
- return () => {
96
- let context
97
- try {
98
- context = transform(data)
99
- } catch (err) {
100
- process.nextTick(() => {
101
- throw err
102
- })
103
- return next()
104
- }
105
-
106
- return store.run(context, next)
107
- }
108
- }
109
-
110
- function getActiveChannelPrototype () {
111
- const dummyChannel = channel('foo')
112
- const listener = () => {}
113
-
114
- dummyChannel.subscribe(listener)
115
- const ActiveChannelPrototype = Object.getPrototypeOf(dummyChannel)
116
- dummyChannel.unsubscribe(listener)
117
-
118
- return ActiveChannelPrototype
119
- }
120
-
121
- module.exports = dc