dd-trace 5.53.0 → 5.54.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 (319) hide show
  1. package/LICENSE-3rdparty.csv +2 -1
  2. package/index.d.ts +33 -16
  3. package/initialize.mjs +3 -4
  4. package/package.json +36 -34
  5. package/packages/datadog-core/src/utils/src/get.js +1 -1
  6. package/packages/datadog-core/src/utils/src/has.js +1 -1
  7. package/packages/datadog-core/src/utils/src/kebabcase.js +4 -6
  8. package/packages/datadog-core/src/utils/src/parse-tags.js +1 -1
  9. package/packages/datadog-core/src/utils/src/pick.js +2 -2
  10. package/packages/datadog-core/src/utils/src/set.js +1 -1
  11. package/packages/datadog-core/src/utils/src/uniq.js +1 -1
  12. package/packages/datadog-instrumentations/src/amqp10.js +19 -17
  13. package/packages/datadog-instrumentations/src/amqplib.js +52 -35
  14. package/packages/datadog-instrumentations/src/apollo.js +2 -2
  15. package/packages/datadog-instrumentations/src/aws-sdk.js +1 -1
  16. package/packages/datadog-instrumentations/src/cassandra-driver.js +5 -4
  17. package/packages/datadog-instrumentations/src/child_process.js +1 -2
  18. package/packages/datadog-instrumentations/src/confluentinc-kafka-javascript.js +88 -73
  19. package/packages/datadog-instrumentations/src/couchbase.js +3 -3
  20. package/packages/datadog-instrumentations/src/cucumber.js +87 -40
  21. package/packages/datadog-instrumentations/src/cypress.js +2 -1
  22. package/packages/datadog-instrumentations/src/dns.js +1 -1
  23. package/packages/datadog-instrumentations/src/fs.js +1 -1
  24. package/packages/datadog-instrumentations/src/google-cloud-pubsub.js +28 -34
  25. package/packages/datadog-instrumentations/src/graphql.js +7 -10
  26. package/packages/datadog-instrumentations/src/grpc/client.js +11 -23
  27. package/packages/datadog-instrumentations/src/grpc/server.js +7 -20
  28. package/packages/datadog-instrumentations/src/helpers/extract-package-and-module-path.js +16 -10
  29. package/packages/datadog-instrumentations/src/helpers/hook.js +1 -1
  30. package/packages/datadog-instrumentations/src/helpers/hooks.js +0 -1
  31. package/packages/datadog-instrumentations/src/helpers/instrument.js +1 -41
  32. package/packages/datadog-instrumentations/src/helpers/register.js +5 -7
  33. package/packages/datadog-instrumentations/src/http/client.js +14 -20
  34. package/packages/datadog-instrumentations/src/jest.js +137 -48
  35. package/packages/datadog-instrumentations/src/kafkajs.js +52 -44
  36. package/packages/datadog-instrumentations/src/knex.js +4 -4
  37. package/packages/datadog-instrumentations/src/ldapjs.js +3 -4
  38. package/packages/datadog-instrumentations/src/mariadb.js +38 -61
  39. package/packages/datadog-instrumentations/src/mocha/main.js +63 -24
  40. package/packages/datadog-instrumentations/src/mocha/utils.js +36 -12
  41. package/packages/datadog-instrumentations/src/mocha/worker.js +6 -0
  42. package/packages/datadog-instrumentations/src/mongodb-core.js +1 -1
  43. package/packages/datadog-instrumentations/src/mysql.js +20 -36
  44. package/packages/datadog-instrumentations/src/mysql2.js +53 -47
  45. package/packages/datadog-instrumentations/src/net.js +1 -1
  46. package/packages/datadog-instrumentations/src/next.js +1 -0
  47. package/packages/datadog-instrumentations/src/nyc.js +1 -1
  48. package/packages/datadog-instrumentations/src/openai.js +21 -23
  49. package/packages/datadog-instrumentations/src/oracledb.js +1 -1
  50. package/packages/datadog-instrumentations/src/pg.js +1 -2
  51. package/packages/datadog-instrumentations/src/playwright.js +112 -69
  52. package/packages/datadog-instrumentations/src/redis.js +3 -3
  53. package/packages/datadog-instrumentations/src/restify.js +2 -2
  54. package/packages/datadog-instrumentations/src/rhea.js +42 -54
  55. package/packages/datadog-instrumentations/src/router.js +22 -25
  56. package/packages/datadog-instrumentations/src/tedious.js +1 -1
  57. package/packages/datadog-instrumentations/src/vitest.js +77 -28
  58. package/packages/datadog-plugin-amqp10/src/consumer.js +7 -3
  59. package/packages/datadog-plugin-amqp10/src/producer.js +7 -3
  60. package/packages/datadog-plugin-amqplib/src/client.js +6 -2
  61. package/packages/datadog-plugin-amqplib/src/consumer.js +7 -3
  62. package/packages/datadog-plugin-amqplib/src/producer.js +7 -3
  63. package/packages/datadog-plugin-amqplib/src/util.js +1 -1
  64. package/packages/datadog-plugin-apollo/src/gateway/request.js +5 -6
  65. package/packages/datadog-plugin-apollo/src/gateway/validate.js +2 -3
  66. package/packages/datadog-plugin-aws-sdk/src/base.js +3 -2
  67. package/packages/datadog-plugin-aws-sdk/src/services/bedrockruntime/tracing.js +2 -2
  68. package/packages/datadog-plugin-aws-sdk/src/services/bedrockruntime/utils.js +13 -13
  69. package/packages/datadog-plugin-aws-sdk/src/services/dynamodb.js +24 -31
  70. package/packages/datadog-plugin-aws-sdk/src/services/eventbridge.js +2 -2
  71. package/packages/datadog-plugin-aws-sdk/src/services/kinesis.js +6 -6
  72. package/packages/datadog-plugin-aws-sdk/src/services/lambda.js +1 -1
  73. package/packages/datadog-plugin-aws-sdk/src/services/sns.js +1 -1
  74. package/packages/datadog-plugin-aws-sdk/src/services/sqs.js +4 -5
  75. package/packages/datadog-plugin-aws-sdk/src/services/stepfunctions.js +1 -1
  76. package/packages/datadog-plugin-aws-sdk/src/util.js +5 -6
  77. package/packages/datadog-plugin-cassandra-driver/src/index.js +1 -1
  78. package/packages/datadog-plugin-child_process/src/index.js +4 -4
  79. package/packages/datadog-plugin-child_process/src/scrub-cmd-params.js +23 -23
  80. package/packages/datadog-plugin-cucumber/src/index.js +57 -2
  81. package/packages/datadog-plugin-cypress/src/cypress-plugin.js +97 -27
  82. package/packages/datadog-plugin-cypress/src/plugin.js +11 -1
  83. package/packages/datadog-plugin-cypress/src/support.js +24 -5
  84. package/packages/datadog-plugin-express/src/code_origin.js +30 -0
  85. package/packages/datadog-plugin-express/src/index.js +10 -12
  86. package/packages/datadog-plugin-express/src/tracing.js +19 -0
  87. package/packages/datadog-plugin-google-cloud-pubsub/src/client.js +7 -3
  88. package/packages/datadog-plugin-google-cloud-pubsub/src/consumer.js +12 -7
  89. package/packages/datadog-plugin-google-cloud-pubsub/src/producer.js +6 -2
  90. package/packages/datadog-plugin-google-cloud-vertexai/src/tracing.js +26 -9
  91. package/packages/datadog-plugin-graphql/src/execute.js +2 -2
  92. package/packages/datadog-plugin-graphql/src/index.js +7 -6
  93. package/packages/datadog-plugin-graphql/src/resolve.js +2 -2
  94. package/packages/datadog-plugin-graphql/src/tools/index.js +1 -0
  95. package/packages/datadog-plugin-graphql/src/tools/signature.js +1 -0
  96. package/packages/datadog-plugin-graphql/src/tools/transforms.js +1 -0
  97. package/packages/datadog-plugin-grpc/src/client.js +2 -2
  98. package/packages/datadog-plugin-grpc/src/util.js +2 -2
  99. package/packages/datadog-plugin-http/src/client.js +18 -7
  100. package/packages/datadog-plugin-http2/src/client.js +20 -20
  101. package/packages/datadog-plugin-jest/src/index.js +23 -21
  102. package/packages/datadog-plugin-jest/src/util.js +8 -8
  103. package/packages/datadog-plugin-kafkajs/src/batch-consumer.js +3 -1
  104. package/packages/datadog-plugin-kafkajs/src/consumer.js +9 -5
  105. package/packages/datadog-plugin-kafkajs/src/producer.js +8 -3
  106. package/packages/datadog-plugin-kafkajs/src/utils.js +1 -1
  107. package/packages/datadog-plugin-langchain/src/handlers/chain.js +7 -7
  108. package/packages/datadog-plugin-langchain/src/handlers/embedding.js +2 -2
  109. package/packages/datadog-plugin-langchain/src/handlers/language_models/chat_model.js +6 -4
  110. package/packages/datadog-plugin-langchain/src/handlers/language_models/llm.js +5 -4
  111. package/packages/datadog-plugin-langchain/src/tracing.js +11 -10
  112. package/packages/datadog-plugin-mariadb/src/index.js +3 -9
  113. package/packages/datadog-plugin-mocha/src/index.js +33 -13
  114. package/packages/datadog-plugin-mongodb-core/src/index.js +1 -1
  115. package/packages/datadog-plugin-mysql/src/index.js +11 -9
  116. package/packages/datadog-plugin-mysql2/src/index.js +16 -0
  117. package/packages/datadog-plugin-net/src/tcp.js +1 -1
  118. package/packages/datadog-plugin-next/src/index.js +6 -5
  119. package/packages/datadog-plugin-openai/src/services.js +6 -10
  120. package/packages/datadog-plugin-openai/src/tracing.js +10 -14
  121. package/packages/datadog-plugin-oracledb/src/index.js +1 -1
  122. package/packages/datadog-plugin-playwright/src/index.js +22 -2
  123. package/packages/datadog-plugin-redis/src/index.js +1 -1
  124. package/packages/datadog-plugin-rhea/src/consumer.js +8 -6
  125. package/packages/datadog-plugin-rhea/src/producer.js +5 -2
  126. package/packages/datadog-plugin-router/src/index.js +1 -1
  127. package/packages/datadog-plugin-selenium/src/index.js +1 -6
  128. package/packages/datadog-plugin-vitest/src/index.js +47 -31
  129. package/packages/datadog-shimmer/src/shimmer.js +4 -8
  130. package/packages/dd-trace/src/appsec/api_security_sampler.js +2 -2
  131. package/packages/dd-trace/src/appsec/blocked_templates.js +1 -1
  132. package/packages/dd-trace/src/appsec/blocking.js +6 -20
  133. package/packages/dd-trace/src/appsec/iast/analyzers/hardcoded-password-rules.js +1 -1
  134. package/packages/dd-trace/src/appsec/iast/analyzers/hardcoded-secret-rules.js +1 -1
  135. package/packages/dd-trace/src/appsec/iast/analyzers/hardcoded-secrets-rules.js +1 -1
  136. package/packages/dd-trace/src/appsec/iast/analyzers/header-injection-analyzer.js +4 -6
  137. package/packages/dd-trace/src/appsec/iast/analyzers/hsts-header-missing-analyzer.js +7 -12
  138. package/packages/dd-trace/src/appsec/iast/analyzers/missing-header-analyzer.js +4 -6
  139. package/packages/dd-trace/src/appsec/iast/analyzers/nosql-injection-mongodb-analyzer.js +4 -0
  140. package/packages/dd-trace/src/appsec/iast/analyzers/path-traversal-analyzer.js +9 -12
  141. package/packages/dd-trace/src/appsec/iast/analyzers/vulnerability-analyzer.js +5 -4
  142. package/packages/dd-trace/src/appsec/iast/context/context-plugin.js +2 -3
  143. package/packages/dd-trace/src/appsec/iast/iast-plugin.js +3 -3
  144. package/packages/dd-trace/src/appsec/iast/index.js +1 -0
  145. package/packages/dd-trace/src/appsec/iast/overhead-controller.js +102 -7
  146. package/packages/dd-trace/src/appsec/iast/path-line.js +7 -8
  147. package/packages/dd-trace/src/appsec/iast/security-controls/index.js +6 -13
  148. package/packages/dd-trace/src/appsec/iast/security-controls/parser.js +6 -6
  149. package/packages/dd-trace/src/appsec/iast/taint-tracking/filter.js +2 -2
  150. package/packages/dd-trace/src/appsec/iast/taint-tracking/operations-taint-object.js +3 -3
  151. package/packages/dd-trace/src/appsec/iast/taint-tracking/operations.js +4 -28
  152. package/packages/dd-trace/src/appsec/iast/taint-tracking/plugin.js +1 -7
  153. package/packages/dd-trace/src/appsec/iast/taint-tracking/plugins/kafka.js +3 -4
  154. package/packages/dd-trace/src/appsec/iast/taint-tracking/rewriter-esm.mjs +1 -1
  155. package/packages/dd-trace/src/appsec/iast/taint-tracking/rewriter.js +5 -7
  156. package/packages/dd-trace/src/appsec/iast/taint-tracking/taint-tracking-impl.js +2 -2
  157. package/packages/dd-trace/src/appsec/iast/telemetry/span-tags.js +6 -6
  158. package/packages/dd-trace/src/appsec/iast/telemetry/verbosity.js +1 -1
  159. package/packages/dd-trace/src/appsec/iast/vulnerabilities-formatter/evidence-redaction/sensitive-analyzers/command-sensitive-analyzer.js +1 -1
  160. package/packages/dd-trace/src/appsec/iast/vulnerabilities-formatter/evidence-redaction/sensitive-analyzers/ldap-sensitive-analyzer.js +1 -1
  161. package/packages/dd-trace/src/appsec/iast/vulnerabilities-formatter/evidence-redaction/sensitive-analyzers/sql-sensitive-analyzer.js +7 -7
  162. package/packages/dd-trace/src/appsec/iast/vulnerabilities-formatter/evidence-redaction/sensitive-handler.js +23 -24
  163. package/packages/dd-trace/src/appsec/iast/vulnerabilities-formatter/evidence-redaction/sensitive-regex.js +3 -3
  164. package/packages/dd-trace/src/appsec/iast/vulnerabilities-formatter/index.js +4 -4
  165. package/packages/dd-trace/src/appsec/iast/vulnerabilities-formatter/utils.js +6 -11
  166. package/packages/dd-trace/src/appsec/iast/vulnerability-reporter.js +9 -11
  167. package/packages/dd-trace/src/appsec/index.js +1 -1
  168. package/packages/dd-trace/src/appsec/rasp/index.js +15 -15
  169. package/packages/dd-trace/src/appsec/rasp/lfi.js +2 -1
  170. package/packages/dd-trace/src/appsec/reporter.js +233 -40
  171. package/packages/dd-trace/src/appsec/rule_manager.js +2 -2
  172. package/packages/dd-trace/src/appsec/stack_trace.js +2 -4
  173. package/packages/dd-trace/src/appsec/telemetry/rasp.js +3 -5
  174. package/packages/dd-trace/src/appsec/telemetry/waf.js +3 -5
  175. package/packages/dd-trace/src/appsec/user_tracking.js +3 -5
  176. package/packages/dd-trace/src/appsec/waf/waf_context_wrapper.js +2 -2
  177. package/packages/dd-trace/src/azure_metadata.js +2 -7
  178. package/packages/dd-trace/src/ci-visibility/dynamic-instrumentation/index.js +1 -1
  179. package/packages/dd-trace/src/ci-visibility/dynamic-instrumentation/worker/index.js +2 -2
  180. package/packages/dd-trace/src/ci-visibility/early-flake-detection/get-known-tests.js +1 -1
  181. package/packages/dd-trace/src/ci-visibility/exporters/agent-proxy/index.js +3 -3
  182. package/packages/dd-trace/src/ci-visibility/exporters/agentless/coverage-writer.js +1 -1
  183. package/packages/dd-trace/src/ci-visibility/exporters/agentless/di-logs-writer.js +1 -1
  184. package/packages/dd-trace/src/ci-visibility/exporters/agentless/writer.js +1 -1
  185. package/packages/dd-trace/src/ci-visibility/exporters/ci-visibility-exporter.js +6 -4
  186. package/packages/dd-trace/src/ci-visibility/exporters/git/git_metadata.js +2 -2
  187. package/packages/dd-trace/src/ci-visibility/exporters/test-worker/writer.js +0 -2
  188. package/packages/dd-trace/src/ci-visibility/intelligent-test-runner/get-skippable-suites.js +1 -1
  189. package/packages/dd-trace/src/ci-visibility/log-submission/log-submission-plugin.js +1 -1
  190. package/packages/dd-trace/src/ci-visibility/requests/get-library-configuration.js +8 -5
  191. package/packages/dd-trace/src/ci-visibility/telemetry.js +4 -0
  192. package/packages/dd-trace/src/ci-visibility/test-management/get-test-management-tests.js +1 -1
  193. package/packages/dd-trace/src/config.js +82 -51
  194. package/packages/dd-trace/src/config_stable.js +3 -3
  195. package/packages/dd-trace/src/datastreams/encoding.js +9 -9
  196. package/packages/dd-trace/src/datastreams/fnv.js +1 -1
  197. package/packages/dd-trace/src/datastreams/pathway.js +4 -4
  198. package/packages/dd-trace/src/datastreams/processor.js +5 -7
  199. package/packages/dd-trace/src/datastreams/schemas/schema_builder.js +1 -1
  200. package/packages/dd-trace/src/datastreams/schemas/schema_sampler.js +4 -6
  201. package/packages/dd-trace/src/datastreams/size.js +1 -1
  202. package/packages/dd-trace/src/debugger/devtools_client/breakpoints.js +74 -67
  203. package/packages/dd-trace/src/debugger/devtools_client/condition.js +6 -8
  204. package/packages/dd-trace/src/debugger/devtools_client/defaults.js +1 -1
  205. package/packages/dd-trace/src/debugger/devtools_client/index.js +7 -1
  206. package/packages/dd-trace/src/debugger/devtools_client/remote_config.js +18 -38
  207. package/packages/dd-trace/src/debugger/devtools_client/snapshot/index.js +1 -1
  208. package/packages/dd-trace/src/debugger/devtools_client/snapshot/processor.js +8 -10
  209. package/packages/dd-trace/src/debugger/devtools_client/snapshot/redaction.js +3 -3
  210. package/packages/dd-trace/src/debugger/devtools_client/source-maps.js +2 -10
  211. package/packages/dd-trace/src/debugger/devtools_client/state.js +10 -3
  212. package/packages/dd-trace/src/dogstatsd.js +5 -4
  213. package/packages/dd-trace/src/encode/0.4.js +9 -9
  214. package/packages/dd-trace/src/encode/0.5.js +1 -1
  215. package/packages/dd-trace/src/encode/agentless-ci-visibility.js +3 -3
  216. package/packages/dd-trace/src/encode/coverage-ci-visibility.js +1 -1
  217. package/packages/dd-trace/src/encode/tags-processors.js +1 -1
  218. package/packages/dd-trace/src/exporter.js +6 -6
  219. package/packages/dd-trace/src/exporters/agent/writer.js +1 -5
  220. package/packages/dd-trace/src/exporters/common/docker.js +1 -1
  221. package/packages/dd-trace/src/exporters/common/form-data.js +6 -4
  222. package/packages/dd-trace/src/exporters/common/request.js +1 -1
  223. package/packages/dd-trace/src/exporters/common/util.js +1 -1
  224. package/packages/dd-trace/src/external-logger/src/index.js +5 -5
  225. package/packages/dd-trace/src/flare/file.js +1 -5
  226. package/packages/dd-trace/src/format.js +1 -1
  227. package/packages/dd-trace/src/git_properties.js +1 -1
  228. package/packages/dd-trace/src/id.js +12 -6
  229. package/packages/dd-trace/src/iitm.js +10 -22
  230. package/packages/dd-trace/src/lambda/handler.js +6 -6
  231. package/packages/dd-trace/src/lambda/runtime/patch.js +4 -4
  232. package/packages/dd-trace/src/lambda/runtime/ritm.js +1 -1
  233. package/packages/dd-trace/src/llmobs/plugins/bedrockruntime.js +6 -6
  234. package/packages/dd-trace/src/llmobs/plugins/langchain/handlers/chain.js +2 -6
  235. package/packages/dd-trace/src/llmobs/plugins/langchain/handlers/chat_model.js +3 -3
  236. package/packages/dd-trace/src/llmobs/plugins/langchain/index.js +6 -6
  237. package/packages/dd-trace/src/llmobs/plugins/openai.js +1 -1
  238. package/packages/dd-trace/src/llmobs/sdk.js +2 -2
  239. package/packages/dd-trace/src/llmobs/tagger.js +110 -96
  240. package/packages/dd-trace/src/llmobs/util.js +9 -9
  241. package/packages/dd-trace/src/llmobs/writers/base.js +1 -1
  242. package/packages/dd-trace/src/llmobs/writers/util.js +1 -1
  243. package/packages/dd-trace/src/log/index.js +4 -4
  244. package/packages/dd-trace/src/log/log.js +1 -1
  245. package/packages/dd-trace/src/log/writer.js +2 -2
  246. package/packages/dd-trace/src/msgpack/chunk.js +3 -3
  247. package/packages/dd-trace/src/msgpack/encoder.js +28 -28
  248. package/packages/dd-trace/src/noop/dogstatsd.js +6 -6
  249. package/packages/dd-trace/src/noop/span.js +3 -5
  250. package/packages/dd-trace/src/noop/tracer.js +1 -2
  251. package/packages/dd-trace/src/opentelemetry/span_processor.js +2 -2
  252. package/packages/dd-trace/src/opentelemetry/tracer.js +6 -5
  253. package/packages/dd-trace/src/opentracing/propagation/log.js +6 -8
  254. package/packages/dd-trace/src/opentracing/propagation/text_map.js +27 -23
  255. package/packages/dd-trace/src/opentracing/propagation/tracestate.js +8 -4
  256. package/packages/dd-trace/src/opentracing/span.js +9 -14
  257. package/packages/dd-trace/src/opentracing/tracer.js +9 -6
  258. package/packages/dd-trace/src/payload-tagging/index.js +1 -1
  259. package/packages/dd-trace/src/payload-tagging/tagging.js +6 -6
  260. package/packages/dd-trace/src/pkg.js +1 -1
  261. package/packages/dd-trace/src/plugins/ci_plugin.js +62 -10
  262. package/packages/dd-trace/src/plugins/consumer.js +2 -2
  263. package/packages/dd-trace/src/plugins/inbound.js +5 -1
  264. package/packages/dd-trace/src/plugins/index.js +0 -1
  265. package/packages/dd-trace/src/plugins/outbound.js +4 -5
  266. package/packages/dd-trace/src/plugins/plugin.js +1 -1
  267. package/packages/dd-trace/src/plugins/producer.js +2 -2
  268. package/packages/dd-trace/src/plugins/storage.js +2 -2
  269. package/packages/dd-trace/src/plugins/util/ci.js +23 -15
  270. package/packages/dd-trace/src/plugins/util/git.js +165 -11
  271. package/packages/dd-trace/src/plugins/util/inferred_proxy.js +1 -1
  272. package/packages/dd-trace/src/plugins/util/ip_extractor.js +1 -1
  273. package/packages/dd-trace/src/plugins/util/llm.js +27 -10
  274. package/packages/dd-trace/src/plugins/util/stacktrace.js +1 -1
  275. package/packages/dd-trace/src/plugins/util/test.js +311 -48
  276. package/packages/dd-trace/src/plugins/util/url.js +1 -1
  277. package/packages/dd-trace/src/plugins/util/urlfilter.js +13 -17
  278. package/packages/dd-trace/src/plugins/util/user-provided-git.js +12 -3
  279. package/packages/dd-trace/src/plugins/util/web.js +5 -4
  280. package/packages/dd-trace/src/priority_sampler.js +22 -22
  281. package/packages/dd-trace/src/profiling/config.js +44 -8
  282. package/packages/dd-trace/src/profiling/exporters/event_serializer.js +5 -5
  283. package/packages/dd-trace/src/profiling/exporters/file.js +2 -1
  284. package/packages/dd-trace/src/profiling/profiler.js +37 -2
  285. package/packages/dd-trace/src/profiling/profilers/events.js +14 -17
  286. package/packages/dd-trace/src/profiling/profilers/shared.js +6 -1
  287. package/packages/dd-trace/src/profiling/profilers/space.js +3 -3
  288. package/packages/dd-trace/src/profiling/profilers/wall.js +6 -7
  289. package/packages/dd-trace/src/profiling/ssi-heuristics.js +3 -5
  290. package/packages/dd-trace/src/profiling/tagger.js +3 -5
  291. package/packages/dd-trace/src/profiling/webspan-utils.js +1 -1
  292. package/packages/dd-trace/src/proxy.js +7 -9
  293. package/packages/dd-trace/src/random_sampler.js +40 -0
  294. package/packages/dd-trace/src/rate_limiter.js +4 -4
  295. package/packages/dd-trace/src/remote_config/index.js +3 -7
  296. package/packages/dd-trace/src/remote_config/manager.js +25 -13
  297. package/packages/dd-trace/src/require-package-json.js +1 -1
  298. package/packages/dd-trace/src/ritm.js +4 -4
  299. package/packages/dd-trace/src/runtime_metrics/runtime_metrics.js +2 -2
  300. package/packages/dd-trace/src/sampler.js +33 -4
  301. package/packages/dd-trace/src/sampling_rule.js +12 -3
  302. package/packages/dd-trace/src/scope.js +1 -1
  303. package/packages/dd-trace/src/service-naming/schemas/util.js +1 -1
  304. package/packages/dd-trace/src/service-naming/schemas/v0/web.js +2 -3
  305. package/packages/dd-trace/src/span_processor.js +3 -3
  306. package/packages/dd-trace/src/span_sampler.js +4 -1
  307. package/packages/dd-trace/src/standalone/tracesource.js +1 -1
  308. package/packages/dd-trace/src/startup-log.js +2 -2
  309. package/packages/dd-trace/src/telemetry/dependencies.js +4 -4
  310. package/packages/dd-trace/src/telemetry/logs/log-collector.js +9 -10
  311. package/packages/dd-trace/src/telemetry/metrics.js +10 -5
  312. package/packages/dd-trace/src/telemetry/send-data.js +1 -1
  313. package/packages/dd-trace/src/telemetry/telemetry.js +23 -24
  314. package/packages/dd-trace/src/util.js +1 -1
  315. package/version.js +1 -0
  316. package/packages/datadog-instrumentations/src/paperplane.js +0 -77
  317. package/packages/datadog-plugin-paperplane/src/index.js +0 -25
  318. package/packages/datadog-plugin-paperplane/src/logger.js +0 -11
  319. package/packages/datadog-plugin-paperplane/src/server.js +0 -24
@@ -1,6 +1,6 @@
1
1
  'use strict'
2
2
 
3
- const lock = require('mutexify/promise')()
3
+ const mutex = require('mutexify/promise')()
4
4
  const { getGeneratedPosition } = require('./source-maps')
5
5
  const session = require('./session')
6
6
  const { compile: compileCondition, compileSegments, templateRequiresEvaluation } = require('./condition')
@@ -36,8 +36,9 @@ session.on('scriptLoadingStabilized', () => {
36
36
  })
37
37
 
38
38
  module.exports = {
39
- addBreakpoint,
40
- removeBreakpoint
39
+ addBreakpoint: lock(addBreakpoint),
40
+ removeBreakpoint: lock(removeBreakpoint),
41
+ modifyBreakpoint: lock(modifyBreakpoint)
41
42
  }
42
43
 
43
44
  async function addBreakpoint (probe) {
@@ -89,89 +90,84 @@ async function addBreakpoint (probe) {
89
90
  throw new Error(`Cannot compile expression: ${probe.when.dsl}`, { cause: err })
90
91
  }
91
92
 
92
- const release = await lock()
93
-
94
- try {
95
- const locationKey = generateLocationKey(scriptId, lineNumber, columnNumber)
96
- const breakpoint = locationToBreakpoint.get(locationKey)
97
-
98
- log.debug(
99
- '[debugger:devtools_client] %s breakpoint at %s:%d:%d (probe: %s, version: %d)',
100
- breakpoint ? 'Updating' : 'Adding', url, lineNumber, columnNumber, probe.id, probe.version
101
- )
102
-
103
- if (breakpoint) {
104
- // A breakpoint already exists at this location, so we need to add the probe to the existing breakpoint
105
- await updateBreakpoint(breakpoint, probe)
106
- } else {
107
- // No breakpoint exists at this location, so we need to create a new one
108
- const location = {
109
- scriptId,
110
- lineNumber: lineNumber - 1, // Beware! lineNumber is zero-indexed
111
- columnNumber
112
- }
113
- let result
114
- try {
115
- result = await session.post('Debugger.setBreakpoint', {
116
- location,
117
- condition: probe.condition
118
- })
119
- } catch (err) {
120
- throw new Error(`Error setting breakpoint for probe ${probe.id}`, { cause: err })
121
- }
122
- probeToLocation.set(probe.id, locationKey)
123
- locationToBreakpoint.set(locationKey, { id: result.breakpointId, location, locationKey })
124
- breakpointToProbes.set(result.breakpointId, new Map([[probe.id, probe]]))
93
+ const locationKey = generateLocationKey(scriptId, lineNumber, columnNumber)
94
+ const breakpoint = locationToBreakpoint.get(locationKey)
95
+
96
+ log.debug(
97
+ '[debugger:devtools_client] %s breakpoint at %s:%d:%d (probe: %s, version: %d)',
98
+ breakpoint ? 'Updating' : 'Adding', url, lineNumber, columnNumber, probe.id, probe.version
99
+ )
100
+
101
+ if (breakpoint) {
102
+ // A breakpoint already exists at this location, so we need to add the probe to the existing breakpoint
103
+ await updateBreakpointInternal(breakpoint, probe)
104
+ } else {
105
+ // No breakpoint exists at this location, so we need to create a new one
106
+ const location = {
107
+ scriptId,
108
+ lineNumber: lineNumber - 1, // Beware! lineNumber is zero-indexed
109
+ columnNumber
110
+ }
111
+ let result
112
+ try {
113
+ result = await session.post('Debugger.setBreakpoint', {
114
+ location,
115
+ condition: probe.condition
116
+ })
117
+ } catch (err) {
118
+ throw new Error(`Error setting breakpoint for probe ${probe.id}`, { cause: err })
125
119
  }
126
- } finally {
127
- release()
120
+ probeToLocation.set(probe.id, locationKey)
121
+ locationToBreakpoint.set(locationKey, { id: result.breakpointId, location, locationKey })
122
+ breakpointToProbes.set(result.breakpointId, new Map([[probe.id, probe]]))
128
123
  }
129
124
  }
130
125
 
131
126
  async function removeBreakpoint ({ id }) {
132
127
  if (!sessionStarted) {
133
128
  // We should not get in this state, but abort if we do, so the code doesn't fail unexpected
134
- throw Error(`Cannot remove probe ${id}: Debugger not started`)
129
+ throw new Error(`Cannot remove probe ${id}: Debugger not started`)
135
130
  }
136
131
  if (!probeToLocation.has(id)) {
137
- throw Error(`Unknown probe id: ${id}`)
132
+ throw new Error(`Unknown probe id: ${id}`)
138
133
  }
139
134
 
140
135
  probes.delete(id)
141
136
 
142
- const release = await lock()
137
+ const locationKey = probeToLocation.get(id)
138
+ const breakpoint = locationToBreakpoint.get(locationKey)
139
+ const probesAtLocation = breakpointToProbes.get(breakpoint.id)
143
140
 
144
- try {
145
- const locationKey = probeToLocation.get(id)
146
- const breakpoint = locationToBreakpoint.get(locationKey)
147
- const probesAtLocation = breakpointToProbes.get(breakpoint.id)
148
-
149
- probesAtLocation.delete(id)
150
- probeToLocation.delete(id)
151
-
152
- if (probesAtLocation.size === 0) {
153
- locationToBreakpoint.delete(locationKey)
154
- breakpointToProbes.delete(breakpoint.id)
155
- if (breakpointToProbes.size === 0) {
156
- await stop() // TODO: Will this actually delete the breakpoint?
157
- } else {
158
- try {
159
- await session.post('Debugger.removeBreakpoint', { breakpointId: breakpoint.id })
160
- } catch (err) {
161
- throw new Error(`Error removing breakpoint for probe ${id}`, { cause: err })
162
- }
163
- }
141
+ probesAtLocation.delete(id)
142
+ probeToLocation.delete(id)
143
+
144
+ if (probesAtLocation.size === 0) {
145
+ locationToBreakpoint.delete(locationKey)
146
+ breakpointToProbes.delete(breakpoint.id)
147
+ // TODO: If anything below in this if-block throws, the state is out of sync.
148
+ if (breakpointToProbes.size === 0) {
149
+ await stop() // This will also remove the breakpoint
164
150
  } else {
165
- await updateBreakpoint(breakpoint)
151
+ try {
152
+ await session.post('Debugger.removeBreakpoint', { breakpointId: breakpoint.id })
153
+ } catch (err) {
154
+ throw new Error(`Error removing breakpoint for probe ${id}`, { cause: err })
155
+ }
166
156
  }
167
- } finally {
168
- release()
157
+ } else {
158
+ await updateBreakpointInternal(breakpoint)
169
159
  }
170
160
  }
171
161
 
172
- async function updateBreakpoint (breakpoint, probe) {
162
+ // TODO: Modify existing probe instead of removing it (DEBUG-2817)
163
+ async function modifyBreakpoint (probe) {
164
+ await removeBreakpoint(probe)
165
+ await addBreakpoint(probe)
166
+ }
167
+
168
+ async function updateBreakpointInternal (breakpoint, probe) {
173
169
  const probesAtLocation = breakpointToProbes.get(breakpoint.id)
174
- const conditionBeforeNewProbe = compileCompoundCondition(Array.from(probesAtLocation.values()))
170
+ const conditionBeforeNewProbe = compileCompoundCondition([...probesAtLocation.values()])
175
171
 
176
172
  // If a probe is provided, add it to the breakpoint. If not, it's because we're removing a probe, but potentially
177
173
  // need to update the condtion of the breakpoint.
@@ -180,7 +176,7 @@ async function updateBreakpoint (breakpoint, probe) {
180
176
  probeToLocation.set(probe.id, breakpoint.locationKey)
181
177
  }
182
178
 
183
- const condition = compileCompoundCondition(Array.from(probesAtLocation.values()))
179
+ const condition = compileCompoundCondition([...probesAtLocation.values()])
184
180
 
185
181
  if (condition || conditionBeforeNewProbe !== condition) {
186
182
  try {
@@ -235,6 +231,17 @@ function stop () {
235
231
  return session.post('Debugger.disable')
236
232
  }
237
233
 
234
+ function lock (fn) {
235
+ return async function (...args) {
236
+ const release = await mutex()
237
+ try {
238
+ return await fn(...args)
239
+ } finally {
240
+ release()
241
+ }
242
+ }
243
+ }
244
+
238
245
  // Only if all probes have a condition can we use a compound condition.
239
246
  // Otherwise, we need to evaluate each probe individually once the breakpoint is hit.
240
247
  function compileCompoundCondition (probes) {
@@ -51,9 +51,8 @@ function compileSegments (segments) {
51
51
  let result = '['
52
52
  for (let i = 0; i < segments.length; i++) {
53
53
  const { str, dsl, json } = segments[i]
54
- result += str !== undefined
55
- ? JSON.stringify(str)
56
- : `(() => {
54
+ result += str === undefined
55
+ ? `(() => {
57
56
  try {
58
57
  const result = ${compile(json)}
59
58
  return typeof result === 'string' ? result : $dd_inspect(result, $dd_segmentInspectOptions)
@@ -61,6 +60,7 @@ function compileSegments (segments) {
61
60
  return { expr: ${JSON.stringify(dsl)}, message: \`\${e.name}: \${e.message}\` }
62
61
  }
63
62
  })()`
63
+ : JSON.stringify(str)
64
64
  if (i !== segments.length - 1) {
65
65
  result += ','
66
66
  }
@@ -95,11 +95,9 @@ function compile (node) {
95
95
  }
96
96
  })()`
97
97
  } else if (type === 'instanceof') {
98
- if (isPrimitiveType(value[1])) {
99
- return `(typeof ${compile(value[0])} === '${value[1]}')` // TODO: Is parenthesizing necessary?
100
- } else {
101
- return `Function.prototype[Symbol.hasInstance].call(${assertIdentifier(value[1])}, ${compile(value[0])})`
102
- }
98
+ return isPrimitiveType(value[1])
99
+ ? `(typeof ${compile(value[0])} === '${value[1]}')` // TODO: Is parenthesizing necessary?
100
+ : `Function.prototype[Symbol.hasInstance].call(${assertIdentifier(value[1])}, ${compile(value[0])})`
103
101
  } else if (type === 'ref') {
104
102
  if (value === '@it') {
105
103
  return '$dd_it'
@@ -3,5 +3,5 @@
3
3
  module.exports = {
4
4
  MAX_SNAPSHOTS_PER_SECOND_GLOBALLY: 25,
5
5
  MAX_SNAPSHOTS_PER_SECOND_PER_PROBE: 1,
6
- MAX_NON_SNAPSHOTS_PER_SECOND_PER_PROBE: 5_000
6
+ MAX_NON_SNAPSHOTS_PER_SECOND_PER_PROBE: 5000
7
7
  }
@@ -65,6 +65,12 @@ session.on('Debugger.paused', async ({ params }) => {
65
65
  for (let i = 0; i < params.hitBreakpoints.length; i++) {
66
66
  const probesAtLocation = breakpointToProbes.get(params.hitBreakpoints[i])
67
67
 
68
+ if (probesAtLocation === undefined) {
69
+ // This might happen due to a race condition where the breakpoint is in the process of being removed
70
+ log.error('[debugger:devtools_client] No probes found for breakpoint %s', params.hitBreakpoints[i])
71
+ continue
72
+ }
73
+
68
74
  if (probesAtLocation.size !== 1) {
69
75
  numberOfProbesOnBreakpoint = numberOfProbesOnBreakpoint + probesAtLocation.size - 1
70
76
  if (numberOfProbesOnBreakpoint > snapshotProbeIndex.length) {
@@ -155,7 +161,7 @@ session.on('Debugger.paused', async ({ params }) => {
155
161
 
156
162
  log.debug(
157
163
  '[debugger:devtools_client] Finished processing breakpoints - main thread paused for: %d ms',
158
- Number(diff) / 1000000
164
+ Number(diff) / 1_000_000
159
165
  )
160
166
 
161
167
  const logger = {
@@ -1,8 +1,7 @@
1
1
  'use strict'
2
2
 
3
3
  const { workerData: { rcPort } } = require('node:worker_threads')
4
- const lock = require('mutexify/promise')()
5
- const { addBreakpoint, removeBreakpoint } = require('./breakpoints')
4
+ const { addBreakpoint, removeBreakpoint, modifyBreakpoint } = require('./breakpoints')
6
5
  const { ackReceived, ackInstalled, ackError } = require('./status')
7
6
  const log = require('../../log')
8
7
 
@@ -57,45 +56,26 @@ async function processMsg (action, probe) {
57
56
  }
58
57
  if (!probe.where.sourceFile && !probe.where.lines) {
59
58
  throw new Error(
60
- // eslint-disable-next-line @stylistic/js/max-len
59
+ // eslint-disable-next-line @stylistic/max-len
61
60
  `Unsupported probe insertion point! Only line-based probes are supported (id: ${probe.id}, version: ${probe.version})`
62
61
  )
63
62
  }
64
63
 
65
- // This lock is to ensure that we don't get the following race condition:
66
- //
67
- // When a breakpoint is being removed and there are no other breakpoints, we disable the debugger by calling
68
- // `Debugger.disable` to free resources. However, if a new breakpoint is being added around the same time, we might
69
- // have a race condition where the new breakpoint thinks that the debugger is already enabled because the removal of
70
- // the other breakpoint hasn't had a chance to call `Debugger.disable` yet. Then once the code that's adding the new
71
- // breakpoints tries to call `Debugger.setBreakpoint` it fails because in the meantime `Debugger.disable` was called.
72
- //
73
- // If the code is ever refactored to not tear down the debugger if there's no active breakpoints, we can safely remove
74
- // this lock.
75
- const release = await lock()
76
-
77
- try {
78
- switch (action) {
79
- case 'unapply':
80
- await removeBreakpoint(probe)
81
- break
82
- case 'apply':
83
- await addBreakpoint(probe)
84
- ackInstalled(probe)
85
- break
86
- case 'modify':
87
- // TODO: Modify existing probe instead of removing it (DEBUG-2817)
88
- await removeBreakpoint(probe)
89
- await addBreakpoint(probe)
90
- ackInstalled(probe) // TODO: Should we also send ackInstalled when modifying a probe?
91
- break
92
- default:
93
- throw new Error(
94
- // eslint-disable-next-line @stylistic/js/max-len
95
- `Cannot process probe ${probe.id} (version: ${probe.version}) - unknown remote configuration action: ${action}`
96
- )
97
- }
98
- } finally {
99
- release()
64
+ switch (action) {
65
+ case 'unapply':
66
+ await removeBreakpoint(probe)
67
+ break
68
+ case 'apply':
69
+ await addBreakpoint(probe)
70
+ ackInstalled(probe)
71
+ break
72
+ case 'modify':
73
+ await modifyBreakpoint(probe)
74
+ ackInstalled(probe)
75
+ break
76
+ default:
77
+ throw new Error(
78
+ `Cannot process probe ${probe.id} (version: ${probe.version}) - unknown remote configuration action: ${action}`
79
+ )
100
80
  }
101
81
  }
@@ -40,7 +40,7 @@ async function getLocalStateForCallFrame (
40
40
  return () => new Error('Error getting local state')
41
41
  }
42
42
 
43
- // Deplay calling `processRawState` so the caller gets a chance to resume the main thread before processing `rawState`
43
+ // Delay calling `processRawState` so the caller gets a chance to resume the main thread before processing `rawState`
44
44
  return () => {
45
45
  processedState = processedState ?? processRawState(rawState, maxLength)
46
46
  return processedState
@@ -238,16 +238,14 @@ function toArrayBuffer (type, bytes, maxLength) {
238
238
 
239
239
  const size = bytes.length
240
240
 
241
- if (size > maxLength) {
242
- return {
243
- type,
244
- value: arrayBufferToString(bytes, maxLength),
245
- truncated: true,
246
- size: bytes.length
247
- }
248
- } else {
249
- return { type, value: arrayBufferToString(bytes, size) }
250
- }
241
+ return size > maxLength
242
+ ? {
243
+ type,
244
+ value: arrayBufferToString(bytes, maxLength),
245
+ truncated: true,
246
+ size: bytes.length
247
+ }
248
+ : { type, value: arrayBufferToString(bytes, size) }
251
249
  }
252
250
 
253
251
  function arrayBufferToString (bytes, size) {
@@ -2,8 +2,8 @@
2
2
 
3
3
  const config = require('../config')
4
4
 
5
- const excludedIdentifiers = config.dynamicInstrumentation.redactionExcludedIdentifiers
6
- .map((name) => normalizeName(name))
5
+ const excludedIdentifiers = new Set(config.dynamicInstrumentation.redactionExcludedIdentifiers
6
+ .map((name) => normalizeName(name)))
7
7
 
8
8
  const REDACTED_IDENTIFIERS = new Set(
9
9
  [
@@ -98,7 +98,7 @@ const REDACTED_IDENTIFIERS = new Set(
98
98
  ...config.dynamicInstrumentation.redactedIdentifiers
99
99
  ]
100
100
  .map((name) => normalizeName(name))
101
- .filter((name) => excludedIdentifiers.includes(name) === false)
101
+ .filter((name) => excludedIdentifiers.has(name) === false)
102
102
  )
103
103
 
104
104
  function normalizeName (name, isSymbol) {
@@ -4,7 +4,6 @@ const { join, dirname } = require('path')
4
4
  const { readFileSync } = require('fs')
5
5
  const { readFile } = require('fs/promises')
6
6
  const { SourceMapConsumer } = require('source-map')
7
- const { NODE_MAJOR } = require('../../../../../version')
8
7
 
9
8
  const cache = new Map()
10
9
  let cacheTimer = null
@@ -35,14 +34,7 @@ const self = module.exports = {
35
34
  }
36
35
  }
37
36
 
38
- // The version check inside this function is to guard against a bug Node.js version 18, in which calls to `setTimeout`
39
- // might throw an uncatchable error from within `AsyncLocalStorage._propagate` with the following error message:
40
- //
41
- // TypeError: Cannot read properties of undefined (reading 'Symbol(kResourceStore)')
42
- //
43
- // Source: https://github.com/nodejs/node/blob/v18.20.6/lib/async_hooks.js#L312
44
37
  function cacheIt (key, value) {
45
- if (NODE_MAJOR < 20) return value
46
38
  cacheTime = Date.now()
47
39
  setCacheTTL()
48
40
  cache.set(key, value)
@@ -54,7 +46,7 @@ function setCacheTTL () {
54
46
 
55
47
  cacheTimer = setTimeout(function () {
56
48
  cacheTimer = null
57
- if (Date.now() - cacheTime < 2_500) {
49
+ if (Date.now() - cacheTime < 2500) {
58
50
  // If the last cache entry was added recently, keep the cache alive
59
51
  setCacheTTL()
60
52
  } else {
@@ -62,7 +54,7 @@ function setCacheTTL () {
62
54
  // Clear cache a few seconds after it was last used
63
55
  cache.clear()
64
56
  }
65
- }, 5_000).unref()
57
+ }, 5000).unref()
66
58
  }
67
59
 
68
60
  function loadInlineSourceMap (data) {
@@ -1,6 +1,7 @@
1
1
  'use strict'
2
2
 
3
3
  const { join, dirname } = require('path')
4
+ const { normalize } = require('source-map/lib/util')
4
5
  const { loadSourceMapSync } = require('./source-maps')
5
6
  const session = require('./session')
6
7
  const log = require('../../log')
@@ -92,7 +93,7 @@ module.exports = {
92
93
  }
93
94
  }
94
95
 
95
- return maxMatchLength !== -1 ? bestMatch : null
96
+ return maxMatchLength === -1 ? null : bestMatch
96
97
  },
97
98
 
98
99
  getStackFromCallFrames (callFrames) {
@@ -102,7 +103,7 @@ module.exports = {
102
103
  // the `scriptUrls` map. That might result in this the `scriptUrls.get` call above returning `undefined`, which
103
104
  // will throw when `startsWith` is called on it.
104
105
  let fileName = scriptUrls.get(frame.location.scriptId)
105
- if (fileName.startsWith('file://')) fileName = fileName.substr(7) // TODO: This might not be required
106
+ if (fileName.startsWith('file://')) fileName = fileName.slice(7) // TODO: This might not be required
106
107
  return {
107
108
  fileName,
108
109
  function: frame.functionName,
@@ -151,7 +152,13 @@ session.on('Debugger.scriptParsed', ({ params }) => {
151
152
  ...params,
152
153
  sourceUrl: params.url,
153
154
  url: new URL(join(dir, source), 'file:').href,
154
- source
155
+ // The source url provided by V8 unfortunately doesn't always match the source url used internally in the
156
+ // `source-map` dependency. Both read the same source maps, but the `source-map` dependency iterates over all
157
+ // the `sources` and normalize them using an internal `normalize` function. If these two strings don't match,
158
+ // the `source-map` dependency will not be able to find the generated position. Below we use the same
159
+ // internal `normalize` function, to ensure compatibility.
160
+ // TODO: Consider swapping out the `source-map` dependency for something better so we don't have to do this.
161
+ source: normalize(source)
155
162
  })
156
163
  }
157
164
  } else {
@@ -94,13 +94,13 @@ class DogStatsDClient {
94
94
  }
95
95
 
96
96
  _sendUdp (queue) {
97
- if (this._family !== 0) {
98
- this._sendUdpFromQueue(queue, this._host, this._family)
99
- } else {
97
+ if (this._family === 0) {
100
98
  lookup(this._host, (err, address, family) => {
101
99
  if (err) return log.error('DogStatsDClient: Host not found', err)
102
100
  this._sendUdpFromQueue(queue, address, family)
103
101
  })
102
+ } else {
103
+ this._sendUdpFromQueue(queue, this._host, this._family)
104
104
  }
105
105
  }
106
106
 
@@ -116,7 +116,8 @@ class DogStatsDClient {
116
116
  _add (stat, value, type, tags) {
117
117
  const message = `${this._prefix + stat}:${value}|${type}`
118
118
 
119
- tags = tags ? this._tags.concat(tags) : this._tags
119
+ // Don't manipulate this._tags as it is still used
120
+ tags = tags ? [...this._tags, ...tags] : this._tags
120
121
 
121
122
  if (tags.length > 0) {
122
123
  this._write(`${message}|#${tags.join(',')}\n`)
@@ -13,11 +13,11 @@ function formatSpan (span, config) {
13
13
  span = normalizeSpan(truncateSpan(span, false))
14
14
  if (span.span_events) {
15
15
  // ensure span events are encoded as tags if agent doesn't support native top level span events
16
- if (!config?.trace?.nativeSpanEvents) {
16
+ if (config?.trace?.nativeSpanEvents) {
17
+ formatSpanEvents(span)
18
+ } else {
17
19
  span.meta.events = JSON.stringify(span.span_events)
18
20
  delete span.span_events
19
- } else {
20
- formatSpanEvents(span)
21
21
  }
22
22
  }
23
23
  return span
@@ -175,7 +175,7 @@ class AgentEncoder {
175
175
 
176
176
  id = id.toArray()
177
177
 
178
- bytes.buffer[offset] = 0xcf
178
+ bytes.buffer[offset] = 0xCF
179
179
  bytes.buffer[offset + 1] = id[0]
180
180
  bytes.buffer[offset + 2] = id[1]
181
181
  bytes.buffer[offset + 3] = id[2]
@@ -266,7 +266,7 @@ class AgentEncoder {
266
266
 
267
267
  // we should do it after encoding the object to know the real length
268
268
  const length = bytes.length - offset - prefixLength
269
- bytes.buffer[offset] = 0xc6
269
+ bytes.buffer[offset] = 0xC6
270
270
  bytes.buffer[offset + 1] = length >> 24
271
271
  bytes.buffer[offset + 2] = length >> 16
272
272
  bytes.buffer[offset + 3] = length >> 8
@@ -326,7 +326,7 @@ class AgentEncoder {
326
326
  }
327
327
 
328
328
  _writeArrayPrefix (buffer, offset, count) {
329
- buffer[offset++] = 0xdd
329
+ buffer[offset++] = 0xDD
330
330
  buffer.writeUInt32BE(count, offset)
331
331
 
332
332
  return offset + 4
@@ -351,10 +351,10 @@ function formatSpanEvents (span) {
351
351
  if (spanEvent.attributes) {
352
352
  for (const [key, value] of Object.entries(spanEvent.attributes)) {
353
353
  const newValue = convertSpanEventAttributeValues(key, value)
354
- if (newValue !== undefined) {
355
- spanEvent.attributes[key] = newValue
356
- } else {
354
+ if (newValue === undefined) {
357
355
  delete spanEvent.attributes[key] // delete from attributes if undefined
356
+ } else {
357
+ spanEvent.attributes[key] = newValue
358
358
  }
359
359
  }
360
360
  if (Object.keys(spanEvent.attributes).length === 0) {
@@ -4,7 +4,7 @@ const { truncateSpan, normalizeSpan } = require('./tags-processors')
4
4
  const { AgentEncoder: BaseEncoder } = require('./0.4')
5
5
 
6
6
  const ARRAY_OF_TWO = 0x92
7
- const ARRAY_OF_TWELVE = 0x9c
7
+ const ARRAY_OF_TWELVE = 0x9C
8
8
 
9
9
  function formatSpan (span) {
10
10
  span = normalizeSpan(truncateSpan(span, false))
@@ -11,7 +11,7 @@ const {
11
11
  } = require('../ci-visibility/telemetry')
12
12
 
13
13
  const ENCODING_VERSION = 1
14
- const ALLOWED_CONTENT_TYPES = ['test_session_end', 'test_module_end', 'test_suite_end', 'test']
14
+ const ALLOWED_CONTENT_TYPES = new Set(['test_session_end', 'test_module_end', 'test_suite_end', 'test'])
15
15
 
16
16
  const TEST_SUITE_KEYS_LENGTH = 12
17
17
  const TEST_MODULE_KEYS_LENGTH = 11
@@ -26,7 +26,7 @@ function formatSpan (span) {
26
26
  encodingVersion = 2
27
27
  }
28
28
  return {
29
- type: ALLOWED_CONTENT_TYPES.includes(span.type) ? span.type : 'span',
29
+ type: ALLOWED_CONTENT_TYPES.has(span.type) ? span.type : 'span',
30
30
  version: encodingVersion,
31
31
  content: normalizeSpan(truncateSpan(span))
32
32
  }
@@ -292,7 +292,7 @@ class AgentlessCiVisibilityEncoder extends AgentEncoder {
292
292
  const eventsOffset = this._eventsOffset
293
293
  const eventsCount = this._eventCount
294
294
 
295
- bytes.buffer[eventsOffset] = 0xdd
295
+ bytes.buffer[eventsOffset] = 0xDD
296
296
  bytes.buffer[eventsOffset + 1] = eventsCount >> 24
297
297
  bytes.buffer[eventsOffset + 2] = eventsCount >> 16
298
298
  bytes.buffer[eventsOffset + 3] = eventsCount >> 8
@@ -92,7 +92,7 @@ class CoverageCIVisibilityEncoder extends AgentEncoder {
92
92
  const coveragesCount = this._coveragesCount
93
93
 
94
94
  // update with number of coverages
95
- bytes.buffer[coveragesOffset] = 0xdd
95
+ bytes.buffer[coveragesOffset] = 0xDD
96
96
  bytes.buffer[coveragesOffset + 1] = coveragesCount >> 24
97
97
  bytes.buffer[coveragesOffset + 2] = coveragesCount >> 16
98
98
  bytes.buffer[coveragesOffset + 3] = coveragesCount >> 8
@@ -6,7 +6,7 @@ const MAX_RESOURCE_NAME_LENGTH = 5000
6
6
  // MAX_META_KEY_LENGTH the maximum length of metadata key
7
7
  const MAX_META_KEY_LENGTH = 200
8
8
  // MAX_META_VALUE_LENGTH the maximum length of metadata value
9
- const MAX_META_VALUE_LENGTH = 25000
9
+ const MAX_META_VALUE_LENGTH = 25_000
10
10
  // MAX_METRIC_KEY_LENGTH the maximum length of a metric name key
11
11
  const MAX_METRIC_KEY_LENGTH = MAX_META_KEY_LENGTH
12
12
 
@@ -4,10 +4,7 @@ const exporters = require('../../../ext/exporters')
4
4
  const fs = require('fs')
5
5
  const constants = require('./constants')
6
6
 
7
- module.exports = name => {
8
- const inAWSLambda = process.env.AWS_LAMBDA_FUNCTION_NAME !== undefined
9
- const usingLambdaExtension = inAWSLambda && fs.existsSync(constants.DATADOG_LAMBDA_EXTENSION_PATH)
10
-
7
+ module.exports = function getExporter (name) {
11
8
  switch (name) {
12
9
  case exporters.LOG:
13
10
  return require('./exporters/log')
@@ -22,7 +19,10 @@ module.exports = name => {
22
19
  case exporters.MOCHA_WORKER:
23
20
  case exporters.PLAYWRIGHT_WORKER:
24
21
  return require('./ci-visibility/exporters/test-worker')
25
- default:
26
- return inAWSLambda && !usingLambdaExtension ? require('./exporters/log') : require('./exporters/agent')
22
+ default: {
23
+ const inAWSLambda = process.env.AWS_LAMBDA_FUNCTION_NAME !== undefined
24
+ const usingLambdaExtension = inAWSLambda && fs.existsSync(constants.DATADOG_LAMBDA_EXTENSION_PATH)
25
+ return require(inAWSLambda && !usingLambdaExtension ? './exporters/log' : './exporters/agent')
26
+ }
27
27
  }
28
28
  }
@@ -69,11 +69,7 @@ function setHeader (headers, key, value) {
69
69
  }
70
70
 
71
71
  function getEncoder (protocolVersion) {
72
- if (protocolVersion === '0.5') {
73
- return require('../../encode/0.5').AgentEncoder
74
- } else {
75
- return require('../../encode/0.4').AgentEncoder
76
- }
72
+ return require(`../../encode/${protocolVersion === '0.5' ? '0.5' : '0.4'}`).AgentEncoder
77
73
  }
78
74
 
79
75
  function makeRequest (version, data, count, url, headers, lookup, needsStartupLog, cb) {