dd-trace 5.61.1 → 5.63.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 (215) hide show
  1. package/README.md +0 -5
  2. package/package.json +2 -2
  3. package/packages/datadog-instrumentations/src/ai.js +140 -0
  4. package/packages/datadog-instrumentations/src/apollo-server.js +50 -8
  5. package/packages/datadog-instrumentations/src/aws-sdk.js +49 -60
  6. package/packages/datadog-instrumentations/src/couchbase.js +102 -65
  7. package/packages/datadog-instrumentations/src/fastify.js +61 -55
  8. package/packages/datadog-instrumentations/src/graphql.js +90 -122
  9. package/packages/datadog-instrumentations/src/helpers/hooks.js +1 -0
  10. package/packages/datadog-instrumentations/src/helpers/register.js +2 -22
  11. package/packages/datadog-instrumentations/src/hono.js +11 -8
  12. package/packages/datadog-instrumentations/src/http2/server.js +14 -20
  13. package/packages/datadog-instrumentations/src/knex.js +15 -17
  14. package/packages/datadog-instrumentations/src/microgateway-core.js +16 -15
  15. package/packages/datadog-instrumentations/src/mongodb-core.js +35 -32
  16. package/packages/datadog-instrumentations/src/mongodb.js +9 -13
  17. package/packages/datadog-instrumentations/src/mongoose.js +25 -29
  18. package/packages/datadog-instrumentations/src/next.js +4 -8
  19. package/packages/datadog-instrumentations/src/openai.js +0 -2
  20. package/packages/datadog-instrumentations/src/oracledb.js +39 -33
  21. package/packages/datadog-instrumentations/src/pg.js +38 -48
  22. package/packages/datadog-plugin-aerospike/src/index.js +11 -11
  23. package/packages/datadog-plugin-ai/src/index.js +17 -0
  24. package/packages/datadog-plugin-ai/src/tracing.js +33 -0
  25. package/packages/datadog-plugin-ai/src/utils.js +28 -0
  26. package/packages/datadog-plugin-amqp10/src/consumer.js +2 -2
  27. package/packages/datadog-plugin-amqp10/src/index.js +1 -1
  28. package/packages/datadog-plugin-amqp10/src/producer.js +3 -3
  29. package/packages/datadog-plugin-amqplib/src/client.js +3 -3
  30. package/packages/datadog-plugin-amqplib/src/consumer.js +2 -2
  31. package/packages/datadog-plugin-amqplib/src/index.js +1 -1
  32. package/packages/datadog-plugin-amqplib/src/producer.js +2 -2
  33. package/packages/datadog-plugin-apollo/src/gateway/execute.js +2 -4
  34. package/packages/datadog-plugin-apollo/src/gateway/fetch.js +2 -4
  35. package/packages/datadog-plugin-apollo/src/gateway/index.js +1 -1
  36. package/packages/datadog-plugin-apollo/src/gateway/plan.js +2 -4
  37. package/packages/datadog-plugin-apollo/src/gateway/postprocessing.js +2 -4
  38. package/packages/datadog-plugin-apollo/src/gateway/request.js +2 -4
  39. package/packages/datadog-plugin-apollo/src/gateway/validate.js +2 -4
  40. package/packages/datadog-plugin-apollo/src/index.js +1 -1
  41. package/packages/datadog-plugin-avsc/src/index.js +2 -2
  42. package/packages/datadog-plugin-aws-sdk/src/base.js +70 -46
  43. package/packages/datadog-plugin-aws-sdk/src/index.js +1 -3
  44. package/packages/datadog-plugin-aws-sdk/src/services/bedrockruntime/index.js +1 -3
  45. package/packages/datadog-plugin-aws-sdk/src/services/bedrockruntime/tracing.js +1 -1
  46. package/packages/datadog-plugin-aws-sdk/src/services/cloudwatchlogs.js +1 -1
  47. package/packages/datadog-plugin-aws-sdk/src/services/dynamodb.js +3 -3
  48. package/packages/datadog-plugin-aws-sdk/src/services/eventbridge.js +2 -2
  49. package/packages/datadog-plugin-aws-sdk/src/services/kinesis.js +22 -20
  50. package/packages/datadog-plugin-aws-sdk/src/services/lambda.js +1 -1
  51. package/packages/datadog-plugin-aws-sdk/src/services/redshift.js +1 -1
  52. package/packages/datadog-plugin-aws-sdk/src/services/s3.js +3 -3
  53. package/packages/datadog-plugin-aws-sdk/src/services/sfn.js +1 -1
  54. package/packages/datadog-plugin-aws-sdk/src/services/sns.js +3 -3
  55. package/packages/datadog-plugin-aws-sdk/src/services/sqs.js +17 -15
  56. package/packages/datadog-plugin-aws-sdk/src/services/states.js +1 -1
  57. package/packages/datadog-plugin-aws-sdk/src/services/stepfunctions.js +1 -1
  58. package/packages/datadog-plugin-azure-functions/src/index.js +5 -5
  59. package/packages/datadog-plugin-azure-service-bus/src/index.js +1 -1
  60. package/packages/datadog-plugin-azure-service-bus/src/producer.js +2 -2
  61. package/packages/datadog-plugin-bunyan/src/index.js +3 -5
  62. package/packages/datadog-plugin-cassandra-driver/src/index.js +3 -3
  63. package/packages/datadog-plugin-child_process/src/index.js +2 -2
  64. package/packages/datadog-plugin-confluentinc-kafka-javascript/src/batch-consumer.js +1 -3
  65. package/packages/datadog-plugin-confluentinc-kafka-javascript/src/consumer.js +1 -3
  66. package/packages/datadog-plugin-confluentinc-kafka-javascript/src/index.js +1 -1
  67. package/packages/datadog-plugin-confluentinc-kafka-javascript/src/producer.js +1 -3
  68. package/packages/datadog-plugin-connect/src/index.js +1 -3
  69. package/packages/datadog-plugin-couchbase/src/index.js +39 -19
  70. package/packages/datadog-plugin-cucumber/src/index.js +1 -3
  71. package/packages/datadog-plugin-cypress/src/index.js +1 -3
  72. package/packages/datadog-plugin-dd-trace-api/src/index.js +1 -3
  73. package/packages/datadog-plugin-dns/src/index.js +1 -1
  74. package/packages/datadog-plugin-dns/src/lookup.js +2 -2
  75. package/packages/datadog-plugin-dns/src/lookup_service.js +2 -2
  76. package/packages/datadog-plugin-dns/src/resolve.js +2 -2
  77. package/packages/datadog-plugin-dns/src/reverse.js +2 -2
  78. package/packages/datadog-plugin-elasticsearch/src/index.js +1 -1
  79. package/packages/datadog-plugin-express/src/code_origin.js +1 -3
  80. package/packages/datadog-plugin-express/src/index.js +1 -1
  81. package/packages/datadog-plugin-express/src/tracing.js +1 -3
  82. package/packages/datadog-plugin-fastify/src/code_origin.js +1 -3
  83. package/packages/datadog-plugin-fastify/src/index.js +1 -1
  84. package/packages/datadog-plugin-fastify/src/tracing.js +18 -3
  85. package/packages/datadog-plugin-fetch/src/index.js +2 -2
  86. package/packages/datadog-plugin-find-my-way/src/index.js +1 -3
  87. package/packages/datadog-plugin-fs/src/index.js +2 -2
  88. package/packages/datadog-plugin-google-cloud-pubsub/src/client.js +3 -3
  89. package/packages/datadog-plugin-google-cloud-pubsub/src/consumer.js +2 -2
  90. package/packages/datadog-plugin-google-cloud-pubsub/src/index.js +1 -1
  91. package/packages/datadog-plugin-google-cloud-pubsub/src/producer.js +2 -2
  92. package/packages/datadog-plugin-google-cloud-vertexai/src/index.js +1 -1
  93. package/packages/datadog-plugin-google-cloud-vertexai/src/tracing.js +2 -4
  94. package/packages/datadog-plugin-graphql/src/execute.js +16 -9
  95. package/packages/datadog-plugin-graphql/src/index.js +1 -1
  96. package/packages/datadog-plugin-graphql/src/parse.js +12 -7
  97. package/packages/datadog-plugin-graphql/src/resolve.js +50 -16
  98. package/packages/datadog-plugin-graphql/src/validate.js +13 -7
  99. package/packages/datadog-plugin-grpc/src/client.js +4 -4
  100. package/packages/datadog-plugin-grpc/src/index.js +1 -1
  101. package/packages/datadog-plugin-grpc/src/server.js +3 -3
  102. package/packages/datadog-plugin-hapi/src/index.js +1 -3
  103. package/packages/datadog-plugin-hono/src/index.js +1 -3
  104. package/packages/datadog-plugin-http/src/client.js +2 -2
  105. package/packages/datadog-plugin-http/src/index.js +1 -1
  106. package/packages/datadog-plugin-http/src/server.js +3 -7
  107. package/packages/datadog-plugin-http2/src/client.js +2 -2
  108. package/packages/datadog-plugin-http2/src/index.js +1 -1
  109. package/packages/datadog-plugin-http2/src/server.js +22 -11
  110. package/packages/datadog-plugin-ioredis/src/index.js +1 -3
  111. package/packages/datadog-plugin-iovalkey/src/index.js +2 -4
  112. package/packages/datadog-plugin-jest/src/index.js +1 -3
  113. package/packages/datadog-plugin-kafkajs/src/batch-consumer.js +2 -2
  114. package/packages/datadog-plugin-kafkajs/src/consumer.js +2 -2
  115. package/packages/datadog-plugin-kafkajs/src/index.js +1 -1
  116. package/packages/datadog-plugin-kafkajs/src/producer.js +3 -3
  117. package/packages/datadog-plugin-koa/src/index.js +1 -3
  118. package/packages/datadog-plugin-langchain/src/index.js +2 -2
  119. package/packages/datadog-plugin-langchain/src/tracing.js +30 -48
  120. package/packages/datadog-plugin-mariadb/src/index.js +2 -2
  121. package/packages/datadog-plugin-memcached/src/index.js +1 -1
  122. package/packages/datadog-plugin-microgateway-core/src/index.js +4 -4
  123. package/packages/datadog-plugin-mocha/src/index.js +1 -3
  124. package/packages/datadog-plugin-moleculer/src/client.js +2 -2
  125. package/packages/datadog-plugin-moleculer/src/index.js +1 -1
  126. package/packages/datadog-plugin-moleculer/src/server.js +2 -2
  127. package/packages/datadog-plugin-mongodb-core/src/index.js +9 -5
  128. package/packages/datadog-plugin-mongoose/src/index.js +20 -0
  129. package/packages/datadog-plugin-mysql/src/index.js +2 -2
  130. package/packages/datadog-plugin-mysql2/src/index.js +1 -1
  131. package/packages/datadog-plugin-net/src/index.js +1 -1
  132. package/packages/datadog-plugin-net/src/ipc.js +2 -2
  133. package/packages/datadog-plugin-net/src/tcp.js +2 -2
  134. package/packages/datadog-plugin-next/src/index.js +1 -3
  135. package/packages/datadog-plugin-nyc/src/index.js +1 -3
  136. package/packages/datadog-plugin-openai/src/index.js +1 -1
  137. package/packages/datadog-plugin-openai/src/tracing.js +7 -411
  138. package/packages/datadog-plugin-opensearch/src/index.js +1 -3
  139. package/packages/datadog-plugin-oracledb/src/index.js +9 -5
  140. package/packages/datadog-plugin-pg/src/index.js +8 -5
  141. package/packages/datadog-plugin-pino/src/index.js +3 -5
  142. package/packages/datadog-plugin-playwright/src/index.js +1 -3
  143. package/packages/datadog-plugin-prisma/src/client.js +4 -6
  144. package/packages/datadog-plugin-prisma/src/engine.js +3 -3
  145. package/packages/datadog-plugin-prisma/src/index.js +1 -1
  146. package/packages/datadog-plugin-protobufjs/src/index.js +2 -6
  147. package/packages/datadog-plugin-redis/src/index.js +2 -2
  148. package/packages/datadog-plugin-restify/src/index.js +1 -3
  149. package/packages/datadog-plugin-rhea/src/consumer.js +1 -1
  150. package/packages/datadog-plugin-rhea/src/index.js +1 -1
  151. package/packages/datadog-plugin-rhea/src/producer.js +2 -2
  152. package/packages/datadog-plugin-router/src/index.js +1 -3
  153. package/packages/datadog-plugin-selenium/src/index.js +1 -3
  154. package/packages/datadog-plugin-sharedb/src/index.js +1 -1
  155. package/packages/datadog-plugin-tedious/src/index.js +3 -3
  156. package/packages/datadog-plugin-undici/src/index.js +2 -4
  157. package/packages/datadog-plugin-vitest/src/index.js +1 -3
  158. package/packages/datadog-plugin-web/src/index.js +1 -3
  159. package/packages/datadog-plugin-winston/src/index.js +3 -5
  160. package/packages/dd-trace/src/appsec/channels.js +1 -0
  161. package/packages/dd-trace/src/appsec/graphql.js +14 -12
  162. package/packages/dd-trace/src/appsec/iast/analyzers/sql-injection-analyzer.js +14 -7
  163. package/packages/dd-trace/src/appsec/iast/taint-tracking/plugin.js +4 -4
  164. package/packages/dd-trace/src/appsec/recommended.json +271 -2
  165. package/packages/dd-trace/src/appsec/waf/waf_manager.js +1 -1
  166. package/packages/dd-trace/src/ci-visibility/log-submission/log-submission-plugin.js +1 -3
  167. package/packages/dd-trace/src/ci-visibility/test-api-manual/test-api-manual-plugin.js +1 -3
  168. package/packages/dd-trace/src/config.js +1 -1
  169. package/packages/dd-trace/src/datastreams/checkpointer.js +23 -2
  170. package/packages/dd-trace/src/datastreams/processor.js +4 -3
  171. package/packages/dd-trace/src/guardrails/telemetry.js +18 -2
  172. package/packages/dd-trace/src/llmobs/plugins/ai/index.js +351 -0
  173. package/packages/dd-trace/src/llmobs/plugins/ai/util.js +179 -0
  174. package/packages/dd-trace/src/llmobs/plugins/langchain/index.js +30 -50
  175. package/packages/dd-trace/src/llmobs/plugins/openai.js +3 -5
  176. package/packages/dd-trace/src/llmobs/plugins/vertexai.js +3 -5
  177. package/packages/dd-trace/src/llmobs/writers/base.js +3 -2
  178. package/packages/dd-trace/src/opentracing/propagation/text_map.js +25 -2
  179. package/packages/dd-trace/src/opentracing/span_context.js +4 -0
  180. package/packages/dd-trace/src/plugin_manager.js +8 -4
  181. package/packages/dd-trace/src/plugins/apollo.js +3 -3
  182. package/packages/dd-trace/src/plugins/cache.js +1 -1
  183. package/packages/dd-trace/src/plugins/client.js +3 -3
  184. package/packages/dd-trace/src/plugins/consumer.js +3 -3
  185. package/packages/dd-trace/src/plugins/database.js +2 -2
  186. package/packages/dd-trace/src/plugins/index.js +2 -0
  187. package/packages/dd-trace/src/plugins/log_plugin.js +1 -5
  188. package/packages/dd-trace/src/plugins/outbound.js +1 -1
  189. package/packages/dd-trace/src/plugins/plugin.js +1 -1
  190. package/packages/dd-trace/src/plugins/producer.js +3 -3
  191. package/packages/dd-trace/src/plugins/server.js +3 -3
  192. package/packages/dd-trace/src/plugins/storage.js +1 -1
  193. package/packages/dd-trace/src/plugins/tracing.js +24 -6
  194. package/packages/dd-trace/src/plugins/util/ci.js +11 -7
  195. package/packages/dd-trace/src/plugins/util/inferred_proxy.js +15 -19
  196. package/packages/dd-trace/src/plugins/util/ip_extractor.js +44 -3
  197. package/packages/dd-trace/src/plugins/util/tags.js +2 -0
  198. package/packages/dd-trace/src/plugins/util/web.js +26 -7
  199. package/packages/dd-trace/src/profiling/config.js +2 -0
  200. package/packages/dd-trace/src/profiling/exporters/event_serializer.js +2 -21
  201. package/packages/dd-trace/src/profiling/libuv-size.js +49 -0
  202. package/packages/dd-trace/src/profiling/profilers/event_plugins/dns.js +2 -6
  203. package/packages/dd-trace/src/profiling/profilers/event_plugins/dns_lookup.js +1 -3
  204. package/packages/dd-trace/src/profiling/profilers/event_plugins/dns_lookupservice.js +1 -3
  205. package/packages/dd-trace/src/profiling/profilers/event_plugins/dns_resolve.js +1 -3
  206. package/packages/dd-trace/src/profiling/profilers/event_plugins/dns_reverse.js +1 -3
  207. package/packages/dd-trace/src/profiling/profilers/event_plugins/event.js +24 -23
  208. package/packages/dd-trace/src/profiling/profilers/event_plugins/fs.js +3 -9
  209. package/packages/dd-trace/src/profiling/profilers/event_plugins/net.js +3 -9
  210. package/packages/dd-trace/src/profiling/profilers/events.js +83 -64
  211. package/packages/dd-trace/src/profiling/profilers/poisson.js +105 -0
  212. package/packages/dd-trace/src/profiling/profilers/wall.js +3 -3
  213. package/packages/dd-trace/src/remote_config/manager.js +1 -1
  214. package/packages/dd-trace/src/supported-configurations.json +2 -0
  215. package/packages/dd-trace/src/tracer_metadata.js +1 -1
@@ -6,12 +6,14 @@ const { extractErrorIntoSpanEvent } = require('./utils')
6
6
  let tools
7
7
 
8
8
  class GraphQLExecutePlugin extends TracingPlugin {
9
- static get id () { return 'graphql' }
10
- static get operation () { return 'execute' }
11
- static get type () { return 'graphql' }
12
- static get kind () { return 'server' }
9
+ static id = 'graphql'
10
+ static operation = 'execute'
11
+ static type = 'graphql'
12
+ static kind = 'server'
13
+
14
+ bindStart (ctx) {
15
+ const { operation, args, docSource } = ctx
13
16
 
14
- start ({ operation, args, docSource }) {
15
17
  const type = operation && operation.operation
16
18
  const name = operation && operation.name && operation.name.value
17
19
  const document = args.document
@@ -27,20 +29,25 @@ class GraphQLExecutePlugin extends TracingPlugin {
27
29
  'graphql.operation.name': name,
28
30
  'graphql.source': source
29
31
  }
30
- })
32
+ }, ctx)
31
33
 
32
34
  addVariableTags(this.config, span, args.variableValues)
35
+
36
+ return ctx.currentStore
33
37
  }
34
38
 
35
- finish ({ res, args }) {
36
- const span = this.activeSpan
39
+ finish (ctx) {
40
+ const { res, args } = ctx
41
+ const span = ctx?.currentStore?.span || this.activeSpan
37
42
  this.config.hooks.execute(span, args, res)
38
43
  if (res?.errors) {
39
44
  for (const err of res.errors) {
40
45
  extractErrorIntoSpanEvent(this._tracerConfig, span, err)
41
46
  }
42
47
  }
43
- super.finish()
48
+ super.finish(ctx)
49
+
50
+ return ctx.parentStore
44
51
  }
45
52
  }
46
53
 
@@ -9,7 +9,7 @@ const GraphQLValidatePlugin = require('./validate')
9
9
  const GraphQLResolvePlugin = require('./resolve')
10
10
 
11
11
  class GraphQLPlugin extends CompositePlugin {
12
- static get id () { return 'graphql' }
12
+ static id = 'graphql'
13
13
  static get plugins () {
14
14
  return {
15
15
  execute: GraphQLExecutePlugin,
@@ -3,19 +3,22 @@
3
3
  const TracingPlugin = require('../../dd-trace/src/plugins/tracing')
4
4
 
5
5
  class GraphQLParsePlugin extends TracingPlugin {
6
- static get id () { return 'graphql' }
7
- static get operation () { return 'parser' }
6
+ static id = 'graphql'
7
+ static operation = 'parser'
8
8
 
9
- start () {
9
+ bindStart (ctx) {
10
10
  this.startSpan('graphql.parse', {
11
11
  service: this.config.service,
12
12
  type: 'graphql',
13
13
  meta: {}
14
- })
14
+ }, ctx)
15
+
16
+ return ctx.currentStore
15
17
  }
16
18
 
17
- finish ({ source, document, docSource }) {
18
- const span = this.activeSpan
19
+ finish (ctx) {
20
+ const { source, document, docSource } = ctx
21
+ const span = ctx?.currentStore?.span || this.activeSpan
19
22
 
20
23
  if (this.config.source && document) {
21
24
  span.setTag('graphql.source', docSource)
@@ -23,7 +26,9 @@ class GraphQLParsePlugin extends TracingPlugin {
23
26
 
24
27
  this.config.hooks.parse(span, source, document)
25
28
 
26
- super.finish()
29
+ super.finish(ctx)
30
+
31
+ return ctx.parentStore
27
32
  }
28
33
  }
29
34
 
@@ -6,28 +6,37 @@ const dc = require('dc-polyfill')
6
6
  const collapsedPathSym = Symbol('collapsedPaths')
7
7
 
8
8
  class GraphQLResolvePlugin extends TracingPlugin {
9
- static get id () { return 'graphql' }
10
- static get operation () { return 'resolve' }
9
+ static id = 'graphql'
10
+ static operation = 'resolve'
11
+
12
+ start (fieldCtx) {
13
+ const { info, rootCtx, args } = fieldCtx
11
14
 
12
- start ({ info, context, args }) {
13
15
  const path = getPath(info, this.config)
14
16
 
17
+ // we need to get the parent span to the field if it exists for correct span parenting
18
+ // of nested fields
19
+ const parentField = getParentField(rootCtx, pathToArray(info && info.path))
20
+ const childOf = parentField?.ctx?.currentStore?.span
21
+
22
+ fieldCtx.parent = parentField
23
+
15
24
  if (!shouldInstrument(this.config, path)) return
16
25
  const computedPathString = path.join('.')
17
26
 
18
27
  if (this.config.collapse) {
19
- if (context.fields[computedPathString]) return
28
+ if (rootCtx.fields[computedPathString]) return
20
29
 
21
- if (!context[collapsedPathSym]) {
22
- context[collapsedPathSym] = {}
23
- } else if (context[collapsedPathSym][computedPathString]) {
30
+ if (!rootCtx[collapsedPathSym]) {
31
+ rootCtx[collapsedPathSym] = {}
32
+ } else if (rootCtx[collapsedPathSym][computedPathString]) {
24
33
  return
25
34
  }
26
35
 
27
- context[collapsedPathSym][computedPathString] = true
36
+ rootCtx[collapsedPathSym][computedPathString] = true
28
37
  }
29
38
 
30
- const document = context.source
39
+ const document = rootCtx.source
31
40
  const fieldNode = info.fieldNodes.find(fieldNode => fieldNode.kind === 'Field')
32
41
  const loc = this.config.source && document && fieldNode && fieldNode.loc
33
42
  const source = loc && document.slice(loc.start, loc.end)
@@ -35,6 +44,7 @@ class GraphQLResolvePlugin extends TracingPlugin {
35
44
  const span = this.startSpan('graphql.resolve', {
36
45
  service: this.config.service,
37
46
  resource: `${info.fieldName}:${info.returnType}`,
47
+ childOf,
38
48
  type: 'graphql',
39
49
  meta: {
40
50
  'graphql.field.name': info.fieldName,
@@ -42,7 +52,7 @@ class GraphQLResolvePlugin extends TracingPlugin {
42
52
  'graphql.field.type': info.returnType.name,
43
53
  'graphql.source': source
44
54
  }
45
- })
55
+ }, fieldCtx)
46
56
 
47
57
  if (fieldNode && this.config.variables && fieldNode.arguments) {
48
58
  const variables = this.config.variables(info.variableValues)
@@ -56,21 +66,25 @@ class GraphQLResolvePlugin extends TracingPlugin {
56
66
  }
57
67
 
58
68
  if (this.resolverStartCh.hasSubscribers) {
59
- this.resolverStartCh.publish({ context, resolverInfo: getResolverInfo(info, args) })
69
+ this.resolverStartCh.publish({ ctx: rootCtx, resolverInfo: getResolverInfo(info, args) })
60
70
  }
71
+
72
+ return fieldCtx.currentStore
61
73
  }
62
74
 
63
75
  constructor (...args) {
64
76
  super(...args)
65
77
 
66
- this.addTraceSub('updateField', ({ field, info, err }) => {
78
+ this.addTraceSub('updateField', (ctx) => {
79
+ const { field, info, error } = ctx
80
+
67
81
  const path = getPath(info, this.config)
68
82
 
69
83
  if (!shouldInstrument(this.config, path)) return
70
84
 
71
- const span = this.activeSpan
85
+ const span = ctx?.currentStore?.span || this.activeSpan
72
86
  field.finishTime = span._getTime ? span._getTime() : 0
73
- field.error = field.error || err
87
+ field.error = field.error || error
74
88
  })
75
89
 
76
90
  this.resolverStartCh = dc.channel('datadog:graphql:resolver:start')
@@ -81,8 +95,13 @@ class GraphQLResolvePlugin extends TracingPlugin {
81
95
  super.configure(config.depth === 0 ? false : config)
82
96
  }
83
97
 
84
- finish (finishTime) {
85
- this.activeSpan.finish(finishTime)
98
+ finish (ctx) {
99
+ const { finishTime } = ctx
100
+
101
+ const span = ctx?.currentStore?.span || this.activeSpan
102
+ span.finish(finishTime)
103
+
104
+ return ctx.parentStore
86
105
  }
87
106
  }
88
107
 
@@ -154,4 +173,19 @@ function getResolverInfo (info, args) {
154
173
  return resolverInfo
155
174
  }
156
175
 
176
+ function getParentField (parentCtx, path) {
177
+ for (let i = path.length - 1; i > 0; i--) {
178
+ const field = getField(parentCtx, path.slice(0, i))
179
+ if (field) {
180
+ return field
181
+ }
182
+ }
183
+
184
+ return null
185
+ }
186
+
187
+ function getField (parentCtx, path) {
188
+ return parentCtx.fields[path.join('.')]
189
+ }
190
+
157
191
  module.exports = GraphQLResolvePlugin
@@ -4,10 +4,11 @@ const TracingPlugin = require('../../dd-trace/src/plugins/tracing')
4
4
  const { extractErrorIntoSpanEvent } = require('./utils')
5
5
 
6
6
  class GraphQLValidatePlugin extends TracingPlugin {
7
- static get id () { return 'graphql' }
8
- static get operation () { return 'validate' }
7
+ static id = 'graphql'
8
+ static operation = 'validate'
9
9
 
10
- start ({ docSource, document }) {
10
+ bindStart (ctx) {
11
+ const { docSource, document } = ctx
11
12
  const source = this.config.source && document && docSource
12
13
 
13
14
  this.startSpan('graphql.validate', {
@@ -16,18 +17,23 @@ class GraphQLValidatePlugin extends TracingPlugin {
16
17
  meta: {
17
18
  'graphql.source': source
18
19
  }
19
- })
20
+ }, ctx)
21
+
22
+ return ctx.currentStore
20
23
  }
21
24
 
22
- finish ({ document, errors }) {
23
- const span = this.activeSpan
25
+ finish (ctx) {
26
+ const { document, errors } = ctx
27
+ const span = ctx?.currentStore?.span || this.activeSpan
24
28
  this.config.hooks.validate(span, document, errors)
25
29
  if (errors) {
26
30
  for (const err of errors) {
27
31
  extractErrorIntoSpanEvent(this._tracerConfig, span, err)
28
32
  }
29
33
  }
30
- super.finish()
34
+ super.finish(ctx)
35
+
36
+ return ctx.parentStore
31
37
  }
32
38
  }
33
39
 
@@ -6,10 +6,10 @@ const { TEXT_MAP } = require('../../../ext/formats')
6
6
  const { addMetadataTags, getFilter, getMethodMetadata } = require('./util')
7
7
 
8
8
  class GrpcClientPlugin extends ClientPlugin {
9
- static get id () { return 'grpc' }
10
- static get operation () { return 'client:request' }
11
- static get prefix () { return 'apm:grpc:client:request' }
12
- static get peerServicePrecursors () { return ['rpc.service'] }
9
+ static id = 'grpc'
10
+ static operation = 'client:request'
11
+ static prefix = 'apm:grpc:client:request'
12
+ static peerServicePrecursors = ['rpc.service']
13
13
 
14
14
  constructor (...args) {
15
15
  super(...args)
@@ -5,7 +5,7 @@ const GrpcClientPlugin = require('./client')
5
5
  const CompositePlugin = require('../../dd-trace/src/plugins/composite')
6
6
 
7
7
  class GrpcPlugin extends CompositePlugin {
8
- static get id () { return 'grpc' }
8
+ static id = 'grpc'
9
9
  static get plugins () {
10
10
  return {
11
11
  server: GrpcServerPlugin,
@@ -6,9 +6,9 @@ const { TEXT_MAP } = require('../../../ext/formats')
6
6
  const { addMetadataTags, getFilter, getMethodMetadata } = require('./util')
7
7
 
8
8
  class GrpcServerPlugin extends ServerPlugin {
9
- static get id () { return 'grpc' }
10
- static get operation () { return 'server:request' }
11
- static get prefix () { return 'apm:grpc:server:request' }
9
+ static id = 'grpc'
10
+ static operation = 'server:request'
11
+ static prefix = 'apm:grpc:server:request'
12
12
 
13
13
  constructor (...args) {
14
14
  super(...args)
@@ -5,9 +5,7 @@ const RouterPlugin = require('../../datadog-plugin-router/src')
5
5
  const web = require('../../dd-trace/src/plugins/util/web')
6
6
 
7
7
  class HapiPlugin extends RouterPlugin {
8
- static get id () {
9
- return 'hapi'
10
- }
8
+ static id = 'hapi'
11
9
 
12
10
  constructor (...args) {
13
11
  super(...args)
@@ -4,9 +4,7 @@ const RouterPlugin = require('../../datadog-plugin-router/src')
4
4
  const web = require('../../dd-trace/src/plugins/util/web')
5
5
 
6
6
  class HonoPlugin extends RouterPlugin {
7
- static get id () {
8
- return 'hono'
9
- }
7
+ static id = 'hono'
10
8
 
11
9
  constructor (...args) {
12
10
  super(...args)
@@ -16,8 +16,8 @@ const HTTP_REQUEST_HEADERS = tags.HTTP_REQUEST_HEADERS
16
16
  const HTTP_RESPONSE_HEADERS = tags.HTTP_RESPONSE_HEADERS
17
17
 
18
18
  class HttpClientPlugin extends ClientPlugin {
19
- static get id () { return 'http' }
20
- static get prefix () { return 'apm:http:client:request' }
19
+ static id = 'http'
20
+ static prefix = 'apm:http:client:request'
21
21
 
22
22
  bindStart (message) {
23
23
  const { args, http = {} } = message
@@ -5,7 +5,7 @@ const HttpClientPlugin = require('./client')
5
5
  const CompositePlugin = require('../../dd-trace/src/plugins/composite')
6
6
 
7
7
  class HttpPlugin extends CompositePlugin {
8
- static get id () { return 'http' }
8
+ static id = 'http'
9
9
  static get plugins () {
10
10
  return {
11
11
  server: HttpServerPlugin,
@@ -7,9 +7,9 @@ const { incomingHttpRequestStart, incomingHttpRequestEnd } = require('../../dd-t
7
7
  const { COMPONENT } = require('../../dd-trace/src/constants')
8
8
 
9
9
  class HttpServerPlugin extends ServerPlugin {
10
- static get id () {
11
- return 'http'
12
- }
10
+ static id = 'http'
11
+
12
+ static prefix = 'apm:http:server:request'
13
13
 
14
14
  constructor (...args) {
15
15
  super(...args)
@@ -17,10 +17,6 @@ class HttpServerPlugin extends ServerPlugin {
17
17
  this.addTraceSub('exit', message => this.exit(message))
18
18
  }
19
19
 
20
- addTraceSub (eventName, handler) {
21
- this.addSub(`apm:${this.constructor.id}:server:${this.operation}:${eventName}`, handler)
22
- }
23
-
24
20
  start ({ req, res, abortController }) {
25
21
  const store = storage('legacy').getStore()
26
22
  const span = web.startSpan(
@@ -24,8 +24,8 @@ const HTTP2_HEADER_STATUS = ':status'
24
24
  const HTTP2_METHOD_GET = 'GET'
25
25
 
26
26
  class Http2ClientPlugin extends ClientPlugin {
27
- static get id () { return 'http2' }
28
- static get prefix () { return 'apm:http2:client:request' }
27
+ static id = 'http2'
28
+ static prefix = 'apm:http2:client:request'
29
29
 
30
30
  bindStart (message) {
31
31
  const { authority, options, headers = {} } = message
@@ -5,7 +5,7 @@ const Http2ClientPlugin = require('./client')
5
5
  const CompositePlugin = require('../../dd-trace/src/plugins/composite')
6
6
 
7
7
  class Http2Plugin extends CompositePlugin {
8
- static get id () { return 'http2' }
8
+ static id = 'http2'
9
9
  static get plugins () {
10
10
  return {
11
11
  server: Http2ServerPlugin,
@@ -3,21 +3,22 @@
3
3
  // Plugin temporarily disabled. See https://github.com/DataDog/dd-trace-js/issues/312
4
4
 
5
5
  const ServerPlugin = require('../../dd-trace/src/plugins/server')
6
- const { storage } = require('../../datadog-core')
7
6
  const web = require('../../dd-trace/src/plugins/util/web')
8
7
  const { COMPONENT } = require('../../dd-trace/src/constants')
9
8
 
10
9
  class Http2ServerPlugin extends ServerPlugin {
11
- static get id () {
12
- return 'http2'
10
+ constructor (tracer, config) {
11
+ super(tracer, config)
12
+ this.addBind('apm:http2:server:response:emit', this.bindEmit)
13
13
  }
14
14
 
15
- addTraceSub (eventName, handler) {
16
- this.addSub(`apm:${this.constructor.id}:server:${this.operation}:${eventName}`, handler)
17
- }
15
+ static id = 'http2'
16
+
17
+ static prefix = 'apm:http2:server:request'
18
+
19
+ bindStart (ctx) {
20
+ const { req, res } = ctx
18
21
 
19
- start ({ req, res }) {
20
- const store = storage('legacy').getStore()
21
22
  const span = web.startSpan(
22
23
  this.tracer,
23
24
  {
@@ -26,13 +27,15 @@ class Http2ServerPlugin extends ServerPlugin {
26
27
  },
27
28
  req,
28
29
  res,
29
- this.operationName()
30
+ this.operationName(),
31
+ ctx
30
32
  )
31
33
 
32
34
  span.setTag(COMPONENT, this.constructor.id)
33
35
  span._integrationName = this.constructor.id
34
36
 
35
- this.enter(span, { ...store, req, res })
37
+ ctx.currentStore.req = req
38
+ ctx.currentStore.res = res
36
39
 
37
40
  const context = web.getContext(req)
38
41
 
@@ -40,14 +43,22 @@ class Http2ServerPlugin extends ServerPlugin {
40
43
  context.res.writeHead = web.wrapWriteHead(context)
41
44
  context.instrumented = true
42
45
  }
46
+
47
+ return ctx.currentStore
43
48
  }
44
49
 
45
- finish ({ req }) {
50
+ bindEmit (ctx) {
51
+ if (ctx.eventName !== 'close') return ctx.currentStore
52
+
53
+ const { req } = ctx
54
+
46
55
  const context = web.getContext(req)
47
56
 
48
57
  if (!context || !context.res) return // Not created by a http.Server instance.
49
58
 
50
59
  web.finishAll(context)
60
+
61
+ return ctx.currentStore
51
62
  }
52
63
 
53
64
  error (error) {
@@ -3,9 +3,7 @@
3
3
  const RedisPlugin = require('../../datadog-plugin-redis/src')
4
4
 
5
5
  class IORedisPlugin extends RedisPlugin {
6
- static get id () {
7
- return 'ioredis'
8
- }
6
+ static id = 'ioredis'
9
7
  }
10
8
 
11
9
  module.exports = IORedisPlugin
@@ -3,11 +3,9 @@
3
3
  const RedisPlugin = require('../../datadog-plugin-redis/src')
4
4
 
5
5
  class IOValkeyPlugin extends RedisPlugin {
6
- static get id () {
7
- return 'iovalkey'
8
- }
6
+ static id = 'iovalkey'
9
7
 
10
- static get system () { return 'valkey' }
8
+ static system = 'valkey'
11
9
 
12
10
  constructor (...args) {
13
11
  super(...args)
@@ -67,9 +67,7 @@ function withTimeout (promise, timeoutMs) {
67
67
  }
68
68
 
69
69
  class JestPlugin extends CiPlugin {
70
- static get id () {
71
- return 'jest'
72
- }
70
+ static id = 'jest'
73
71
 
74
72
  // The lists are the same for every test suite, so we can cache them
75
73
  getUnskippableSuites (unskippableSuitesList) {
@@ -5,8 +5,8 @@ const { getMessageSize } = require('../../dd-trace/src/datastreams')
5
5
  const { convertToTextMap } = require('./utils')
6
6
 
7
7
  class KafkajsBatchConsumerPlugin extends ConsumerPlugin {
8
- static get id () { return 'kafkajs' }
9
- static get operation () { return 'consume-batch' }
8
+ static id = 'kafkajs'
9
+ static operation = 'consume-batch'
10
10
 
11
11
  start (ctx) {
12
12
  const { topic, messages, groupId, clusterId } = ctx.extractedArgs || ctx
@@ -10,8 +10,8 @@ const beforeFinishCh = dc.channel('dd-trace:kafkajs:consumer:beforeFinish')
10
10
  const MESSAGING_DESTINATION_KEY = 'messaging.destination.name'
11
11
 
12
12
  class KafkajsConsumerPlugin extends ConsumerPlugin {
13
- static get id () { return 'kafkajs' }
14
- static get operation () { return 'consume' }
13
+ static id = 'kafkajs'
14
+ static operation = 'consume'
15
15
 
16
16
  constructor () {
17
17
  super(...arguments)
@@ -6,7 +6,7 @@ const BatchConsumerPlugin = require('./batch-consumer')
6
6
  const CompositePlugin = require('../../dd-trace/src/plugins/composite')
7
7
 
8
8
  class KafkajsPlugin extends CompositePlugin {
9
- static get id () { return 'kafkajs' }
9
+ static id = 'kafkajs'
10
10
  static get plugins () {
11
11
  return {
12
12
  producer: ProducerPlugin,
@@ -7,9 +7,9 @@ const BOOTSTRAP_SERVERS_KEY = 'messaging.kafka.bootstrap.servers'
7
7
  const MESSAGING_DESTINATION_KEY = 'messaging.destination.name'
8
8
 
9
9
  class KafkajsProducerPlugin extends ProducerPlugin {
10
- static get id () { return 'kafkajs' }
11
- static get operation () { return 'produce' }
12
- static get peerServicePrecursors () { return [BOOTSTRAP_SERVERS_KEY] }
10
+ static id = 'kafkajs'
11
+ static operation = 'produce'
12
+ static peerServicePrecursors = [BOOTSTRAP_SERVERS_KEY]
13
13
 
14
14
  constructor () {
15
15
  super(...arguments)
@@ -4,9 +4,7 @@ const RouterPlugin = require('../../datadog-plugin-router/src')
4
4
  const web = require('../../dd-trace/src/plugins/util/web')
5
5
 
6
6
  class KoaPlugin extends RouterPlugin {
7
- static get id () {
8
- return 'koa'
9
- }
7
+ static id = 'koa'
10
8
 
11
9
  constructor (...args) {
12
10
  super(...args)
@@ -19,8 +19,8 @@ for (const Plugin of langChainTracingPlugins) {
19
19
  }
20
20
 
21
21
  class LangChainPlugin extends CompositePlugin {
22
- static get id () { return 'langchain' }
23
- static get plugins () { return plugins }
22
+ static id = 'langchain'
23
+ static plugins = plugins
24
24
  }
25
25
 
26
26
  module.exports = LangChainPlugin