dd-trace 3.5.0 → 3.6.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 (85) hide show
  1. package/index.d.ts +40 -2
  2. package/package.json +1 -1
  3. package/packages/datadog-instrumentations/src/cucumber.js +0 -2
  4. package/packages/datadog-instrumentations/src/elasticsearch.js +51 -47
  5. package/packages/datadog-instrumentations/src/google-cloud-pubsub.js +1 -1
  6. package/packages/datadog-instrumentations/src/helpers/hooks.js +1 -0
  7. package/packages/datadog-instrumentations/src/mariadb.js +43 -69
  8. package/packages/datadog-instrumentations/src/mocha.js +14 -18
  9. package/packages/datadog-instrumentations/src/opensearch.js +10 -0
  10. package/packages/datadog-instrumentations/src/pg.js +2 -1
  11. package/packages/datadog-instrumentations/src/rhea.js +20 -17
  12. package/packages/datadog-plugin-amqp10/src/consumer.js +32 -0
  13. package/packages/datadog-plugin-amqp10/src/index.js +11 -101
  14. package/packages/datadog-plugin-amqp10/src/producer.js +34 -0
  15. package/packages/datadog-plugin-amqp10/src/util.js +15 -0
  16. package/packages/datadog-plugin-amqplib/src/client.js +38 -0
  17. package/packages/datadog-plugin-amqplib/src/consumer.js +40 -0
  18. package/packages/datadog-plugin-amqplib/src/index.js +14 -102
  19. package/packages/datadog-plugin-amqplib/src/producer.js +37 -0
  20. package/packages/datadog-plugin-amqplib/src/util.js +14 -0
  21. package/packages/datadog-plugin-dns/src/index.js +16 -91
  22. package/packages/datadog-plugin-dns/src/lookup.js +40 -0
  23. package/packages/datadog-plugin-dns/src/lookup_service.js +24 -0
  24. package/packages/datadog-plugin-dns/src/resolve.js +24 -0
  25. package/packages/datadog-plugin-dns/src/reverse.js +21 -0
  26. package/packages/datadog-plugin-elasticsearch/src/index.js +7 -7
  27. package/packages/datadog-plugin-google-cloud-pubsub/src/client.js +25 -0
  28. package/packages/datadog-plugin-google-cloud-pubsub/src/consumer.js +42 -0
  29. package/packages/datadog-plugin-google-cloud-pubsub/src/index.js +14 -99
  30. package/packages/datadog-plugin-google-cloud-pubsub/src/producer.js +34 -0
  31. package/packages/datadog-plugin-graphql/src/execute.js +73 -0
  32. package/packages/datadog-plugin-graphql/src/index.js +14 -176
  33. package/packages/datadog-plugin-graphql/src/parse.js +32 -0
  34. package/packages/datadog-plugin-graphql/src/resolve.js +70 -76
  35. package/packages/datadog-plugin-graphql/src/validate.js +28 -0
  36. package/packages/datadog-plugin-grpc/src/client.js +46 -55
  37. package/packages/datadog-plugin-grpc/src/index.js +7 -24
  38. package/packages/datadog-plugin-grpc/src/server.js +50 -52
  39. package/packages/datadog-plugin-grpc/src/util.js +15 -14
  40. package/packages/datadog-plugin-http/src/index.js +7 -22
  41. package/packages/datadog-plugin-http2/src/index.js +8 -26
  42. package/packages/datadog-plugin-jest/src/index.js +3 -0
  43. package/packages/datadog-plugin-kafkajs/src/consumer.js +42 -0
  44. package/packages/datadog-plugin-kafkajs/src/index.js +11 -87
  45. package/packages/datadog-plugin-kafkajs/src/producer.js +31 -0
  46. package/packages/datadog-plugin-mocha/src/index.js +2 -2
  47. package/packages/datadog-plugin-moleculer/src/client.js +22 -36
  48. package/packages/datadog-plugin-moleculer/src/index.js +8 -26
  49. package/packages/datadog-plugin-moleculer/src/server.js +18 -30
  50. package/packages/datadog-plugin-net/src/ipc.js +21 -0
  51. package/packages/datadog-plugin-net/src/tcp.js +46 -0
  52. package/packages/datadog-plugin-opensearch/src/index.js +11 -0
  53. package/packages/datadog-plugin-pg/src/index.js +2 -1
  54. package/packages/datadog-plugin-rhea/src/consumer.js +55 -0
  55. package/packages/datadog-plugin-rhea/src/index.js +11 -99
  56. package/packages/datadog-plugin-rhea/src/producer.js +45 -0
  57. package/packages/datadog-plugin-sharedb/src/index.js +22 -39
  58. package/packages/dd-trace/src/appsec/iast/analyzers/vulnerability-analyzer.js +1 -1
  59. package/packages/dd-trace/src/appsec/iast/index.js +4 -6
  60. package/packages/dd-trace/src/appsec/iast/path-line.js +3 -0
  61. package/packages/dd-trace/src/ci-visibility/exporters/agentless/coverage-writer.js +2 -5
  62. package/packages/dd-trace/src/ci-visibility/exporters/agentless/writer.js +2 -5
  63. package/packages/dd-trace/src/config.js +26 -6
  64. package/packages/dd-trace/src/constants.js +3 -0
  65. package/packages/dd-trace/src/dogstatsd.js +42 -10
  66. package/packages/dd-trace/src/encode/agentless-ci-visibility.js +10 -2
  67. package/packages/dd-trace/src/exporters/agent/writer.js +2 -9
  68. package/packages/dd-trace/src/exporters/common/request.js +12 -0
  69. package/packages/dd-trace/src/format.js +13 -0
  70. package/packages/dd-trace/src/metrics.js +10 -2
  71. package/packages/dd-trace/src/plugins/client.js +3 -1
  72. package/packages/dd-trace/src/plugins/composite.js +26 -0
  73. package/packages/dd-trace/src/plugins/consumer.js +9 -0
  74. package/packages/dd-trace/src/plugins/incoming.js +7 -0
  75. package/packages/dd-trace/src/plugins/index.js +1 -0
  76. package/packages/dd-trace/src/plugins/outgoing.js +1 -1
  77. package/packages/dd-trace/src/plugins/producer.js +9 -0
  78. package/packages/dd-trace/src/plugins/server.js +9 -0
  79. package/packages/dd-trace/src/plugins/storage.js +0 -4
  80. package/packages/dd-trace/src/plugins/tracing.js +9 -9
  81. package/packages/dd-trace/src/profiling/profiler.js +8 -1
  82. package/packages/dd-trace/src/span_processor.js +3 -0
  83. package/packages/dd-trace/src/span_sampler.js +80 -0
  84. package/packages/dd-trace/src/tracer.js +6 -2
  85. package/packages/dd-trace/src/util.js +43 -1
@@ -0,0 +1,80 @@
1
+ 'use strict'
2
+ const { globMatch } = require('../src/util')
3
+ const {
4
+ USER_KEEP,
5
+ AUTO_KEEP
6
+ } = require('../../../ext').priority
7
+ const RateLimiter = require('./rate_limiter')
8
+
9
+ class SpanSampler {
10
+ constructor ({ spanSamplingRules = [] }) {
11
+ this._rules = spanSamplingRules
12
+ this._limiters = {}
13
+ }
14
+
15
+ sample (spanContext) {
16
+ const decision = spanContext._sampling.priority
17
+ if (decision === USER_KEEP || decision === AUTO_KEEP) return
18
+
19
+ const { started } = spanContext._trace
20
+ for (const span of started) {
21
+ const service = span.tracer()._service
22
+ const name = span._name
23
+ const rule = findRule(this._rules, service, name)
24
+ if (!rule) continue
25
+
26
+ const sampleRate = getSampleRate(rule.sampleRate)
27
+ const maxPerSecond = getMaxPerSecond(rule.maxPerSecond)
28
+ const sampled = sample(sampleRate)
29
+ if (!sampled) continue
30
+
31
+ const key = `${service}:${name}`
32
+ const limiter = getLimiter(this._limiters, key, maxPerSecond)
33
+ if (limiter.isAllowed()) {
34
+ span.context()._sampling.spanSampling = {
35
+ sampleRate,
36
+ maxPerSecond
37
+ }
38
+ }
39
+ }
40
+ }
41
+ }
42
+
43
+ function findRule (rules, service, name) {
44
+ for (const rule of rules) {
45
+ const servicePattern = getService(rule.service)
46
+ const namePattern = getName(rule.name)
47
+ if (globMatch(servicePattern, service) && globMatch(namePattern, name)) {
48
+ return rule
49
+ }
50
+ }
51
+ }
52
+
53
+ function getLimiter (list, key, maxPerSecond) {
54
+ if (typeof list[key] === 'undefined') {
55
+ list[key] = new RateLimiter(maxPerSecond)
56
+ }
57
+ return list[key]
58
+ }
59
+
60
+ function sample (sampleRate) {
61
+ return Math.random() < sampleRate
62
+ }
63
+
64
+ function getService (service) {
65
+ return service || '*'
66
+ }
67
+
68
+ function getName (name) {
69
+ return name || '*'
70
+ }
71
+
72
+ function getSampleRate (sampleRate) {
73
+ return sampleRate || 1.0
74
+ }
75
+
76
+ function getMaxPerSecond (maxPerSecond) {
77
+ return maxPerSecond || Infinity
78
+ }
79
+
80
+ module.exports = SpanSampler
@@ -44,11 +44,15 @@ class DatadogTracer extends Tracer {
44
44
  const result = this.scope().activate(span, () => fn(span))
45
45
 
46
46
  if (result && typeof result.then === 'function') {
47
- result.then(
48
- () => span.finish(),
47
+ return result.then(
48
+ value => {
49
+ span.finish()
50
+ return value
51
+ },
49
52
  err => {
50
53
  addError(span, err)
51
54
  span.finish()
55
+ throw err
52
56
  }
53
57
  )
54
58
  } else {
@@ -20,8 +20,50 @@ function isError (value) {
20
20
  return false
21
21
  }
22
22
 
23
+ // Matches a glob pattern to a given subject string
24
+ function globMatch (pattern, subject) {
25
+ let px = 0 // [p]attern inde[x]
26
+ let sx = 0 // [s]ubject inde[x]
27
+ let nextPx = 0
28
+ let nextSx = 0
29
+ while (px < pattern.length || sx < subject.length) {
30
+ if (px < pattern.length) {
31
+ const c = pattern[px]
32
+ switch (c) {
33
+ default: // ordinary character
34
+ if (sx < subject.length && subject[sx] === c) {
35
+ px++
36
+ sx++
37
+ continue
38
+ }
39
+ break
40
+ case '?':
41
+ if (sx < subject.length) {
42
+ px++
43
+ sx++
44
+ continue
45
+ }
46
+ break
47
+ case '*':
48
+ nextPx = px
49
+ nextSx = sx + 1
50
+ px++
51
+ continue
52
+ }
53
+ }
54
+ if (nextSx > 0 && nextSx <= subject.length) {
55
+ px = nextPx
56
+ sx = nextSx
57
+ continue
58
+ }
59
+ return false
60
+ }
61
+ return true
62
+ }
63
+
23
64
  module.exports = {
24
65
  isTrue,
25
66
  isFalse,
26
- isError
67
+ isError,
68
+ globMatch
27
69
  }