dd-trace 5.124.0 → 5.126.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 (208) hide show
  1. package/LICENSE-3rdparty.csv +3 -1
  2. package/ci/init.js +8 -3
  3. package/ci/test-optimization-validation/ci-package-scripts.js +2 -2
  4. package/ci/test-optimization-validation/ci-remediation.js +6 -6
  5. package/ci/test-optimization-validation/command-blocker.js +7 -5
  6. package/ci/test-optimization-validation/framework-adapters/cucumber.js +1 -1
  7. package/ci/test-optimization-validation/framework-adapters/vitest.js +3 -3
  8. package/ci/test-optimization-validation/package-check.js +1 -1
  9. package/ci/test-optimization-validation/report-writer.js +7 -5
  10. package/ci/vitest-no-worker-init-runner-setup.mjs +8 -0
  11. package/ci/vitest-no-worker-init-setup.mjs +13 -13
  12. package/ci/vitest-no-worker-init-v5-setup.mjs +4 -0
  13. package/index.d.ts +8 -0
  14. package/package.json +13 -10
  15. package/packages/datadog-esbuild/index.js +3 -1
  16. package/packages/datadog-instrumentations/src/cypress-config.js +19 -17
  17. package/packages/datadog-instrumentations/src/fs.js +24 -20
  18. package/packages/datadog-instrumentations/src/google-cloud-vertexai.js +2 -2
  19. package/packages/datadog-instrumentations/src/graphql.js +16 -16
  20. package/packages/datadog-instrumentations/src/helpers/graphql-jit-runtime.js +504 -0
  21. package/packages/datadog-instrumentations/src/helpers/hooks.js +2 -0
  22. package/packages/datadog-instrumentations/src/helpers/pool-acquire.js +265 -0
  23. package/packages/datadog-instrumentations/src/helpers/rewriter/compiler.js +1 -2
  24. package/packages/datadog-instrumentations/src/helpers/rewriter/index.js +95 -30
  25. package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/ai.js +0 -25
  26. package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/graphql-jit.js +83 -0
  27. package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/graphql.js +85 -1
  28. package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/index.js +1 -0
  29. package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/mercurius.js +30 -12
  30. package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/playwright.js +14 -5
  31. package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/webdriverio.js +251 -0
  32. package/packages/datadog-instrumentations/src/helpers/rewriter/targets.json +11 -1
  33. package/packages/datadog-instrumentations/src/helpers/rewriter/transforms.js +562 -27
  34. package/packages/datadog-instrumentations/src/jest.js +166 -45
  35. package/packages/datadog-instrumentations/src/knex.js +76 -0
  36. package/packages/datadog-instrumentations/src/mariadb.js +6 -0
  37. package/packages/datadog-instrumentations/src/mocha/common.js +59 -2
  38. package/packages/datadog-instrumentations/src/mocha/main.js +66 -20
  39. package/packages/datadog-instrumentations/src/mocha/utils.js +2 -1
  40. package/packages/datadog-instrumentations/src/mocha/webdriverio-protocol.js +98 -0
  41. package/packages/datadog-instrumentations/src/mocha/worker.js +12 -8
  42. package/packages/datadog-instrumentations/src/net.js +14 -17
  43. package/packages/datadog-instrumentations/src/next.js +212 -62
  44. package/packages/datadog-instrumentations/src/openai.js +42 -40
  45. package/packages/datadog-instrumentations/src/pg.js +15 -0
  46. package/packages/datadog-instrumentations/src/playwright.js +113 -13
  47. package/packages/datadog-instrumentations/src/rum-browser-scripts.js +40 -0
  48. package/packages/datadog-instrumentations/src/sequelize.js +94 -2
  49. package/packages/datadog-instrumentations/src/undici.js +53 -4
  50. package/packages/datadog-instrumentations/src/vitest-main-no-worker-init.js +37 -3
  51. package/packages/datadog-instrumentations/src/vitest-main.js +92 -9
  52. package/packages/datadog-instrumentations/src/vitest-worker.js +71 -14
  53. package/packages/datadog-instrumentations/src/webdriverio.js +965 -6
  54. package/packages/datadog-plugin-amqp10/src/consumer.js +3 -1
  55. package/packages/datadog-plugin-amqp10/src/producer.js +3 -1
  56. package/packages/datadog-plugin-amqp10/src/util.js +2 -1
  57. package/packages/datadog-plugin-avsc/src/schema_iterator.js +6 -1
  58. package/packages/datadog-plugin-aws-sdk/src/services/bedrockruntime/utils.js +16 -5
  59. package/packages/datadog-plugin-cassandra-driver/src/index.js +8 -3
  60. package/packages/datadog-plugin-cucumber/src/index.js +0 -2
  61. package/packages/datadog-plugin-cypress/src/cypress-plugin.js +262 -48
  62. package/packages/datadog-plugin-google-cloud-pubsub/src/client.js +4 -1
  63. package/packages/datadog-plugin-graphql/src/execute.js +998 -196
  64. package/packages/datadog-plugin-graphql/src/index.js +27 -7
  65. package/packages/datadog-plugin-graphql/src/jit.js +136 -0
  66. package/packages/datadog-plugin-graphql/src/request.js +18 -27
  67. package/packages/datadog-plugin-graphql/src/resolve-error.js +108 -0
  68. package/packages/datadog-plugin-graphql/src/tools/signature.js +1 -2
  69. package/packages/datadog-plugin-graphql/src/tools/transforms.js +45 -3
  70. package/packages/datadog-plugin-graphql/src/utils.js +208 -120
  71. package/packages/datadog-plugin-graphql/src/validate.js +10 -23
  72. package/packages/datadog-plugin-jest/src/index.js +0 -6
  73. package/packages/datadog-plugin-langchain/src/tracing.js +7 -0
  74. package/packages/datadog-plugin-mocha/src/index.js +403 -75
  75. package/packages/datadog-plugin-mongodb-core/src/query.js +6 -0
  76. package/packages/datadog-plugin-mysql/src/index.js +41 -15
  77. package/packages/datadog-plugin-net/src/tcp.js +3 -1
  78. package/packages/datadog-plugin-next/src/index.js +63 -29
  79. package/packages/datadog-plugin-playwright/src/index.js +167 -27
  80. package/packages/datadog-plugin-undici/src/index.js +27 -41
  81. package/packages/datadog-plugin-vitest/src/index.js +6 -12
  82. package/packages/dd-trace/src/aiguard/evaluation.js +2 -1
  83. package/packages/dd-trace/src/aiguard/messages/anthropic.js +8 -1
  84. package/packages/dd-trace/src/aiguard/messages/openai.js +8 -1
  85. package/packages/dd-trace/src/aiguard/messages/vercel-ai.js +20 -6
  86. package/packages/dd-trace/src/appsec/api_security/index.js +23 -6
  87. package/packages/dd-trace/src/appsec/api_security/sampler.js +99 -40
  88. package/packages/dd-trace/src/appsec/graphql.js +6 -2
  89. package/packages/dd-trace/src/appsec/iast/taint-tracking/plugin.js +3 -3
  90. package/packages/dd-trace/src/appsec/iast/taint-tracking/taint-tracking-impl.js +2 -1
  91. package/packages/dd-trace/src/appsec/iast/telemetry/span-tags.js +8 -2
  92. package/packages/dd-trace/src/appsec/iast/vulnerabilities-formatter/evidence-redaction/sensitive-analyzers/command-sensitive-analyzer.js +3 -1
  93. package/packages/dd-trace/src/appsec/iast/vulnerabilities-formatter/evidence-redaction/sensitive-analyzers/sql-sensitive-analyzer.js +531 -95
  94. package/packages/dd-trace/src/appsec/iast/vulnerabilities-formatter/evidence-redaction/sensitive-analyzers/url-sensitive-analyzer.js +1 -1
  95. package/packages/dd-trace/src/appsec/lambda.js +44 -26
  96. package/packages/dd-trace/src/ci-visibility/encode/json-encoder.js +32 -2
  97. package/packages/dd-trace/src/ci-visibility/exporters/agent-proxy/index.js +8 -8
  98. package/packages/dd-trace/src/ci-visibility/exporters/agentless/coverage-writer.js +6 -4
  99. package/packages/dd-trace/src/ci-visibility/exporters/agentless/di-logs-writer.js +20 -4
  100. package/packages/dd-trace/src/ci-visibility/exporters/agentless/request-tracker.js +5 -173
  101. package/packages/dd-trace/src/ci-visibility/exporters/agentless/writer.js +7 -6
  102. package/packages/dd-trace/src/ci-visibility/exporters/agents.js +54 -0
  103. package/packages/dd-trace/src/ci-visibility/exporters/ci-validation/writer.js +1 -2
  104. package/packages/dd-trace/src/ci-visibility/exporters/ci-visibility-exporter.js +394 -225
  105. package/packages/dd-trace/src/ci-visibility/exporters/limits.js +9 -0
  106. package/packages/dd-trace/src/ci-visibility/exporters/request.js +323 -31
  107. package/packages/dd-trace/src/ci-visibility/exporters/settings-cache-key.js +42 -0
  108. package/packages/dd-trace/src/ci-visibility/final-flush.js +2 -1
  109. package/packages/dd-trace/src/ci-visibility/requests/fs-cache.js +57 -18
  110. package/packages/dd-trace/src/ci-visibility/requests/get-library-configuration.js +0 -3
  111. package/packages/dd-trace/src/ci-visibility/requests/request.js +11 -0
  112. package/packages/dd-trace/src/ci-visibility/requests/upload-test-screenshot.js +164 -71
  113. package/packages/dd-trace/src/ci-visibility/requests/video-request.js +180 -0
  114. package/packages/dd-trace/src/ci-visibility/telemetry.js +10 -7
  115. package/packages/dd-trace/src/ci-visibility/test-video.js +61 -0
  116. package/packages/dd-trace/src/config/generated-config-types.d.ts +4 -0
  117. package/packages/dd-trace/src/config/index.js +73 -13
  118. package/packages/dd-trace/src/config/parsers.js +11 -1
  119. package/packages/dd-trace/src/config/stable.js +3 -3
  120. package/packages/dd-trace/src/config/supported-configurations.json +22 -2
  121. package/packages/dd-trace/src/crashtracking/crashtracker.js +82 -18
  122. package/packages/dd-trace/src/debugger/config.js +12 -1
  123. package/packages/dd-trace/src/debugger/constants.js +1 -0
  124. package/packages/dd-trace/src/debugger/devtools_client/breakpoints.js +2 -1
  125. package/packages/dd-trace/src/debugger/devtools_client/request-options.js +28 -0
  126. package/packages/dd-trace/src/debugger/devtools_client/send.js +7 -40
  127. package/packages/dd-trace/src/debugger/devtools_client/status.js +11 -6
  128. package/packages/dd-trace/src/debugger/devtools_client/tags.js +41 -0
  129. package/packages/dd-trace/src/debugger/index.js +23 -3
  130. package/packages/dd-trace/src/dogstatsd.js +510 -76
  131. package/packages/dd-trace/src/encode/0.4-cross-payload.js +170 -0
  132. package/packages/dd-trace/src/encode/0.4.js +5 -5
  133. package/packages/dd-trace/src/encode/agentless-ci-visibility.js +9 -8
  134. package/packages/dd-trace/src/evp_proxy/direct.js +3 -25
  135. package/packages/dd-trace/src/exporters/agent/index.js +2 -1
  136. package/packages/dd-trace/src/exporters/agent/writer.js +24 -7
  137. package/packages/dd-trace/src/exporters/agentless/index.js +7 -9
  138. package/packages/dd-trace/src/exporters/agentless/writer.js +103 -119
  139. package/packages/dd-trace/src/exporters/common/agents.js +28 -6
  140. package/packages/dd-trace/src/exporters/common/buffering-exporter.js +2 -2
  141. package/packages/dd-trace/src/exporters/common/final-flush-request-tracker.js +191 -0
  142. package/packages/dd-trace/src/exporters/common/proxy.js +52 -0
  143. package/packages/dd-trace/src/exporters/common/request.js +42 -14
  144. package/packages/dd-trace/src/exporters/common/url.js +40 -1
  145. package/packages/dd-trace/src/exporters/common/writer.js +9 -7
  146. package/packages/dd-trace/src/flush.js +6 -3
  147. package/packages/dd-trace/src/id.js +14 -0
  148. package/packages/dd-trace/src/index.js +5 -2
  149. package/packages/dd-trace/src/llmobs/experiments/dataset.js +2 -1
  150. package/packages/dd-trace/src/llmobs/index.js +32 -32
  151. package/packages/dd-trace/src/llmobs/plugins/ai/ddTelemetry.js +22 -71
  152. package/packages/dd-trace/src/llmobs/plugins/ai/vercelTelemetry.js +23 -13
  153. package/packages/dd-trace/src/llmobs/plugins/langchain/index.js +7 -0
  154. package/packages/dd-trace/src/llmobs/util.js +0 -33
  155. package/packages/dd-trace/src/llmobs/writers/base.js +49 -32
  156. package/packages/dd-trace/src/log/index.js +7 -1
  157. package/packages/dd-trace/src/{ci-visibility/log-submission → log-submission}/log-submission-plugin.js +48 -19
  158. package/packages/dd-trace/src/openfeature/writers/base.js +14 -12
  159. package/packages/dd-trace/src/openfeature/writers/util.js +1 -1
  160. package/packages/dd-trace/src/opentelemetry/logs/index.js +5 -24
  161. package/packages/dd-trace/src/opentelemetry/logs/otlp_http_log_exporter.js +14 -4
  162. package/packages/dd-trace/src/opentelemetry/metrics/index.js +15 -22
  163. package/packages/dd-trace/src/opentelemetry/metrics/otlp_http_metric_exporter.js +14 -4
  164. package/packages/dd-trace/src/opentelemetry/metrics/otlp_span_stats_exporter.js +10 -0
  165. package/packages/dd-trace/src/opentelemetry/otlp/otlp_http_exporter_base.js +5 -0
  166. package/packages/dd-trace/src/opentelemetry/otlp/otlp_transformer_base.js +19 -4
  167. package/packages/dd-trace/src/opentelemetry/resource-attributes.js +55 -0
  168. package/packages/dd-trace/src/opentelemetry/trace/index.js +6 -1
  169. package/packages/dd-trace/src/opentelemetry/trace/otlp_http_trace_exporter.js +10 -0
  170. package/packages/dd-trace/src/opentracing/propagation/text_map.js +101 -20
  171. package/packages/dd-trace/src/payload-tagging/index.js +2 -1
  172. package/packages/dd-trace/src/plugins/ci_plugin.js +1 -6
  173. package/packages/dd-trace/src/plugins/tracing.js +12 -10
  174. package/packages/dd-trace/src/plugins/util/ci.js +3 -1
  175. package/packages/dd-trace/src/plugins/util/inferred_proxy.js +16 -15
  176. package/packages/dd-trace/src/plugins/util/test.js +83 -20
  177. package/packages/dd-trace/src/plugins/util/url.js +2 -2
  178. package/packages/dd-trace/src/plugins/util/web.js +4 -9
  179. package/packages/dd-trace/src/priority_sampler.js +4 -0
  180. package/packages/dd-trace/src/profiling/config.js +1 -0
  181. package/packages/dd-trace/src/profiling/oom.js +7 -2
  182. package/packages/dd-trace/src/profiling/profiler.js +23 -13
  183. package/packages/dd-trace/src/profiling/profilers/space.js +38 -11
  184. package/packages/dd-trace/src/profiling/webspan-utils.js +7 -4
  185. package/packages/dd-trace/src/proxy.js +75 -5
  186. package/packages/dd-trace/src/remote_config/index.js +319 -101
  187. package/packages/dd-trace/src/remote_config/scheduler.js +37 -12
  188. package/packages/dd-trace/src/runtime_metrics/client.js +37 -8
  189. package/packages/dd-trace/src/runtime_metrics/otlp_runtime_metrics.js +5 -1
  190. package/packages/dd-trace/src/runtime_metrics/runtime_metrics.js +5 -1
  191. package/packages/dd-trace/src/sampling_rule.js +39 -10
  192. package/packages/dd-trace/src/serverless/telemetry-delivery-tracker.js +4 -8
  193. package/packages/dd-trace/src/serverless/vercel.js +53 -20
  194. package/packages/dd-trace/src/serverless.js +10 -3
  195. package/packages/dd-trace/src/service-naming/schemas/util.js +1 -1
  196. package/packages/dd-trace/src/span_processor.js +18 -3
  197. package/packages/dd-trace/src/span_stats.js +24 -28
  198. package/packages/dd-trace/src/startup-log.js +3 -2
  199. package/packages/dd-trace/src/telemetry/agentless-url.js +28 -0
  200. package/packages/dd-trace/src/telemetry/send-data.js +23 -20
  201. package/packages/dd-trace/src/telemetry/session-propagation.js +3 -2
  202. package/packages/dd-trace/src/tracer.js +4 -5
  203. package/packages/dd-trace/src/tracer_metadata.js +11 -3
  204. package/vendor/dist/@datadog/sketches-js/index.js +1 -1
  205. package/vendor/dist/protobufjs/index.js +1 -1
  206. package/vendor/dist/protobufjs/minimal/index.js +1 -1
  207. package/packages/datadog-instrumentations/src/playwright-browser-scripts.js +0 -27
  208. package/packages/dd-trace/src/encode/agentless-json.js +0 -210
@@ -3,12 +3,61 @@
3
3
  const { EOL, platform } = require('node:os')
4
4
 
5
5
  // Load binding first to not import other modules if it throws
6
- const libdatadog = require('@datadog/libdatadog')
7
- const binding = libdatadog.load('crashtracker')
6
+ const libdatadogExtras = require('@datadog/libdatadog-extras')
7
+ const binding = libdatadogExtras.load('crashtracker')
8
8
 
9
+ const { channel } = require('dc-polyfill')
10
+ const { getEnvironmentVariable } = require('../config/helper')
9
11
  const log = require('../log')
10
12
  const pkg = require('../../../../package.json')
11
13
  const processTags = require('../process-tags')
14
+ const getAgentlessTelemetryUrl = require('../telemetry/agentless-url')
15
+
16
+ const identityRefreshChannel = channel('datadog:identity:refresh')
17
+ const INHERITED_RECEIVER_ENVIRONMENT_VARIABLES = [
18
+ 'HTTP_PROXY',
19
+ 'HTTPS_PROXY',
20
+ 'NO_PROXY',
21
+ 'http_proxy',
22
+ 'https_proxy',
23
+ 'no_proxy',
24
+ 'SSL_CERT_FILE',
25
+ 'SSL_CERT_DIR',
26
+ ]
27
+
28
+ /**
29
+ * Builds the minimal receiver environment libdatadog needs to select its two direct crash
30
+ * destinations independently: instrumentation telemetry and Errors Tracking intake.
31
+ *
32
+ * @param {import('../config/config-base')} config - Tracer configuration
33
+ * @returns {Array<[string, string]>}
34
+ */
35
+ function getAgentlessReceiverEnvironment (config) {
36
+ if (!config.DD_API_KEY) {
37
+ throw new Error('DD_API_KEY is required for agentless crash tracking')
38
+ }
39
+
40
+ const site = config.site.toLowerCase()
41
+ const telemetryUrl = getAgentlessTelemetryUrl(site).origin
42
+
43
+ const environment = /** @type {Array<[string, string]>} */ ([
44
+ ['_DD_DIRECT_SUBMISSION_ENABLED', 'true'],
45
+ ['DD_API_KEY', config.DD_API_KEY],
46
+ ['DD_SITE', site],
47
+ ['DD_APM_TELEMETRY_DD_URL', telemetryUrl],
48
+ // libdatadog v43 parses the dedicated URL above but does not use it when constructing the
49
+ // endpoint. Keep this compatibility fallback until its telemetry config honors that setting.
50
+ ['DD_TRACE_AGENT_URL', telemetryUrl],
51
+ ])
52
+
53
+ // The receiver environment does not inherit from this process.
54
+ for (const name of INHERITED_RECEIVER_ENVIRONMENT_VARIABLES) {
55
+ const value = getEnvironmentVariable(name)
56
+ if (value) environment.push([name, value])
57
+ }
58
+
59
+ return environment
60
+ }
12
61
 
13
62
  class Crashtracker {
14
63
  #started = false
@@ -33,11 +82,12 @@ class Crashtracker {
33
82
  try {
34
83
  binding.init(
35
84
  this.#getConfig(config),
36
- this.#getReceiverConfig(),
85
+ this.#getReceiverConfig(config),
37
86
  this.#getMetadata(config)
38
87
  )
39
88
  this.#started = true
40
89
  this.#trackUnhandledExceptions()
90
+ identityRefreshChannel.subscribe((config) => this.configure(config))
41
91
  } catch (e) {
42
92
  log.error('Error initializing crashtracker', e)
43
93
  }
@@ -67,7 +117,21 @@ class Crashtracker {
67
117
  * @param {import('../config/config-base')} config - Tracer configuration
68
118
  */
69
119
  #getConfig (config) {
70
- const url = config.url
120
+ let endpoint = null
121
+ if (!config.DD_AGENTLESS_ENABLED) {
122
+ const url = config.url
123
+ endpoint = {
124
+ // TODO: Use the string directly when deserialization is fixed.
125
+ url: {
126
+ scheme: url.protocol.slice(0, -1),
127
+ authority: url.protocol === 'unix:'
128
+ ? Buffer.from(url.pathname).toString('hex')
129
+ : url.host,
130
+ path_and_query: '',
131
+ },
132
+ timeout_ms: 3000,
133
+ }
134
+ }
71
135
 
72
136
  // Out-of-process symbolication currently works on
73
137
  // Linux only, does not work on Mac.
@@ -80,17 +144,7 @@ class Crashtracker {
80
144
  collect_all_threads: true,
81
145
  create_alt_stack: true,
82
146
  use_alt_stack: true,
83
- endpoint: {
84
- // TODO: Use the string directly when deserialization is fixed.
85
- url: {
86
- scheme: url.protocol.slice(0, -1),
87
- authority: url.protocol === 'unix:'
88
- ? Buffer.from(url.pathname).toString('hex')
89
- : url.host,
90
- path_and_query: '',
91
- },
92
- timeout_ms: 3000,
93
- },
147
+ endpoint,
94
148
  timeout: { secs: 5, nanos: 0 },
95
149
  demangle_names: true,
96
150
  signals: [],
@@ -124,11 +178,21 @@ class Crashtracker {
124
178
  }
125
179
  }
126
180
 
127
- #getReceiverConfig () {
181
+ /**
182
+ * @param {import('../config/config-base')} config - Tracer configuration
183
+ * @returns {{
184
+ * args: string[],
185
+ * env: Array<[string, string]>,
186
+ * path_to_receiver_binary: string,
187
+ * stderr_filename: null,
188
+ * stdout_filename: null
189
+ * }}
190
+ */
191
+ #getReceiverConfig (config) {
128
192
  return {
129
193
  args: [],
130
- env: [],
131
- path_to_receiver_binary: libdatadog.find('crashtracker-receiver', true),
194
+ env: config.DD_AGENTLESS_ENABLED ? getAgentlessReceiverEnvironment(config) : [],
195
+ path_to_receiver_binary: libdatadogExtras.find('crashtracker-receiver', true),
132
196
  stderr_filename: null,
133
197
  stdout_filename: null,
134
198
  }
@@ -1,10 +1,21 @@
1
1
  'use strict'
2
2
 
3
+ const { createSiteUrl } = require('../exporters/common/url')
3
4
  const getGitMetadata = require('../git_metadata')
4
5
 
6
+ /**
7
+ * @param {ReturnType<import('../config')>} config
8
+ * @param {string} [inputPath]
9
+ */
5
10
  module.exports = function getDebuggerConfig (config, inputPath) {
6
11
  const { commitSHA, repositoryUrl } = getGitMetadata(config)
12
+ const agentless = config.DD_AGENTLESS_ENABLED
13
+ const agentlessUrl = agentless ? createSiteUrl(config.site, 'debugger-intake') : undefined
14
+ if (agentless && agentlessUrl === undefined) return
15
+
7
16
  return {
17
+ agentless,
18
+ apiKey: agentless ? config.DD_API_KEY : undefined,
8
19
  commitSHA,
9
20
  debug: config.debug,
10
21
  dynamicInstrumentation: config.dynamicInstrumentation,
@@ -16,7 +27,7 @@ module.exports = function getDebuggerConfig (config, inputPath) {
16
27
  repositoryUrl,
17
28
  runtimeId: config.tags['runtime-id'],
18
29
  service: config.service,
19
- url: config.url.toString(),
30
+ url: agentless ? agentlessUrl.origin : config.url.toString(),
20
31
  version: config.version,
21
32
  inputPath,
22
33
  }
@@ -1,6 +1,7 @@
1
1
  'use strict'
2
2
 
3
3
  module.exports = {
4
+ DEBUGGER_INPUT_DIRECT: '/api/v2/debugger',
4
5
  DEBUGGER_DIAGNOSTICS_V1: '/debugger/v1/diagnostics',
5
6
  DEBUGGER_INPUT_V1: '/debugger/v1/input',
6
7
  DEBUGGER_INPUT_V2: '/debugger/v2/input',
@@ -1,6 +1,7 @@
1
1
  'use strict'
2
2
 
3
- const mutex = require('../../../../../vendor/dist/mutexify/promise')()
3
+ const createMutex = require('../../../../../vendor/dist/mutexify/promise')
4
+ const mutex = createMutex()
4
5
  const { getGeneratedPosition } = require('./source-maps')
5
6
  const session = require('./session')
6
7
  const { compile, compileSegments, templateRequiresEvaluation } = require('./condition')
@@ -0,0 +1,28 @@
1
+ 'use strict'
2
+
3
+ /**
4
+ * @param {ReturnType<import('../config')>} config - Debugger configuration
5
+ * @param {string} path - Request path
6
+ * @param {Record<string, string>} headers - Payload headers
7
+ * @returns {{
8
+ * method: 'POST',
9
+ * url: string | URL,
10
+ * path: string,
11
+ * headers: Record<string, string>
12
+ * }}
13
+ */
14
+ module.exports = function getRequestOptions (config, path, headers) {
15
+ const options = {
16
+ method: 'POST',
17
+ url: config.url,
18
+ path,
19
+ headers,
20
+ }
21
+
22
+ if (config.agentless) {
23
+ if (config.apiKey !== undefined) headers['DD-API-KEY'] = config.apiKey
24
+ headers['DD-EVP-ORIGIN'] = 'agent-debugger'
25
+ }
26
+
27
+ return options
28
+ }
@@ -5,12 +5,13 @@ const { stringify } = require('querystring')
5
5
 
6
6
  const { version } = require('../../../../../package.json')
7
7
  const request = require('../../exporters/common/request')
8
- const { GIT_COMMIT_SHA, GIT_REPOSITORY_URL } = require('../../plugins/util/tags')
9
8
  const { DEBUGGER_DIAGNOSTICS_V1, DEBUGGER_INPUT_V2 } = require('../constants')
10
9
  const log = require('./log')
11
10
  const JSONBuffer = require('./json-buffer')
12
11
  const config = require('./config')
12
+ const getRequestOptions = require('./request-options')
13
13
  const { pruneSnapshot } = require('./snapshot-pruner')
14
+ const buildTags = require('./tags')
14
15
 
15
16
  module.exports = send
16
17
 
@@ -22,14 +23,7 @@ const ddsource = 'dd_debugger'
22
23
  const hostname = getHostname()
23
24
  const service = config.service
24
25
 
25
- const ddtags = buildTags([
26
- ['env', config.env],
27
- ['version', config.version],
28
- ['debugger_version', version],
29
- ['host_name', hostname],
30
- [GIT_COMMIT_SHA, config.commitSHA],
31
- [GIT_REPOSITORY_URL, config.repositoryUrl],
32
- ])
26
+ const ddtags = buildTags(config, hostname, version, log)
33
27
 
34
28
  let path
35
29
  setInputPath(config.inputPath)
@@ -85,7 +79,7 @@ function send (message, logger, dd, snapshot, processTags) {
85
79
  function onFlush (payload) {
86
80
  log.debug('[debugger:devtools_client] Flushing probe payload buffer')
87
81
 
88
- request(payload, buildRequestOpts(), (err, res, statusCode) => {
82
+ request(payload, buildRequestOptions(), (err, res, statusCode) => {
89
83
  if (!handleV2FallbackIfNeeded(statusCode, payload) && err) {
90
84
  log.error('[debugger:devtools_client] Error sending probe payload', err)
91
85
  }
@@ -108,7 +102,7 @@ function handleV2FallbackIfNeeded (statusCode, payload) {
108
102
 
109
103
  setInputPath(DEBUGGER_DIAGNOSTICS_V1)
110
104
 
111
- request(payload, buildRequestOpts(), (err) => {
105
+ request(payload, buildRequestOptions(), (err) => {
112
106
  if (err) {
113
107
  log.error('[debugger:devtools_client] Error sending probe payload after fallback to %s',
114
108
  DEBUGGER_DIAGNOSTICS_V1,
@@ -119,13 +113,8 @@ function handleV2FallbackIfNeeded (statusCode, payload) {
119
113
  return true
120
114
  }
121
115
 
122
- function buildRequestOpts () {
123
- return {
124
- method: 'POST',
125
- url: config.url,
126
- path,
127
- headers: { 'Content-Type': 'application/json; charset=utf-8' },
128
- }
116
+ function buildRequestOptions () {
117
+ return getRequestOptions(config, path, { 'Content-Type': 'application/json; charset=utf-8' })
129
118
  }
130
119
 
131
120
  /**
@@ -135,25 +124,3 @@ function setInputPath (newPath) {
135
124
  config.inputPath = newPath
136
125
  path = `${newPath}?${stringify({ ddtags })}`
137
126
  }
138
-
139
- /**
140
- * @param {Array<[string, unknown]>} tags - The tags to serialize.
141
- * @returns {string} The serialized tags.
142
- */
143
- function buildTags (tags) {
144
- let serializedTags = ''
145
-
146
- for (const [key, rawValue] of tags) {
147
- if (rawValue === undefined) continue
148
-
149
- if (String(rawValue).includes(',')) {
150
- log.warn('[debugger:devtools_client] Skipping invalid tag value for %s', key)
151
- continue
152
- }
153
-
154
- if (serializedTags) serializedTags += ','
155
- serializedTags += `${key}:${rawValue}`
156
- }
157
-
158
- return serializedTags
159
- }
@@ -1,5 +1,9 @@
1
1
  'use strict'
2
2
 
3
+ const { hostname: getHostname } = require('node:os')
4
+ const { stringify } = require('node:querystring')
5
+
6
+ const { version } = require('../../../../../package.json')
3
7
  const TTLSet = require('../../../../../vendor/dist/ttl-set')
4
8
  const request = require('../../exporters/common/request')
5
9
  const FormData = require('../../exporters/common/form-data')
@@ -7,6 +11,8 @@ const { DEBUGGER_DIAGNOSTICS_V1 } = require('../constants')
7
11
  const config = require('./config')
8
12
  const JSONBuffer = require('./json-buffer')
9
13
  const log = require('./log')
14
+ const getRequestOptions = require('./request-options')
15
+ const buildTags = require('./tags')
10
16
 
11
17
  module.exports = {
12
18
  ackReceived,
@@ -18,6 +24,7 @@ module.exports = {
18
24
  const ddsource = 'dd_debugger'
19
25
  const service = config.service
20
26
  const runtimeId = config.runtimeId
27
+ const ddtags = buildTags(config, getHostname(), version, log)
21
28
 
22
29
  const cache = new TTLSet(60 * 60 * 1000) // 1 hour
23
30
 
@@ -93,12 +100,10 @@ function onFlush (payload) {
93
100
  { filename: 'event.json', contentType: 'application/json; charset=utf-8' }
94
101
  )
95
102
 
96
- const options = {
97
- method: 'POST',
98
- url: config.url,
99
- path: DEBUGGER_DIAGNOSTICS_V1,
100
- headers: form.getHeaders(),
101
- }
103
+ const path = config.agentless
104
+ ? `${config.inputPath}?${stringify({ ddtags })}`
105
+ : DEBUGGER_DIAGNOSTICS_V1
106
+ const options = getRequestOptions(config, path, form.getHeaders())
102
107
 
103
108
  request(form, options, (err) => {
104
109
  if (err) log.error('[debugger:devtools_client] Error sending diagnostics payload', err)
@@ -0,0 +1,41 @@
1
+ 'use strict'
2
+
3
+ const { GIT_COMMIT_SHA, GIT_REPOSITORY_URL } = require('../../plugins/util/tags')
4
+
5
+ /**
6
+ * @param {ReturnType<import('../config')>} config - Debugger configuration
7
+ * @param {string} hostname - Host name
8
+ * @param {string} debuggerVersion - Debugger version
9
+ * @param {typeof import('./log')} log - Debugger logger
10
+ */
11
+ module.exports = function buildTags (config, hostname, debuggerVersion, log) {
12
+ let tags = ''
13
+
14
+ if (isValidTag('env', config.env, log)) tags += `,env:${config.env}`
15
+ if (isValidTag('version', config.version, log)) tags += `,version:${config.version}`
16
+ if (isValidTag('debugger_version', debuggerVersion, log)) tags += `,debugger_version:${debuggerVersion}`
17
+ if (config.agentless && isValidTag('runtime_id', config.runtimeId, log)) tags += `,runtime_id:${config.runtimeId}`
18
+ if (isValidTag('host_name', hostname, log)) tags += `,host_name:${hostname}`
19
+ if (isValidTag(GIT_COMMIT_SHA, config.commitSHA, log)) tags += `,${GIT_COMMIT_SHA}:${config.commitSHA}`
20
+ if (isValidTag(GIT_REPOSITORY_URL, config.repositoryUrl, log)) {
21
+ tags += `,${GIT_REPOSITORY_URL}:${config.repositoryUrl}`
22
+ }
23
+
24
+ return tags.slice(1)
25
+ }
26
+
27
+ /**
28
+ * @param {string} key
29
+ * @param {string | number | undefined} value
30
+ * @param {typeof import('./log')} log
31
+ */
32
+ function isValidTag (key, value, log) {
33
+ if (value === undefined) return false
34
+
35
+ if (String(value).includes(',')) {
36
+ log.warn('[debugger:devtools_client] Skipping invalid tag value for %s', key)
37
+ return false
38
+ }
39
+
40
+ return true
41
+ }
@@ -7,7 +7,12 @@ const { Worker, MessageChannel, threadId: parentThreadId } = require('worker_thr
7
7
  const log = require('../log')
8
8
  const { fetchAgentInfo } = require('../agent/info')
9
9
  const getDebuggerConfig = require('./config')
10
- const { DEBUGGER_DIAGNOSTICS_V1, DEBUGGER_INPUT_V2, INSPECT_SEGMENT_GLOBAL_PROPERTY } = require('./constants')
10
+ const {
11
+ DEBUGGER_DIAGNOSTICS_V1,
12
+ DEBUGGER_INPUT_DIRECT,
13
+ DEBUGGER_INPUT_V2,
14
+ INSPECT_SEGMENT_GLOBAL_PROPERTY,
15
+ } = require('./constants')
11
16
  const { installProbeSampler, uninstallProbeSampler } = require('./probe_sampler')
12
17
 
13
18
  /**
@@ -55,6 +60,10 @@ function isStarted () {
55
60
  */
56
61
  function start (config, rcInstance) {
57
62
  if (worker !== null) return
63
+ if (config.DD_AGENTLESS_ENABLED && getDebuggerConfig(config) === undefined) {
64
+ log.error('[debugger] Invalid DD_SITE for agentless Dynamic Instrumentation: %s', config.site)
65
+ return
66
+ }
58
67
 
59
68
  log.debug('[debugger] Starting Dynamic Instrumentation client...')
60
69
 
@@ -156,7 +165,12 @@ function start (config, rcInstance) {
156
165
  */
157
166
  function configure (config) {
158
167
  if (configChannel === null) return
159
- configChannel.port2.postMessage(getDebuggerConfig(config, inputPath))
168
+ const debuggerConfig = getDebuggerConfig(config, inputPath)
169
+ if (debuggerConfig === undefined) {
170
+ log.error('[debugger] Invalid DD_SITE for agentless Dynamic Instrumentation: %s', config.site)
171
+ return
172
+ }
173
+ configChannel.port2.postMessage(debuggerConfig)
160
174
  }
161
175
 
162
176
  /**
@@ -201,7 +215,8 @@ function cleanup (error) {
201
215
  // Pass error for unexpected exits, or undefined for graceful shutdown
202
216
  if (rcAckCallbacks) {
203
217
  for (const ackId of rcAckCallbacks.keys()) {
204
- rcAckCallbacks.get(ackId)(error)
218
+ const acknowledge = rcAckCallbacks.get(ackId)
219
+ acknowledge(error)
205
220
  rcAckCallbacks.delete(ackId)
206
221
  }
207
222
  rcAckCallbacks = null
@@ -215,6 +230,11 @@ function cleanup (error) {
215
230
  * @param {(endpointPath: string) => void} cb - Callback with the detected endpoint path
216
231
  */
217
232
  function detectDebuggerEndpoint (config, cb) {
233
+ if (config.DD_AGENTLESS_ENABLED) {
234
+ cb(DEBUGGER_INPUT_DIRECT)
235
+ return
236
+ }
237
+
218
238
  log.debug('[debugger] Detecting available debugger endpoints...')
219
239
 
220
240
  fetchAgentInfo(config.url, (err, agentInfo) => {