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
@@ -62,9 +62,9 @@ class PrioritySampler {
62
62
  * @param opts {SamplingConfig}
63
63
  */
64
64
  configure (env, opts = {}) {
65
- const { sampleRate, provenance = undefined, rateLimit = 100, rules = [] } = opts
65
+ const { sampleRate, provenance, rateLimit = 100, rules = [] } = opts
66
66
  this._env = env
67
- this._rules = this.#_normalizeRules(rules, sampleRate, rateLimit, provenance)
67
+ this._rules = this.#normalizeRules(rules, sampleRate, rateLimit, provenance)
68
68
  this._limiter = new RateLimiter(rateLimit)
69
69
 
70
70
  log.trace(env, opts)
@@ -110,7 +110,7 @@ class PrioritySampler {
110
110
  return
111
111
  }
112
112
 
113
- this.#_addDecisionMaker(root)
113
+ this.#addDecisionMaker(root)
114
114
  }
115
115
 
116
116
  /**
@@ -174,7 +174,7 @@ class PrioritySampler {
174
174
 
175
175
  log.trace(span, samplingPriority, mechanism)
176
176
 
177
- this.#_addDecisionMaker(root)
177
+ this.#addDecisionMaker(root)
178
178
  }
179
179
 
180
180
  /**
@@ -193,11 +193,11 @@ class PrioritySampler {
193
193
  */
194
194
  _getPriorityFromAuto (span) {
195
195
  const context = this._getContext(span)
196
- const rule = this.#_findRule(span)
196
+ const rule = this.#findRule(span)
197
197
 
198
198
  return rule
199
- ? this.#_getPriorityByRule(context, rule)
200
- : this.#_getPriorityByAgent(context)
199
+ ? this.#getPriorityByRule(context, rule)
200
+ : this.#getPriorityByAgent(context)
201
201
  }
202
202
 
203
203
  /**
@@ -213,7 +213,7 @@ class PrioritySampler {
213
213
  } else if (hasOwn(tags, MANUAL_DROP) && tags[MANUAL_DROP] !== false) {
214
214
  return USER_REJECT
215
215
  } else {
216
- const priority = parseInt(tags[SAMPLING_PRIORITY], 10)
216
+ const priority = Number.parseInt(tags[SAMPLING_PRIORITY], 10)
217
217
 
218
218
  if (priority === 1 || priority === 2) {
219
219
  return USER_KEEP
@@ -229,13 +229,13 @@ class PrioritySampler {
229
229
  * @param rule {SamplingRule}
230
230
  * @returns {SamplingPriority}
231
231
  */
232
- #_getPriorityByRule (context, rule) {
232
+ #getPriorityByRule (context, rule) {
233
233
  context._trace[SAMPLING_RULE_DECISION] = rule.sampleRate
234
234
  context._sampling.mechanism = SAMPLING_MECHANISM_RULE
235
235
  if (rule.provenance === 'customer') context._sampling.mechanism = SAMPLING_MECHANISM_REMOTE_USER
236
236
  if (rule.provenance === 'dynamic') context._sampling.mechanism = SAMPLING_MECHANISM_REMOTE_DYNAMIC
237
237
 
238
- return rule.sample() && this._isSampledByRateLimit(context)
238
+ return rule.sample(context) && this._isSampledByRateLimit(context)
239
239
  ? USER_KEEP
240
240
  : USER_REJECT
241
241
  }
@@ -260,17 +260,13 @@ class PrioritySampler {
260
260
  * @returns {SamplingPriority}
261
261
  * @private
262
262
  */
263
- #_getPriorityByAgent (context) {
263
+ #getPriorityByAgent (context) {
264
264
  const key = `service:${context._tags[SERVICE_NAME]},env:${this._env}`
265
265
  const sampler = this._samplers[key] || this._samplers[DEFAULT_KEY]
266
266
 
267
267
  context._trace[SAMPLING_AGENT_DECISION] = sampler.rate()
268
268
 
269
- if (sampler === defaultSampler) {
270
- context._sampling.mechanism = SAMPLING_MECHANISM_DEFAULT
271
- } else {
272
- context._sampling.mechanism = SAMPLING_MECHANISM_AGENT
273
- }
269
+ context._sampling.mechanism = sampler === defaultSampler ? SAMPLING_MECHANISM_DEFAULT : SAMPLING_MECHANISM_AGENT
274
270
 
275
271
  return sampler.isSampled(context) ? AUTO_KEEP : AUTO_REJECT
276
272
  }
@@ -281,7 +277,7 @@ class PrioritySampler {
281
277
  * @private
282
278
  * @returns {void}
283
279
  */
284
- #_addDecisionMaker (span) {
280
+ #addDecisionMaker (span) {
285
281
  const context = span.context()
286
282
  const trace = context._trace
287
283
  const priority = context._sampling.priority
@@ -305,13 +301,14 @@ class PrioritySampler {
305
301
  * @returns {SamplingRule[]}
306
302
  * @private
307
303
  */
308
- #_normalizeRules (rules, sampleRate, rateLimit, provenance) {
304
+ #normalizeRules (rules, sampleRate, rateLimit, provenance) {
309
305
  rules = [].concat(rules || [])
310
306
 
307
+ rules.push({ sampleRate, maxPerSecond: rateLimit, provenance })
308
+
311
309
  return rules
312
- .concat({ sampleRate, maxPerSecond: rateLimit, provenance })
313
- .map(rule => ({ ...rule, sampleRate: parseFloat(rule.sampleRate) }))
314
- .filter(rule => !isNaN(rule.sampleRate))
310
+ .map(rule => ({ ...rule, sampleRate: Number.parseFloat(rule.sampleRate) }))
311
+ .filter(rule => !Number.isNaN(rule.sampleRate))
315
312
  .map(SamplingRule.from)
316
313
  }
317
314
 
@@ -321,8 +318,11 @@ class PrioritySampler {
321
318
  * @returns {SamplingRule}
322
319
  * @private
323
320
  */
324
- #_findRule (span) {
321
+ #findRule (span) {
325
322
  for (const rule of this._rules) {
323
+ // Rule is a special object with a .match() property.
324
+ // It has nothing to do with a regular expression.
325
+ // eslint-disable-next-line unicorn/prefer-regexp-test
326
326
  if (rule.match(span)) return rule
327
327
  }
328
328
  }
@@ -25,6 +25,7 @@ class Config {
25
25
  DD_PROFILING_CODEHOTSPOTS_ENABLED,
26
26
  DD_PROFILING_CPU_ENABLED,
27
27
  DD_PROFILING_DEBUG_SOURCE_MAPS,
28
+ DD_PROFILING_DEBUG_UPLOAD_COMPRESSION,
28
29
  DD_PROFILING_ENDPOINT_COLLECTION_ENABLED,
29
30
  DD_PROFILING_EXPERIMENTAL_CODEHOTSPOTS_ENABLED,
30
31
  DD_PROFILING_EXPERIMENTAL_CPU_ENABLED,
@@ -35,6 +36,7 @@ class Config {
35
36
  DD_PROFILING_EXPERIMENTAL_OOM_MONITORING_ENABLED,
36
37
  DD_PROFILING_EXPERIMENTAL_TIMELINE_ENABLED,
37
38
  DD_PROFILING_HEAP_ENABLED,
39
+ DD_PROFILING_HEAP_SAMPLING_INTERVAL,
38
40
  DD_PROFILING_PPROF_PREFIX,
39
41
  DD_PROFILING_PROFILERS,
40
42
  DD_PROFILING_SOURCE_MAP,
@@ -163,13 +165,11 @@ class Config {
163
165
  exportCommand
164
166
  }
165
167
 
166
- const profilers = options.profilers
167
- ? options.profilers
168
- : getProfilers({
169
- DD_PROFILING_HEAP_ENABLED,
170
- DD_PROFILING_WALLTIME_ENABLED,
171
- DD_PROFILING_PROFILERS
172
- })
168
+ const profilers = options.profilers || getProfilers({
169
+ DD_PROFILING_HEAP_ENABLED,
170
+ DD_PROFILING_WALLTIME_ENABLED,
171
+ DD_PROFILING_PROFILERS
172
+ })
173
173
 
174
174
  this.timelineEnabled = isTrue(coalesce(options.timelineEnabled,
175
175
  DD_PROFILING_TIMELINE_ENABLED,
@@ -191,6 +191,42 @@ class Config {
191
191
  logExperimentalVarDeprecation('CPU_ENABLED')
192
192
  checkOptionWithSamplingContextAllowed(this.cpuProfilingEnabled, 'CPU profiling')
193
193
 
194
+ this.heapSamplingInterval = coalesce(options.heapSamplingInterval,
195
+ Number(DD_PROFILING_HEAP_SAMPLING_INTERVAL))
196
+ const uploadCompression0 = coalesce(options.uploadCompression, DD_PROFILING_DEBUG_UPLOAD_COMPRESSION, 'on')
197
+ let [uploadCompression, level0] = uploadCompression0.split('-')
198
+ if (!['on', 'off', 'gzip', 'zstd'].includes(uploadCompression)) {
199
+ logger.warn(`Invalid profile upload compression method "${uploadCompression0}". Will use "on".`)
200
+ uploadCompression = 'on'
201
+ }
202
+ let level = level0 ? Number.parseInt(level0, 10) : undefined
203
+ if (level !== undefined) {
204
+ if (['on', 'off'].includes(uploadCompression)) {
205
+ logger.warn(`Compression levels are not supported for "${uploadCompression}".`)
206
+ level = undefined
207
+ } else if (Number.isNaN(level)) {
208
+ logger.warn(
209
+ `Invalid compression level "${level0}". Will use default level.`)
210
+ level = undefined
211
+ } else if (level < 1) {
212
+ logger.warn(`Invalid compression level ${level}. Will use 1.`)
213
+ level = 1
214
+ } else {
215
+ const maxLevel = { gzip: 9, zstd: 22 }[uploadCompression]
216
+ if (level > maxLevel) {
217
+ logger.warn(`Invalid compression level ${level}. Will use ${maxLevel}.`)
218
+ level = maxLevel
219
+ }
220
+ }
221
+ }
222
+
223
+ // Default to gzip
224
+ if (uploadCompression === 'on') {
225
+ uploadCompression = 'gzip'
226
+ }
227
+
228
+ this.uploadCompression = { method: uploadCompression, level }
229
+
194
230
  this.profilers = ensureProfilers(profilers, this)
195
231
  }
196
232
  }
@@ -307,7 +343,7 @@ function ensureProfilers (profilers, options) {
307
343
  }
308
344
 
309
345
  // Filter out any invalid profilers
310
- return profilers.filter(v => v)
346
+ return profilers.filter(Boolean)
311
347
  }
312
348
 
313
349
  function ensureLogger (logger) {
@@ -6,16 +6,16 @@ const libuvThreadPoolSize = (() => {
6
6
  const ss = process.env.UV_THREADPOOL_SIZE
7
7
  if (ss === undefined) {
8
8
  // Backend will apply the default size based on Node version.
9
- return undefined
9
+ return
10
10
  }
11
11
  // libuv uses atoi to parse the value, which is almost the same as parseInt, except that parseInt
12
12
  // will return NaN on invalid input, while atoi will return 0. This is handled at return.
13
- const s = parseInt(ss)
14
- // We dont' interpret the value further here in the library. Backend will interpret the number
13
+ const s = Number.parseInt(ss)
14
+ // We don't interpret the value further here in the library. Backend will interpret the number
15
15
  // based on Node version. In all currently known Node versions, 0 results in 1 worker thread,
16
16
  // negative values (because they're assigned to an unsigned int) become very high positive values,
17
17
  // and the value is finally capped at 1024.
18
- return isNaN(s) ? 0 : s
18
+ return Number.isNaN(s) ? 0 : s
19
19
  })()
20
20
 
21
21
  class EventSerializer {
@@ -87,7 +87,7 @@ class EventSerializer {
87
87
  // We'll keep it like this as we want cross-engine consistency. We
88
88
  // also aren't changing the format of the existing tag as we don't want
89
89
  // to break it.
90
- version: process.version.substring(1)
90
+ version: process.version.slice(1)
91
91
  }
92
92
  }
93
93
  })
@@ -6,8 +6,9 @@ const { threadId } = require('worker_threads')
6
6
  const writeFile = promisify(fs.writeFile)
7
7
  const { EventSerializer } = require('./event_serializer')
8
8
 
9
+ const pad = (n) => String(n).padStart(2, '0')
10
+
9
11
  function formatDateTime (t) {
10
- const pad = (n) => String(n).padStart(2, '0')
11
12
  return `${t.getUTCFullYear()}${pad(t.getUTCMonth() + 1)}${pad(t.getUTCDate())}` +
12
13
  `T${pad(t.getUTCHours())}${pad(t.getUTCMinutes())}${pad(t.getUTCSeconds())}Z`
13
14
  }
@@ -8,6 +8,9 @@ const { isWebServerSpan, endpointNameFromTags, getStartedSpans } = require('./we
8
8
  const dc = require('dc-polyfill')
9
9
  const crashtracker = require('../crashtracking')
10
10
 
11
+ const { promisify } = require('util')
12
+ const zlib = require('zlib')
13
+
11
14
  const profileSubmittedChannel = dc.channel('datadog:profiling:profile-submitted')
12
15
  const spanFinishedChannel = dc.channel('dd-trace:span:finish')
13
16
 
@@ -83,9 +86,37 @@ class Profiler extends EventEmitter {
83
86
  this._logger.debug(() => {
84
87
  return mapper.infoMap.size === 0
85
88
  ? 'Found no source maps'
86
- : `Found source maps for following files: [${Array.from(mapper.infoMap.keys()).join(', ')}]`
89
+ : `Found source maps for following files: [${[...mapper.infoMap.keys()].join(', ')}]`
87
90
  })
88
91
  }
92
+
93
+ const clevel = config.uploadCompression.level
94
+ switch (config.uploadCompression.method) {
95
+ case 'gzip':
96
+ this._compressionFn = promisify(zlib.gzip)
97
+ if (clevel !== undefined) {
98
+ this._compressionOptions = {
99
+ level: clevel
100
+ }
101
+ }
102
+ break
103
+ case 'zstd':
104
+ if (typeof zlib.zstdCompress === 'function') {
105
+ this._compressionFn = promisify(zlib.zstdCompress)
106
+ if (clevel !== undefined) {
107
+ this._compressionOptions = {
108
+ params: {
109
+ [zlib.constants.ZSTD_c_compressionLevel]: clevel
110
+ }
111
+ }
112
+ }
113
+ } else {
114
+ const zstdCompress = require('@datadog/libdatadog').load('datadog-js-zstd').zstd_compress
115
+ const level = clevel ?? 0 // 0 is zstd default compression level
116
+ this._compressionFn = (buffer) => Promise.resolve(Buffer.from(zstdCompress(buffer, level)))
117
+ }
118
+ break
119
+ }
89
120
  } catch (err) {
90
121
  this._logError(err)
91
122
  }
@@ -218,7 +249,11 @@ class Profiler extends EventEmitter {
218
249
  // encode and export asynchronously
219
250
  for (const { profiler, profile } of profiles) {
220
251
  try {
221
- encodedProfiles[profiler.type] = await profiler.encode(profile)
252
+ const encoded = await profiler.encode(profile)
253
+ const compressed = encoded instanceof Buffer && this._compressionFn !== undefined
254
+ ? await this._compressionFn(encoded, this._compressionOptions)
255
+ : encoded
256
+ encodedProfiles[profiler.type] = compressed
222
257
  this._logger.debug(() => {
223
258
  const profileJson = JSON.stringify(profile, (key, value) => {
224
259
  return typeof value === 'bigint' ? value.toString() : value
@@ -1,10 +1,9 @@
1
1
  const { performance, constants, PerformanceObserver } = require('perf_hooks')
2
- const { END_TIMESTAMP_LABEL, SPAN_ID_LABEL, LOCAL_ROOT_SPAN_ID_LABEL } = require('./shared')
2
+ const { END_TIMESTAMP_LABEL, SPAN_ID_LABEL, LOCAL_ROOT_SPAN_ID_LABEL, encodeProfileAsync } = require('./shared')
3
3
  const { Function, Label, Line, Location, Profile, Sample, StringTable, ValueType } = require('pprof-format')
4
- const pprof = require('@datadog/pprof/')
5
4
 
6
5
  // perf_hooks uses millis, with fractional part representing nanos. We emit nanos into the pprof file.
7
- const MS_TO_NS = 1000000
6
+ const MS_TO_NS = 1_000_000
8
7
 
9
8
  // While this is an "events profiler", meaning it emits a pprof file based on events observed as
10
9
  // perf_hooks events, the emitted pprof file uses the type "timeline".
@@ -50,10 +49,10 @@ class GCDecorator {
50
49
  // Create labels for all GC performance flags and kinds of GC
51
50
  for (const [key, value] of Object.entries(constants)) {
52
51
  if (key.startsWith('NODE_PERFORMANCE_GC_FLAGS_')) {
53
- this.flagObj[key.substring(26).toLowerCase()] = value
52
+ this.flagObj[key.slice(26).toLowerCase()] = value
54
53
  } else if (key.startsWith('NODE_PERFORMANCE_GC_')) {
55
54
  // It's a constant for a kind of GC
56
- const kind = key.substring(20).toLowerCase()
55
+ const kind = key.slice(20).toLowerCase()
57
56
  this.kindLabels[value] = labelFromStr(stringTable, kindLabelKey, kind)
58
57
  }
59
58
  }
@@ -258,6 +257,12 @@ class EventSerializer {
258
257
  }
259
258
  }
260
259
 
260
+ function add (items) {
261
+ for (const item of items.getEntries()) {
262
+ this.eventHandler(item)
263
+ }
264
+ }
265
+
261
266
  /**
262
267
  * Class that sources timeline events through Node.js performance measurement APIs.
263
268
  */
@@ -272,12 +277,6 @@ class NodeApiEventSource {
272
277
  // if already started, do nothing
273
278
  if (this.observer) return
274
279
 
275
- function add (items) {
276
- for (const item of items.getEntries()) {
277
- this.eventHandler(item)
278
- }
279
- }
280
-
281
280
  this.observer = new PerformanceObserver(add.bind(this))
282
281
  this.observer.observe({ entryTypes: this.entryTypes })
283
282
  }
@@ -381,17 +380,15 @@ class EventsProfiler {
381
380
  }
382
381
  }
383
382
 
384
- if (options.codeHotspotsEnabled) {
383
+ this.eventSource = options.codeHotspotsEnabled
385
384
  // Use Datadog instrumentation to collect events with span IDs. Still use
386
385
  // Node API for GC events.
387
- this.eventSource = new CompositeEventSource([
386
+ ? new CompositeEventSource([
388
387
  new DatadogInstrumentationEventSource(eventHandler, eventFilter),
389
388
  new NodeApiEventSource(filteringEventHandler, ['gc'])
390
389
  ])
391
- } else {
392
390
  // Use Node API instrumentation to collect events without span IDs
393
- this.eventSource = new NodeApiEventSource(filteringEventHandler)
394
- }
391
+ : new NodeApiEventSource(filteringEventHandler)
395
392
  }
396
393
 
397
394
  start () {
@@ -412,7 +409,7 @@ class EventsProfiler {
412
409
  }
413
410
 
414
411
  encode (profile) {
415
- return pprof.encode(profile())
412
+ return encodeProfileAsync(profile())
416
413
  }
417
414
  }
418
415
 
@@ -36,6 +36,10 @@ function getNonJSThreadsLabels () {
36
36
  return { [THREAD_NAME_LABEL]: 'Non-JS threads', [THREAD_ID_LABEL]: 'NA', [OS_THREAD_ID_LABEL]: 'NA' }
37
37
  }
38
38
 
39
+ function encodeProfileAsync (profile) {
40
+ return profile.encodeAsync().then(Buffer.from)
41
+ }
42
+
39
43
  module.exports = {
40
44
  END_TIMESTAMP_LABEL,
41
45
  THREAD_NAME_LABEL,
@@ -46,5 +50,6 @@ module.exports = {
46
50
  threadNamePrefix,
47
51
  eventLoopThreadName,
48
52
  getNonJSThreadsLabels,
49
- getThreadLabels: cacheThreadLabels()
53
+ getThreadLabels: cacheThreadLabels(),
54
+ encodeProfileAsync
50
55
  }
@@ -1,7 +1,7 @@
1
1
  'use strict'
2
2
 
3
3
  const { oomExportStrategies } = require('../constants')
4
- const { getThreadLabels } = require('./shared')
4
+ const { encodeProfileAsync, getThreadLabels } = require('./shared')
5
5
 
6
6
  function strategiesToCallbackMode (strategies, callbackMode) {
7
7
  return strategies.includes(oomExportStrategies.ASYNC_CALLBACK) ? callbackMode.Async : 0
@@ -10,7 +10,7 @@ function strategiesToCallbackMode (strategies, callbackMode) {
10
10
  class NativeSpaceProfiler {
11
11
  constructor (options = {}) {
12
12
  this.type = 'space'
13
- this._samplingInterval = options.samplingInterval || 512 * 1024
13
+ this._samplingInterval = options.heapSamplingInterval || 512 * 1024
14
14
  this._stackDepth = options.stackDepth || 64
15
15
  this._pprof = undefined
16
16
  this._oomMonitoring = options.oomMonitoring || {}
@@ -47,7 +47,7 @@ class NativeSpaceProfiler {
47
47
  }
48
48
 
49
49
  encode (profile) {
50
- return this._pprof.encode(profile)
50
+ return encodeProfileAsync(profile)
51
51
  }
52
52
 
53
53
  stop () {
@@ -10,7 +10,8 @@ const {
10
10
  SPAN_ID_LABEL,
11
11
  LOCAL_ROOT_SPAN_ID_LABEL,
12
12
  getNonJSThreadsLabels,
13
- getThreadLabels
13
+ getThreadLabels,
14
+ encodeProfileAsync
14
15
  } = require('./shared')
15
16
 
16
17
  const { isWebServerSpan, endpointNameFromTags, getStartedSpans } = require('../webspan-utils')
@@ -89,11 +90,9 @@ class NativeWallProfiler {
89
90
  this._pprof = undefined
90
91
 
91
92
  // Bind these to this so they can be used as callbacks
92
- if (this._withContexts) {
93
- if (this._captureSpanData) {
94
- this._enter = this._enter.bind(this)
95
- this._spanFinished = this._spanFinished.bind(this)
96
- }
93
+ if (this._withContexts && this._captureSpanData) {
94
+ this._enter = this._enter.bind(this)
95
+ this._spanFinished = this._spanFinished.bind(this)
97
96
  }
98
97
  this._generateLabels = this._generateLabels.bind(this)
99
98
 
@@ -326,7 +325,7 @@ class NativeWallProfiler {
326
325
  }
327
326
 
328
327
  encode (profile) {
329
- return this._pprof.encode(profile)
328
+ return encodeProfileAsync(profile)
330
329
  }
331
330
 
332
331
  stop () {
@@ -6,7 +6,7 @@ const dc = require('dc-polyfill')
6
6
  const log = require('../log')
7
7
 
8
8
  // If the process lives for at least 30 seconds, it's considered long-lived
9
- const DEFAULT_LONG_LIVED_THRESHOLD = 30000
9
+ const DEFAULT_LONG_LIVED_THRESHOLD = 30_000
10
10
 
11
11
  /**
12
12
  * This class embodies the SSI profiler-triggering heuristics and also emits telemetry metrics about
@@ -107,10 +107,8 @@ class SSIHeuristics {
107
107
  }
108
108
 
109
109
  _maybeTriggered () {
110
- if (!this.shortLived && !this.noSpan) {
111
- if (typeof this.triggeredCallback === 'function') {
112
- this.triggeredCallback.call(null)
113
- }
110
+ if (!this.shortLived && !this.noSpan && typeof this.triggeredCallback === 'function') {
111
+ this.triggeredCallback.call(null)
114
112
  }
115
113
  }
116
114
 
@@ -6,8 +6,8 @@ const tagger = {
6
6
 
7
7
  switch (typeof tags) {
8
8
  case 'object':
9
- if (Array.isArray(tags)) {
10
- return tags.reduce((prev, next) => {
9
+ return Array.isArray(tags)
10
+ ? tags.reduce((prev, next) => {
11
11
  const parts = next.split(':')
12
12
  const key = parts.shift().trim()
13
13
  const value = parts.join(':').trim()
@@ -16,11 +16,9 @@ const tagger = {
16
16
 
17
17
  return Object.assign(prev, { [key]: value })
18
18
  }, {})
19
- } else {
20
- return tagger.parse(Object.keys(tags)
19
+ : tagger.parse(Object.keys(tags)
21
20
  .filter(key => tags[key] !== undefined && tags[key] !== null)
22
21
  .map(key => `${key}:${tags[key]}`))
23
- }
24
22
  case 'string':
25
23
  return tagger.parse(tags.split(','))
26
24
  default:
@@ -9,7 +9,7 @@ function endpointNameFromTags (tags) {
9
9
  return tags[RESOURCE_NAME] || [
10
10
  tags[HTTP_METHOD],
11
11
  tags[HTTP_ROUTE]
12
- ].filter(v => v).join(' ')
12
+ ].filter(Boolean).join(' ')
13
13
  }
14
14
 
15
15
  function getStartedSpans (context) {
@@ -189,15 +189,13 @@ class Tracer extends NoopProxy {
189
189
 
190
190
  this._modules.rewriter.enable(config)
191
191
 
192
- if (config.tracing) {
193
- if (config.isManualApiEnabled) {
194
- const TestApiManualPlugin = require('./ci-visibility/test-api-manual/test-api-manual-plugin')
195
- this._testApiManualPlugin = new TestApiManualPlugin(this)
196
- // `shouldGetEnvironmentData` is passed as false so that we only lazily calculate it
197
- // This is the only place where we need to do this because the rest of the plugins
198
- // are lazily configured when the library is imported.
199
- this._testApiManualPlugin.configure({ ...config, enabled: true }, false)
200
- }
192
+ if (config.tracing && config.isManualApiEnabled) {
193
+ const TestApiManualPlugin = require('./ci-visibility/test-api-manual/test-api-manual-plugin')
194
+ this._testApiManualPlugin = new TestApiManualPlugin(this)
195
+ // `shouldGetEnvironmentData` is passed as false so that we only lazily calculate it
196
+ // This is the only place where we need to do this because the rest of the plugins
197
+ // are lazily configured when the library is imported.
198
+ this._testApiManualPlugin.configure({ ...config, enabled: true }, false)
201
199
  }
202
200
  if (config.ciVisAgentlessLogSubmissionEnabled) {
203
201
  if (process.env.DD_API_KEY) {
@@ -0,0 +1,40 @@
1
+ 'use strict'
2
+
3
+ /**
4
+ * `RandomSampler` determines whether or not to sample an operation based on random chance.
5
+ *
6
+ * Use this class **only** when the operation you are sampling does **not have access**
7
+ * to a `Span` or its `SpanContext`.
8
+ *
9
+ * If a `Span` or its `SpanContext` **is** available, use the `Sampler` class instead as
10
+ * it uses a deterministic sampling algorithm consistent across all languages.
11
+ */
12
+ class RandomSampler {
13
+ /**
14
+ * @param {number} rate
15
+ */
16
+ constructor (rate) {
17
+ this._rate = rate
18
+ }
19
+
20
+ /**
21
+ * @returns {number}
22
+ */
23
+ rate () {
24
+ return this._rate
25
+ }
26
+
27
+ /**
28
+ * Determines whether an operation should be sampled based on the configured sampling rate.
29
+ *
30
+ * Returns `true` if the sampling decision passes (i.e., the operation should be sampled).
31
+ * This happens if the sampling rate is `1` (i.e., always sample) or if a random value falls below the rate.
32
+ *
33
+ * @returns {boolean} `true` if the operation should be sampled, otherwise `false`.
34
+ */
35
+ isSampled () {
36
+ return this._rate === 1 || Math.random() < this._rate
37
+ }
38
+ }
39
+
40
+ module.exports = RandomSampler
@@ -4,7 +4,7 @@ const limiter = require('limiter')
4
4
 
5
5
  class RateLimiter {
6
6
  constructor (rateLimit, interval = 'second') {
7
- this._rateLimit = parseInt(rateLimit)
7
+ this._rateLimit = Number.parseInt(rateLimit)
8
8
  this._limiter = new limiter.RateLimiter(this._rateLimit, interval)
9
9
  this._tokensRequested = 0
10
10
  this._prevIntervalTokens = 0
@@ -16,12 +16,12 @@ class RateLimiter {
16
16
  const curIntervalTokens = this._limiter.tokensThisInterval
17
17
  const allowed = this._isAllowed()
18
18
 
19
- if (curIntervalStart !== this._limiter.curIntervalStart) {
19
+ if (curIntervalStart === this._limiter.curIntervalStart) {
20
+ this._tokensRequested++
21
+ } else {
20
22
  this._prevIntervalTokens = curIntervalTokens
21
23
  this._prevTokensRequested = this._tokensRequested
22
24
  this._tokensRequested = 1
23
- } else {
24
- this._tokensRequested++
25
25
  }
26
26
 
27
27
  return allowed
@@ -61,13 +61,9 @@ function enable (config, appsec) {
61
61
 
62
62
  function enableOrDisableAppsec (action, rcConfig, config, appsec) {
63
63
  if (typeof rcConfig.asm?.enabled === 'boolean') {
64
- let shouldEnable
65
-
66
- if (action === 'apply' || action === 'modify') {
67
- shouldEnable = rcConfig.asm.enabled // take control
68
- } else {
69
- shouldEnable = config.appsec.enabled // give back control to local config
70
- }
64
+ const shouldEnable = action === 'apply' || action === 'modify'
65
+ ? rcConfig.asm.enabled // take control
66
+ : config.appsec.enabled // give back control to local config
71
67
 
72
68
  if (shouldEnable) {
73
69
  appsec.enable(config)