dd-trace 5.102.0 → 5.103.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 (133) hide show
  1. package/ext/exporters.js +1 -0
  2. package/package.json +12 -11
  3. package/packages/datadog-esbuild/src/utils.js +2 -2
  4. package/packages/datadog-instrumentations/src/ai.js +1 -1
  5. package/packages/datadog-instrumentations/src/confluentinc-kafka-javascript.js +32 -15
  6. package/packages/datadog-instrumentations/src/couchbase.js +69 -220
  7. package/packages/datadog-instrumentations/src/cucumber.js +1 -1
  8. package/packages/datadog-instrumentations/src/electron/preload.js +42 -0
  9. package/packages/datadog-instrumentations/src/electron.js +240 -0
  10. package/packages/datadog-instrumentations/src/fetch.js +5 -5
  11. package/packages/datadog-instrumentations/src/graphql.js +13 -12
  12. package/packages/datadog-instrumentations/src/helpers/callback-instrumentor.js +1 -1
  13. package/packages/datadog-instrumentations/src/helpers/hook.js +4 -1
  14. package/packages/datadog-instrumentations/src/helpers/hooks.js +1 -0
  15. package/packages/datadog-instrumentations/src/helpers/instrument.js +2 -2
  16. package/packages/datadog-instrumentations/src/helpers/kafka.js +41 -0
  17. package/packages/datadog-instrumentations/src/ioredis.js +16 -12
  18. package/packages/datadog-instrumentations/src/jest.js +351 -50
  19. package/packages/datadog-instrumentations/src/kafkajs.js +164 -173
  20. package/packages/datadog-instrumentations/src/mocha/main.js +73 -1
  21. package/packages/datadog-instrumentations/src/mongodb-core.js +33 -8
  22. package/packages/datadog-instrumentations/src/pg.js +24 -10
  23. package/packages/datadog-instrumentations/src/playwright.js +427 -55
  24. package/packages/datadog-instrumentations/src/redis.js +19 -10
  25. package/packages/datadog-plugin-apollo/src/gateway/request.js +1 -21
  26. package/packages/datadog-plugin-aws-sdk/src/base.js +18 -24
  27. package/packages/datadog-plugin-aws-sdk/src/services/cloudwatchlogs.js +1 -1
  28. package/packages/datadog-plugin-aws-sdk/src/services/eventbridge.js +1 -1
  29. package/packages/datadog-plugin-aws-sdk/src/services/kinesis.js +1 -1
  30. package/packages/datadog-plugin-aws-sdk/src/services/lambda.js +1 -1
  31. package/packages/datadog-plugin-aws-sdk/src/services/redshift.js +1 -1
  32. package/packages/datadog-plugin-aws-sdk/src/services/s3.js +1 -1
  33. package/packages/datadog-plugin-aws-sdk/src/services/sns.js +2 -2
  34. package/packages/datadog-plugin-aws-sdk/src/services/sqs.js +1 -1
  35. package/packages/datadog-plugin-aws-sdk/src/services/stepfunctions.js +1 -1
  36. package/packages/datadog-plugin-couchbase/src/index.js +58 -52
  37. package/packages/datadog-plugin-cucumber/src/index.js +1 -0
  38. package/packages/datadog-plugin-cypress/src/cypress-plugin.js +214 -22
  39. package/packages/datadog-plugin-cypress/src/support.js +13 -1
  40. package/packages/datadog-plugin-electron/src/index.js +17 -0
  41. package/packages/datadog-plugin-electron/src/ipc.js +143 -0
  42. package/packages/datadog-plugin-electron/src/net.js +82 -0
  43. package/packages/datadog-plugin-google-cloud-pubsub/src/producer.js +27 -18
  44. package/packages/datadog-plugin-graphql/src/execute.js +6 -28
  45. package/packages/datadog-plugin-graphql/src/resolve.js +30 -35
  46. package/packages/datadog-plugin-graphql/src/tools/signature.js +32 -7
  47. package/packages/datadog-plugin-graphql/src/tools/transforms.js +118 -100
  48. package/packages/datadog-plugin-graphql/src/utils.js +29 -0
  49. package/packages/datadog-plugin-grpc/src/client.js +6 -7
  50. package/packages/datadog-plugin-grpc/src/util.js +57 -22
  51. package/packages/datadog-plugin-http/src/client.js +2 -2
  52. package/packages/datadog-plugin-jest/src/index.js +92 -50
  53. package/packages/datadog-plugin-mocha/src/index.js +1 -0
  54. package/packages/datadog-plugin-mongodb-core/src/index.js +36 -70
  55. package/packages/datadog-plugin-mysql/src/index.js +1 -1
  56. package/packages/datadog-plugin-openai/src/services.js +2 -1
  57. package/packages/datadog-plugin-pg/src/index.js +3 -3
  58. package/packages/datadog-plugin-playwright/src/index.js +4 -0
  59. package/packages/datadog-plugin-redis/src/index.js +18 -23
  60. package/packages/dd-trace/src/aiguard/index.js +3 -1
  61. package/packages/dd-trace/src/aiguard/sdk.js +36 -30
  62. package/packages/dd-trace/src/aiguard/tags.js +20 -11
  63. package/packages/dd-trace/src/appsec/iast/taint-tracking/rewriter.js +2 -2
  64. package/packages/dd-trace/src/appsec/iast/vulnerability-reporter.js +1 -1
  65. package/packages/dd-trace/src/azure_metadata.js +17 -6
  66. package/packages/dd-trace/src/ci-visibility/dynamic-instrumentation/index.js +4 -4
  67. package/packages/dd-trace/src/ci-visibility/exporters/ci-visibility-exporter.js +4 -2
  68. package/packages/dd-trace/src/ci-visibility/exporters/test-worker/index.js +6 -4
  69. package/packages/dd-trace/src/ci-visibility/requests/fs-cache.js +1 -1
  70. package/packages/dd-trace/src/config/defaults.js +3 -14
  71. package/packages/dd-trace/src/config/generated-config-types.d.ts +3 -1
  72. package/packages/dd-trace/src/config/helper.js +4 -0
  73. package/packages/dd-trace/src/config/index.js +2 -2
  74. package/packages/dd-trace/src/config/major-overrides.js +98 -0
  75. package/packages/dd-trace/src/config/parsers.js +7 -1
  76. package/packages/dd-trace/src/config/supported-configurations.json +51 -38
  77. package/packages/dd-trace/src/datastreams/checkpointer.js +2 -2
  78. package/packages/dd-trace/src/datastreams/manager.js +1 -1
  79. package/packages/dd-trace/src/datastreams/processor.js +2 -2
  80. package/packages/dd-trace/src/debugger/devtools_client/snapshot/collector.js +2 -2
  81. package/packages/dd-trace/src/debugger/devtools_client/source-maps.js +1 -1
  82. package/packages/dd-trace/src/debugger/devtools_client/state.js +2 -1
  83. package/packages/dd-trace/src/debugger/index.js +7 -7
  84. package/packages/dd-trace/src/dogstatsd.js +2 -2
  85. package/packages/dd-trace/src/encode/0.4.js +45 -54
  86. package/packages/dd-trace/src/encode/0.5.js +34 -3
  87. package/packages/dd-trace/src/encode/agentless-json.js +1 -1
  88. package/packages/dd-trace/src/exporter.js +2 -0
  89. package/packages/dd-trace/src/exporters/agent/index.js +2 -1
  90. package/packages/dd-trace/src/exporters/agentless/index.js +3 -2
  91. package/packages/dd-trace/src/exporters/agentless/writer.js +2 -2
  92. package/packages/dd-trace/src/exporters/common/buffering-exporter.js +2 -1
  93. package/packages/dd-trace/src/exporters/common/request.js +1 -1
  94. package/packages/dd-trace/src/exporters/electron/index.js +49 -0
  95. package/packages/dd-trace/src/external-logger/src/index.js +2 -1
  96. package/packages/dd-trace/src/git_metadata.js +10 -8
  97. package/packages/dd-trace/src/lambda/handler-paths.js +52 -0
  98. package/packages/dd-trace/src/lambda/index.js +62 -14
  99. package/packages/dd-trace/src/lambda/runtime/patch.js +21 -46
  100. package/packages/dd-trace/src/llmobs/index.js +13 -2
  101. package/packages/dd-trace/src/llmobs/plugins/bedrockruntime.js +45 -15
  102. package/packages/dd-trace/src/llmobs/writers/base.js +2 -1
  103. package/packages/dd-trace/src/openfeature/writers/base.js +2 -1
  104. package/packages/dd-trace/src/opentelemetry/metrics/periodic_metric_reader.js +2 -1
  105. package/packages/dd-trace/src/opentracing/propagation/text_map.js +20 -9
  106. package/packages/dd-trace/src/payload-tagging/config/index.js +2 -2
  107. package/packages/dd-trace/src/plugins/ci_plugin.js +49 -4
  108. package/packages/dd-trace/src/plugins/database.js +54 -12
  109. package/packages/dd-trace/src/plugins/index.js +1 -0
  110. package/packages/dd-trace/src/plugins/plugin.js +2 -4
  111. package/packages/dd-trace/src/plugins/util/ci.js +8 -8
  112. package/packages/dd-trace/src/plugins/util/git-cache.js +20 -18
  113. package/packages/dd-trace/src/plugins/util/stacktrace.js +2 -2
  114. package/packages/dd-trace/src/plugins/util/test.js +37 -5
  115. package/packages/dd-trace/src/plugins/util/user-provided-git.js +17 -15
  116. package/packages/dd-trace/src/priority_sampler.js +1 -1
  117. package/packages/dd-trace/src/profiling/profiler.js +1 -1
  118. package/packages/dd-trace/src/profiling/profilers/wall.js +1 -1
  119. package/packages/dd-trace/src/profiling/ssi-heuristics.js +1 -1
  120. package/packages/dd-trace/src/rate_limiter.js +1 -1
  121. package/packages/dd-trace/src/remote_config/scheduler.js +1 -1
  122. package/packages/dd-trace/src/ritm.js +2 -1
  123. package/packages/dd-trace/src/runtime_metrics/runtime_metrics.js +5 -8
  124. package/packages/dd-trace/src/serverless.js +5 -2
  125. package/packages/dd-trace/src/service-naming/schemas/v0/messaging.js +20 -0
  126. package/packages/dd-trace/src/service-naming/schemas/v0/web.js +4 -0
  127. package/packages/dd-trace/src/service-naming/schemas/v1/messaging.js +20 -0
  128. package/packages/dd-trace/src/service-naming/schemas/v1/web.js +4 -0
  129. package/packages/dd-trace/src/span_stats.js +1 -1
  130. package/packages/dd-trace/src/telemetry/dependencies.js +1 -1
  131. package/packages/dd-trace/src/telemetry/endpoints.js +1 -1
  132. package/packages/dd-trace/src/telemetry/telemetry.js +2 -2
  133. package/packages/dd-trace/src/lambda/runtime/ritm.js +0 -133
@@ -254,7 +254,8 @@
254
254
  "appsec.extendedHeadersCollection.redaction",
255
255
  "experimental.appsec.extendedHeadersCollection.redaction"
256
256
  ],
257
- "default": "true"
257
+ "default": "true",
258
+ "deprecated": true
258
259
  }
259
260
  ],
260
261
  "DD_APPSEC_HTTP_BLOCKED_TEMPLATE_HTML": [
@@ -289,7 +290,8 @@
289
290
  "appsec.extendedHeadersCollection.maxHeaders",
290
291
  "experimental.appsec.extendedHeadersCollection.maxHeaders"
291
292
  ],
292
- "default": "50"
293
+ "default": "50",
294
+ "deprecated": true
293
295
  }
294
296
  ],
295
297
  "DD_APPSEC_MAX_STACK_TRACES": [
@@ -597,6 +599,13 @@
597
599
  "default": "true"
598
600
  }
599
601
  ],
602
+ "DD_CUSTOM_PARENT_ID": [
603
+ {
604
+ "implementation": "A",
605
+ "type": "string",
606
+ "default": null
607
+ }
608
+ ],
600
609
  "DD_CUSTOM_TRACE_ID": [
601
610
  {
602
611
  "implementation": "A",
@@ -780,9 +789,9 @@
780
789
  ],
781
790
  "DD_EXPERIMENTAL_TEST_OPT_GIT_CACHE_DIR": [
782
791
  {
783
- "implementation": "A",
792
+ "implementation": "B",
784
793
  "type": "string",
785
- "default": "${os.tmpdir()}/dd-trace-git-cache"
794
+ "default": null
786
795
  }
787
796
  ],
788
797
  "DD_EXPERIMENTAL_TEST_OPT_GIT_CACHE_ENABLED": [
@@ -1062,10 +1071,7 @@
1062
1071
  {
1063
1072
  "implementation": "B",
1064
1073
  "type": "string",
1065
- "configurationNames": [
1066
- "iast.securityControlsConfiguration",
1067
- "experimental.iast.securityControlsConfiguration"
1068
- ],
1074
+ "internalPropertyName": "iast.securityControlsConfiguration",
1069
1075
  "default": null
1070
1076
  }
1071
1077
  ],
@@ -1934,9 +1940,9 @@
1934
1940
  ],
1935
1941
  "DD_TRACE_AWS_SDK_AWS_BATCH_PROPAGATION_ENABLED": [
1936
1942
  {
1937
- "implementation": "A",
1943
+ "implementation": "B",
1938
1944
  "type": "boolean",
1939
- "default": "true"
1945
+ "default": "false"
1940
1946
  }
1941
1947
  ],
1942
1948
  "DD_TRACE_AWS_SDK_AWS_ENABLED": [
@@ -1948,16 +1954,16 @@
1948
1954
  ],
1949
1955
  "DD_TRACE_AWS_SDK_BATCH_PROPAGATION_ENABLED": [
1950
1956
  {
1951
- "implementation": "A",
1957
+ "implementation": "B",
1952
1958
  "type": "boolean",
1953
- "default": "true"
1959
+ "default": "false"
1954
1960
  }
1955
1961
  ],
1956
1962
  "DD_TRACE_AWS_SDK_BEDROCKRUNTIME_BATCH_PROPAGATION_ENABLED": [
1957
1963
  {
1958
- "implementation": "A",
1964
+ "implementation": "B",
1959
1965
  "type": "boolean",
1960
- "default": "true"
1966
+ "default": "false"
1961
1967
  }
1962
1968
  ],
1963
1969
  "DD_TRACE_AWS_SDK_BEDROCKRUNTIME_ENABLED": [
@@ -1969,9 +1975,9 @@
1969
1975
  ],
1970
1976
  "DD_TRACE_AWS_SDK_CLOUDWATCHLOGS_BATCH_PROPAGATION_ENABLED": [
1971
1977
  {
1972
- "implementation": "A",
1978
+ "implementation": "B",
1973
1979
  "type": "boolean",
1974
- "default": "true"
1980
+ "default": "false"
1975
1981
  }
1976
1982
  ],
1977
1983
  "DD_TRACE_AWS_SDK_CLOUDWATCHLOGS_ENABLED": [
@@ -1983,9 +1989,9 @@
1983
1989
  ],
1984
1990
  "DD_TRACE_AWS_SDK_DYNAMODB_BATCH_PROPAGATION_ENABLED": [
1985
1991
  {
1986
- "implementation": "A",
1992
+ "implementation": "B",
1987
1993
  "type": "boolean",
1988
- "default": "true"
1994
+ "default": "false"
1989
1995
  }
1990
1996
  ],
1991
1997
  "DD_TRACE_AWS_SDK_DYNAMODB_ENABLED": [
@@ -2004,9 +2010,9 @@
2004
2010
  ],
2005
2011
  "DD_TRACE_AWS_SDK_EVENTBRIDGE_BATCH_PROPAGATION_ENABLED": [
2006
2012
  {
2007
- "implementation": "A",
2013
+ "implementation": "B",
2008
2014
  "type": "boolean",
2009
- "default": "true"
2015
+ "default": "false"
2010
2016
  }
2011
2017
  ],
2012
2018
  "DD_TRACE_AWS_SDK_EVENTBRIDGE_ENABLED": [
@@ -2018,9 +2024,9 @@
2018
2024
  ],
2019
2025
  "DD_TRACE_AWS_SDK_KINESIS_BATCH_PROPAGATION_ENABLED": [
2020
2026
  {
2021
- "implementation": "A",
2027
+ "implementation": "B",
2022
2028
  "type": "boolean",
2023
- "default": "true"
2029
+ "default": "false"
2024
2030
  }
2025
2031
  ],
2026
2032
  "DD_TRACE_AWS_SDK_KINESIS_ENABLED": [
@@ -2032,9 +2038,9 @@
2032
2038
  ],
2033
2039
  "DD_TRACE_AWS_SDK_LAMBDA_BATCH_PROPAGATION_ENABLED": [
2034
2040
  {
2035
- "implementation": "A",
2041
+ "implementation": "B",
2036
2042
  "type": "boolean",
2037
- "default": "true"
2043
+ "default": "false"
2038
2044
  }
2039
2045
  ],
2040
2046
  "DD_TRACE_AWS_SDK_LAMBDA_ENABLED": [
@@ -2053,9 +2059,9 @@
2053
2059
  ],
2054
2060
  "DD_TRACE_AWS_SDK_REDSHIFT_BATCH_PROPAGATION_ENABLED": [
2055
2061
  {
2056
- "implementation": "A",
2062
+ "implementation": "B",
2057
2063
  "type": "boolean",
2058
- "default": "true"
2064
+ "default": "false"
2059
2065
  }
2060
2066
  ],
2061
2067
  "DD_TRACE_AWS_SDK_REDSHIFT_ENABLED": [
@@ -2067,9 +2073,9 @@
2067
2073
  ],
2068
2074
  "DD_TRACE_AWS_SDK_S3_BATCH_PROPAGATION_ENABLED": [
2069
2075
  {
2070
- "implementation": "A",
2076
+ "implementation": "B",
2071
2077
  "type": "boolean",
2072
- "default": "true"
2078
+ "default": "false"
2073
2079
  }
2074
2080
  ],
2075
2081
  "DD_TRACE_AWS_SDK_S3_ENABLED": [
@@ -2081,9 +2087,9 @@
2081
2087
  ],
2082
2088
  "DD_TRACE_AWS_SDK_SFN_BATCH_PROPAGATION_ENABLED": [
2083
2089
  {
2084
- "implementation": "A",
2090
+ "implementation": "B",
2085
2091
  "type": "boolean",
2086
- "default": "true"
2092
+ "default": "false"
2087
2093
  }
2088
2094
  ],
2089
2095
  "DD_TRACE_AWS_SDK_SFN_CLIENT_ENABLED": [
@@ -2109,9 +2115,9 @@
2109
2115
  ],
2110
2116
  "DD_TRACE_AWS_SDK_SNS_BATCH_PROPAGATION_ENABLED": [
2111
2117
  {
2112
- "implementation": "A",
2118
+ "implementation": "B",
2113
2119
  "type": "boolean",
2114
- "default": "true"
2120
+ "default": "false"
2115
2121
  }
2116
2122
  ],
2117
2123
  "DD_TRACE_AWS_SDK_SNS_ENABLED": [
@@ -2123,9 +2129,9 @@
2123
2129
  ],
2124
2130
  "DD_TRACE_AWS_SDK_SQS_BATCH_PROPAGATION_ENABLED": [
2125
2131
  {
2126
- "implementation": "A",
2132
+ "implementation": "B",
2127
2133
  "type": "boolean",
2128
- "default": "true"
2134
+ "default": "false"
2129
2135
  }
2130
2136
  ],
2131
2137
  "DD_TRACE_AWS_SDK_SQS_ENABLED": [
@@ -2137,9 +2143,9 @@
2137
2143
  ],
2138
2144
  "DD_TRACE_AWS_SDK_STATES_BATCH_PROPAGATION_ENABLED": [
2139
2145
  {
2140
- "implementation": "A",
2146
+ "implementation": "B",
2141
2147
  "type": "boolean",
2142
- "default": "true"
2148
+ "default": "false"
2143
2149
  }
2144
2150
  ],
2145
2151
  "DD_TRACE_AWS_SDK_STATES_ENABLED": [
@@ -2151,9 +2157,9 @@
2151
2157
  ],
2152
2158
  "DD_TRACE_AWS_SDK_STEPFUNCTIONS_BATCH_PROPAGATION_ENABLED": [
2153
2159
  {
2154
- "implementation": "A",
2160
+ "implementation": "B",
2155
2161
  "type": "boolean",
2156
- "default": "true"
2162
+ "default": "false"
2157
2163
  }
2158
2164
  ],
2159
2165
  "DD_TRACE_AWS_SDK_STEPFUNCTIONS_ENABLED": [
@@ -2485,6 +2491,13 @@
2485
2491
  "default": "true"
2486
2492
  }
2487
2493
  ],
2494
+ "DD_TRACE_ELECTRON_ENABLED": [
2495
+ {
2496
+ "implementation": "A",
2497
+ "type": "boolean",
2498
+ "default": "true"
2499
+ }
2500
+ ],
2488
2501
  "DD_TRACE_ENABLED": [
2489
2502
  {
2490
2503
  "implementation": "A",
@@ -33,7 +33,7 @@ class DataStreamsCheckpointer {
33
33
  * Examples include kafka, kinesis, sns etc.
34
34
  * @param {string} source - The source of data. This can be a topic, exchange or stream name.
35
35
  * @param {object} carrier - The carrier object to extract context from.
36
- * @param {boolean} [manualCheckpoint=true] - Whether this checkpoint was manually set. Keep true if manually
36
+ * @param {boolean} [manualCheckpoint] - Whether this checkpoint was manually set. Keep true if manually
37
37
  * instrumenting. Manual instrumentation always overrides automatic
38
38
  * instrumentation in the case a call is both manually and automatically
39
39
  * instrumented.
@@ -60,7 +60,7 @@ class DataStreamsCheckpointer {
60
60
  * Tags the active span (or the provided span) with the transaction ID and checkpoint name.
61
61
  * @param {string} transactionId - The transaction identifier to track.
62
62
  * @param {string} checkpointName - The logical checkpoint name.
63
- * @param {object|null} [span=null] - Span to tag. Defaults to the currently active span.
63
+ * @param {object|null} [span] - Span to tag. Defaults to the currently active span.
64
64
  */
65
65
  trackTransaction (transactionId, checkpointName, span = null) {
66
66
  if (!this.config.dsmEnabled) return
@@ -26,7 +26,7 @@ class DataStreamsManager {
26
26
  /**
27
27
  * @param {string} transactionId
28
28
  * @param {string} checkpointName
29
- * @param {object|null} [span=null]
29
+ * @param {object|null} [span]
30
30
  */
31
31
  trackTransaction (transactionId, checkpointName, span = null) {
32
32
  this._dataStreamsProcessor.trackTransaction(transactionId, checkpointName, span)
@@ -237,7 +237,7 @@ class DataStreamsProcessor {
237
237
 
238
238
  if (this.enabled) {
239
239
  this.timer = setInterval(this.onInterval.bind(this), flushInterval)
240
- this.timer.unref()
240
+ this.timer.unref?.()
241
241
  }
242
242
  globalThis[Symbol.for('dd-trace')].beforeExitHandlers.add(this.onInterval.bind(this))
243
243
  }
@@ -377,7 +377,7 @@ class DataStreamsProcessor {
377
377
  *
378
378
  * @param {string} transactionId - Truncated to 255 UTF-8 bytes.
379
379
  * @param {string} checkpointName - Mapped to a stable 1-byte ID; silently dropped if registry full.
380
- * @param {import('../opentelemetry/span').Span|null} [span=null] - Active span to tag with DSM transaction metadata.
380
+ * @param {import('../opentelemetry/span').Span|null} [span] - Active span to tag with DSM transaction metadata.
381
381
  */
382
382
  trackTransaction (transactionId, checkpointName, span = null) {
383
383
  if (!this.enabled) {
@@ -72,9 +72,9 @@ module.exports = {
72
72
  * @param {string} objectId - The ID of the object to get the properties of
73
73
  * @param {GetObjectOptions} opts - The options for the snapshot. Also used to track the deadline and communicate the
74
74
  * deadline overrun to the caller using the `deadlineReached` flag.
75
- * @param {number} [depth=0] - The depth of the object. Only used internally by this module to track the current depth
75
+ * @param {number} [depth] - The depth of the object. Only used internally by this module to track the current depth
76
76
  * and should not be set by the caller.
77
- * @param {boolean} [collection=false] - Whether the object is a collection. Only used internally by this module to
77
+ * @param {boolean} [collection] - Whether the object is a collection. Only used internally by this module to
78
78
  * track the current object type and should not be set by the caller.
79
79
  * @returns {Promise<object[]>} The properties of the object
80
80
  */
@@ -63,7 +63,7 @@ function setCacheTTL () {
63
63
  // Clear cache a few seconds after it was last used
64
64
  cache.clear()
65
65
  }
66
- }, 5000).unref()
66
+ }, 5000).unref?.()
67
67
  }
68
68
 
69
69
  function loadInlineSourceMap (data) {
@@ -230,7 +230,8 @@ session.on('Debugger.scriptParsed', ({ params }) => {
230
230
  if (reEvaluateProbesTimer === null) {
231
231
  reEvaluateProbesTimer = setTimeout(() => {
232
232
  session.emit('scriptLoadingStabilized')
233
- }, 500).unref()
233
+ }, 500)
234
+ reEvaluateProbesTimer.unref?.()
234
235
  } else {
235
236
  reEvaluateProbesTimer.refresh()
236
237
  }
@@ -132,13 +132,13 @@ function start (config, rcInstance) {
132
132
  cleanup(error) // Be nice, clean up now that the worker thread encountered an issue and we can't continue
133
133
  })
134
134
 
135
- worker.unref()
136
- probeChannel.port1.unref()
137
- probeChannel.port2.unref()
138
- logChannel.port1.unref()
139
- logChannel.port2.unref()
140
- configChannel.port1.unref()
141
- configChannel.port2.unref()
135
+ worker.unref?.()
136
+ probeChannel.port1.unref?.()
137
+ probeChannel.port2.unref?.()
138
+ logChannel.port1.unref?.()
139
+ logChannel.port2.unref?.()
140
+ configChannel.port1.unref?.()
141
+ configChannel.port2.unref?.()
142
142
  })
143
143
  }
144
144
 
@@ -161,7 +161,7 @@ class DogStatsDClient {
161
161
  const socket = dgram.createSocket(type)
162
162
 
163
163
  socket.on('error', () => {})
164
- socket.unref()
164
+ socket.unref?.()
165
165
 
166
166
  return socket
167
167
  }
@@ -361,7 +361,7 @@ class CustomMetrics {
361
361
  const flush = this.flush.bind(this)
362
362
 
363
363
  // TODO(bengl) this magic number should be configurable
364
- setInterval(flush, 10 * 1000).unref()
364
+ setInterval(flush, 10 * 1000).unref?.()
365
365
 
366
366
  globalThis[Symbol.for('dd-trace')].beforeExitHandlers.add(flush)
367
367
  }
@@ -40,14 +40,14 @@ const KEY_TYPE = buildKey('type')
40
40
  const KEY_NAME = buildKey('name')
41
41
  const KEY_RESOURCE = buildKey('resource')
42
42
  const KEY_SERVICE = buildKey('service')
43
+ const KEY_ERROR = buildKey('error')
44
+ const KEY_START = buildKey('start')
45
+ const KEY_DURATION = buildKey('duration')
43
46
  const KEY_SPAN_EVENTS = buildKey('span_events')
44
47
  const KEY_META_STRUCT = buildKey('meta_struct')
45
48
  const KEY_TRACE_ID_PREFIX = buildKeyWithPrefix('trace_id', 0xCF)
46
49
  const KEY_SPAN_ID_PREFIX = buildKeyWithPrefix('span_id', 0xCF)
47
50
  const KEY_PARENT_ID_PREFIX = buildKeyWithPrefix('parent_id', 0xCF)
48
- const KEY_ERROR_PREFIX = buildKeyWithPrefix('error', 0xCE)
49
- const KEY_START_PREFIX = buildKeyWithPrefix('start', 0xCF)
50
- const KEY_DURATION_PREFIX = buildKeyWithPrefix('duration', 0xCF)
51
51
  const KEY_META_PREFIX = buildKeyWithPrefix('meta', 0xDF)
52
52
  const KEY_METRICS_PREFIX = buildKeyWithPrefix('metrics', 0xDF)
53
53
 
@@ -344,9 +344,12 @@ class AgentEncoder {
344
344
  cursor += KEY_SERVICE.length
345
345
  target.set(serviceEntry, cursor)
346
346
 
347
- this.#writeIntegerField(bytes, KEY_ERROR_PREFIX, span.error)
348
- this.#writeLongField(bytes, KEY_START_PREFIX, span.start)
349
- this.#writeLongField(bytes, KEY_DURATION_PREFIX, span.duration)
347
+ bytes.set(KEY_ERROR)
348
+ this._encodeIntOrFloat(bytes, span.error)
349
+ bytes.set(KEY_START)
350
+ this._encodeIntOrFloat(bytes, span.start)
351
+ bytes.set(KEY_DURATION)
352
+ this._encodeIntOrFloat(bytes, span.duration)
350
353
 
351
354
  this.#encodeMetaEntries(bytes, KEY_META_PREFIX, span.meta)
352
355
  this.#encodeMetaEntries(bytes, KEY_METRICS_PREFIX, span.metrics)
@@ -448,6 +451,8 @@ class AgentEncoder {
448
451
  }
449
452
 
450
453
  // Single pass: reserve the count slot, encode entries while counting, patch the count.
454
+ // Subclasses (0.5, CI visibility encoders) inherit this; the wire stays on float64
455
+ // for numeric values to keep their established trace / events intake unchanged.
451
456
  _encodeMap (bytes, value) {
452
457
  const offset = bytes.length
453
458
  bytes.reserve(5)
@@ -542,12 +547,9 @@ class AgentEncoder {
542
547
  target.set(keyEntry, writeOffset)
543
548
  target.set(valueEntry, writeOffset + keyEntryLen)
544
549
  } else {
545
- bytes.reserve(keyEntryLen + 9)
546
- const target = bytes.buffer
547
- target.set(keyEntry, writeOffset)
548
- const valueOffset = writeOffset + keyEntryLen
549
- target[valueOffset] = 0xCB
550
- bytes.view.setFloat64(valueOffset + 1, entryValue)
550
+ bytes.reserve(keyEntryLen)
551
+ bytes.buffer.set(keyEntry, writeOffset)
552
+ this._encodeIntOrFloat(bytes, entryValue)
551
553
  }
552
554
  count++
553
555
  }
@@ -588,49 +590,38 @@ class AgentEncoder {
588
590
  }
589
591
 
590
592
  /**
593
+ * Emit `value` as the smallest valid msgpack number encoding: compact
594
+ * unsigned/signed int when integer, float64 otherwise. Unlike
595
+ * `MsgpackEncoder#encodeNumber`, NaN keeps its float64 bits instead of
596
+ * coercing to fixint 0.
597
+ *
598
+ * Underscore-protected so the 0.5 subclass can call it from its own
599
+ * `_encode` / `_encodeMap` overrides.
600
+ *
591
601
  * @param {MsgpackChunk} bytes
592
- * @param {Buffer} keyPrefix Precomputed `[key, 0xCE]`.
593
602
  * @param {number} value
594
603
  */
595
- #writeIntegerField (bytes, keyPrefix, value) {
596
- const keyPrefixLen = keyPrefix.length
597
- const offset = bytes.length
598
- bytes.reserve(keyPrefixLen + 4)
599
-
600
- const target = bytes.buffer
601
- target.set(keyPrefix, offset)
602
-
603
- const valueOffset = offset + keyPrefixLen
604
- target[valueOffset] = value >> 24
605
- target[valueOffset + 1] = value >> 16
606
- target[valueOffset + 2] = value >> 8
607
- target[valueOffset + 3] = value
608
- }
609
-
610
- /**
611
- * @param {MsgpackChunk} bytes
612
- * @param {Buffer} keyPrefix Precomputed `[key, 0xCF]`.
613
- * @param {number} value Up to a 53-bit safe integer.
614
- */
615
- #writeLongField (bytes, keyPrefix, value) {
616
- const high = (value / 2 ** 32) >> 0
617
- const low = value >>> 0
618
- const keyPrefixLen = keyPrefix.length
619
- const offset = bytes.length
620
- bytes.reserve(keyPrefixLen + 8)
621
-
622
- const target = bytes.buffer
623
- target.set(keyPrefix, offset)
624
-
625
- const valueOffset = offset + keyPrefixLen
626
- target[valueOffset] = high >> 24
627
- target[valueOffset + 1] = high >> 16
628
- target[valueOffset + 2] = high >> 8
629
- target[valueOffset + 3] = high
630
- target[valueOffset + 4] = low >> 24
631
- target[valueOffset + 5] = low >> 16
632
- target[valueOffset + 6] = low >> 8
633
- target[valueOffset + 7] = low
604
+ _encodeIntOrFloat (bytes, value) {
605
+ // Fast path: positive fixint (0..127). `value === (value & 0x7F)` is true
606
+ // iff `value` is an exact integer in that range — covers `error: 0/1`,
607
+ // priority flags, attribute counts, HTTP status codes mapped to numbers,
608
+ // and most small metrics. NaN, ±Infinity, negatives, and any non-integer
609
+ // float fall through.
610
+ if (value === (value & 0x7F)) {
611
+ const offset = bytes.length
612
+ bytes.reserve(1)
613
+ bytes.buffer[offset] = value
614
+ return
615
+ }
616
+ if (Number.isInteger(value)) {
617
+ if (value >= 0) {
618
+ this.#msgpack.encodeUnsigned(bytes, value)
619
+ } else {
620
+ this.#msgpack.encodeSigned(bytes, value)
621
+ }
622
+ } else {
623
+ this.#encodeFloat(bytes, value)
624
+ }
634
625
  }
635
626
 
636
627
  /**
@@ -853,7 +844,7 @@ class AgentEncoder {
853
844
  if (typeof value === 'number') {
854
845
  this._encodeString(bytes, key)
855
846
  bytes.set(Number.isInteger(value) ? ATTR_PREFIX_INT : ATTR_PREFIX_DOUBLE)
856
- this.#encodeFloat(bytes, value)
847
+ this._encodeIntOrFloat(bytes, value)
857
848
  return true
858
849
  }
859
850
  if (typeof value === 'boolean') {
@@ -923,7 +914,7 @@ class AgentEncoder {
923
914
  }
924
915
  if (typeof value === 'number') {
925
916
  bytes.set(Number.isInteger(value) ? ATTR_PREFIX_INT : ATTR_PREFIX_DOUBLE)
926
- this.#encodeFloat(bytes, value)
917
+ this._encodeIntOrFloat(bytes, value)
927
918
  return true
928
919
  }
929
920
  if (typeof value === 'boolean') {
@@ -46,15 +46,46 @@ class AgentEncoder extends BaseEncoder {
46
46
  this._encodeId(bytes, span.trace_id)
47
47
  this._encodeId(bytes, span.span_id)
48
48
  this._encodeId(bytes, span.parent_id)
49
- this._encodeLong(bytes, span.start || 0)
50
- this._encodeLong(bytes, span.duration || 0)
51
- this._encodeInteger(bytes, span.error)
49
+ this._encodeIntOrFloat(bytes, span.start || 0)
50
+ this._encodeIntOrFloat(bytes, span.duration || 0)
51
+ this._encodeIntOrFloat(bytes, span.error)
52
52
  this._encodeMap(bytes, span.meta || {})
53
53
  this._encodeMap(bytes, span.metrics || {})
54
54
  this._encodeString(bytes, span.type)
55
55
  }
56
56
  }
57
57
 
58
+ // Override the inherited 0.4 `_encodeMap` so the v0.5 wire emits each numeric
59
+ // value via `_encodeIntOrFloat` (compact unsigned/signed int when integer,
60
+ // float64 otherwise) instead of always float64. The 0.4 base method stays on
61
+ // float64 because the CI-visibility encoders inherit it and target a
62
+ // different intake.
63
+ _encodeMap (bytes, value) {
64
+ const offset = bytes.length
65
+ bytes.reserve(5)
66
+ bytes.buffer[offset] = 0xDF
67
+
68
+ let count = 0
69
+ for (const key of Object.keys(value)) {
70
+ const entryValue = value[key]
71
+ if (typeof entryValue === 'string') {
72
+ this._encodeString(bytes, key)
73
+ this._encodeString(bytes, entryValue)
74
+ count++
75
+ } else if (typeof entryValue === 'number') {
76
+ this._encodeString(bytes, key)
77
+ this._encodeIntOrFloat(bytes, entryValue)
78
+ count++
79
+ }
80
+ }
81
+
82
+ const target = bytes.buffer
83
+ target[offset + 1] = count >>> 24
84
+ target[offset + 2] = count >>> 16
85
+ target[offset + 3] = count >>> 8
86
+ target[offset + 4] = count
87
+ }
88
+
58
89
  _encodeString (bytes, value = '') {
59
90
  let index = this._stringMap[value]
60
91
  if (index === undefined) {
@@ -85,7 +85,7 @@ function spanToJSON (span) {
85
85
  class AgentlessJSONEncoder {
86
86
  /**
87
87
  * @param {object} writer - Writer instance with a flush() method, called when the buffer exceeds the soft limit
88
- * @param {object} [metadata={}] - Shared metadata spread into each trace object (hostname, env, tracerVersion, etc.)
88
+ * @param {object} [metadata] - Shared metadata spread into each trace object (hostname, env, tracerVersion, etc.)
89
89
  */
90
90
  constructor (writer, metadata = {}) {
91
91
  this._writer = writer
@@ -7,6 +7,8 @@ const constants = require('./constants')
7
7
 
8
8
  module.exports = function getExporter (name) {
9
9
  switch (name) {
10
+ case exporters.ELECTRON:
11
+ return require('./exporters/electron')
10
12
  case exporters.LOG:
11
13
  return require('./exporters/log')
12
14
  case exporters.AGENT:
@@ -50,7 +50,8 @@ class AgentExporter {
50
50
  this.#timer = setTimeout(() => {
51
51
  this._writer.flush()
52
52
  this.#timer = undefined
53
- }, flushInterval).unref()
53
+ }, flushInterval)
54
+ this.#timer.unref?.()
54
55
  }
55
56
  }
56
57
 
@@ -18,7 +18,7 @@ class AgentlessExporter {
18
18
 
19
19
  /**
20
20
  * @param {object} config - Configuration object
21
- * @param {string} [config.site='datadoghq.com'] - The Datadog site
21
+ * @param {string} [config.site] - The Datadog site. Defaults to 'datadoghq.com'.
22
22
  * @param {string} [config.url] - Override intake URL
23
23
  * @param {number} [config.flushInterval] - Batch flush interval in ms
24
24
  * @param {string} [config.env] - Environment name
@@ -109,7 +109,8 @@ class AgentlessExporter {
109
109
  log.error('Failed to flush traces on timer: %s', err.message)
110
110
  }
111
111
  this.#timer = undefined
112
- }, flushInterval).unref()
112
+ }, flushInterval)
113
+ this.#timer.unref?.()
113
114
  }
114
115
  }
115
116
 
@@ -19,8 +19,8 @@ class AgentlessWriter extends BaseWriter {
19
19
  /**
20
20
  * @param {object} options - Writer options
21
21
  * @param {URL} [options.url] - The intake URL. If not provided, constructed from site.
22
- * @param {string} [options.site='datadoghq.com'] - The Datadog site
23
- * @param {object} [options.metadata={}] - Metadata to pass to the encoder (hostname, env, etc.)
22
+ * @param {string} [options.site] - The Datadog site
23
+ * @param {object} [options.metadata] - Metadata to pass to the encoder (hostname, env, etc.)
24
24
  */
25
25
  constructor ({ url, site = 'datadoghq.com', metadata = {} }) {
26
26
  super({ url })
@@ -39,7 +39,8 @@ class BufferingExporter {
39
39
  this[timerKey] = setTimeout(() => {
40
40
  writer.flush()
41
41
  this[timerKey] = undefined
42
- }, flushInterval).unref()
42
+ }, flushInterval)
43
+ this[timerKey].unref?.()
43
44
  }
44
45
  }
45
46
 
@@ -180,7 +180,7 @@ function request (data, options, callback) {
180
180
  // Unref so a pending retry never keeps the host process alive past
181
181
  // its natural exit point; long-running apps still retry because the
182
182
  // event loop is held open by their own work.
183
- setTimeout(attempt, getRetryDelay(options, attemptIndex), attemptIndex + 1).unref()
183
+ setTimeout(attempt, getRetryDelay(options, attemptIndex), attemptIndex + 1).unref?.()
184
184
  } else {
185
185
  callback(error)
186
186
  }