dd-trace 5.53.0 → 5.55.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 (368) hide show
  1. package/LICENSE-3rdparty.csv +2 -1
  2. package/ci/cypress/plugin.js +8 -0
  3. package/ci/cypress/polyfills.js +23 -0
  4. package/ci/init.js +8 -7
  5. package/index.d.ts +33 -16
  6. package/initialize.mjs +5 -6
  7. package/package.json +40 -38
  8. package/packages/datadog-code-origin/index.js +22 -4
  9. package/packages/datadog-core/src/utils/src/get.js +1 -1
  10. package/packages/datadog-core/src/utils/src/has.js +1 -1
  11. package/packages/datadog-core/src/utils/src/kebabcase.js +4 -6
  12. package/packages/datadog-core/src/utils/src/parse-tags.js +1 -1
  13. package/packages/datadog-core/src/utils/src/pick.js +2 -2
  14. package/packages/datadog-core/src/utils/src/set.js +1 -1
  15. package/packages/datadog-core/src/utils/src/uniq.js +1 -1
  16. package/packages/datadog-instrumentations/src/amqp10.js +19 -17
  17. package/packages/datadog-instrumentations/src/amqplib.js +52 -35
  18. package/packages/datadog-instrumentations/src/apollo.js +2 -2
  19. package/packages/datadog-instrumentations/src/aws-sdk.js +1 -1
  20. package/packages/datadog-instrumentations/src/cassandra-driver.js +10 -10
  21. package/packages/datadog-instrumentations/src/child_process.js +1 -2
  22. package/packages/datadog-instrumentations/src/confluentinc-kafka-javascript.js +89 -75
  23. package/packages/datadog-instrumentations/src/cookie-parser.js +1 -1
  24. package/packages/datadog-instrumentations/src/couchbase.js +6 -9
  25. package/packages/datadog-instrumentations/src/cucumber.js +108 -68
  26. package/packages/datadog-instrumentations/src/cypress.js +2 -1
  27. package/packages/datadog-instrumentations/src/dns.js +5 -5
  28. package/packages/datadog-instrumentations/src/elasticsearch.js +9 -10
  29. package/packages/datadog-instrumentations/src/fastify.js +7 -9
  30. package/packages/datadog-instrumentations/src/fs.js +1 -1
  31. package/packages/datadog-instrumentations/src/google-cloud-pubsub.js +35 -43
  32. package/packages/datadog-instrumentations/src/graphql.js +7 -10
  33. package/packages/datadog-instrumentations/src/grpc/client.js +11 -23
  34. package/packages/datadog-instrumentations/src/grpc/server.js +7 -20
  35. package/packages/datadog-instrumentations/src/hapi.js +10 -11
  36. package/packages/datadog-instrumentations/src/helpers/extract-package-and-module-path.js +16 -10
  37. package/packages/datadog-instrumentations/src/helpers/fetch.js +4 -5
  38. package/packages/datadog-instrumentations/src/helpers/hook.js +2 -3
  39. package/packages/datadog-instrumentations/src/helpers/hooks.js +0 -1
  40. package/packages/datadog-instrumentations/src/helpers/instrument.js +1 -41
  41. package/packages/datadog-instrumentations/src/helpers/register.js +11 -12
  42. package/packages/datadog-instrumentations/src/http/client.js +14 -20
  43. package/packages/datadog-instrumentations/src/jest.js +201 -143
  44. package/packages/datadog-instrumentations/src/kafkajs.js +52 -44
  45. package/packages/datadog-instrumentations/src/knex.js +4 -4
  46. package/packages/datadog-instrumentations/src/koa.js +2 -3
  47. package/packages/datadog-instrumentations/src/ldapjs.js +3 -4
  48. package/packages/datadog-instrumentations/src/mariadb.js +49 -65
  49. package/packages/datadog-instrumentations/src/mocha/main.js +116 -73
  50. package/packages/datadog-instrumentations/src/mocha/utils.js +36 -12
  51. package/packages/datadog-instrumentations/src/mocha/worker.js +6 -0
  52. package/packages/datadog-instrumentations/src/mocha.js +3 -1
  53. package/packages/datadog-instrumentations/src/mongodb-core.js +1 -1
  54. package/packages/datadog-instrumentations/src/mysql.js +30 -37
  55. package/packages/datadog-instrumentations/src/mysql2.js +53 -47
  56. package/packages/datadog-instrumentations/src/net.js +1 -1
  57. package/packages/datadog-instrumentations/src/next.js +1 -0
  58. package/packages/datadog-instrumentations/src/nyc.js +3 -2
  59. package/packages/datadog-instrumentations/src/openai.js +22 -24
  60. package/packages/datadog-instrumentations/src/oracledb.js +1 -1
  61. package/packages/datadog-instrumentations/src/otel-sdk-trace.js +4 -3
  62. package/packages/datadog-instrumentations/src/pg.js +3 -5
  63. package/packages/datadog-instrumentations/src/playwright.js +123 -83
  64. package/packages/datadog-instrumentations/src/protobufjs.js +3 -4
  65. package/packages/datadog-instrumentations/src/redis.js +4 -4
  66. package/packages/datadog-instrumentations/src/restify.js +9 -13
  67. package/packages/datadog-instrumentations/src/rhea.js +42 -54
  68. package/packages/datadog-instrumentations/src/router.js +30 -32
  69. package/packages/datadog-instrumentations/src/tedious.js +2 -3
  70. package/packages/datadog-instrumentations/src/vitest.js +87 -52
  71. package/packages/datadog-plugin-amqp10/src/consumer.js +7 -3
  72. package/packages/datadog-plugin-amqp10/src/producer.js +7 -3
  73. package/packages/datadog-plugin-amqplib/src/client.js +6 -2
  74. package/packages/datadog-plugin-amqplib/src/consumer.js +7 -3
  75. package/packages/datadog-plugin-amqplib/src/producer.js +7 -3
  76. package/packages/datadog-plugin-amqplib/src/util.js +1 -1
  77. package/packages/datadog-plugin-apollo/src/gateway/request.js +5 -6
  78. package/packages/datadog-plugin-apollo/src/gateway/validate.js +2 -3
  79. package/packages/datadog-plugin-avsc/src/schema_iterator.js +12 -12
  80. package/packages/datadog-plugin-aws-sdk/src/base.js +15 -10
  81. package/packages/datadog-plugin-aws-sdk/src/services/bedrockruntime/tracing.js +2 -2
  82. package/packages/datadog-plugin-aws-sdk/src/services/bedrockruntime/utils.js +13 -13
  83. package/packages/datadog-plugin-aws-sdk/src/services/cloudwatchlogs.js +3 -5
  84. package/packages/datadog-plugin-aws-sdk/src/services/dynamodb.js +28 -43
  85. package/packages/datadog-plugin-aws-sdk/src/services/eventbridge.js +2 -2
  86. package/packages/datadog-plugin-aws-sdk/src/services/kinesis.js +10 -11
  87. package/packages/datadog-plugin-aws-sdk/src/services/lambda.js +4 -6
  88. package/packages/datadog-plugin-aws-sdk/src/services/redshift.js +3 -5
  89. package/packages/datadog-plugin-aws-sdk/src/services/s3.js +3 -5
  90. package/packages/datadog-plugin-aws-sdk/src/services/sns.js +2 -3
  91. package/packages/datadog-plugin-aws-sdk/src/services/sqs.js +11 -15
  92. package/packages/datadog-plugin-aws-sdk/src/services/stepfunctions.js +1 -1
  93. package/packages/datadog-plugin-aws-sdk/src/util.js +5 -6
  94. package/packages/datadog-plugin-cassandra-driver/src/index.js +1 -1
  95. package/packages/datadog-plugin-child_process/src/index.js +4 -4
  96. package/packages/datadog-plugin-child_process/src/scrub-cmd-params.js +23 -23
  97. package/packages/datadog-plugin-cucumber/src/index.js +60 -4
  98. package/packages/datadog-plugin-cypress/src/cypress-plugin.js +99 -28
  99. package/packages/datadog-plugin-cypress/src/plugin.js +11 -1
  100. package/packages/datadog-plugin-cypress/src/support.js +24 -5
  101. package/packages/datadog-plugin-dd-trace-api/src/index.js +2 -1
  102. package/packages/datadog-plugin-elasticsearch/src/index.js +1 -1
  103. package/packages/datadog-plugin-express/src/code_origin.js +30 -0
  104. package/packages/datadog-plugin-express/src/index.js +10 -12
  105. package/packages/datadog-plugin-express/src/tracing.js +19 -0
  106. package/packages/datadog-plugin-google-cloud-pubsub/src/client.js +7 -3
  107. package/packages/datadog-plugin-google-cloud-pubsub/src/consumer.js +12 -7
  108. package/packages/datadog-plugin-google-cloud-pubsub/src/producer.js +6 -2
  109. package/packages/datadog-plugin-google-cloud-vertexai/src/tracing.js +27 -10
  110. package/packages/datadog-plugin-graphql/src/execute.js +2 -2
  111. package/packages/datadog-plugin-graphql/src/index.js +10 -8
  112. package/packages/datadog-plugin-graphql/src/resolve.js +19 -12
  113. package/packages/datadog-plugin-graphql/src/tools/index.js +1 -0
  114. package/packages/datadog-plugin-graphql/src/tools/signature.js +1 -0
  115. package/packages/datadog-plugin-graphql/src/tools/transforms.js +1 -0
  116. package/packages/datadog-plugin-grpc/src/client.js +2 -2
  117. package/packages/datadog-plugin-grpc/src/util.js +2 -2
  118. package/packages/datadog-plugin-http/src/client.js +23 -13
  119. package/packages/datadog-plugin-http2/src/client.js +24 -25
  120. package/packages/datadog-plugin-jest/src/index.js +26 -23
  121. package/packages/datadog-plugin-jest/src/util.js +8 -8
  122. package/packages/datadog-plugin-kafkajs/src/batch-consumer.js +3 -1
  123. package/packages/datadog-plugin-kafkajs/src/consumer.js +9 -5
  124. package/packages/datadog-plugin-kafkajs/src/producer.js +8 -3
  125. package/packages/datadog-plugin-kafkajs/src/utils.js +1 -1
  126. package/packages/datadog-plugin-langchain/src/handlers/chain.js +7 -7
  127. package/packages/datadog-plugin-langchain/src/handlers/embedding.js +2 -2
  128. package/packages/datadog-plugin-langchain/src/handlers/language_models/chat_model.js +6 -4
  129. package/packages/datadog-plugin-langchain/src/handlers/language_models/llm.js +5 -4
  130. package/packages/datadog-plugin-langchain/src/tracing.js +11 -10
  131. package/packages/datadog-plugin-mariadb/src/index.js +3 -9
  132. package/packages/datadog-plugin-mocha/src/index.js +39 -14
  133. package/packages/datadog-plugin-mongodb-core/src/index.js +3 -2
  134. package/packages/datadog-plugin-mysql/src/index.js +22 -9
  135. package/packages/datadog-plugin-mysql2/src/index.js +16 -0
  136. package/packages/datadog-plugin-net/src/tcp.js +1 -1
  137. package/packages/datadog-plugin-next/src/index.js +7 -6
  138. package/packages/datadog-plugin-openai/src/services.js +6 -10
  139. package/packages/datadog-plugin-openai/src/tracing.js +12 -18
  140. package/packages/datadog-plugin-oracledb/src/index.js +1 -1
  141. package/packages/datadog-plugin-playwright/src/index.js +25 -4
  142. package/packages/datadog-plugin-protobufjs/src/schema_iterator.js +8 -9
  143. package/packages/datadog-plugin-redis/src/index.js +2 -4
  144. package/packages/datadog-plugin-rhea/src/consumer.js +8 -6
  145. package/packages/datadog-plugin-rhea/src/producer.js +5 -2
  146. package/packages/datadog-plugin-router/src/index.js +1 -1
  147. package/packages/datadog-plugin-selenium/src/index.js +1 -6
  148. package/packages/datadog-plugin-vitest/src/index.js +52 -35
  149. package/packages/datadog-shimmer/src/shimmer.js +4 -8
  150. package/packages/dd-trace/src/appsec/api_security_sampler.js +2 -2
  151. package/packages/dd-trace/src/appsec/blocked_templates.js +1 -1
  152. package/packages/dd-trace/src/appsec/blocking.js +6 -20
  153. package/packages/dd-trace/src/appsec/iast/analyzers/analyzers.js +0 -1
  154. package/packages/dd-trace/src/appsec/iast/analyzers/hardcoded-password-rules.js +0 -1
  155. package/packages/dd-trace/src/appsec/iast/analyzers/hardcoded-secret-rules.js +0 -1
  156. package/packages/dd-trace/src/appsec/iast/analyzers/hardcoded-secrets-rules.js +0 -1
  157. package/packages/dd-trace/src/appsec/iast/analyzers/hsts-header-missing-analyzer.js +7 -12
  158. package/packages/dd-trace/src/appsec/iast/analyzers/missing-header-analyzer.js +5 -8
  159. package/packages/dd-trace/src/appsec/iast/analyzers/nosql-injection-mongodb-analyzer.js +4 -0
  160. package/packages/dd-trace/src/appsec/iast/analyzers/path-traversal-analyzer.js +9 -12
  161. package/packages/dd-trace/src/appsec/iast/analyzers/vulnerability-analyzer.js +5 -4
  162. package/packages/dd-trace/src/appsec/iast/context/context-plugin.js +2 -3
  163. package/packages/dd-trace/src/appsec/iast/iast-plugin.js +3 -3
  164. package/packages/dd-trace/src/appsec/iast/index.js +1 -0
  165. package/packages/dd-trace/src/appsec/iast/overhead-controller.js +102 -7
  166. package/packages/dd-trace/src/appsec/iast/path-line.js +7 -8
  167. package/packages/dd-trace/src/appsec/iast/security-controls/index.js +16 -24
  168. package/packages/dd-trace/src/appsec/iast/security-controls/parser.js +6 -6
  169. package/packages/dd-trace/src/appsec/iast/taint-tracking/filter.js +2 -2
  170. package/packages/dd-trace/src/appsec/iast/taint-tracking/operations-taint-object.js +3 -3
  171. package/packages/dd-trace/src/appsec/iast/taint-tracking/operations.js +4 -28
  172. package/packages/dd-trace/src/appsec/iast/taint-tracking/plugin.js +2 -8
  173. package/packages/dd-trace/src/appsec/iast/taint-tracking/plugins/kafka.js +3 -4
  174. package/packages/dd-trace/src/appsec/iast/taint-tracking/rewriter-esm.mjs +1 -1
  175. package/packages/dd-trace/src/appsec/iast/taint-tracking/rewriter.js +7 -8
  176. package/packages/dd-trace/src/appsec/iast/taint-tracking/taint-tracking-impl.js +2 -2
  177. package/packages/dd-trace/src/appsec/iast/telemetry/span-tags.js +7 -7
  178. package/packages/dd-trace/src/appsec/iast/telemetry/verbosity.js +2 -3
  179. package/packages/dd-trace/src/appsec/iast/vulnerabilities-formatter/evidence-redaction/range-utils.js +10 -11
  180. package/packages/dd-trace/src/appsec/iast/vulnerabilities-formatter/evidence-redaction/sensitive-analyzers/command-sensitive-analyzer.js +1 -1
  181. package/packages/dd-trace/src/appsec/iast/vulnerabilities-formatter/evidence-redaction/sensitive-analyzers/ldap-sensitive-analyzer.js +1 -1
  182. package/packages/dd-trace/src/appsec/iast/vulnerabilities-formatter/evidence-redaction/sensitive-analyzers/sql-sensitive-analyzer.js +7 -7
  183. package/packages/dd-trace/src/appsec/iast/vulnerabilities-formatter/evidence-redaction/sensitive-handler.js +23 -28
  184. package/packages/dd-trace/src/appsec/iast/vulnerabilities-formatter/evidence-redaction/sensitive-regex.js +3 -3
  185. package/packages/dd-trace/src/appsec/iast/vulnerabilities-formatter/index.js +4 -4
  186. package/packages/dd-trace/src/appsec/iast/vulnerabilities-formatter/utils.js +6 -11
  187. package/packages/dd-trace/src/appsec/iast/vulnerabilities.js +0 -1
  188. package/packages/dd-trace/src/appsec/iast/vulnerability-reporter.js +9 -11
  189. package/packages/dd-trace/src/appsec/index.js +5 -5
  190. package/packages/dd-trace/src/appsec/rasp/index.js +15 -15
  191. package/packages/dd-trace/src/appsec/rasp/lfi.js +2 -1
  192. package/packages/dd-trace/src/appsec/reporter.js +232 -41
  193. package/packages/dd-trace/src/appsec/rule_manager.js +2 -2
  194. package/packages/dd-trace/src/appsec/sdk/set_user.js +2 -2
  195. package/packages/dd-trace/src/appsec/sdk/track_event.js +3 -3
  196. package/packages/dd-trace/src/appsec/stack_trace.js +2 -4
  197. package/packages/dd-trace/src/appsec/telemetry/index.js +31 -1
  198. package/packages/dd-trace/src/appsec/telemetry/rasp.js +3 -5
  199. package/packages/dd-trace/src/appsec/telemetry/waf.js +3 -5
  200. package/packages/dd-trace/src/appsec/user_tracking.js +3 -5
  201. package/packages/dd-trace/src/appsec/waf/waf_context_wrapper.js +8 -4
  202. package/packages/dd-trace/src/azure_metadata.js +9 -9
  203. package/packages/dd-trace/src/ci-visibility/dynamic-instrumentation/index.js +9 -8
  204. package/packages/dd-trace/src/ci-visibility/dynamic-instrumentation/worker/index.js +2 -2
  205. package/packages/dd-trace/src/ci-visibility/early-flake-detection/get-known-tests.js +3 -2
  206. package/packages/dd-trace/src/ci-visibility/exporters/agent-proxy/index.js +3 -3
  207. package/packages/dd-trace/src/ci-visibility/exporters/agentless/coverage-writer.js +3 -2
  208. package/packages/dd-trace/src/ci-visibility/exporters/agentless/di-logs-writer.js +3 -2
  209. package/packages/dd-trace/src/ci-visibility/exporters/agentless/writer.js +3 -2
  210. package/packages/dd-trace/src/ci-visibility/exporters/ci-visibility-exporter.js +6 -4
  211. package/packages/dd-trace/src/ci-visibility/exporters/git/git_metadata.js +6 -5
  212. package/packages/dd-trace/src/ci-visibility/exporters/test-worker/index.js +7 -6
  213. package/packages/dd-trace/src/ci-visibility/exporters/test-worker/writer.js +0 -2
  214. package/packages/dd-trace/src/ci-visibility/intelligent-test-runner/get-skippable-suites.js +3 -2
  215. package/packages/dd-trace/src/ci-visibility/log-submission/log-submission-plugin.js +5 -4
  216. package/packages/dd-trace/src/ci-visibility/requests/get-library-configuration.js +12 -8
  217. package/packages/dd-trace/src/ci-visibility/telemetry.js +4 -0
  218. package/packages/dd-trace/src/ci-visibility/test-management/get-test-management-tests.js +3 -2
  219. package/packages/dd-trace/src/config-helper.js +89 -0
  220. package/packages/dd-trace/src/config.js +159 -129
  221. package/packages/dd-trace/src/config_stable.js +10 -7
  222. package/packages/dd-trace/src/datastreams/encoding.js +9 -9
  223. package/packages/dd-trace/src/datastreams/fnv.js +2 -2
  224. package/packages/dd-trace/src/datastreams/pathway.js +4 -4
  225. package/packages/dd-trace/src/datastreams/processor.js +5 -7
  226. package/packages/dd-trace/src/datastreams/schemas/schema_builder.js +7 -7
  227. package/packages/dd-trace/src/datastreams/schemas/schema_sampler.js +4 -6
  228. package/packages/dd-trace/src/datastreams/size.js +1 -1
  229. package/packages/dd-trace/src/debugger/devtools_client/breakpoints.js +75 -69
  230. package/packages/dd-trace/src/debugger/devtools_client/condition.js +7 -10
  231. package/packages/dd-trace/src/debugger/devtools_client/defaults.js +1 -1
  232. package/packages/dd-trace/src/debugger/devtools_client/index.js +9 -2
  233. package/packages/dd-trace/src/debugger/devtools_client/remote_config.js +18 -38
  234. package/packages/dd-trace/src/debugger/devtools_client/send.js +3 -2
  235. package/packages/dd-trace/src/debugger/devtools_client/snapshot/collector.js +1 -2
  236. package/packages/dd-trace/src/debugger/devtools_client/snapshot/index.js +1 -1
  237. package/packages/dd-trace/src/debugger/devtools_client/snapshot/processor.js +11 -14
  238. package/packages/dd-trace/src/debugger/devtools_client/snapshot/redaction.js +4 -4
  239. package/packages/dd-trace/src/debugger/devtools_client/source-maps.js +2 -10
  240. package/packages/dd-trace/src/debugger/devtools_client/state.js +10 -3
  241. package/packages/dd-trace/src/debugger/index.js +1 -0
  242. package/packages/dd-trace/src/dogstatsd.js +7 -6
  243. package/packages/dd-trace/src/encode/0.4.js +14 -11
  244. package/packages/dd-trace/src/encode/0.5.js +4 -6
  245. package/packages/dd-trace/src/encode/agentless-ci-visibility.js +8 -8
  246. package/packages/dd-trace/src/encode/coverage-ci-visibility.js +1 -1
  247. package/packages/dd-trace/src/encode/tags-processors.js +1 -1
  248. package/packages/dd-trace/src/exporter.js +7 -6
  249. package/packages/dd-trace/src/exporters/agent/writer.js +1 -5
  250. package/packages/dd-trace/src/exporters/common/docker.js +4 -3
  251. package/packages/dd-trace/src/exporters/common/form-data.js +6 -4
  252. package/packages/dd-trace/src/exporters/common/request.js +5 -2
  253. package/packages/dd-trace/src/exporters/common/util.js +4 -2
  254. package/packages/dd-trace/src/external-logger/src/index.js +5 -5
  255. package/packages/dd-trace/src/flare/file.js +1 -5
  256. package/packages/dd-trace/src/format.js +1 -1
  257. package/packages/dd-trace/src/git_properties.js +1 -1
  258. package/packages/dd-trace/src/id.js +15 -9
  259. package/packages/dd-trace/src/iitm.js +10 -22
  260. package/packages/dd-trace/src/index.js +4 -3
  261. package/packages/dd-trace/src/lambda/handler.js +7 -6
  262. package/packages/dd-trace/src/lambda/index.js +2 -1
  263. package/packages/dd-trace/src/lambda/runtime/patch.js +7 -6
  264. package/packages/dd-trace/src/lambda/runtime/ritm.js +4 -3
  265. package/packages/dd-trace/src/llmobs/constants/tags.js +1 -0
  266. package/packages/dd-trace/src/llmobs/index.js +21 -5
  267. package/packages/dd-trace/src/llmobs/noop.js +18 -20
  268. package/packages/dd-trace/src/llmobs/plugins/bedrockruntime.js +6 -6
  269. package/packages/dd-trace/src/llmobs/plugins/langchain/handlers/chain.js +2 -6
  270. package/packages/dd-trace/src/llmobs/plugins/langchain/handlers/chat_model.js +3 -3
  271. package/packages/dd-trace/src/llmobs/plugins/langchain/handlers/index.js +11 -13
  272. package/packages/dd-trace/src/llmobs/plugins/langchain/index.js +6 -6
  273. package/packages/dd-trace/src/llmobs/plugins/openai.js +2 -3
  274. package/packages/dd-trace/src/llmobs/sdk.js +4 -3
  275. package/packages/dd-trace/src/llmobs/span_processor.js +1 -1
  276. package/packages/dd-trace/src/llmobs/tagger.js +129 -102
  277. package/packages/dd-trace/src/llmobs/util.js +9 -9
  278. package/packages/dd-trace/src/llmobs/writers/base.js +1 -1
  279. package/packages/dd-trace/src/llmobs/writers/util.js +1 -1
  280. package/packages/dd-trace/src/log/index.js +9 -8
  281. package/packages/dd-trace/src/log/log.js +1 -1
  282. package/packages/dd-trace/src/log/writer.js +3 -4
  283. package/packages/dd-trace/src/msgpack/chunk.js +3 -3
  284. package/packages/dd-trace/src/msgpack/encoder.js +31 -31
  285. package/packages/dd-trace/src/noop/dogstatsd.js +6 -6
  286. package/packages/dd-trace/src/noop/span.js +4 -6
  287. package/packages/dd-trace/src/noop/tracer.js +1 -2
  288. package/packages/dd-trace/src/opentelemetry/span_processor.js +2 -2
  289. package/packages/dd-trace/src/opentelemetry/tracer.js +7 -6
  290. package/packages/dd-trace/src/opentracing/propagation/log.js +10 -13
  291. package/packages/dd-trace/src/opentracing/propagation/text_map.js +40 -37
  292. package/packages/dd-trace/src/opentracing/propagation/tracestate.js +8 -4
  293. package/packages/dd-trace/src/opentracing/span.js +16 -20
  294. package/packages/dd-trace/src/opentracing/tracer.js +9 -6
  295. package/packages/dd-trace/src/payload-tagging/config/index.js +17 -21
  296. package/packages/dd-trace/src/payload-tagging/index.js +1 -1
  297. package/packages/dd-trace/src/payload-tagging/tagging.js +6 -6
  298. package/packages/dd-trace/src/pkg.js +1 -1
  299. package/packages/dd-trace/src/plugin_manager.js +4 -3
  300. package/packages/dd-trace/src/plugins/ci_plugin.js +87 -11
  301. package/packages/dd-trace/src/plugins/consumer.js +2 -2
  302. package/packages/dd-trace/src/plugins/inbound.js +5 -1
  303. package/packages/dd-trace/src/plugins/index.js +0 -1
  304. package/packages/dd-trace/src/plugins/outbound.js +4 -5
  305. package/packages/dd-trace/src/plugins/plugin.js +1 -1
  306. package/packages/dd-trace/src/plugins/producer.js +2 -2
  307. package/packages/dd-trace/src/plugins/storage.js +2 -2
  308. package/packages/dd-trace/src/plugins/util/ci.js +28 -20
  309. package/packages/dd-trace/src/plugins/util/git.js +166 -12
  310. package/packages/dd-trace/src/plugins/util/inferred_proxy.js +1 -1
  311. package/packages/dd-trace/src/plugins/util/ip_extractor.js +1 -1
  312. package/packages/dd-trace/src/plugins/util/llm.js +27 -10
  313. package/packages/dd-trace/src/plugins/util/stacktrace.js +9 -2
  314. package/packages/dd-trace/src/plugins/util/test.js +315 -51
  315. package/packages/dd-trace/src/plugins/util/url.js +1 -1
  316. package/packages/dd-trace/src/plugins/util/urlfilter.js +13 -17
  317. package/packages/dd-trace/src/plugins/util/user-provided-git.js +14 -4
  318. package/packages/dd-trace/src/plugins/util/web.js +8 -8
  319. package/packages/dd-trace/src/priority_sampler.js +64 -53
  320. package/packages/dd-trace/src/profiling/config.js +51 -35
  321. package/packages/dd-trace/src/profiling/exporter_cli.js +20 -20
  322. package/packages/dd-trace/src/profiling/exporters/agent.js +1 -1
  323. package/packages/dd-trace/src/profiling/exporters/event_serializer.js +7 -6
  324. package/packages/dd-trace/src/profiling/exporters/file.js +2 -1
  325. package/packages/dd-trace/src/profiling/index.js +2 -1
  326. package/packages/dd-trace/src/profiling/profiler.js +44 -6
  327. package/packages/dd-trace/src/profiling/profilers/events.js +14 -17
  328. package/packages/dd-trace/src/profiling/profilers/shared.js +6 -1
  329. package/packages/dd-trace/src/profiling/profilers/space.js +3 -3
  330. package/packages/dd-trace/src/profiling/profilers/wall.js +6 -7
  331. package/packages/dd-trace/src/profiling/ssi-heuristics.js +3 -5
  332. package/packages/dd-trace/src/profiling/ssi-telemetry-mock-profiler.js +3 -1
  333. package/packages/dd-trace/src/profiling/tagger.js +21 -13
  334. package/packages/dd-trace/src/profiling/webspan-utils.js +1 -1
  335. package/packages/dd-trace/src/proxy.js +9 -10
  336. package/packages/dd-trace/src/random_sampler.js +40 -0
  337. package/packages/dd-trace/src/rate_limiter.js +4 -4
  338. package/packages/dd-trace/src/remote_config/index.js +3 -7
  339. package/packages/dd-trace/src/remote_config/manager.js +25 -13
  340. package/packages/dd-trace/src/require-package-json.js +1 -1
  341. package/packages/dd-trace/src/ritm.js +8 -8
  342. package/packages/dd-trace/src/runtime_metrics/runtime_metrics.js +5 -4
  343. package/packages/dd-trace/src/sampler.js +41 -4
  344. package/packages/dd-trace/src/sampling_rule.js +12 -3
  345. package/packages/dd-trace/src/scope.js +1 -1
  346. package/packages/dd-trace/src/serverless.js +11 -4
  347. package/packages/dd-trace/src/service-naming/schemas/util.js +1 -1
  348. package/packages/dd-trace/src/service-naming/schemas/v0/web.js +2 -3
  349. package/packages/dd-trace/src/span_processor.js +5 -4
  350. package/packages/dd-trace/src/span_sampler.js +4 -1
  351. package/packages/dd-trace/src/standalone/tracesource.js +2 -3
  352. package/packages/dd-trace/src/standalone/tracesource_priority_sampler.js +1 -2
  353. package/packages/dd-trace/src/startup-log.js +6 -18
  354. package/packages/dd-trace/src/supported-configurations.json +439 -0
  355. package/packages/dd-trace/src/telemetry/dependencies.js +64 -59
  356. package/packages/dd-trace/src/telemetry/logs/log-collector.js +9 -10
  357. package/packages/dd-trace/src/telemetry/metrics.js +10 -5
  358. package/packages/dd-trace/src/telemetry/send-data.js +8 -7
  359. package/packages/dd-trace/src/telemetry/telemetry.js +31 -45
  360. package/packages/dd-trace/src/tracer.js +3 -7
  361. package/packages/dd-trace/src/util.js +1 -6
  362. package/version.js +1 -0
  363. package/packages/datadog-instrumentations/src/paperplane.js +0 -77
  364. package/packages/datadog-plugin-paperplane/src/index.js +0 -25
  365. package/packages/datadog-plugin-paperplane/src/logger.js +0 -11
  366. package/packages/datadog-plugin-paperplane/src/server.js +0 -24
  367. package/packages/dd-trace/src/appsec/iast/analyzers/header-injection-analyzer.js +0 -122
  368. package/packages/dd-trace/src/appsec/iast/vulnerabilities-formatter/evidence-redaction/sensitive-analyzers/header-sensitive-analyzer.js +0 -20
@@ -129,11 +129,10 @@ function toFunctionOrClass (value, maxLength) {
129
129
  // This is a function
130
130
  // TODO: Would it make sense to detect if it's an arrow function or not?
131
131
  return toObject(value.className, value.properties, maxLength)
132
- } else {
133
- // This is a class
134
- const className = classMatch[1].trim()
135
- return { type: className ? `class ${className}` : 'class' }
136
132
  }
133
+ // This is a class
134
+ const className = classMatch[1].trim()
135
+ return { type: className ? `class ${className}` : 'class' }
137
136
  }
138
137
 
139
138
  function toString (str, maxLength) {
@@ -238,16 +237,14 @@ function toArrayBuffer (type, bytes, maxLength) {
238
237
 
239
238
  const size = bytes.length
240
239
 
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
- }
240
+ return size > maxLength
241
+ ? {
242
+ type,
243
+ value: arrayBufferToString(bytes, maxLength),
244
+ truncated: true,
245
+ size: bytes.length
246
+ }
247
+ : { type, value: arrayBufferToString(bytes, size) }
251
248
  }
252
249
 
253
250
  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,12 +98,12 @@ 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) {
105
105
  if (isSymbol) name = name.slice(7, -1) // Remove `Symbol(` and `)`
106
- return name.toLowerCase().replace(/[-_@$.]/g, '')
106
+ return name.toLowerCase().replaceAll(/[-_@$.]/g, '')
107
107
  }
108
108
 
109
109
  module.exports = {
@@ -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 {
@@ -9,6 +9,7 @@ let worker = null
9
9
  let configChannel = null
10
10
  let ackId = 0
11
11
 
12
+ // eslint-disable-next-line eslint-rules/eslint-process-env
12
13
  const { NODE_OPTIONS, ...env } = process.env
13
14
 
14
15
  module.exports = {
@@ -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`)
@@ -168,7 +169,7 @@ class DogStatsDClient {
168
169
  })
169
170
  .forEach(key => {
170
171
  // https://docs.datadoghq.com/tagging/#defining-tags
171
- const value = config.tags[key].replace(/[^a-z0-9_:./-]/ig, '_')
172
+ const value = config.tags[key].replaceAll(/[^a-z0-9_:./-]/ig, '_')
172
173
 
173
174
  tags.push(`${key}:${value}`)
174
175
  })
@@ -243,7 +244,7 @@ class MetricsAggregationClient {
243
244
  const container = monotonic ? this._counters : this._gauges
244
245
  const node = this._ensureTree(container, name, tags, 0)
245
246
 
246
- node.value = node.value + count
247
+ node.value += count
247
248
  }
248
249
 
249
250
  gauge (name, value, tags) {
@@ -6,6 +6,7 @@ const log = require('../log')
6
6
  const { isTrue } = require('../util')
7
7
  const coalesce = require('koalas')
8
8
  const { memoize } = require('../log/utils')
9
+ const { getEnvironmentVariable } = require('../config-helper')
9
10
 
10
11
  const SOFT_LIMIT = 8 * 1024 * 1024 // 8MB
11
12
 
@@ -13,11 +14,11 @@ function formatSpan (span, config) {
13
14
  span = normalizeSpan(truncateSpan(span, false))
14
15
  if (span.span_events) {
15
16
  // ensure span events are encoded as tags if agent doesn't support native top level span events
16
- if (!config?.trace?.nativeSpanEvents) {
17
+ if (config?.trace?.nativeSpanEvents) {
18
+ formatSpanEvents(span)
19
+ } else {
17
20
  span.meta.events = JSON.stringify(span.span_events)
18
21
  delete span.span_events
19
- } else {
20
- formatSpanEvents(span)
21
22
  }
22
23
  }
23
24
  return span
@@ -32,7 +33,7 @@ class AgentEncoder {
32
33
  this._writer = writer
33
34
  this._reset()
34
35
  this._debugEncoding = isTrue(coalesce(
35
- process.env.DD_TRACE_ENCODING_DEBUG,
36
+ getEnvironmentVariable('DD_TRACE_ENCODING_DEBUG'),
36
37
  false
37
38
  ))
38
39
  this._config = this._writer?._config
@@ -175,7 +176,7 @@ class AgentEncoder {
175
176
 
176
177
  id = id.toArray()
177
178
 
178
- bytes.buffer[offset] = 0xcf
179
+ bytes.buffer[offset] = 0xCF
179
180
  bytes.buffer[offset + 1] = id[0]
180
181
  bytes.buffer[offset + 2] = id[1]
181
182
  bytes.buffer[offset + 3] = id[2]
@@ -266,7 +267,7 @@ class AgentEncoder {
266
267
 
267
268
  // we should do it after encoding the object to know the real length
268
269
  const length = bytes.length - offset - prefixLength
269
- bytes.buffer[offset] = 0xc6
270
+ bytes.buffer[offset] = 0xC6
270
271
  bytes.buffer[offset + 1] = length >> 24
271
272
  bytes.buffer[offset + 2] = length >> 16
272
273
  bytes.buffer[offset + 3] = length >> 8
@@ -326,7 +327,7 @@ class AgentEncoder {
326
327
  }
327
328
 
328
329
  _writeArrayPrefix (buffer, offset, count) {
329
- buffer[offset++] = 0xdd
330
+ buffer[offset++] = 0xDD
330
331
  buffer.writeUInt32BE(count, offset)
331
332
 
332
333
  return offset + 4
@@ -349,15 +350,17 @@ const memoizedLogDebug = memoize((key, message) => {
349
350
  function formatSpanEvents (span) {
350
351
  for (const spanEvent of span.span_events) {
351
352
  if (spanEvent.attributes) {
353
+ let hasAttributes = false
352
354
  for (const [key, value] of Object.entries(spanEvent.attributes)) {
353
355
  const newValue = convertSpanEventAttributeValues(key, value)
354
- if (newValue !== undefined) {
355
- spanEvent.attributes[key] = newValue
356
- } else {
356
+ if (newValue === undefined) {
357
357
  delete spanEvent.attributes[key] // delete from attributes if undefined
358
+ } else {
359
+ hasAttributes = true
360
+ spanEvent.attributes[key] = newValue
358
361
  }
359
362
  }
360
- if (Object.keys(spanEvent.attributes).length === 0) {
363
+ if (!hasAttributes) {
361
364
  delete spanEvent.attributes
362
365
  }
363
366
  }
@@ -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))
@@ -23,12 +23,10 @@ class AgentEncoder extends BaseEncoder {
23
23
  const traceSize = this._traceBytes.length + 5
24
24
  const buffer = Buffer.allocUnsafe(prefixSize + stringSize + traceSize)
25
25
 
26
- let offset = 0
26
+ buffer[0] = ARRAY_OF_TWO
27
27
 
28
- buffer[offset++] = ARRAY_OF_TWO
29
-
30
- offset = this._writeStrings(buffer, offset)
31
- offset = this._writeTraces(buffer, offset)
28
+ const offset = this._writeStrings(buffer, 1)
29
+ this._writeTraces(buffer, offset)
32
30
 
33
31
  this._reset()
34
32
 
@@ -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
  }
@@ -161,20 +161,20 @@ class AgentlessCiVisibilityEncoder extends AgentEncoder {
161
161
  _encodeEventContent (bytes, content) {
162
162
  let totalKeysLength = TEST_AND_SPAN_KEYS_LENGTH
163
163
  if (content.meta.test_session_id) {
164
- totalKeysLength = totalKeysLength + 1
164
+ totalKeysLength += 1
165
165
  }
166
166
  if (content.meta.test_module_id) {
167
- totalKeysLength = totalKeysLength + 1
167
+ totalKeysLength += 1
168
168
  }
169
169
  if (content.meta.test_suite_id) {
170
- totalKeysLength = totalKeysLength + 1
170
+ totalKeysLength += 1
171
171
  }
172
172
  const itrCorrelationId = content.meta[ITR_CORRELATION_ID]
173
173
  if (itrCorrelationId) {
174
- totalKeysLength = totalKeysLength + 1
174
+ totalKeysLength += 1
175
175
  }
176
176
  if (content.type) {
177
- totalKeysLength = totalKeysLength + 1
177
+ totalKeysLength += 1
178
178
  }
179
179
  this._encodeMapPrefix(bytes, totalKeysLength)
180
180
  if (content.type) {
@@ -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
 
@@ -3,11 +3,9 @@
3
3
  const exporters = require('../../../ext/exporters')
4
4
  const fs = require('fs')
5
5
  const constants = require('./constants')
6
+ const { getEnvironmentVariable } = require('../../dd-trace/src/config-helper')
6
7
 
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
-
8
+ module.exports = function getExporter (name) {
11
9
  switch (name) {
12
10
  case exporters.LOG:
13
11
  return require('./exporters/log')
@@ -22,7 +20,10 @@ module.exports = name => {
22
20
  case exporters.MOCHA_WORKER:
23
21
  case exporters.PLAYWRIGHT_WORKER:
24
22
  return require('./ci-visibility/exporters/test-worker')
25
- default:
26
- return inAWSLambda && !usingLambdaExtension ? require('./exporters/log') : require('./exporters/agent')
23
+ default: {
24
+ const inAWSLambda = getEnvironmentVariable('AWS_LAMBDA_FUNCTION_NAME') !== undefined
25
+ const usingLambdaExtension = inAWSLambda && fs.existsSync(constants.DATADOG_LAMBDA_EXTENSION_PATH)
26
+ return require(inAWSLambda && !usingLambdaExtension ? './exporters/log' : './exporters/agent')
27
+ }
27
28
  }
28
29
  }
@@ -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) {
@@ -1,15 +1,16 @@
1
1
  'use strict'
2
2
 
3
3
  const fs = require('fs')
4
+ const { getEnvironmentVariable } = require('../../config-helper')
4
5
 
5
- const { DD_EXTERNAL_ENV } = process.env
6
+ const DD_EXTERNAL_ENV = getEnvironmentVariable('DD_EXTERNAL_ENV')
6
7
 
7
8
  // The second part is the PCF / Garden regexp. We currently assume no suffix($) to avoid matching pod UIDs
8
9
  // See https://github.com/DataDog/datadog-agent/blob/7.40.x/pkg/util/cgroups/reader.go#L50
9
10
  const uuidSource =
10
11
  '[0-9a-f]{8}[-_][0-9a-f]{4}[-_][0-9a-f]{4}[-_][0-9a-f]{4}[-_][0-9a-f]{12}|[0-9a-f]{8}(?:-[0-9a-f]{4}){4}$'
11
12
  const containerSource = '[0-9a-f]{64}'
12
- const taskSource = '[0-9a-f]{32}-\\d+'
13
+ const taskSource = String.raw`[0-9a-f]{32}-\d+`
13
14
  const lineReg = /^(\d+):([^:]*):(.+)$/m
14
15
  const entityReg = new RegExp(`.*(${uuidSource}|${containerSource}|${taskSource})(?:\\.scope)?$`, 'm')
15
16
 
@@ -24,7 +25,7 @@ try {
24
25
 
25
26
  const inodePath = cgroup.match(lineReg)?.[3]
26
27
  if (inodePath) {
27
- const strippedPath = inodePath.replace(/^\/|\/$/g, '')
28
+ const strippedPath = inodePath.replaceAll(/^\/|\/$/g, '')
28
29
 
29
30
  try {
30
31
  inode = fs.statSync(`/sys/fs/cgroup/${strippedPath}`).ino
@@ -38,10 +38,12 @@ class FormData extends Readable {
38
38
  }
39
39
 
40
40
  _appendFile (key, value, { filename, contentType = 'application/octet-stream' }) {
41
- this._data.push(`Content-Disposition: form-data; name="${key}"; filename="${filename}"\r\n`)
42
- this._data.push(`Content-Type: ${contentType}\r\n\r\n`)
43
- this._data.push(value)
44
- this._data.push('\r\n')
41
+ this._data.push(
42
+ `Content-Disposition: form-data; name="${key}"; filename="${filename}"\r\n`,
43
+ `Content-Type: ${contentType}\r\n\r\n`,
44
+ value,
45
+ '\r\n'
46
+ )
45
47
  }
46
48
 
47
49
  _read () {
@@ -56,9 +56,12 @@ function request (data, options, callback) {
56
56
  const timeout = options.timeout || 2000
57
57
  const isSecure = options.protocol === 'https:'
58
58
  const client = isSecure ? https : http
59
- const dataArray = [].concat(data)
59
+ let dataArray = data
60
60
 
61
61
  if (!isReadable) {
62
+ if (!Array.isArray(data)) {
63
+ dataArray = [data]
64
+ }
62
65
  options.headers['Content-Length'] = byteLength(dataArray)
63
66
  }
64
67
 
@@ -100,7 +103,7 @@ function request (data, options, callback) {
100
103
  options.url || options.hostname || `http://localhost:${options.port}`
101
104
  ).href
102
105
  errorMessage = `Error from ${fullUrl}: ${res.statusCode} ${http.STATUS_CODES[res.statusCode]}.`
103
- } catch (e) {
106
+ } catch {
104
107
  // ignore error
105
108
  }
106
109
  const responseData = buffer.toString()
@@ -1,8 +1,10 @@
1
+ const { getEnvironmentVariable } = require('../../config-helper')
2
+
1
3
  function safeJSONStringify (value) {
2
4
  return JSON.stringify(
3
5
  value,
4
- (key, value) => key !== 'dd-api-key' ? value : undefined,
5
- process.env.DD_TRACE_BEAUTIFUL_LOGS ? 2 : undefined
6
+ (key, value) => key === 'dd-api-key' ? undefined : value,
7
+ getEnvironmentVariable('DD_TRACE_BEAUTIFUL_LOGS') ? 2 : undefined
6
8
  )
7
9
  }
8
10
 
@@ -5,7 +5,7 @@ const https = require('https')
5
5
  class ExternalLogger {
6
6
  // Note: these attribute names match the corresponding entry in the JSON payload.
7
7
  constructor ({
8
- ddsource, hostname, service, apiKey, site = 'datadoghq.com', interval = 10000, timeout = 2000, limit = 1000
8
+ ddsource, hostname, service, apiKey, site = 'datadoghq.com', interval = 10_000, timeout = 2000, limit = 1000
9
9
  }) {
10
10
  this.enabled = !!apiKey
11
11
 
@@ -128,10 +128,10 @@ class ExternalLogger {
128
128
  }
129
129
 
130
130
  class NoopExternalLogger {
131
- log () { }
132
- enqueue () { }
133
- shutdown () { }
134
- flush () { }
131
+ log () {}
132
+ enqueue () {}
133
+ shutdown () {}
134
+ flush () {}
135
135
  }
136
136
 
137
137
  module.exports.ExternalLogger = ExternalLogger
@@ -22,11 +22,7 @@ class FlareFile extends Writable {
22
22
 
23
23
  this._reserve(length)
24
24
 
25
- if (Buffer.isBuffer(chunk)) {
26
- this.length += chunk.copy(this._buffer, this.length)
27
- } else {
28
- this.length += this._buffer.write(chunk, encoding)
29
- }
25
+ this.length += Buffer.isBuffer(chunk) ? chunk.copy(this._buffer, this.length) : this._buffer.write(chunk, encoding)
30
26
 
31
27
  callback()
32
28
  }
@@ -224,7 +224,7 @@ function addTag (meta, metrics, key, value, nested) {
224
224
  meta[key] = value
225
225
  break
226
226
  case 'number':
227
- if (isNaN(value)) break
227
+ if (Number.isNaN(value)) break
228
228
  metrics[key] = value
229
229
  break
230
230
  case 'boolean':
@@ -9,7 +9,7 @@ function removeUserSensitiveInfo (repositoryUrl) {
9
9
  return `${parsedUrl.origin}${parsedUrl.pathname}`
10
10
  }
11
11
  return repositoryUrl
12
- } catch (e) {
12
+ } catch {
13
13
  // if protocol isn't https, no password will be used
14
14
  return repositoryUrl
15
15
  }
@@ -2,7 +2,7 @@
2
2
 
3
3
  const { randomFillSync } = require('crypto')
4
4
 
5
- const UINT_MAX = 4294967296
5
+ const UINT_MAX = 4_294_967_296
6
6
 
7
7
  const data = new Uint8Array(8 * 8192)
8
8
  const zeroId = new Uint8Array(8)
@@ -26,6 +26,10 @@ class Identifier {
26
26
  : toNumberString(this._buffer, radix)
27
27
  }
28
28
 
29
+ toBigInt () {
30
+ return Buffer.from(this._buffer).readBigUInt64BE(0)
31
+ }
32
+
29
33
  toBuffer () {
30
34
  return this._buffer
31
35
  }
@@ -61,12 +65,12 @@ function createBuffer (value) {
61
65
 
62
66
  const size = Math.ceil(value.length / 16) * 16
63
67
  const bytes = size / 2
64
- const buffer = new Array(bytes)
68
+ const buffer = []
65
69
 
66
70
  value = value.padStart(size, '0')
67
71
 
68
72
  for (let i = 0; i < bytes; i++) {
69
- buffer[i] = parseInt(value.substring(i * 2, i * 2 + 2), 16)
73
+ buffer[i] = Number.parseInt(value.slice(i * 2, i * 2 + 2), 16)
70
74
  }
71
75
 
72
76
  return buffer
@@ -86,7 +90,7 @@ function fromString (str, raddix) {
86
90
  const sign = pos
87
91
 
88
92
  while (pos < len) {
89
- const chr = parseInt(str[pos++], raddix)
93
+ const chr = Number.parseInt(str[pos++], raddix)
90
94
 
91
95
  if (!(chr >= 0)) break // NaN
92
96
 
@@ -161,7 +165,7 @@ function pseudoRandom () {
161
165
 
162
166
  // Read a buffer to unsigned integer bytes.
163
167
  function readInt32 (buffer, offset) {
164
- return (buffer[offset + 0] * 16777216) +
168
+ return (buffer[offset + 0] * 16_777_216) +
165
169
  (buffer[offset + 1] << 16) +
166
170
  (buffer[offset + 2] << 8) +
167
171
  buffer[offset + 3]
@@ -170,12 +174,14 @@ function readInt32 (buffer, offset) {
170
174
  // Write unsigned integer bytes to a buffer.
171
175
  function writeUInt32BE (buffer, value, offset) {
172
176
  buffer[3 + offset] = value & 255
173
- value = value >> 8
177
+ value >>= 8
174
178
  buffer[2 + offset] = value & 255
175
- value = value >> 8
179
+ value >>= 8
176
180
  buffer[1 + offset] = value & 255
177
- value = value >> 8
181
+ value >>= 8
178
182
  buffer[0 + offset] = value & 255
179
183
  }
180
184
 
181
- module.exports = (value, radix) => new Identifier(value, radix)
185
+ module.exports = function createIdentifier (value, radix) {
186
+ return new Identifier(value, radix)
187
+ }