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
@@ -2,8 +2,7 @@
2
2
 
3
3
  const {
4
4
  addHook,
5
- channel,
6
- AsyncResource
5
+ channel
7
6
  } = require('./helpers/instrument')
8
7
  const shimmer = require('../../datadog-shimmer')
9
8
 
@@ -89,29 +88,28 @@ function wrapParse (parse) {
89
88
  return parse.apply(this, arguments)
90
89
  }
91
90
 
92
- const asyncResource = new AsyncResource('bound-anonymous-fn')
93
-
94
- return asyncResource.runInAsyncScope(() => {
95
- parseStartCh.publish()
96
- let document
91
+ const ctx = { source }
92
+ return parseStartCh.runStores(ctx, () => {
97
93
  try {
98
- document = parse.apply(this, arguments)
99
- const operation = getOperation(document)
94
+ ctx.document = parse.apply(this, arguments)
95
+ const operation = getOperation(ctx.document)
100
96
 
101
- if (!operation) return document
97
+ if (!operation) return ctx.document
102
98
 
103
99
  if (source) {
104
- documentSources.set(document, source.body || source)
100
+ documentSources.set(ctx.document, source.body || source)
105
101
  }
102
+ ctx.docSource = documentSources.get(ctx.document)
106
103
 
107
- return document
104
+ return ctx.document
108
105
  } catch (err) {
109
106
  err.stack
110
- parseErrorCh.publish(err)
107
+ ctx.error = err
108
+ parseErrorCh.publish(ctx)
111
109
 
112
110
  throw err
113
111
  } finally {
114
- parseFinishCh.publish({ source, document, docSource: documentSources.get(document) })
112
+ parseFinishCh.publish(ctx)
115
113
  }
116
114
  })
117
115
  }
@@ -123,25 +121,25 @@ function wrapValidate (validate) {
123
121
  return validate.apply(this, arguments)
124
122
  }
125
123
 
126
- const asyncResource = new AsyncResource('bound-anonymous-fn')
127
-
128
- return asyncResource.runInAsyncScope(() => {
129
- validateStartCh.publish({ docSource: documentSources.get(document), document })
130
-
124
+ const ctx = { docSource: documentSources.get(document), document }
125
+ return validateStartCh.runStores(ctx, () => {
131
126
  let errors
132
127
  try {
133
128
  errors = validate.apply(this, arguments)
134
129
  if (errors && errors[0]) {
135
- validateErrorCh.publish(errors && errors[0])
130
+ ctx.error = errors && errors[0]
131
+ validateErrorCh.publish(ctx)
136
132
  }
137
133
  return errors
138
134
  } catch (err) {
139
135
  err.stack
140
- validateErrorCh.publish(err)
136
+ ctx.error = err
137
+ validateErrorCh.publish(ctx)
141
138
 
142
139
  throw err
143
140
  } finally {
144
- validateFinishCh.publish({ document, errors })
141
+ ctx.errors = errors
142
+ validateFinishCh.publish(ctx)
145
143
  }
146
144
  })
147
145
  }
@@ -155,44 +153,46 @@ function wrapExecute (execute) {
155
153
  return exe.apply(this, arguments)
156
154
  }
157
155
 
158
- const asyncResource = new AsyncResource('bound-anonymous-fn')
159
- return asyncResource.runInAsyncScope(() => {
160
- const args = normalizeArgs(arguments, defaultFieldResolver)
161
- const schema = args.schema
162
- const document = args.document
163
- const source = documentSources.get(document)
164
- const contextValue = args.contextValue
165
- const operation = getOperation(document, args.operationName)
166
-
167
- if (contexts.has(contextValue)) {
168
- return exe.apply(this, arguments)
169
- }
156
+ const args = normalizeArgs(arguments, defaultFieldResolver)
157
+ const schema = args.schema
158
+ const document = args.document
159
+ const source = documentSources.get(document)
160
+ const contextValue = args.contextValue
161
+ const operation = getOperation(document, args.operationName)
162
+
163
+ if (contexts.has(contextValue)) {
164
+ return exe.apply(this, arguments)
165
+ }
166
+
167
+ const ctx = {
168
+ operation,
169
+ args,
170
+ docSource: documentSources.get(document),
171
+ source,
172
+ fields: {},
173
+ abortController: new AbortController()
174
+ }
170
175
 
176
+ return startExecuteCh.runStores(ctx, () => {
171
177
  if (schema) {
172
178
  wrapFields(schema._queryType)
173
179
  wrapFields(schema._mutationType)
174
180
  }
175
181
 
176
- startExecuteCh.publish({
177
- operation,
178
- args,
179
- docSource: documentSources.get(document)
180
- })
181
-
182
- const context = { source, asyncResource, fields: {}, abortController: new AbortController() }
183
-
184
- contexts.set(contextValue, context)
182
+ contexts.set(contextValue, ctx)
185
183
 
186
- return callInAsyncScope(exe, asyncResource, this, arguments, context.abortController, (err, res) => {
187
- if (finishResolveCh.hasSubscribers) finishResolvers(context)
184
+ return callInAsyncScope(exe, this, arguments, ctx.abortController, (err, res) => {
185
+ if (finishResolveCh.hasSubscribers) finishResolvers(ctx)
188
186
 
189
187
  const error = err || (res && res.errors && res.errors[0])
190
188
 
191
189
  if (error) {
192
- executeErrorCh.publish(error)
190
+ ctx.error = error
191
+ executeErrorCh.publish(ctx)
193
192
  }
194
193
 
195
- finishExecuteCh.publish({ res, args, context })
194
+ ctx.res = res
195
+ finishExecuteCh.publish(ctx)
196
196
  })
197
197
  })
198
198
  }
@@ -205,14 +205,17 @@ function wrapResolve (resolve) {
205
205
  function resolveAsync (source, args, contextValue, info) {
206
206
  if (!startResolveCh.hasSubscribers) return resolve.apply(this, arguments)
207
207
 
208
- const context = contexts.get(contextValue)
208
+ const ctx = contexts.get(contextValue)
209
209
 
210
- if (!context) return resolve.apply(this, arguments)
210
+ if (!ctx) return resolve.apply(this, arguments)
211
211
 
212
- const field = assertField(context, info, args)
212
+ const field = assertField(ctx, info, args)
213
213
 
214
- return callInAsyncScope(resolve, field.asyncResource, this, arguments, context.abortController, (err) => {
215
- updateFieldCh.publish({ field, info, err })
214
+ return callInAsyncScope(resolve, this, arguments, ctx.abortController, (err) => {
215
+ field.ctx.error = err
216
+ field.ctx.info = info
217
+ field.ctx.field = field
218
+ updateFieldCh.publish(field.ctx)
216
219
  })
217
220
  }
218
221
 
@@ -221,32 +224,30 @@ function wrapResolve (resolve) {
221
224
  return resolveAsync
222
225
  }
223
226
 
224
- function callInAsyncScope (fn, aR, thisArg, args, abortController, cb) {
227
+ function callInAsyncScope (fn, thisArg, args, abortController, cb) {
225
228
  cb = cb || (() => {})
226
229
 
227
- return aR.runInAsyncScope(() => {
228
- if (abortController?.signal.aborted) {
229
- cb(null, null)
230
- throw new AbortError('Aborted')
231
- }
230
+ if (abortController?.signal.aborted) {
231
+ cb(null, null)
232
+ throw new AbortError('Aborted')
233
+ }
232
234
 
233
- try {
234
- const result = fn.apply(thisArg, args)
235
- if (result && typeof result.then === 'function') {
236
- // bind callback to this scope
237
- result.then(
238
- aR.bind(res => cb(null, res)),
239
- aR.bind(err => cb(err))
240
- )
241
- } else {
242
- cb(null, result)
243
- }
244
- return result
245
- } catch (err) {
246
- cb(err)
247
- throw err
235
+ try {
236
+ const result = fn.apply(thisArg, args)
237
+ if (result && typeof result.then === 'function') {
238
+ // bind callback to this scope
239
+ result.then(
240
+ res => cb(null, res),
241
+ err => cb(err)
242
+ )
243
+ } else {
244
+ cb(null, result)
248
245
  }
249
- })
246
+ return result
247
+ } catch (err) {
248
+ cb(err)
249
+ throw err
250
+ }
250
251
  }
251
252
 
252
253
  function pathToArray (path) {
@@ -259,59 +260,26 @@ function pathToArray (path) {
259
260
  return flattened.reverse()
260
261
  }
261
262
 
262
- function assertField (context, info, args) {
263
+ function assertField (rootCtx, info, args) {
263
264
  const pathInfo = info && info.path
264
265
 
265
266
  const path = pathToArray(pathInfo)
266
267
 
267
268
  const pathString = path.join('.')
268
- const fields = context.fields
269
+ const fields = rootCtx.fields
269
270
 
270
271
  let field = fields[pathString]
271
272
 
272
273
  if (!field) {
273
- const parent = getParentField(context, path)
274
-
275
- // we want to spawn the new span off of the parent, not a new async resource
276
- parent.asyncResource.runInAsyncScope(() => {
277
- /* this child resource will run a branched scope off of the parent resource, which
278
- accesses the parent span from the storage unit in its own scope */
279
- const childResource = new AsyncResource('bound-anonymous-fn')
280
-
281
- childResource.runInAsyncScope(() => {
282
- startResolveCh.publish({
283
- info,
284
- context,
285
- args
286
- })
287
- })
288
-
289
- field = fields[pathString] = {
290
- parent,
291
- asyncResource: childResource,
292
- error: null
293
- }
294
- })
295
- }
296
-
297
- return field
298
- }
299
-
300
- function getParentField (context, path) {
301
- for (let i = path.length - 1; i > 0; i--) {
302
- const field = getField(context, path.slice(0, i))
303
- if (field) {
304
- return field
274
+ const fieldCtx = { info, rootCtx, args }
275
+ startResolveCh.publish(fieldCtx)
276
+ field = fields[pathString] = {
277
+ error: null,
278
+ ctx: fieldCtx
305
279
  }
306
280
  }
307
281
 
308
- return {
309
- asyncResource: context.asyncResource
310
- }
311
- }
312
-
313
- function getField (context, path) {
314
- return context.fields[path.join('.')]
282
+ return field
315
283
  }
316
284
 
317
285
  function wrapFields (type) {
@@ -349,13 +317,13 @@ function wrapFieldType (field) {
349
317
  function finishResolvers ({ fields }) {
350
318
  Object.keys(fields).reverse().forEach(key => {
351
319
  const field = fields[key]
352
- const asyncResource = field.asyncResource
353
- asyncResource.runInAsyncScope(() => {
354
- if (field.error) {
355
- resolveErrorCh.publish(field.error)
356
- }
357
- finishResolveCh.publish(field.finishTime)
358
- })
320
+ field.ctx.finishTime = field.finishTime
321
+ field.ctx.field = field
322
+ if (field.error) {
323
+ field.ctx.error = field.error
324
+ resolveErrorCh.publish(field.ctx)
325
+ }
326
+ finishResolveCh.publish(field.ctx)
359
327
  })
360
328
  }
361
329
 
@@ -30,6 +30,7 @@ module.exports = {
30
30
  '@smithy/smithy-client': () => require('../aws-sdk'),
31
31
  '@vitest/runner': { esmFirst: true, fn: () => require('../vitest') },
32
32
  aerospike: () => require('../aerospike'),
33
+ ai: () => require('../ai'),
33
34
  amqp10: () => require('../amqp10'),
34
35
  amqplib: () => require('../amqplib'),
35
36
  avsc: () => require('../avsc'),
@@ -9,7 +9,6 @@ const log = require('../../../dd-trace/src/log')
9
9
  const checkRequireCache = require('./check-require-cache')
10
10
  const telemetry = require('../../../dd-trace/src/guardrails/telemetry')
11
11
  const { isInServerlessEnvironment } = require('../../../dd-trace/src/serverless')
12
- const { isFalse, isTrue, normalizePluginEnvName } = require('../../../dd-trace/src/util')
13
12
  const { getEnvironmentVariables } = require('../../../dd-trace/src/config-helper')
14
13
 
15
14
  const envs = getEnvironmentVariables()
@@ -25,22 +24,8 @@ const names = Object.keys(hooks)
25
24
  const pathSepExpr = new RegExp(`\\${path.sep}`, 'g')
26
25
 
27
26
  const disabledInstrumentations = new Set(
28
- DD_TRACE_DISABLED_INSTRUMENTATIONS?.split(',').map(name => normalizePluginEnvName(name, true)) ?? []
27
+ DD_TRACE_DISABLED_INSTRUMENTATIONS?.split(',')
29
28
  )
30
- const reenabledInstrumentations = new Set()
31
-
32
- // Check for DD_TRACE_<INTEGRATION>_ENABLED environment variables
33
- for (const [key, value] of Object.entries(envs)) {
34
- const match = key.match(/^DD_TRACE_(.+)_ENABLED$/)
35
- if (match && value) {
36
- const integration = normalizePluginEnvName(match[1], true)
37
- if (isFalse(value)) {
38
- disabledInstrumentations.add(integration)
39
- } else if (isTrue(value)) {
40
- reenabledInstrumentations.add(integration)
41
- }
42
- }
43
- }
44
29
 
45
30
  const loadChannel = channel('dd-trace:instrumentation:load')
46
31
 
@@ -65,8 +50,7 @@ const allInstrumentations = {}
65
50
 
66
51
  // TODO: make this more efficient
67
52
  for (const packageName of names) {
68
- const normalizedPackageName = normalizePluginEnvName(packageName, true)
69
- if (disabledInstrumentations.has(normalizedPackageName)) continue
53
+ if (disabledInstrumentations.has(packageName)) continue
70
54
 
71
55
  const hookOptions = {}
72
56
 
@@ -75,10 +59,6 @@ for (const packageName of names) {
75
59
  if (hook !== null && typeof hook === 'object') {
76
60
  if (hook.serverless === false && isInServerlessEnvironment()) continue
77
61
 
78
- // some integrations are disabled by default, but can be enabled by setting
79
- // the DD_TRACE_<INTEGRATION>_ENABLED environment variable to true
80
- if (hook.disabled && !reenabledInstrumentations.has(normalizedPackageName)) continue
81
-
82
62
  hookOptions.internals = hook.esmFirst
83
63
  hook = hook.fn
84
64
  }
@@ -17,8 +17,14 @@ function wrapFetch (fetch) {
17
17
  }
18
18
  }
19
19
 
20
+ function onErrorFn (error, _context_) {
21
+ throw error
22
+ }
23
+
20
24
  function wrapCompose (compose) {
21
- return function (middleware, onError, onNotFound) {
25
+ return function (middlewares, onError, onNotFound) {
26
+ onError ??= onErrorFn
27
+
22
28
  const instrumentedOnError = (...args) => {
23
29
  const [error, context] = args
24
30
  const req = context.env.incoming
@@ -26,23 +32,20 @@ function wrapCompose (compose) {
26
32
  return onError(...args)
27
33
  }
28
34
 
29
- const instrumentedMiddlewares = middleware.map(h => {
35
+ const instrumentedMiddlewares = middlewares.map(h => {
30
36
  const [[fn, meta], params] = h
31
37
 
32
- // TODO: handle middleware instrumentation
33
38
  const instrumentedFn = (...args) => {
34
39
  const context = args[0]
35
- const req = context.env.incoming
36
- const route = meta.path
37
40
  routeChannel.publish({
38
- req,
39
- route
41
+ req: context.env.incoming,
42
+ route: meta?.path
40
43
  })
41
44
  return fn(...args)
42
45
  }
43
46
  return [[instrumentedFn, meta], params]
44
47
  })
45
- return compose.apply(this, [instrumentedMiddlewares, instrumentedOnError, onNotFound])
48
+ return compose.call(this, instrumentedMiddlewares, instrumentedOnError, onNotFound)
46
49
  }
47
50
  }
48
51
 
@@ -5,14 +5,13 @@
5
5
 
6
6
  const {
7
7
  channel,
8
- addHook,
9
- AsyncResource
8
+ addHook
10
9
  } = require('../helpers/instrument')
11
10
  const shimmer = require('../../../datadog-shimmer')
12
11
 
13
12
  const startServerCh = channel('apm:http2:server:request:start')
14
13
  const errorServerCh = channel('apm:http2:server:request:error')
15
- const finishServerCh = channel('apm:http2:server:request:finish')
14
+ const emitCh = channel('apm:http2:server:response:emit')
16
15
 
17
16
  const names = ['http2', 'node:http2']
18
17
 
@@ -30,18 +29,14 @@ function wrapCreateServer (createServer) {
30
29
  }
31
30
  }
32
31
 
33
- function wrapResponseEmit (emit) {
34
- const asyncResource = new AsyncResource('bound-anonymous-fn')
32
+ function wrapResponseEmit (emit, ctx) {
35
33
  return function (eventName, event) {
36
- return asyncResource.runInAsyncScope(() => {
37
- if (eventName === 'close' && finishServerCh.hasSubscribers) {
38
- finishServerCh.publish({ req: this.req })
39
- }
40
-
41
- return emit.apply(this, arguments)
42
- })
34
+ ctx.req = this.req
35
+ ctx.eventName = eventName
36
+ return emitCh.runStores(ctx, emit, this, ...arguments)
43
37
  }
44
38
  }
39
+
45
40
  function wrapEmit (emit) {
46
41
  return function (eventName, req, res) {
47
42
  if (!startServerCh.hasSubscribers) {
@@ -51,18 +46,17 @@ function wrapEmit (emit) {
51
46
  if (eventName === 'request') {
52
47
  res.req = req
53
48
 
54
- const asyncResource = new AsyncResource('bound-anonymous-fn')
55
- return asyncResource.runInAsyncScope(() => {
56
- startServerCh.publish({ req, res })
57
-
58
- shimmer.wrap(res, 'emit', wrapResponseEmit)
49
+ const ctx = { req, res }
50
+ return startServerCh.runStores(ctx, () => {
51
+ shimmer.wrap(res, 'emit', emit => wrapResponseEmit(emit, ctx))
59
52
 
60
53
  try {
61
54
  return emit.apply(this, arguments)
62
- } catch (err) {
63
- errorServerCh.publish(err)
55
+ } catch (error) {
56
+ ctx.error = error
57
+ errorServerCh.publish(ctx)
64
58
 
65
- throw err
59
+ throw error
66
60
  }
67
61
  })
68
62
  }
@@ -1,10 +1,11 @@
1
1
  'use strict'
2
2
 
3
- const { addHook, channel, AsyncResource } = require('./helpers/instrument')
3
+ const { addHook, channel } = require('./helpers/instrument')
4
4
  const { wrapThen } = require('./helpers/promise')
5
5
  const shimmer = require('../../datadog-shimmer')
6
6
 
7
7
  const startRawQueryCh = channel('datadog:knex:raw:start')
8
+ const rawQuerySubscribes = channel('datadog:knex:raw:subscribes')
8
9
  const finishRawQueryCh = channel('datadog:knex:raw:finish')
9
10
 
10
11
  patch('lib/query/builder.js')
@@ -22,8 +23,8 @@ function patch (file) {
22
23
  })
23
24
  }
24
25
 
25
- function finish () {
26
- finishRawQueryCh.publish()
26
+ function finish (context, cb) {
27
+ finishRawQueryCh.runStores(context, cb)
27
28
  }
28
29
 
29
30
  addHook({
@@ -43,21 +44,18 @@ addHook({
43
44
  return raw.apply(this, arguments)
44
45
  }
45
46
 
46
- const asyncResource = new AsyncResource('bound-anonymous-fn')
47
-
48
- return asyncResource.runInAsyncScope(() => {
49
- startRawQueryCh.publish({ sql, dialect: this.dialect })
50
-
47
+ const context = { sql, dialect: this.dialect }
48
+ return startRawQueryCh.runStores(context, () => {
51
49
  const rawResult = raw.apply(this, arguments)
52
50
  shimmer.wrap(rawResult, 'then', originalThen => function () {
53
- return asyncResource.runInAsyncScope(() => {
54
- arguments[0] = wrapCallbackWithFinish(arguments[0], finish)
55
- if (arguments[1]) arguments[1] = wrapCallbackWithFinish(arguments[1], finish)
51
+ return rawQuerySubscribes.runStores(context, () => {
52
+ arguments[0] = wrapCallbackWithFinish(arguments[0], finish, context)
53
+ if (arguments[1]) arguments[1] = wrapCallbackWithFinish(arguments[1], finish, context)
56
54
 
57
55
  const originalThenResult = originalThen.apply(this, arguments)
58
56
 
59
57
  shimmer.wrap(originalThenResult, 'catch', originalCatch => function () {
60
- arguments[0] = wrapCallbackWithFinish(arguments[0], finish)
58
+ arguments[0] = wrapCallbackWithFinish(arguments[0], finish, context)
61
59
  return originalCatch.apply(this, arguments)
62
60
  })
63
61
 
@@ -66,8 +64,8 @@ addHook({
66
64
  })
67
65
 
68
66
  shimmer.wrap(rawResult, 'asCallback', originalAsCallback => function () {
69
- return asyncResource.runInAsyncScope(() => {
70
- arguments[0] = wrapCallbackWithFinish(arguments[0], finish)
67
+ return rawQuerySubscribes.runStores(context, () => {
68
+ arguments[0] = wrapCallbackWithFinish(arguments[0], finish, context)
71
69
  return originalAsCallback.apply(this, arguments)
72
70
  })
73
71
  })
@@ -75,14 +73,14 @@ addHook({
75
73
  return rawResult
76
74
  })
77
75
  })
76
+
78
77
  return Knex
79
78
  })
80
79
 
81
- function wrapCallbackWithFinish (callback, finish) {
80
+ function wrapCallbackWithFinish (callback, finish, context) {
82
81
  if (typeof callback !== 'function') return callback
83
82
 
84
83
  return shimmer.wrapFunction(callback, callback => function () {
85
- finish()
86
- callback.apply(this, arguments)
84
+ finish(context, () => callback.apply(this, arguments))
87
85
  })
88
86
  }
@@ -1,7 +1,7 @@
1
1
  'use strict'
2
2
 
3
3
  const shimmer = require('../../datadog-shimmer')
4
- const { addHook, channel, AsyncResource } = require('./helpers/instrument')
4
+ const { addHook, channel } = require('./helpers/instrument')
5
5
 
6
6
  const handleChannel = channel('apm:microgateway-core:request:handle')
7
7
  const routeChannel = channel('apm:microgateway-core:request:route')
@@ -11,18 +11,18 @@ const name = 'microgateway-core'
11
11
 
12
12
  // TODO Remove " <=3.0.0" when "volos-util-apigee" module is fixed
13
13
  const versions = ['>=2.1 <=3.0.0']
14
- const requestResources = new WeakMap()
14
+ const requestContexts = new WeakMap()
15
15
 
16
16
  function wrapConfigProxyFactory (configProxyFactory) {
17
17
  return function () {
18
18
  const configProxy = configProxyFactory.apply(this, arguments)
19
19
 
20
20
  return function (req, res, next) {
21
- const requestResource = new AsyncResource('bound-anonymous-fn')
21
+ const ctx = { req, res }
22
22
 
23
- requestResources.set(req, requestResource)
23
+ requestContexts.set(req, ctx)
24
24
 
25
- handleChannel.publish({ req, res })
25
+ handleChannel.publish(ctx)
26
26
 
27
27
  return configProxy.apply(this, arguments)
28
28
  }
@@ -43,18 +43,19 @@ function wrapPluginsFactory (pluginsFactory) {
43
43
 
44
44
  function wrapNext (req, res, next) {
45
45
  return shimmer.wrapFunction(next, next => function nextWithTrace (err) {
46
- const requestResource = requestResources.get(req)
46
+ const ctx = requestContexts.get(req)
47
47
 
48
- requestResource.runInAsyncScope(() => {
49
- if (err) {
50
- errorChannel.publish(err)
51
- }
52
-
53
- if (res.proxy && res.proxy.base_path) {
54
- routeChannel.publish({ req, res, route: res.proxy.base_path })
55
- }
56
- })
48
+ if (err) {
49
+ ctx.error = err
50
+ errorChannel.publish(ctx)
51
+ }
57
52
 
53
+ if (res.proxy && res.proxy.base_path) {
54
+ ctx.req = req
55
+ ctx.res = res
56
+ ctx.route = res.proxy.base_path
57
+ routeChannel.publish(ctx)
58
+ }
58
59
  return next.apply(this, arguments)
59
60
  })
60
61
  }