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
@@ -148,63 +148,66 @@ function wrapCommand (command, operation, name) {
148
148
  return wrapped
149
149
  }
150
150
 
151
- function instrument (operation, command, ctx, args, server, ns, ops, options = {}) {
151
+ function instrument (operation, command, instance, args, server, ns, ops, options = {}) {
152
152
  const name = options.name || (ops && Object.keys(ops)[0])
153
153
  const index = args.length - 1
154
- let callback = args[index]
154
+ const callback = args[index]
155
155
 
156
- if (typeof callback !== 'function') return command.apply(ctx, args)
156
+ if (typeof callback !== 'function') return command.apply(instance, args)
157
157
 
158
158
  const serverInfo = server && server.s && server.s.options
159
- const callbackResource = new AsyncResource('bound-anonymous-fn')
160
- const asyncResource = new AsyncResource('bound-anonymous-fn')
161
159
 
162
- callback = callbackResource.bind(callback)
163
-
164
- return asyncResource.runInAsyncScope(() => {
165
- startCh.publish({ ns, ops, options: serverInfo, name })
166
-
167
- args[index] = shimmer.wrapFunction(callback, callback => asyncResource.bind(function (err, res) {
160
+ const ctx = {
161
+ ns,
162
+ ops,
163
+ options: serverInfo,
164
+ name
165
+ }
166
+ return startCh.runStores(ctx, () => {
167
+ args[index] = shimmer.wrapFunction(callback, callback => function (err, res) {
168
168
  if (err) {
169
- errorCh.publish(err)
169
+ ctx.error = err
170
+ errorCh.publish(ctx)
170
171
  }
171
172
 
172
- finishCh.publish()
173
-
174
- if (callback) {
175
- return callback.apply(this, arguments)
176
- }
177
- }))
173
+ return finishCh.runStores(ctx, callback, this, ...arguments)
174
+ })
178
175
 
179
176
  try {
180
- return command.apply(ctx, args)
177
+ return command.apply(instance, args)
181
178
  } catch (err) {
182
- errorCh.publish(err)
179
+ ctx.error = err
180
+ errorCh.publish(ctx)
183
181
 
184
182
  throw err
185
183
  }
186
184
  })
187
185
  }
188
186
 
189
- function instrumentPromise (operation, command, ctx, args, server, ns, ops, options = {}) {
187
+ function instrumentPromise (operation, command, instance, args, server, ns, ops, options = {}) {
190
188
  const name = options.name || (ops && Object.keys(ops)[0])
191
189
 
192
190
  const serverInfo = server && server.s && server.s.options
193
- const asyncResource = new AsyncResource('bound-anonymous-fn')
194
191
 
195
- return asyncResource.runInAsyncScope(() => {
196
- startCh.publish({ ns, ops, options: serverInfo, name })
192
+ const ctx = {
193
+ ns,
194
+ ops,
195
+ options: serverInfo,
196
+ name
197
+ }
197
198
 
198
- const promise = command.apply(ctx, args)
199
+ return startCh.runStores(ctx, () => {
200
+ const promise = command.apply(instance, args)
199
201
 
200
- return promise.then(function (res) {
201
- finishCh.publish()
202
- return res
202
+ promise.then(function (res) {
203
+ ctx.result = res
204
+ finishCh.publish(ctx)
203
205
  }, function (err) {
204
- errorCh.publish(err)
205
- finishCh.publish()
206
-
207
- throw err
206
+ ctx.error = err
207
+ errorCh.publish(ctx)
208
+ finishCh.publish(ctx)
208
209
  })
210
+
211
+ return promise
209
212
  })
210
213
  }
@@ -4,8 +4,7 @@ require('./mongodb-core')
4
4
 
5
5
  const {
6
6
  channel,
7
- addHook,
8
- AsyncResource
7
+ addHook
9
8
  } = require('./helpers/instrument')
10
9
  const shimmer = require('../../datadog-shimmer')
11
10
 
@@ -41,19 +40,16 @@ addHook({ name: 'mongodb', versions: ['>=3.3 <5', '5', '>=6'] }, mongodb => {
41
40
  return method.apply(this, arguments)
42
41
  }
43
42
 
44
- const asyncResource = new AsyncResource('bound-anonymous-fn')
45
-
46
- return asyncResource.runInAsyncScope(() => {
47
- const filters = [arguments[0]]
48
- if (useTwoArguments) {
49
- filters.push(arguments[1])
50
- }
43
+ const ctx = {
44
+ filters: [arguments[0]],
45
+ methodName
46
+ }
51
47
 
52
- startCh.publish({
53
- filters,
54
- methodName
55
- })
48
+ if (useTwoArguments) {
49
+ ctx.filters.push(arguments[1])
50
+ }
56
51
 
52
+ return startCh.runStores(ctx, () => {
57
53
  return method.apply(this, arguments)
58
54
  })
59
55
  }
@@ -2,19 +2,24 @@
2
2
 
3
3
  const { addHook, channel } = require('./helpers/instrument')
4
4
  const { wrapThen } = require('./helpers/promise')
5
- const { AsyncResource } = require('./helpers/instrument')
6
5
  const shimmer = require('../../datadog-shimmer')
7
6
 
7
+ const startCh = channel('datadog:mongoose:model:filter:start')
8
+ const finishCh = channel('datadog:mongoose:model:filter:finish')
9
+ // this channel is for wrapping the callback of exec methods and handling store context
10
+ const execStartCh = channel('apm:mongoose:exec:start')
11
+ const execFinishCh = channel('apm:mongoose:exec:finish')
12
+
8
13
  function wrapAddQueue (addQueue) {
9
- return function addQueueWithTrace (name) {
10
- if (typeof name === 'function') {
11
- arguments[0] = AsyncResource.bind(name)
12
- } else if (typeof this[name] === 'function') {
13
- arguments[0] = AsyncResource.bind((...args) => this[name](...args))
14
- }
14
+ const ctx = {}
15
15
 
16
- return addQueue.apply(this, arguments)
17
- }
16
+ return execStartCh.runStores(ctx, () => {
17
+ return function addQueueWithTrace (name) {
18
+ return execFinishCh.runStores(ctx, () => {
19
+ return addQueue.apply(this, arguments)
20
+ })
21
+ }
22
+ })
18
23
  }
19
24
 
20
25
  addHook({
@@ -31,9 +36,6 @@ addHook({
31
36
  return mongoose
32
37
  })
33
38
 
34
- const startCh = channel('datadog:mongoose:model:filter:start')
35
- const finishCh = channel('datadog:mongoose:model:filter:finish')
36
-
37
39
  const collectionMethodsWithFilter = [
38
40
  'count',
39
41
  'countDocuments',
@@ -68,27 +70,21 @@ addHook({
68
70
  return method.apply(this, arguments)
69
71
  }
70
72
 
71
- const asyncResource = new AsyncResource('bound-anonymous-fn')
72
-
73
73
  const filters = [arguments[0]]
74
74
  if (useTwoArguments) {
75
75
  filters.push(arguments[1])
76
76
  }
77
77
 
78
- const finish = asyncResource.bind(function () {
79
- finishCh.publish()
80
- })
81
-
82
78
  let callbackWrapped = false
83
79
 
84
- const wrapCallbackIfExist = (args) => {
80
+ const wrapCallbackIfExist = (args, ctx) => {
85
81
  const lastArgumentIndex = args.length - 1
86
82
 
87
83
  if (typeof args[lastArgumentIndex] === 'function') {
88
84
  // is a callback, wrap it to execute finish()
89
85
  shimmer.wrap(args, lastArgumentIndex, originalCb => {
90
86
  return function () {
91
- finish()
87
+ finishCh.publish(ctx)
92
88
 
93
89
  return originalCb.apply(this, arguments)
94
90
  }
@@ -98,13 +94,13 @@ addHook({
98
94
  }
99
95
  }
100
96
 
101
- wrapCallbackIfExist(arguments)
97
+ const ctx = {
98
+ filters,
99
+ methodName
100
+ }
102
101
 
103
- return asyncResource.runInAsyncScope(() => {
104
- startCh.publish({
105
- filters,
106
- methodName
107
- })
102
+ return startCh.runStores(ctx, () => {
103
+ wrapCallbackIfExist(arguments, ctx)
108
104
 
109
105
  const res = method.apply(this, arguments)
110
106
 
@@ -113,7 +109,7 @@ addHook({
113
109
  shimmer.wrap(res, 'exec', originalExec => {
114
110
  return function wrappedExec () {
115
111
  if (!callbackWrapped) {
116
- wrapCallbackIfExist(arguments)
112
+ wrapCallbackIfExist(arguments, ctx)
117
113
  }
118
114
 
119
115
  const execResult = originalExec.apply(this, arguments)
@@ -129,7 +125,7 @@ addHook({
129
125
  const reject = arguments[1]
130
126
 
131
127
  arguments[0] = shimmer.wrapFunction(resolve, resolve => function wrappedResolve () {
132
- finish()
128
+ finishCh.publish(ctx)
133
129
 
134
130
  if (resolve) {
135
131
  return resolve.apply(this, arguments)
@@ -137,7 +133,7 @@ addHook({
137
133
  })
138
134
 
139
135
  arguments[1] = shimmer.wrapFunction(reject, reject => function wrappedReject () {
140
- finish()
136
+ finishCh.publish(ctx)
141
137
 
142
138
  if (reject) {
143
139
  return reject.apply(this, arguments)
@@ -162,14 +162,16 @@ function instrument (req, res, handler, error) {
162
162
 
163
163
  // promise should only reject when propagateError is true:
164
164
  // https://github.com/vercel/next.js/blob/cee656238a/packages/next/server/api-utils/node.ts#L547
165
- return promise.then(
165
+ promise.then(
166
166
  result => finish(ctx, result),
167
167
  err => finish(ctx, null, err)
168
168
  )
169
+ return promise
169
170
  } catch (e) {
170
171
  // this will probably never happen as the handler caller is an async function:
171
172
  // https://github.com/vercel/next.js/blob/cee656238a/packages/next/server/api-utils/node.ts#L420
172
- return finish(ctx, null, e)
173
+ finish(ctx, null, e)
174
+ throw e
173
175
  }
174
176
  })
175
177
  }
@@ -198,12 +200,6 @@ function finish (ctx, result, err) {
198
200
  }
199
201
 
200
202
  finishChannel.publish(ctx)
201
-
202
- if (err) {
203
- throw err
204
- }
205
-
206
- return result
207
203
  }
208
204
 
209
205
  // also wrapped in dist/server/future/route-handlers/app-route-route-handler.js
@@ -151,7 +151,6 @@ addHook({ name: 'openai', file: 'dist/api.js', versions: ['>=3.0.0 <4'] }, expor
151
151
  methodName,
152
152
  args: arguments,
153
153
  basePath: this.basePath,
154
- apiKey: this.configuration.apiKey
155
154
  }
156
155
 
157
156
  return ch.tracePromise(fn, ctx, this, ...arguments)
@@ -224,7 +223,6 @@ for (const extension of extensions) {
224
223
  methodName: `${baseResource}.${methodName}`,
225
224
  args: arguments,
226
225
  basePath: client.baseURL,
227
- apiKey: client.apiKey
228
226
  }
229
227
 
230
228
  return ch.start.runStores(ctx, () => {
@@ -2,8 +2,7 @@
2
2
 
3
3
  const {
4
4
  channel,
5
- addHook,
6
- AsyncResource
5
+ addHook
7
6
  } = require('./helpers/instrument')
8
7
  const shimmer = require('../../datadog-shimmer')
9
8
 
@@ -14,11 +13,11 @@ const startChannel = channel('apm:oracledb:query:start')
14
13
  const errorChannel = channel('apm:oracledb:query:error')
15
14
  const finishChannel = channel('apm:oracledb:query:finish')
16
15
 
17
- function finish (err) {
18
- if (err) {
19
- errorChannel.publish(err)
16
+ function finish (ctx) {
17
+ if (ctx.error) {
18
+ errorChannel.publish(ctx)
20
19
  }
21
- finishChannel.publish()
20
+ finishChannel.publish(ctx)
22
21
  }
23
22
 
24
23
  addHook({ name: 'oracledb', versions: ['>=5'] }, oracledb => {
@@ -30,49 +29,55 @@ addHook({ name: 'oracledb', versions: ['>=5'] }, oracledb => {
30
29
 
31
30
  if (arguments.length && typeof arguments[arguments.length - 1] === 'function') {
32
31
  const cb = arguments[arguments.length - 1]
33
- const outerAr = new AsyncResource('apm:oracledb:outer-scope')
34
32
  arguments[arguments.length - 1] = shimmer.wrapFunction(cb, cb => function wrappedCb (err, result) {
35
- finish(err)
36
- return outerAr.runInAsyncScope(() => cb.apply(this, arguments))
33
+ if (err) {
34
+ ctx.error = err
35
+ errorChannel.publish(ctx)
36
+ }
37
+ return finishChannel.runStores(ctx, () => {
38
+ return cb.apply(this, arguments)
39
+ })
37
40
  })
38
41
  }
39
42
 
40
- return new AsyncResource('apm:oracledb:inner-scope').runInAsyncScope(() => {
41
- // The connAttrs are used to pass through the argument to the potential
42
- // serviceName method a user might have passed through as well as parsing
43
- // the connection string in v5.
44
- const connAttrs = connectionAttributes.get(this)
43
+ // The connAttrs are used to pass through the argument to the potential
44
+ // serviceName method a user might have passed through as well as parsing
45
+ // the connection string in v5.
46
+ const connAttrs = connectionAttributes.get(this)
45
47
 
46
- const details = typeof this.hostName === 'string' ? this : this._impl
48
+ const details = typeof this.hostName === 'string' ? this : this._impl
47
49
 
48
- let hostname
49
- let port
50
- let dbInstance
50
+ let hostname
51
+ let port
52
+ let dbInstance
51
53
 
52
- if (details) {
53
- dbInstance = details.serviceName
54
- hostname = details.hostName ?? details.nscon?.ntAdapter?.hostName
55
- port = String(details.port ?? details.nscon?.ntAdapter?.port ?? '')
56
- }
54
+ if (details) {
55
+ dbInstance = details.serviceName
56
+ hostname = details.hostName ?? details.nscon?.ntAdapter?.hostName
57
+ port = String(details.port ?? details.nscon?.ntAdapter?.port ?? '')
58
+ }
57
59
 
58
- startChannel.publish({
59
- query: dbQuery,
60
- connAttrs,
61
- dbInstance,
62
- port,
63
- hostname,
64
- })
60
+ const ctx = {
61
+ dbInstance,
62
+ port,
63
+ hostname,
64
+ query: dbQuery,
65
+ connAttrs
66
+ }
67
+
68
+ return startChannel.runStores(ctx, () => {
65
69
  try {
66
70
  let result = execute.apply(this, arguments)
67
71
 
68
72
  if (typeof result?.then === 'function') {
69
73
  result = result.then(
70
74
  x => {
71
- finish()
75
+ finish(ctx)
72
76
  return x
73
77
  },
74
78
  e => {
75
- finish(e)
79
+ ctx.error = e
80
+ finish(ctx)
76
81
  throw e
77
82
  }
78
83
  )
@@ -80,7 +85,8 @@ addHook({ name: 'oracledb', versions: ['>=5'] }, oracledb => {
80
85
 
81
86
  return result
82
87
  } catch (err) {
83
- errorChannel.publish(err)
88
+ ctx.error = err
89
+ finish(ctx)
84
90
  throw err
85
91
  }
86
92
  })
@@ -2,8 +2,7 @@
2
2
 
3
3
  const {
4
4
  channel,
5
- addHook,
6
- AsyncResource
5
+ addHook
7
6
  } = require('./helpers/instrument')
8
7
  const shimmer = require('../../datadog-shimmer')
9
8
 
@@ -33,8 +32,6 @@ function wrapQuery (query) {
33
32
  return query.apply(this, arguments)
34
33
  }
35
34
 
36
- const callbackResource = new AsyncResource('bound-anonymous-fn')
37
- const asyncResource = new AsyncResource('bound-anonymous-fn')
38
35
  const processId = this.processID
39
36
 
40
37
  const pgQuery = arguments[0] !== null && typeof arguments[0] === 'object'
@@ -46,8 +43,9 @@ function wrapQuery (query) {
46
43
  const stream = typeof textPropObj.read === 'function'
47
44
 
48
45
  // Only alter `text` property if safe to do so. Initially, it's a property, not a getter.
46
+ let originalText
49
47
  if (!textProp || textProp.configurable) {
50
- const originalText = textPropObj.text
48
+ originalText = textPropObj.text
51
49
 
52
50
  Object.defineProperty(textPropObj, 'text', {
53
51
  get () {
@@ -55,25 +53,24 @@ function wrapQuery (query) {
55
53
  }
56
54
  })
57
55
  }
58
-
59
- return asyncResource.runInAsyncScope(() => {
60
- const abortController = new AbortController()
61
-
62
- startCh.publish({
63
- params: this.connectionParameters,
64
- query: textPropObj,
65
- processId,
66
- abortController,
67
- stream
68
- })
69
-
70
- const finish = asyncResource.bind(function (error, res) {
71
- if (error) {
72
- errorCh.publish(error)
73
- }
74
- finishCh.publish({ result: res?.rows })
75
- })
76
-
56
+ const abortController = new AbortController()
57
+ const ctx = {
58
+ params: this.connectionParameters,
59
+ query: textPropObj,
60
+ originalText,
61
+ processId,
62
+ abortController,
63
+ stream
64
+ }
65
+ const finish = (error, res) => {
66
+ if (error) {
67
+ ctx.error = error
68
+ errorCh.publish(ctx)
69
+ }
70
+ ctx.result = res?.rows
71
+ return finishCh.publish(ctx)
72
+ }
73
+ return startCh.runStores(ctx, () => {
77
74
  if (abortController.signal.aborted) {
78
75
  const error = abortController.signal.reason || new Error('Aborted')
79
76
 
@@ -121,10 +118,10 @@ function wrapQuery (query) {
121
118
  }
122
119
 
123
120
  if (newQuery.callback) {
124
- const originalCallback = callbackResource.bind(newQuery.callback)
125
- newQuery.callback = function (err, res) {
126
- finish(err, res)
127
- return originalCallback.apply(this, arguments)
121
+ const originalCallback = newQuery.callback
122
+ newQuery.callback = function (err, ...args) {
123
+ finish(err, ...args)
124
+ return finishCh.runStores(ctx, originalCallback, this, err, ...args)
128
125
  }
129
126
  } else if (newQuery.once) {
130
127
  newQuery
@@ -139,40 +136,33 @@ function wrapQuery (query) {
139
136
 
140
137
  try {
141
138
  return retval
142
- } catch (err) {
143
- errorCh.publish(err)
139
+ } catch (error) {
140
+ ctx.error = error
141
+ errorCh.publish(ctx)
144
142
  }
145
143
  })
146
144
  }
147
145
  }
148
-
146
+ const finish = (ctx) => {
147
+ finishPoolQueryCh.publish(ctx)
148
+ }
149
149
  function wrapPoolQuery (query) {
150
150
  return function () {
151
151
  if (!startPoolQueryCh.hasSubscribers) {
152
152
  return query.apply(this, arguments)
153
153
  }
154
154
 
155
- const asyncResource = new AsyncResource('bound-anonymous-fn')
156
-
157
155
  const pgQuery = arguments[0] !== null && typeof arguments[0] === 'object' ? arguments[0] : { text: arguments[0] }
156
+ const abortController = new AbortController()
158
157
 
159
- return asyncResource.runInAsyncScope(() => {
160
- const abortController = new AbortController()
161
-
162
- startPoolQueryCh.publish({
163
- query: pgQuery,
164
- abortController
165
- })
166
-
167
- const finish = asyncResource.bind(function () {
168
- finishPoolQueryCh.publish()
169
- })
158
+ const ctx = { query: pgQuery, abortController }
170
159
 
160
+ return startPoolQueryCh.runStores(ctx, () => {
171
161
  const cb = arguments[arguments.length - 1]
172
162
 
173
163
  if (abortController.signal.aborted) {
174
164
  const error = abortController.signal.reason || new Error('Aborted')
175
- finish()
165
+ finish(ctx)
176
166
 
177
167
  if (typeof cb === 'function') {
178
168
  cb(error)
@@ -184,7 +174,7 @@ function wrapPoolQuery (query) {
184
174
 
185
175
  if (typeof cb === 'function') {
186
176
  arguments[arguments.length - 1] = shimmer.wrapFunction(cb, cb => function () {
187
- finish()
177
+ finish(ctx)
188
178
  return cb.apply(this, arguments)
189
179
  })
190
180
  }
@@ -193,9 +183,9 @@ function wrapPoolQuery (query) {
193
183
 
194
184
  if (retval?.then) {
195
185
  retval.then(() => {
196
- finish()
186
+ finish(ctx)
197
187
  }).catch(() => {
198
- finish()
188
+ finish(ctx)
199
189
  })
200
190
  }
201
191
 
@@ -6,16 +6,12 @@ const DatabasePlugin = require('../../dd-trace/src/plugins/database')
6
6
  const AEROSPIKE_PEER_SERVICE = 'aerospike.namespace'
7
7
 
8
8
  class AerospikePlugin extends DatabasePlugin {
9
- static get id () { return 'aerospike' }
10
- static get operation () { return 'command' }
11
- static get system () { return 'aerospike' }
12
- static get prefix () {
13
- return 'tracing:apm:aerospike:command'
14
- }
9
+ static id = 'aerospike'
10
+ static operation = 'command'
11
+ static system = 'aerospike'
12
+ static prefix = 'tracing:apm:aerospike:command'
15
13
 
16
- static get peerServicePrecursors () {
17
- return [AEROSPIKE_PEER_SERVICE]
18
- }
14
+ static peerServicePrecursors = [AEROSPIKE_PEER_SERVICE]
19
15
 
20
16
  bindStart (ctx) {
21
17
  const { commandName, commandArgs } = ctx
@@ -68,8 +64,12 @@ class AerospikePlugin extends DatabasePlugin {
68
64
  function getMeta (resourceName, commandArgs) {
69
65
  let meta = {}
70
66
  if (resourceName.includes('Index')) {
71
- const [ns, set, bin, index] = commandArgs
72
- meta = getMetaForIndex(ns, set, bin, index)
67
+ const [ns, set, bin, exp, index] = commandArgs
68
+
69
+ // The `ext` argument was added to IndexCreate in 6.3.0
70
+ meta = commandArgs.length > 8
71
+ ? getMetaForIndex(ns, set, bin, index)
72
+ : getMetaForIndex(ns, set, bin, exp)
73
73
  } else if (resourceName === 'Query') {
74
74
  const { ns, set } = commandArgs[2]
75
75
  meta = getMetaForQuery({ ns, set })
@@ -0,0 +1,17 @@
1
+ 'use strict'
2
+
3
+ const CompositePlugin = require('../../dd-trace/src/plugins/composite')
4
+ const VercelAILLMObsPlugin = require('../../dd-trace/src/llmobs/plugins/ai')
5
+ const VercelAITracingPlugin = require('./tracing')
6
+
7
+ class VercelAIPlugin extends CompositePlugin {
8
+ static get id () { return 'ai' }
9
+ static get plugins () {
10
+ return {
11
+ llmobs: VercelAILLMObsPlugin,
12
+ tracing: VercelAITracingPlugin
13
+ }
14
+ }
15
+ }
16
+
17
+ module.exports = VercelAIPlugin
@@ -0,0 +1,33 @@
1
+ 'use strict'
2
+
3
+ const TracingPlugin = require('../../dd-trace/src/plugins/tracing')
4
+ const { getModelProvider } = require('./utils')
5
+
6
+ class VercelAITracingPlugin extends TracingPlugin {
7
+ static id = 'ai'
8
+ static prefix = 'tracing:dd-trace:vercel-ai'
9
+
10
+ bindStart (ctx) {
11
+ const attributes = ctx.attributes
12
+
13
+ const model = attributes['ai.model.id']
14
+ const modelProvider = getModelProvider(attributes)
15
+
16
+ this.startSpan(ctx.name, {
17
+ meta: {
18
+ 'resource.name': ctx.name,
19
+ 'ai.request.model': model,
20
+ 'ai.request.model_provider': modelProvider
21
+ }
22
+ }, ctx)
23
+
24
+ return ctx.currentStore
25
+ }
26
+
27
+ asyncEnd (ctx) {
28
+ const span = ctx.currentStore?.span
29
+ span?.finish()
30
+ }
31
+ }
32
+
33
+ module.exports = VercelAITracingPlugin