dd-trace 5.24.0 → 5.25.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 (98) hide show
  1. package/LICENSE-3rdparty.csv +1 -0
  2. package/index.d.ts +335 -0
  3. package/package.json +13 -7
  4. package/packages/datadog-code-origin/index.js +4 -4
  5. package/packages/datadog-core/src/utils/src/parse-tags.js +33 -0
  6. package/packages/datadog-esbuild/index.js +4 -2
  7. package/packages/datadog-instrumentations/src/amqplib.js +65 -5
  8. package/packages/datadog-instrumentations/src/child_process.js +135 -27
  9. package/packages/datadog-instrumentations/src/helpers/hooks.js +3 -0
  10. package/packages/datadog-instrumentations/src/helpers/register.js +9 -0
  11. package/packages/datadog-instrumentations/src/kafkajs.js +123 -63
  12. package/packages/datadog-instrumentations/src/mocha/utils.js +2 -2
  13. package/packages/datadog-instrumentations/src/multer.js +37 -0
  14. package/packages/datadog-instrumentations/src/openai.js +2 -2
  15. package/packages/datadog-instrumentations/src/url.js +84 -0
  16. package/packages/datadog-instrumentations/src/utils/src/extract-package-and-module-path.js +7 -4
  17. package/packages/datadog-plugin-amqplib/src/consumer.js +4 -4
  18. package/packages/datadog-plugin-aws-sdk/src/services/eventbridge.js +1 -0
  19. package/packages/datadog-plugin-aws-sdk/src/services/kinesis.js +1 -0
  20. package/packages/datadog-plugin-aws-sdk/src/services/s3.js +1 -0
  21. package/packages/datadog-plugin-aws-sdk/src/services/sqs.js +1 -0
  22. package/packages/datadog-plugin-fastify/src/code_origin.js +2 -2
  23. package/packages/datadog-plugin-google-cloud-pubsub/src/consumer.js +8 -1
  24. package/packages/datadog-plugin-google-cloud-pubsub/src/producer.js +8 -0
  25. package/packages/datadog-plugin-grpc/src/client.js +3 -0
  26. package/packages/datadog-plugin-grpc/src/server.js +3 -0
  27. package/packages/datadog-plugin-kafkajs/src/batch-consumer.js +6 -3
  28. package/packages/datadog-plugin-kafkajs/src/consumer.js +8 -4
  29. package/packages/datadog-plugin-kafkajs/src/producer.js +10 -4
  30. package/packages/datadog-plugin-mocha/src/index.js +4 -1
  31. package/packages/datadog-plugin-openai/src/index.js +9 -1015
  32. package/packages/datadog-plugin-openai/src/tracing.js +1023 -0
  33. package/packages/dd-trace/src/appsec/addresses.js +2 -0
  34. package/packages/dd-trace/src/appsec/channels.js +3 -1
  35. package/packages/dd-trace/src/appsec/iast/taint-tracking/plugin.js +55 -7
  36. package/packages/dd-trace/src/appsec/iast/vulnerability-reporter.js +4 -2
  37. package/packages/dd-trace/src/appsec/index.js +3 -0
  38. package/packages/dd-trace/src/appsec/rasp/command_injection.js +49 -0
  39. package/packages/dd-trace/src/appsec/rasp/index.js +3 -0
  40. package/packages/dd-trace/src/appsec/rasp/ssrf.js +4 -3
  41. package/packages/dd-trace/src/appsec/rasp/utils.js +3 -2
  42. package/packages/dd-trace/src/appsec/recommended.json +2 -4
  43. package/packages/dd-trace/src/appsec/remote_config/capabilities.js +1 -0
  44. package/packages/dd-trace/src/appsec/remote_config/index.js +2 -0
  45. package/packages/dd-trace/src/appsec/reporter.js +5 -4
  46. package/packages/dd-trace/src/appsec/sdk/track_event.js +5 -3
  47. package/packages/dd-trace/src/appsec/waf/waf_manager.js +4 -0
  48. package/packages/dd-trace/src/azure_metadata.js +120 -0
  49. package/packages/dd-trace/src/ci-visibility/dynamic-instrumentation/index.js +97 -0
  50. package/packages/dd-trace/src/ci-visibility/dynamic-instrumentation/worker/index.js +90 -0
  51. package/packages/dd-trace/src/ci-visibility/exporters/agent-proxy/index.js +19 -1
  52. package/packages/dd-trace/src/ci-visibility/exporters/agentless/di-logs-writer.js +53 -0
  53. package/packages/dd-trace/src/ci-visibility/exporters/agentless/index.js +8 -1
  54. package/packages/dd-trace/src/ci-visibility/exporters/ci-visibility-exporter.js +43 -0
  55. package/packages/dd-trace/src/config.js +75 -6
  56. package/packages/dd-trace/src/constants.js +3 -1
  57. package/packages/dd-trace/src/datastreams/pathway.js +1 -0
  58. package/packages/dd-trace/src/debugger/devtools_client/index.js +9 -13
  59. package/packages/dd-trace/src/debugger/devtools_client/send.js +15 -1
  60. package/packages/dd-trace/src/debugger/devtools_client/snapshot/collector.js +57 -23
  61. package/packages/dd-trace/src/debugger/devtools_client/snapshot/index.js +12 -2
  62. package/packages/dd-trace/src/debugger/devtools_client/snapshot/processor.js +31 -20
  63. package/packages/dd-trace/src/debugger/devtools_client/snapshot/symbols.js +6 -0
  64. package/packages/dd-trace/src/debugger/devtools_client/state.js +11 -2
  65. package/packages/dd-trace/src/debugger/index.js +10 -3
  66. package/packages/dd-trace/src/llmobs/constants/tags.js +34 -0
  67. package/packages/dd-trace/src/llmobs/constants/text.js +6 -0
  68. package/packages/dd-trace/src/llmobs/constants/writers.js +13 -0
  69. package/packages/dd-trace/src/llmobs/index.js +103 -0
  70. package/packages/dd-trace/src/llmobs/noop.js +82 -0
  71. package/packages/dd-trace/src/llmobs/plugins/base.js +65 -0
  72. package/packages/dd-trace/src/llmobs/plugins/openai.js +205 -0
  73. package/packages/dd-trace/src/llmobs/sdk.js +377 -0
  74. package/packages/dd-trace/src/llmobs/span_processor.js +195 -0
  75. package/packages/dd-trace/src/llmobs/storage.js +7 -0
  76. package/packages/dd-trace/src/llmobs/tagger.js +322 -0
  77. package/packages/dd-trace/src/llmobs/util.js +176 -0
  78. package/packages/dd-trace/src/llmobs/writers/base.js +111 -0
  79. package/packages/dd-trace/src/llmobs/writers/evaluations.js +29 -0
  80. package/packages/dd-trace/src/llmobs/writers/spans/agentProxy.js +23 -0
  81. package/packages/dd-trace/src/llmobs/writers/spans/agentless.js +17 -0
  82. package/packages/dd-trace/src/llmobs/writers/spans/base.js +49 -0
  83. package/packages/dd-trace/src/noop/proxy.js +3 -0
  84. package/packages/dd-trace/src/noop/span.js +3 -0
  85. package/packages/dd-trace/src/opentelemetry/span.js +1 -1
  86. package/packages/dd-trace/src/opentelemetry/tracer.js +1 -0
  87. package/packages/dd-trace/src/opentracing/propagation/text_map.js +73 -12
  88. package/packages/dd-trace/src/opentracing/span.js +12 -0
  89. package/packages/dd-trace/src/opentracing/tracer.js +8 -1
  90. package/packages/dd-trace/src/payload-tagging/config/aws.json +71 -3
  91. package/packages/dd-trace/src/plugins/outbound.js +9 -0
  92. package/packages/dd-trace/src/priority_sampler.js +16 -0
  93. package/packages/dd-trace/src/profiling/config.js +3 -1
  94. package/packages/dd-trace/src/profiling/exporters/agent.js +7 -5
  95. package/packages/dd-trace/src/profiling/profilers/wall.js +2 -1
  96. package/packages/dd-trace/src/proxy.js +8 -1
  97. package/packages/dd-trace/src/span_processor.js +5 -0
  98. package/packages/dd-trace/src/telemetry/index.js +11 -1
@@ -9,17 +9,18 @@ class AmqplibConsumerPlugin extends ConsumerPlugin {
9
9
  static get id () { return 'amqplib' }
10
10
  static get operation () { return 'command' }
11
11
 
12
- start ({ method, fields, message }) {
12
+ start ({ method, fields, message, queue }) {
13
13
  if (method !== 'basic.deliver' && method !== 'basic.get') return
14
14
 
15
15
  const childOf = extract(this.tracer, message)
16
16
 
17
+ const queueName = queue || fields.queue || fields.routingKey
17
18
  const span = this.startSpan({
18
19
  childOf,
19
20
  resource: getResourceName(method, fields),
20
21
  type: 'worker',
21
22
  meta: {
22
- 'amqp.queue': fields.queue,
23
+ 'amqp.queue': queueName,
23
24
  'amqp.exchange': fields.exchange,
24
25
  'amqp.routingKey': fields.routingKey,
25
26
  'amqp.consumerTag': fields.consumerTag,
@@ -32,10 +33,9 @@ class AmqplibConsumerPlugin extends ConsumerPlugin {
32
33
  this.config.dsmEnabled && message?.properties?.headers
33
34
  ) {
34
35
  const payloadSize = getAmqpMessageSize({ headers: message.properties.headers, content: message.content })
35
- const queue = fields.queue ? fields.queue : fields.routingKey
36
36
  this.tracer.decodeDataStreamsContext(message.properties.headers)
37
37
  this.tracer
38
- .setCheckpoint(['direction:in', `topic:${queue}`, 'type:rabbitmq'], span, payloadSize)
38
+ .setCheckpoint(['direction:in', `topic:${queueName}`, 'type:rabbitmq'], span, payloadSize)
39
39
  }
40
40
  }
41
41
  }
@@ -4,6 +4,7 @@ const BaseAwsSdkPlugin = require('../base')
4
4
 
5
5
  class EventBridge extends BaseAwsSdkPlugin {
6
6
  static get id () { return 'eventbridge' }
7
+ static get isPayloadReporter () { return true }
7
8
 
8
9
  generateTags (params, operation, response) {
9
10
  if (!params || !params.source) return {}
@@ -10,6 +10,7 @@ const { storage } = require('../../../datadog-core')
10
10
  class Kinesis extends BaseAwsSdkPlugin {
11
11
  static get id () { return 'kinesis' }
12
12
  static get peerServicePrecursors () { return ['streamname'] }
13
+ static get isPayloadReporter () { return true }
13
14
 
14
15
  constructor (...args) {
15
16
  super(...args)
@@ -5,6 +5,7 @@ const BaseAwsSdkPlugin = require('../base')
5
5
  class S3 extends BaseAwsSdkPlugin {
6
6
  static get id () { return 's3' }
7
7
  static get peerServicePrecursors () { return ['bucketname'] }
8
+ static get isPayloadReporter () { return true }
8
9
 
9
10
  generateTags (params, operation, response) {
10
11
  const tags = {}
@@ -9,6 +9,7 @@ const { DsmPathwayCodec } = require('../../../dd-trace/src/datastreams/pathway')
9
9
  class Sqs extends BaseAwsSdkPlugin {
10
10
  static get id () { return 'sqs' }
11
11
  static get peerServicePrecursors () { return ['queuename'] }
12
+ static get isPayloadReporter () { return true }
12
13
 
13
14
  constructor (...args) {
14
15
  super(...args)
@@ -1,6 +1,6 @@
1
1
  'use strict'
2
2
 
3
- const { entryTag } = require('../../datadog-code-origin')
3
+ const { entryTags } = require('../../datadog-code-origin')
4
4
  const Plugin = require('../../dd-trace/src/plugins/plugin')
5
5
  const web = require('../../dd-trace/src/plugins/util/web')
6
6
 
@@ -23,7 +23,7 @@ class FastifyCodeOriginForSpansPlugin extends Plugin {
23
23
 
24
24
  this.addSub('apm:fastify:route:added', ({ routeOptions, onRoute }) => {
25
25
  if (!routeOptions.config) routeOptions.config = {}
26
- routeOptions.config[kCodeOriginForSpansTagsSym] = entryTag(onRoute)
26
+ routeOptions.config[kCodeOriginForSpansTagsSym] = entryTags(onRoute)
27
27
  })
28
28
  }
29
29
  }
@@ -1,5 +1,6 @@
1
1
  'use strict'
2
2
 
3
+ const { getMessageSize } = require('../../dd-trace/src/datastreams/processor')
3
4
  const ConsumerPlugin = require('../../dd-trace/src/plugins/consumer')
4
5
 
5
6
  class GoogleCloudPubsubConsumerPlugin extends ConsumerPlugin {
@@ -11,7 +12,7 @@ class GoogleCloudPubsubConsumerPlugin extends ConsumerPlugin {
11
12
  const topic = subscription.metadata && subscription.metadata.topic
12
13
  const childOf = this.tracer.extract('text_map', message.attributes) || null
13
14
 
14
- this.startSpan({
15
+ const span = this.startSpan({
15
16
  childOf,
16
17
  resource: topic,
17
18
  type: 'worker',
@@ -23,6 +24,12 @@ class GoogleCloudPubsubConsumerPlugin extends ConsumerPlugin {
23
24
  'pubsub.ack': 0
24
25
  }
25
26
  })
27
+ if (this.config.dsmEnabled && message?.attributes) {
28
+ const payloadSize = getMessageSize(message)
29
+ this.tracer.decodeDataStreamsContext(message.attributes)
30
+ this.tracer
31
+ .setCheckpoint(['direction:in', `topic:${topic}`, 'type:google-pubsub'], span, payloadSize)
32
+ }
26
33
  }
27
34
 
28
35
  finish (message) {
@@ -1,6 +1,8 @@
1
1
  'use strict'
2
2
 
3
3
  const ProducerPlugin = require('../../dd-trace/src/plugins/producer')
4
+ const { DsmPathwayCodec } = require('../../dd-trace/src/datastreams/pathway')
5
+ const { getHeadersSize } = require('../../dd-trace/src/datastreams/processor')
4
6
 
5
7
  class GoogleCloudPubsubProducerPlugin extends ProducerPlugin {
6
8
  static get id () { return 'google-cloud-pubsub' }
@@ -25,6 +27,12 @@ class GoogleCloudPubsubProducerPlugin extends ProducerPlugin {
25
27
  msg.attributes = {}
26
28
  }
27
29
  this.tracer.inject(span, 'text_map', msg.attributes)
30
+ if (this.config.dsmEnabled) {
31
+ const payloadSize = getHeadersSize(msg)
32
+ const dataStreamsContext = this.tracer
33
+ .setCheckpoint(['direction:out', `topic:${topic}`, 'type:google-pubsub'], span, payloadSize)
34
+ DsmPathwayCodec.encode(dataStreamsContext, msg.attributes)
35
+ }
28
36
  }
29
37
  }
30
38
  }
@@ -64,6 +64,9 @@ class GrpcClientPlugin extends ClientPlugin {
64
64
 
65
65
  error ({ span, error }) {
66
66
  this.addCode(span, error.code)
67
+ if (error.code && !this._tracerConfig.grpc.client.error.statuses.includes(error.code)) {
68
+ return
69
+ }
67
70
  this.addError(error, span)
68
71
  }
69
72
 
@@ -70,6 +70,9 @@ class GrpcServerPlugin extends ServerPlugin {
70
70
  if (!span) return
71
71
 
72
72
  this.addCode(span, error.code)
73
+ if (error.code && !this._tracerConfig.grpc.server.error.statuses.includes(error.code)) {
74
+ return
75
+ }
73
76
  this.addError(error)
74
77
  }
75
78
 
@@ -5,14 +5,17 @@ class KafkajsBatchConsumerPlugin extends ConsumerPlugin {
5
5
  static get id () { return 'kafkajs' }
6
6
  static get operation () { return 'consume-batch' }
7
7
 
8
- start ({ topic, partition, messages, groupId }) {
8
+ start ({ topic, partition, messages, groupId, clusterId }) {
9
9
  if (!this.config.dsmEnabled) return
10
10
  for (const message of messages) {
11
11
  if (!message || !message.headers) continue
12
12
  const payloadSize = getMessageSize(message)
13
13
  this.tracer.decodeDataStreamsContext(message.headers)
14
- this.tracer
15
- .setCheckpoint(['direction:in', `group:${groupId}`, `topic:${topic}`, 'type:kafka'], null, payloadSize)
14
+ const edgeTags = ['direction:in', `group:${groupId}`, `topic:${topic}`, 'type:kafka']
15
+ if (clusterId) {
16
+ edgeTags.push(`kafka_cluster_id:${clusterId}`)
17
+ }
18
+ this.tracer.setCheckpoint(edgeTags, null, payloadSize)
16
19
  }
17
20
  }
18
21
  }
@@ -62,7 +62,7 @@ class KafkajsConsumerPlugin extends ConsumerPlugin {
62
62
  }
63
63
  }
64
64
 
65
- start ({ topic, partition, message, groupId }) {
65
+ start ({ topic, partition, message, groupId, clusterId }) {
66
66
  const childOf = extract(this.tracer, message.headers)
67
67
  const span = this.startSpan({
68
68
  childOf,
@@ -71,7 +71,8 @@ class KafkajsConsumerPlugin extends ConsumerPlugin {
71
71
  meta: {
72
72
  component: 'kafkajs',
73
73
  'kafka.topic': topic,
74
- 'kafka.message.offset': message.offset
74
+ 'kafka.message.offset': message.offset,
75
+ 'kafka.cluster_id': clusterId
75
76
  },
76
77
  metrics: {
77
78
  'kafka.partition': partition
@@ -80,8 +81,11 @@ class KafkajsConsumerPlugin extends ConsumerPlugin {
80
81
  if (this.config.dsmEnabled && message?.headers) {
81
82
  const payloadSize = getMessageSize(message)
82
83
  this.tracer.decodeDataStreamsContext(message.headers)
83
- this.tracer
84
- .setCheckpoint(['direction:in', `group:${groupId}`, `topic:${topic}`, 'type:kafka'], span, payloadSize)
84
+ const edgeTags = ['direction:in', `group:${groupId}`, `topic:${topic}`, 'type:kafka']
85
+ if (clusterId) {
86
+ edgeTags.push(`kafka_cluster_id:${clusterId}`)
87
+ }
88
+ this.tracer.setCheckpoint(edgeTags, span, payloadSize)
85
89
  }
86
90
 
87
91
  if (afterStartCh.hasSubscribers) {
@@ -66,12 +66,13 @@ class KafkajsProducerPlugin extends ProducerPlugin {
66
66
  }
67
67
  }
68
68
 
69
- start ({ topic, messages, bootstrapServers }) {
69
+ start ({ topic, messages, bootstrapServers, clusterId }) {
70
70
  const span = this.startSpan({
71
71
  resource: topic,
72
72
  meta: {
73
73
  component: 'kafkajs',
74
- 'kafka.topic': topic
74
+ 'kafka.topic': topic,
75
+ 'kafka.cluster_id': clusterId
75
76
  },
76
77
  metrics: {
77
78
  'kafka.batch_size': messages.length
@@ -85,8 +86,13 @@ class KafkajsProducerPlugin extends ProducerPlugin {
85
86
  this.tracer.inject(span, 'text_map', message.headers)
86
87
  if (this.config.dsmEnabled) {
87
88
  const payloadSize = getMessageSize(message)
88
- const dataStreamsContext = this.tracer
89
- .setCheckpoint(['direction:out', `topic:${topic}`, 'type:kafka'], span, payloadSize)
89
+ const edgeTags = ['direction:out', `topic:${topic}`, 'type:kafka']
90
+
91
+ if (clusterId) {
92
+ edgeTags.push(`kafka_cluster_id:${clusterId}`)
93
+ }
94
+
95
+ const dataStreamsContext = this.tracer.setCheckpoint(edgeTags, span, payloadSize)
90
96
  DsmPathwayCodec.encode(dataStreamsContext, message.headers)
91
97
  }
92
98
  }
@@ -242,7 +242,7 @@ class MochaPlugin extends CiPlugin {
242
242
  }
243
243
  })
244
244
 
245
- this.addSub('ci:mocha:test:retry', (isFirstAttempt) => {
245
+ this.addSub('ci:mocha:test:retry', ({ isFirstAttempt, err }) => {
246
246
  const store = storage.getStore()
247
247
  const span = store?.span
248
248
  if (span) {
@@ -250,6 +250,9 @@ class MochaPlugin extends CiPlugin {
250
250
  if (!isFirstAttempt) {
251
251
  span.setTag(TEST_IS_RETRY, 'true')
252
252
  }
253
+ if (err) {
254
+ span.setTag('error', err)
255
+ }
253
256
 
254
257
  const spanTags = span.context()._tags
255
258
  this.telemetry.ciVisEvent(