dd-trace 5.109.0 → 5.110.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 (128) hide show
  1. package/ci/init.js +4 -3
  2. package/index.d.ts +66 -24
  3. package/loader-hook.mjs +88 -2
  4. package/package.json +18 -14
  5. package/packages/datadog-esbuild/index.js +26 -0
  6. package/packages/datadog-esbuild/src/utils.js +46 -3
  7. package/packages/datadog-instrumentations/src/connect.js +4 -3
  8. package/packages/datadog-instrumentations/src/fastify.js +4 -12
  9. package/packages/datadog-instrumentations/src/graphql.js +17 -6
  10. package/packages/datadog-instrumentations/src/helpers/check-require-cache.js +81 -8
  11. package/packages/datadog-instrumentations/src/helpers/instrument.js +27 -2
  12. package/packages/datadog-instrumentations/src/helpers/optional-peer-bundler.js +65 -0
  13. package/packages/datadog-instrumentations/src/helpers/register.js +6 -4
  14. package/packages/datadog-instrumentations/src/helpers/require-optional-peer.js +17 -0
  15. package/packages/datadog-instrumentations/src/helpers/rewriter/loader.mjs +18 -2
  16. package/packages/datadog-instrumentations/src/koa.js +3 -2
  17. package/packages/datadog-instrumentations/src/mariadb.js +4 -2
  18. package/packages/datadog-instrumentations/src/mocha/main.js +3 -3
  19. package/packages/datadog-instrumentations/src/next.js +10 -10
  20. package/packages/datadog-instrumentations/src/otel-sdk-trace.js +7 -6
  21. package/packages/datadog-instrumentations/src/playwright.js +1 -1
  22. package/packages/datadog-instrumentations/src/restify.js +4 -3
  23. package/packages/datadog-instrumentations/src/router.js +18 -5
  24. package/packages/datadog-instrumentations/src/selenium.js +1 -2
  25. package/packages/datadog-instrumentations/src/tedious.js +28 -0
  26. package/packages/datadog-instrumentations/src/vitest.js +264 -7
  27. package/packages/datadog-plugin-avsc/src/schema_iterator.js +2 -2
  28. package/packages/datadog-plugin-aws-sdk/src/base.js +13 -9
  29. package/packages/datadog-plugin-aws-sdk/src/services/eventbridge.js +43 -6
  30. package/packages/datadog-plugin-aws-sdk/src/services/sqs.js +83 -91
  31. package/packages/datadog-plugin-cypress/src/cypress-plugin.js +9 -1
  32. package/packages/datadog-plugin-http/src/client.js +8 -3
  33. package/packages/datadog-plugin-http2/src/client.js +5 -2
  34. package/packages/datadog-plugin-mysql/src/index.js +7 -2
  35. package/packages/datadog-plugin-protobufjs/src/schema_iterator.js +2 -2
  36. package/packages/datadog-plugin-undici/src/index.js +5 -2
  37. package/packages/datadog-plugin-vitest/src/index.js +7 -1
  38. package/packages/datadog-webpack/index.js +17 -1
  39. package/packages/datadog-webpack/src/optional-peer-loader.js +17 -0
  40. package/packages/dd-trace/src/aiguard/sdk.js +13 -1
  41. package/packages/dd-trace/src/appsec/api_security/index.js +55 -0
  42. package/packages/dd-trace/src/appsec/api_security/sampler.js +147 -0
  43. package/packages/dd-trace/src/appsec/index.js +10 -6
  44. package/packages/dd-trace/src/appsec/reporter.js +1 -0
  45. package/packages/dd-trace/src/appsec/telemetry/api_security.js +34 -0
  46. package/packages/dd-trace/src/appsec/telemetry/index.js +26 -0
  47. package/packages/dd-trace/src/ci-visibility/requests/request.js +1 -17
  48. package/packages/dd-trace/src/config/defaults.js +22 -3
  49. package/packages/dd-trace/src/config/generated-config-types.d.ts +535 -1
  50. package/packages/dd-trace/src/config/helper.js +133 -33
  51. package/packages/dd-trace/src/config/index.js +4 -1
  52. package/packages/dd-trace/src/config/parsers.js +19 -1
  53. package/packages/dd-trace/src/config/supported-configurations.json +21 -3
  54. package/packages/dd-trace/src/debugger/devtools_client/breakpoints.js +47 -35
  55. package/packages/dd-trace/src/debugger/devtools_client/index.js +31 -66
  56. package/packages/dd-trace/src/debugger/devtools_client/probe_sampler.js +83 -0
  57. package/packages/dd-trace/src/debugger/devtools_client/state.js +1 -0
  58. package/packages/dd-trace/src/debugger/index.js +5 -0
  59. package/packages/dd-trace/src/debugger/probe_sampler.js +112 -0
  60. package/packages/dd-trace/src/debugger/probe_sampler_constants.js +19 -0
  61. package/packages/dd-trace/src/encode/agentless-ci-visibility.js +77 -26
  62. package/packages/dd-trace/src/exporters/common/request.js +1 -20
  63. package/packages/dd-trace/src/exporters/common/url.js +34 -0
  64. package/packages/dd-trace/src/exporters/span-stats/writer.js +1 -3
  65. package/packages/dd-trace/src/guardrails/index.js +8 -5
  66. package/packages/dd-trace/src/index.js +6 -4
  67. package/packages/dd-trace/src/llmobs/constants/tags.js +6 -0
  68. package/packages/dd-trace/src/llmobs/index.js +16 -5
  69. package/packages/dd-trace/src/llmobs/plugins/genai/util.js +3 -3
  70. package/packages/dd-trace/src/llmobs/plugins/langchain/index.js +5 -1
  71. package/packages/dd-trace/src/llmobs/sdk.js +5 -3
  72. package/packages/dd-trace/src/llmobs/span_processor.js +4 -0
  73. package/packages/dd-trace/src/llmobs/tagger.js +55 -0
  74. package/packages/dd-trace/src/llmobs/telemetry.js +1 -0
  75. package/packages/dd-trace/src/log/index.js +18 -20
  76. package/packages/dd-trace/src/openfeature/flagging_provider.js +2 -7
  77. package/packages/dd-trace/src/opentelemetry/bridge-span-base.js +5 -4
  78. package/packages/dd-trace/src/opentelemetry/metrics/instruments.js +2 -1
  79. package/packages/dd-trace/src/opentelemetry/metrics/periodic_metric_reader.js +4 -3
  80. package/packages/dd-trace/src/opentelemetry/metrics/time.js +19 -0
  81. package/packages/dd-trace/src/opentelemetry/otlp/common.proto +2 -2
  82. package/packages/dd-trace/src/opentelemetry/otlp/logs.proto +1 -1
  83. package/packages/dd-trace/src/opentelemetry/otlp/logs_service.proto +1 -1
  84. package/packages/dd-trace/src/opentelemetry/otlp/metrics.proto +1 -1
  85. package/packages/dd-trace/src/opentelemetry/otlp/metrics_service.proto +1 -1
  86. package/packages/dd-trace/src/opentelemetry/otlp/otlp_http_exporter_base.js +11 -4
  87. package/packages/dd-trace/src/opentelemetry/span-helpers.js +29 -13
  88. package/packages/dd-trace/src/opentelemetry/span.js +14 -3
  89. package/packages/dd-trace/src/opentelemetry/span_context.js +1 -0
  90. package/packages/dd-trace/src/opentelemetry/trace/index.js +2 -1
  91. package/packages/dd-trace/src/opentelemetry/trace/otlp_http_trace_exporter.js +3 -2
  92. package/packages/dd-trace/src/opentelemetry/trace/otlp_transformer.js +26 -13
  93. package/packages/dd-trace/src/opentracing/propagation/text_map.js +3 -3
  94. package/packages/dd-trace/src/opentracing/span_context.js +17 -0
  95. package/packages/dd-trace/src/plugin_manager.js +7 -1
  96. package/packages/dd-trace/src/plugins/ci_plugin.js +9 -1
  97. package/packages/dd-trace/src/plugins/util/http-otel-semantics.js +276 -0
  98. package/packages/dd-trace/src/plugins/util/test.js +80 -0
  99. package/packages/dd-trace/src/plugins/util/url.js +68 -1
  100. package/packages/dd-trace/src/plugins/util/web.js +19 -36
  101. package/packages/dd-trace/src/priority_sampler.js +1 -13
  102. package/packages/dd-trace/src/profiling/config.js +129 -198
  103. package/packages/dd-trace/src/profiling/constants.js +4 -7
  104. package/packages/dd-trace/src/profiling/exporter_cli.js +10 -10
  105. package/packages/dd-trace/src/profiling/exporters/agent.js +23 -16
  106. package/packages/dd-trace/src/profiling/exporters/event_serializer.js +45 -14
  107. package/packages/dd-trace/src/profiling/exporters/file.js +16 -5
  108. package/packages/dd-trace/src/profiling/oom.js +71 -0
  109. package/packages/dd-trace/src/profiling/profiler.js +35 -23
  110. package/packages/dd-trace/src/profiling/profilers/events.js +14 -7
  111. package/packages/dd-trace/src/profiling/profilers/space.js +27 -18
  112. package/packages/dd-trace/src/profiling/profilers/wall.js +35 -25
  113. package/packages/dd-trace/src/ritm.js +4 -2
  114. package/packages/dd-trace/src/serverless.js +1 -2
  115. package/packages/dd-trace/src/service-naming/schemas/util.js +36 -5
  116. package/packages/dd-trace/src/service-naming/schemas/v1/web.js +5 -3
  117. package/packages/dd-trace/src/span_format.js +2 -1
  118. package/packages/dd-trace/src/span_processor.js +6 -0
  119. package/packages/dd-trace/src/telemetry/send-data.js +12 -10
  120. package/packages/dd-trace/src/tracer.js +15 -1
  121. package/packages/dd-trace/src/util.js +14 -0
  122. package/register.js +58 -1
  123. package/vendor/dist/@apm-js-collab/code-transformer/index.js +1 -1
  124. package/vendor/dist/@datadog/sketches-js/index.js +1 -1
  125. package/vendor/dist/pprof-format/index.js +1 -1
  126. package/vendor/dist/protobufjs/index.js +1 -1
  127. package/vendor/dist/protobufjs/minimal/index.js +1 -1
  128. package/packages/dd-trace/src/appsec/api_security_sampler.js +0 -117
@@ -8,7 +8,7 @@ const dc = require('dc-polyfill')
8
8
 
9
9
  const parse = require('../../../vendor/dist/module-details-from-path')
10
10
  const { isRelativeRequire } = require('../../datadog-instrumentations/src/helpers/shared-utils')
11
- const { getEnvironmentVariable, getValueFromEnvSources } = require('./config/helper')
11
+ const { getConfiguredEnvName, getEnvironmentVariable } = require('./config/helper')
12
12
 
13
13
  const origRequire = Module.prototype.require
14
14
  // derived from require-in-the-middle@3 with tweaks
@@ -143,7 +143,9 @@ function Hook (modules, options, onrequire) {
143
143
  name = moduleId
144
144
  } else {
145
145
  const inAWSLambda = getEnvironmentVariable('AWS_LAMBDA_FUNCTION_NAME') !== undefined
146
- const hasLambdaHandler = getValueFromEnvSources('DD_LAMBDA_HANDLER') !== undefined
146
+ // Presence check over all sources (incl. stable config) without parsing —
147
+ // parsing here would re-enter this require hook via config/defaults.
148
+ const hasLambdaHandler = getConfiguredEnvName('DD_LAMBDA_HANDLER') !== undefined
147
149
  const segments = filename.split(path.sep)
148
150
  const filenameFromNodeModule = segments.includes('node_modules')
149
151
  // decide how to assign the stat
@@ -1,7 +1,6 @@
1
1
  'use strict'
2
2
 
3
3
  const { getEnvironmentVariable, getValueFromEnvSources } = require('./config/helper')
4
- const { isFalse } = require('./util')
5
4
 
6
5
  function getIsGCPFunction () {
7
6
  const isDeprecatedGCPFunction =
@@ -23,7 +22,7 @@ function getIsGCPFunction () {
23
22
  */
24
23
  function enableGCPPubSubPushSubscription () {
25
24
  return getEnvironmentVariable('K_SERVICE') !== undefined &&
26
- !isFalse(getValueFromEnvSources('DD_TRACE_GCP_PUBSUB_PUSH_ENABLED'))
25
+ getValueFromEnvSources('DD_TRACE_GCP_PUBSUB_PUSH_ENABLED')
27
26
  }
28
27
 
29
28
  function getIsAzureFunction () {
@@ -28,12 +28,43 @@ function optionServiceSource ({ pluginConfig }) {
28
28
  }
29
29
  }
30
30
 
31
- function awsServiceV0 ({ tracerService, awsService }) {
32
- return `${tracerService}-aws-${awsService}`
31
+ /**
32
+ * Resolve a `service` config that may be a string or a function. A string
33
+ * overrides every span; a function is called with the request params so a
34
+ * single resource can be mapped to its own service, and only a non-empty
35
+ * string result is honored — anything else falls back to `defaultService`.
36
+ *
37
+ * @param {{ service?: string | ((params?: object) => unknown) }} [pluginConfig]
38
+ * @param {object} [params]
39
+ * @param {string} defaultService
40
+ * @returns {string}
41
+ */
42
+ function configServiceName (pluginConfig, params, defaultService) {
43
+ const service = pluginConfig?.service
44
+ if (typeof service === 'function') {
45
+ const custom = service(params)
46
+ return typeof custom === 'string' && custom ? custom : defaultService
47
+ }
48
+ return service || defaultService
49
+ }
50
+
51
+ function awsServiceV0 ({ tracerService, pluginConfig, params, awsService }) {
52
+ return configServiceName(pluginConfig, params, `${tracerService}-aws-${awsService}`)
33
53
  }
34
54
 
35
- function awsServiceSource ({ awsService }) {
36
- return awsService
55
+ function awsServiceV1 ({ tracerService, pluginConfig, params }) {
56
+ return configServiceName(pluginConfig, params, tracerService)
37
57
  }
38
58
 
39
- module.exports = { identityService, httpPluginClientService, awsServiceV0, optionServiceSource, awsServiceSource }
59
+ function awsServiceSource ({ awsService, pluginConfig }) {
60
+ return pluginConfig?.service ? 'opt.plugin' : awsService
61
+ }
62
+
63
+ module.exports = {
64
+ identityService,
65
+ httpPluginClientService,
66
+ awsServiceV0,
67
+ awsServiceV1,
68
+ optionServiceSource,
69
+ awsServiceSource,
70
+ }
@@ -1,6 +1,6 @@
1
1
  'use strict'
2
2
 
3
- const { identityService, httpPluginClientService, optionServiceSource } = require('../util')
3
+ const { identityService, httpPluginClientService, optionServiceSource, awsServiceV1 } = require('../util')
4
4
 
5
5
  const web = {
6
6
  client: {
@@ -38,11 +38,13 @@ const web = {
38
38
  },
39
39
  aws: {
40
40
  opName: ({ awsService }) => `aws.${awsService}.request`,
41
- serviceName: identityService,
41
+ serviceName: awsServiceV1,
42
+ serviceSource: optionServiceSource,
42
43
  },
43
44
  lambda: {
44
45
  opName: () => 'aws.lambda.invoke',
45
- serviceName: identityService,
46
+ serviceName: awsServiceV1,
47
+ serviceSource: optionServiceSource,
46
48
  },
47
49
  undici: {
48
50
  opName: () => 'undici.request',
@@ -176,7 +176,8 @@ function extractTags (formattedSpan, span) {
176
176
  metrics[MEASURED] = 1
177
177
  }
178
178
 
179
- const tracerService = span.tracer().serviceLower
179
+ const tracer = span.tracer()
180
+ const tracerService = tracer.serviceLower
180
181
  if (tags['service.name']?.toLowerCase() !== tracerService) {
181
182
  span.setTag(BASE_SERVICE, tracerService)
182
183
 
@@ -5,6 +5,7 @@ const spanFormat = require('./span_format')
5
5
  const SpanSampler = require('./span_sampler')
6
6
  const GitMetadataTagger = require('./git_metadata_tagger')
7
7
  const processTags = require('./process-tags')
8
+ const { applyHttpOtelSemantics } = require('./plugins/util/http-otel-semantics')
8
9
 
9
10
  const startedSpans = new WeakSet()
10
11
  const finishedSpans = new WeakSet()
@@ -61,7 +62,12 @@ class SpanProcessor {
61
62
  } else {
62
63
  const formattedSpan = spanFormat(span, isFirstSpanInChunk, this._processTags)
63
64
  isFirstSpanInChunk = false
65
+ // Span stats read Datadog HTTP tag names from the formatted span, so
66
+ // record them before the OTel rename — an export-only transform.
64
67
  this._stats?.onSpanFinished(formattedSpan)
68
+ if (this._config.DD_TRACE_OTEL_SEMANTICS_ENABLED) {
69
+ applyHttpOtelSemantics(formattedSpan)
70
+ }
65
71
  formatted.push(formattedSpan)
66
72
  }
67
73
  }
@@ -182,7 +182,13 @@ function sendData (config, application, host, reqType, payload = {}, cb = () =>
182
182
  agentTelemetry = false
183
183
  }
184
184
  // figure out which data center to send to
185
- const backendUrl = getAgentlessTelemetryEndpoint(config.site)
185
+ let backendUrl
186
+ try {
187
+ backendUrl = new URL(getAgentlessTelemetryEndpoint(config.site))
188
+ } catch {
189
+ log.error('Invalid Telemetry URL')
190
+ return
191
+ }
186
192
  const backendHeader = { ...options.headers, 'DD-API-KEY': config.apiKey }
187
193
  const backendOptions = {
188
194
  ...options,
@@ -190,15 +196,11 @@ function sendData (config, application, host, reqType, payload = {}, cb = () =>
190
196
  headers: backendHeader,
191
197
  path: '/api/v2/apmtelemetry',
192
198
  }
193
- if (backendUrl) {
194
- request(data, backendOptions, (error) => {
195
- if (error) {
196
- log.error('Error sending telemetry data', error)
197
- }
198
- })
199
- } else {
200
- log.error('Invalid Telemetry URL')
201
- }
199
+ request(data, backendOptions, (error) => {
200
+ if (error) {
201
+ log.error('Error sending telemetry data', error)
202
+ }
203
+ })
202
204
  }
203
205
 
204
206
  if (!error && !agentTelemetry) {
@@ -2,7 +2,11 @@
2
2
 
3
3
  const tags = require('../../../ext/tags')
4
4
  const { ERROR_MESSAGE, ERROR_TYPE, ERROR_STACK } = require('../../dd-trace/src/constants')
5
- const { flushStartupLogs } = require('../../datadog-instrumentations/src/helpers/check-require-cache')
5
+ const {
6
+ flushStartupLogs,
7
+ flushFrameworkWarnings,
8
+ flushLoadOrderWarnings,
9
+ } = require('../../datadog-instrumentations/src/helpers/check-require-cache')
6
10
  const Tracer = require('./opentracing/tracer')
7
11
  const Scope = require('./scope')
8
12
  const { isError } = require('./util')
@@ -10,6 +14,10 @@ const { setStartupLogConfig } = require('./startup-log')
10
14
  const { DataStreamsCheckpointer, DataStreamsManager, DataStreamsProcessor } = require('./datastreams')
11
15
  const { IS_SERVERLESS } = require('./serverless')
12
16
  const log = require('./log')
17
+ // Always-on writer (console.warn), not the channel-gated `log`: these surface regardless of
18
+ // DD_TRACE_DEBUG.
19
+ const { warn } = require('./log/writer')
20
+ const logDiagnostic = message => warn('DATADOG TRACER DIAGNOSTIC - ' + message)
13
21
 
14
22
  const SPAN_TYPE = tags.SPAN_TYPE
15
23
  const RESOURCE_NAME = tags.RESOURCE_NAME
@@ -25,6 +33,12 @@ class DatadogTracer extends Tracer {
25
33
  this._scope = new Scope()
26
34
  setStartupLogConfig(config)
27
35
  flushStartupLogs(log)
36
+ // Curated frameworks (e.g. Next.js) silently no-op when loaded first and their users enable
37
+ // no logging (#5430 / #5432), so surface those unconditionally.
38
+ flushFrameworkWarnings(logDiagnostic)
39
+ if (config.startupLogs) {
40
+ flushLoadOrderWarnings(logDiagnostic)
41
+ }
28
42
 
29
43
  if (!IS_SERVERLESS) {
30
44
  const storeConfig = require('./tracer_metadata')
@@ -91,6 +91,19 @@ function normalizePluginEnvName (envPluginName, makeLowercase = false) {
91
91
  return makeLowercase ? envPluginName.toLowerCase() : envPluginName
92
92
  }
93
93
 
94
+ /**
95
+ * Formats a sampling rate as a string with up to 6 decimal digits and no trailing zeros.
96
+ *
97
+ * @param {number} rate
98
+ */
99
+ function formatKnuthRate (rate) {
100
+ const string = Number(rate).toFixed(6)
101
+ for (let i = string.length - 1; i > 0; i--) {
102
+ if (string[i] === '0') continue
103
+ return string.slice(0, i + (string[i] === '.' ? 0 : 1))
104
+ }
105
+ }
106
+
94
107
  module.exports = {
95
108
  isEmpty,
96
109
  isTrue,
@@ -99,4 +112,5 @@ module.exports = {
99
112
  globMatch,
100
113
  ddBasePath: globalThis.__DD_ESBUILD_BASEPATH || calculateDDBasePath(__dirname),
101
114
  normalizePluginEnvName,
115
+ formatKnuthRate,
102
116
  }
package/register.js CHANGED
@@ -4,5 +4,62 @@
4
4
 
5
5
  const { register } = require('node:module')
6
6
  const { pathToFileURL } = require('node:url')
7
+ const { NODE_MAJOR, NODE_MINOR, NODE_PATCH } = require('./version')
7
8
 
8
- register('./loader-hook.mjs', pathToFileURL(__filename))
9
+ const parentURL = pathToFileURL(__filename)
10
+ let isSyncLoaderRegistered = false
11
+
12
+ if (shouldRegisterSyncLoaderHooks()) {
13
+ let registerSyncLoaderHooks
14
+ let syncRegistrationError
15
+ try {
16
+ ({ registerSyncLoaderHooks } = require('./loader-hook.mjs'))
17
+ if (registerSyncLoaderHooks) {
18
+ isSyncLoaderRegistered = registerSyncLoaderHooks()
19
+ }
20
+ } catch (error) {
21
+ syncRegistrationError = error
22
+ }
23
+
24
+ if (!isSyncLoaderRegistered) {
25
+ warnSyncLoaderFallback(syncRegistrationError)
26
+ }
27
+ }
28
+
29
+ if (!isSyncLoaderRegistered) {
30
+ register('./loader-hook.mjs', parentURL)
31
+ }
32
+
33
+ function shouldRegisterSyncLoaderHooks () {
34
+ if (!isSyncLoaderHookVersionSupported()) {
35
+ return false
36
+ }
37
+
38
+ try {
39
+ return require('import-in-the-middle/create-hook.mjs').supportsSyncHooks()
40
+ } catch (error) {
41
+ if (error?.code !== 'ERR_REQUIRE_ESM') {
42
+ warnSyncLoaderFallback(error)
43
+ }
44
+ }
45
+
46
+ return false
47
+ }
48
+
49
+ function isSyncLoaderHookVersionSupported () {
50
+ if (NODE_MAJOR >= 26) return true
51
+ if (NODE_MAJOR === 25) return NODE_MINOR >= 1
52
+ if (NODE_MAJOR === 24) return NODE_MINOR > 11 || (NODE_MINOR === 11 && NODE_PATCH >= 1)
53
+ if (NODE_MAJOR === 22) return NODE_MINOR > 22 || (NODE_MINOR === 22 && NODE_PATCH >= 3)
54
+ return false
55
+ }
56
+
57
+ function warnSyncLoaderFallback (error) {
58
+ let message = 'dd-trace could not register synchronous loader hooks. Falling back to the asynchronous loader.'
59
+
60
+ if (error?.message) {
61
+ message += ` ${error.message}`
62
+ }
63
+
64
+ process.emitWarning(message)
65
+ }
@@ -1,4 +1,4 @@
1
- (()=>{var i={"./@apm-js-collab/code-transformer/index.js"(i,s,k){"use strict";i.exports=k("./@apm-js-collab/code-transformer/lib/index.js")},"./@apm-js-collab/code-transformer/lib/index.js"(i,s,k){"use strict";let{InstrumentationMatcher:S}=k("./@apm-js-collab/code-transformer/lib/matcher.js");i.exports={create:function(i,s){return new S(i,s)}}},"./@apm-js-collab/code-transformer/lib/matcher.js"(i,s,k){"use strict";let S=k("./semifies/index.js"),{Transformer:E}=k("./@apm-js-collab/code-transformer/lib/transformer.js");let InstrumentationMatcher=class InstrumentationMatcher{#e=[];#t=null;#r={};#n={};constructor(i,s){this.#e=i,this.#t=s||"diagnostics_channel"}free(){this.#r={}}addTransform(i,s){this.#n[i]=s}getTransformer(i,s,k){k=k.replace(/\\/g,"/");let w=`${i}/${k}@${s}`;if(this.#r[w])return this.#r[w];let C=this.#e.filter(({module:E})=>E.name===i&&E.filePath===k&&S(s,E.versionRange));if(0!==C.length)return this.#r[w]=new E(i,s,k,C,this.#t,this.#n),this.#r[w]}};i.exports={InstrumentationMatcher}},"./@apm-js-collab/code-transformer/lib/transformer.js"(i,s,k){"use strict";let S,E,w=k("./esquery/dist/esquery.min.js"),{parse:C}=k("./meriyah/dist/meriyah.cjs"),{generate:T}=k("./astring/dist/astring.js"),_=k("./@apm-js-collab/code-transformer/lib/transforms.js");let Transformer=class Transformer{#a=null;#o=null;#i=null;#e=[];#t=null;#n={};constructor(i,s,k,S,E,w={}){this.#a=i,this.#o=s,this.#i=k,this.#e=S,this.#t=E,this.#n=w}free(){}get moduleName(){return this.#a}get filePath(){return this.#i}transform(i,s,_){let O;if(Buffer.isBuffer(i)&&(i=i.toString()),!i)return{code:i};let N={},D=0;for(let k of this.#e){let{astQuery:S,functionQuery:E={}}=k;if(!O){let k={loc:!0,ranges:!0,raw:!0,module:"esm"===s};try{O=C(i,k)}catch{O=C(i,{...k,module:!k.module})}"esm"===s&&(N=this.#s(O))}let T=this.#l(E,N),_=S||this.#c(T),q={...k,dcModule:this.#t,moduleType:s,moduleVersion:this.#o,functionQuery:T};q.operator=this.#u(q),w.traverse(O,w.parse(_),(...i)=>{D++,this.#p(q,...i)})}if(0===D&&this.#e.length>0){let i=this.#e.map(({functionQuery:i={}})=>{let s=this.#l(i,N),k=i.methodName||i.privateMethodName||i.functionName||i.expressionName||"constructor",S=i.className||i.functionName||i.expressionName,E=s.className||s.functionName||s.expressionName;return S&&S!==E?`${S} (local name: ${E})`:k});throw Error(`Failed to find injection points for: ${JSON.stringify(i)}`)}if(O){S??=k("./@apm-js-collab/code-transformer/node_modules/source-map/source-map.js").SourceMapConsumer,E??=k("./@apm-js-collab/code-transformer/node_modules/source-map/source-map.js").SourceMapGenerator;let i=`${this.#a}/${this.#i}`,s=new E(_?new S(_):{file:i});return{code:T(O,{sourceMap:s}),map:s.toString()}}return{code:i}}#p(i,...s){let k=this.#n[i.operator]??_[i.operator],{index:S=0}=i.functionQuery,[E]=s,w=E.init?.type||E.type;if("ClassDeclaration"===w||"ClassExpression"===w||"VariableDeclarator"!==E.type&&(i.functionIndex=++i.functionIndex||0,null===S||S===i.functionIndex))k(i,...s)}#u({transform:i,functionQuery:{kind:s}}){if(i)return i;switch(s){case"Async":return"tracePromise";case"Auto":return"traceAuto";case"Callback":return"traceCallback";default:return"traceSync"}}#s(i){let s={};for(let k of i.body)if("ExportNamedDeclaration"===k.type&&!k.source){for(let i of k.specifiers)if(i.exported&&i.local){let k=i.exported.name??i.exported.value,S=i.local.name??i.local.value;k&&S&&(s[k]=S)}}return s}#l(i,s){if(!i.isExportAlias)return i;let{functionName:k,expressionName:S,className:E}=i;return k&&s[k]?{...i,functionName:s[k]}:S&&s[S]?{...i,expressionName:s[S]}:E&&s[E]?{...i,className:s[E]}:i}#c(i){let{functionName:s,expressionName:k,className:S,objectName:E,propertyName:w}=i,C=i.privateMethodName?"PrivateIdentifier":"Identifier",T=[],_=i.methodName||i.privateMethodName;if(S?(_??="constructor",T.push(`[id.name="${S}"]`,`[id.name="${S}"] > ClassExpression`,`[id.name="${S}"] > ClassBody > [key.name="${_}"][key.type=${C}] > [async]`,`[id.name="${S}"] > ClassExpression > ClassBody > [key.name="${_}"][key.type=${C}] > [async]`)):_&&T.push(`ClassBody > [key.name="${_}"][key.type=${C}] > [async]`,`Property[key.name="${_}"][key.type=${C}] > [async]`),s?T.push(`FunctionDeclaration[id.name="${s}"][async]`):k&&T.push(`FunctionExpression[id.name="${k}"][async]`,`ArrowFunctionExpression[id.name="${k}"][async]`,`VariableDeclarator[id.name="${k}"] > FunctionExpression[async]`,`VariableDeclarator[id.name="${k}"] > ArrowFunctionExpression[async]`,`AssignmentExpression[left.property.name="${k}"] > FunctionExpression[async]`,`AssignmentExpression[left.property.name="${k}"] > ArrowFunctionExpression[async]`,`AssignmentExpression[left.name="${k}"] > FunctionExpression[async]`,`AssignmentExpression[left.name="${k}"] > ArrowFunctionExpression[async]`),E||w){if(!E||!w)throw Error(`functionQuery: 'objectName' and 'propertyName' must be used together (got objectName=${E}, propertyName=${w})`);let i="this"===E?"left.object.type=ThisExpression":`left.object.name="${E}"`;T.push(`AssignmentExpression[${i}][left.property.name="${w}"] > [async]`)}return T.join(", ")}};i.exports={Transformer}},"./@apm-js-collab/code-transformer/lib/transforms.js"(i,s,k){"use strict";let S=k("./esquery/dist/esquery.min.js"),{parse:E}=k("./meriyah/dist/meriyah.cjs"),tracingChannelPredicate=i=>i.declarations?.[0]?.id?.properties?.[0]?.value?.name==="tr_ch_apm_tracingChannel",w=/[^\w]/g,formatChannelVariable=i=>`tr_ch_apm$${i.replace(w,"_")}`,C=i.exports={tracingChannelImport({dcModule:i,moduleType:s},k){if(k.body.some(tracingChannelPredicate))return;let S={module:"esm"===s},w=k.body.findIndex(i=>"use strict"===i.directive),C="esm"===s?`import tr_ch_apm_dc from "${i}"`:`const tr_ch_apm_dc = require("${i}")`,T=`const tr_ch_apm_hasSubscribers = ch => ch.start.hasSubscribers
1
+ (()=>{var i={"./@apm-js-collab/code-transformer/index.js"(i,s,k){"use strict";i.exports=k("./@apm-js-collab/code-transformer/lib/index.js")},"./@apm-js-collab/code-transformer/lib/index.js"(i,s,k){"use strict";let{InstrumentationMatcher:S}=k("./@apm-js-collab/code-transformer/lib/matcher.js");i.exports={create:function(i,s){return new S(i,s)}}},"./@apm-js-collab/code-transformer/lib/matcher.js"(i,s,k){"use strict";let S=k("./semifies/index.js"),{Transformer:E}=k("./@apm-js-collab/code-transformer/lib/transformer.js");let InstrumentationMatcher=class InstrumentationMatcher{#e=[];#t=null;#r={};#n={};constructor(i,s){this.#e=i,this.#t=s||"diagnostics_channel"}free(){this.#r={}}addTransform(i,s){this.#n[i]=s}getTransformer(i,s,k){k=k.replace(/\\/g,"/");let w=`${i}/${k}@${s}`;if(this.#r[w])return this.#r[w];let C=this.#e.filter(({module:E})=>E.name===i&&E.filePath===k&&S(s,E.versionRange));if(0!==C.length)return this.#r[w]=new E(i,s,k,C,this.#t,this.#n),this.#r[w]}};i.exports={InstrumentationMatcher}},"./@apm-js-collab/code-transformer/lib/transformer.js"(i,s,k){"use strict";let S,E,w=k("./esquery/dist/esquery.min.js"),{parse:C}=k("./meriyah/dist/meriyah.cjs"),{generate:T}=k("./astring/dist/astring.js"),_=k("./@apm-js-collab/code-transformer/lib/transforms.js");let Transformer=class Transformer{#a=null;#o=null;#i=null;#e=[];#t=null;#n={};constructor(i,s,k,S,E,w={}){this.#a=i,this.#o=s,this.#i=k,this.#e=S,this.#t=E,this.#n=w}free(){}get moduleName(){return this.#a}get filePath(){return this.#i}transform(i,s,_){let O;if(Buffer.isBuffer(i)&&(i=i.toString()),!i)return{code:i};let N={},D=0;for(let k of this.#e){let{astQuery:S,functionQuery:E={}}=k;if(!O){let k={loc:!0,ranges:!0,raw:!0,module:"esm"===s};try{O=C(i,k)}catch{O=C(i,{...k,module:!k.module})}"esm"===s&&(N=this.#s(O))}let T=this.#l(E,N),_=S||this.#c(T),q={...k,dcModule:this.#t,moduleType:s,moduleVersion:this.#o,functionQuery:T};q.operator=this.#u(q),w.traverse(O,w.parse(_),(...i)=>{D++,this.#p(q,...i)})}if(0===D&&this.#e.length>0){let i=this.#e.map(({functionQuery:i={}})=>{let s=this.#l(i,N),k=i.methodName||i.privateMethodName||i.functionName||i.expressionName||"constructor",S=i.className||i.functionName||i.expressionName,E=s.className||s.functionName||s.expressionName;return S&&S!==E?`${S} (local name: ${E})`:k});throw Error(`Failed to find injection points for: ${JSON.stringify(i)}`)}if(O){let i;S??=k("./@apm-js-collab/code-transformer/node_modules/source-map/source-map.js").SourceMapConsumer,E??=k("./@apm-js-collab/code-transformer/node_modules/source-map/source-map.js").SourceMapGenerator;let s=`${this.#a}/${this.#i}`;if(_){let k=new S(_);k.file=s,i=E.fromSourceMap(k)}else i=new E({file:s});return{code:T(O,{sourceMap:i}),map:i.toString()}}return{code:i}}#p(i,...s){let k=this.#n[i.operator]??_[i.operator],{index:S=0}=i.functionQuery,[E]=s,w=E.init?.type||E.type;if("ClassDeclaration"===w||"ClassExpression"===w||"VariableDeclarator"!==E.type&&(i.functionIndex=++i.functionIndex||0,null===S||S===i.functionIndex))k(i,...s)}#u({transform:i,functionQuery:{kind:s}}){if(i)return i;switch(s){case"Async":return"tracePromise";case"Auto":return"traceAuto";case"Callback":return"traceCallback";default:return"traceSync"}}#s(i){let s={};for(let k of i.body)if("ExportNamedDeclaration"===k.type&&!k.source){for(let i of k.specifiers)if(i.exported&&i.local){let k=i.exported.name??i.exported.value,S=i.local.name??i.local.value;k&&S&&(s[k]=S)}}return s}#l(i,s){if(!i.isExportAlias)return i;let{functionName:k,expressionName:S,className:E}=i;return k&&s[k]?{...i,functionName:s[k]}:S&&s[S]?{...i,expressionName:s[S]}:E&&s[E]?{...i,className:s[E]}:i}#c(i){let{functionName:s,expressionName:k,className:S,objectName:E,propertyName:w}=i,C=i.privateMethodName?"PrivateIdentifier":"Identifier",T=[],_=i.methodName||i.privateMethodName;if(S?(_??="constructor",T.push(`[id.name="${S}"]`,`[id.name="${S}"] > ClassExpression`,`[id.name="${S}"] > ClassBody > [key.name="${_}"][key.type=${C}] > [async]`,`[id.name="${S}"] > ClassExpression > ClassBody > [key.name="${_}"][key.type=${C}] > [async]`)):_&&T.push(`ClassBody > [key.name="${_}"][key.type=${C}] > [async]`,`Property[key.name="${_}"][key.type=${C}] > [async]`),s?T.push(`FunctionDeclaration[id.name="${s}"][async]`):k&&T.push(`FunctionExpression[id.name="${k}"][async]`,`ArrowFunctionExpression[id.name="${k}"][async]`,`VariableDeclarator[id.name="${k}"] > FunctionExpression[async]`,`VariableDeclarator[id.name="${k}"] > ArrowFunctionExpression[async]`,`AssignmentExpression[left.property.name="${k}"] > FunctionExpression[async]`,`AssignmentExpression[left.property.name="${k}"] > ArrowFunctionExpression[async]`,`AssignmentExpression[left.name="${k}"] > FunctionExpression[async]`,`AssignmentExpression[left.name="${k}"] > ArrowFunctionExpression[async]`),E||w){if(!E||!w)throw Error(`functionQuery: 'objectName' and 'propertyName' must be used together (got objectName=${E}, propertyName=${w})`);let i="this"===E?"left.object.type=ThisExpression":`left.object.name="${E}"`;T.push(`AssignmentExpression[${i}][left.property.name="${w}"] > [async]`)}return T.join(", ")}};i.exports={Transformer}},"./@apm-js-collab/code-transformer/lib/transforms.js"(i,s,k){"use strict";let S=k("./esquery/dist/esquery.min.js"),{parse:E}=k("./meriyah/dist/meriyah.cjs"),tracingChannelPredicate=i=>i.declarations?.[0]?.id?.properties?.[0]?.value?.name==="tr_ch_apm_tracingChannel",w=/[^\w]/g,formatChannelVariable=i=>`tr_ch_apm$${i.replace(w,"_")}`,C=i.exports={tracingChannelImport({dcModule:i,moduleType:s},k){if(k.body.some(tracingChannelPredicate))return;let S={module:"esm"===s},w=k.body.findIndex(i=>"use strict"===i.directive),C="esm"===s?`import tr_ch_apm_dc from "${i}"`:`const tr_ch_apm_dc = require("${i}")`,T=`const tr_ch_apm_hasSubscribers = ch => ch.start.hasSubscribers
2
2
  || ch.end.hasSubscribers
3
3
  || ch.asyncStart.hasSubscribers
4
4
  || ch.asyncEnd.hasSubscribers