dd-trace 5.23.1 → 5.24.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 (84) hide show
  1. package/LICENSE-3rdparty.csv +0 -1
  2. package/ext/types.d.ts +1 -0
  3. package/ext/types.js +1 -0
  4. package/index.d.ts +26 -0
  5. package/package.json +6 -7
  6. package/packages/datadog-code-origin/index.js +38 -0
  7. package/packages/datadog-core/index.js +2 -2
  8. package/packages/datadog-instrumentations/src/avsc.js +37 -0
  9. package/packages/datadog-instrumentations/src/azure-functions.js +48 -0
  10. package/packages/datadog-instrumentations/src/child_process.js +17 -8
  11. package/packages/datadog-instrumentations/src/express.js +37 -4
  12. package/packages/datadog-instrumentations/src/fastify.js +12 -1
  13. package/packages/datadog-instrumentations/src/fs.js +27 -7
  14. package/packages/datadog-instrumentations/src/helpers/hooks.js +3 -0
  15. package/packages/datadog-instrumentations/src/jest.js +2 -1
  16. package/packages/datadog-instrumentations/src/mocha/common.js +1 -1
  17. package/packages/datadog-instrumentations/src/mysql2.js +220 -1
  18. package/packages/datadog-instrumentations/src/protobufjs.js +127 -0
  19. package/packages/datadog-instrumentations/src/winston.js +22 -0
  20. package/packages/datadog-plugin-avsc/src/index.js +9 -0
  21. package/packages/datadog-plugin-avsc/src/schema_iterator.js +169 -0
  22. package/packages/datadog-plugin-azure-functions/src/index.js +77 -0
  23. package/packages/datadog-plugin-fastify/src/code_origin.js +31 -0
  24. package/packages/datadog-plugin-fastify/src/index.js +10 -12
  25. package/packages/datadog-plugin-fastify/src/tracing.js +19 -0
  26. package/packages/datadog-plugin-protobufjs/src/index.js +14 -0
  27. package/packages/datadog-plugin-protobufjs/src/schema_iterator.js +180 -0
  28. package/packages/dd-trace/src/appsec/addresses.js +6 -1
  29. package/packages/dd-trace/src/appsec/channels.js +5 -1
  30. package/packages/dd-trace/src/appsec/iast/analyzers/cookie-analyzer.js +13 -1
  31. package/packages/dd-trace/src/appsec/iast/analyzers/path-traversal-analyzer.js +8 -1
  32. package/packages/dd-trace/src/appsec/iast/iast-plugin.js +1 -1
  33. package/packages/dd-trace/src/appsec/iast/index.js +3 -0
  34. package/packages/dd-trace/src/appsec/iast/taint-tracking/csi-methods.js +1 -0
  35. package/packages/dd-trace/src/appsec/iast/taint-tracking/taint-tracking-impl.js +15 -0
  36. package/packages/dd-trace/src/appsec/index.js +58 -43
  37. package/packages/dd-trace/src/appsec/rasp/fs-plugin.js +99 -0
  38. package/packages/dd-trace/src/appsec/rasp/index.js +24 -10
  39. package/packages/dd-trace/src/appsec/rasp/lfi.js +112 -0
  40. package/packages/dd-trace/src/appsec/rasp/sql_injection.js +24 -4
  41. package/packages/dd-trace/src/appsec/rasp/utils.js +2 -1
  42. package/packages/dd-trace/src/appsec/recommended.json +2 -4
  43. package/packages/dd-trace/src/appsec/remote_config/capabilities.js +5 -1
  44. package/packages/dd-trace/src/appsec/remote_config/index.js +8 -0
  45. package/packages/dd-trace/src/appsec/reporter.js +12 -5
  46. package/packages/dd-trace/src/appsec/sdk/track_event.js +5 -0
  47. package/packages/dd-trace/src/appsec/waf/waf_context_wrapper.js +1 -1
  48. package/packages/dd-trace/src/ci-visibility/early-flake-detection/get-known-tests.js +2 -14
  49. package/packages/dd-trace/src/ci-visibility/log-submission/log-submission-plugin.js +53 -0
  50. package/packages/dd-trace/src/config.js +12 -1
  51. package/packages/dd-trace/src/datastreams/schemas/schema_builder.js +25 -17
  52. package/packages/dd-trace/src/debugger/devtools_client/config.js +2 -0
  53. package/packages/dd-trace/src/debugger/devtools_client/index.js +56 -5
  54. package/packages/dd-trace/src/debugger/devtools_client/remote_config.js +4 -4
  55. package/packages/dd-trace/src/debugger/devtools_client/send.js +14 -1
  56. package/packages/dd-trace/src/debugger/devtools_client/snapshot/collector.js +153 -0
  57. package/packages/dd-trace/src/debugger/devtools_client/snapshot/index.js +30 -0
  58. package/packages/dd-trace/src/debugger/devtools_client/snapshot/processor.js +241 -0
  59. package/packages/dd-trace/src/debugger/devtools_client/state.js +10 -4
  60. package/packages/dd-trace/src/exporters/common/request.js +8 -34
  61. package/packages/dd-trace/src/exporters/common/url-to-http-options-polyfill.js +31 -0
  62. package/packages/dd-trace/src/payload-tagging/index.js +1 -1
  63. package/packages/dd-trace/src/payload-tagging/jsonpath-plus.js +2094 -0
  64. package/packages/dd-trace/src/plugin_manager.js +4 -2
  65. package/packages/dd-trace/src/plugins/ci_plugin.js +2 -0
  66. package/packages/dd-trace/src/plugins/index.js +3 -0
  67. package/packages/dd-trace/src/plugins/log_plugin.js +1 -1
  68. package/packages/dd-trace/src/plugins/schema.js +35 -0
  69. package/packages/dd-trace/src/plugins/util/ci.js +23 -1
  70. package/packages/dd-trace/src/plugins/util/serverless.js +7 -0
  71. package/packages/dd-trace/src/plugins/util/stacktrace.js +94 -0
  72. package/packages/dd-trace/src/plugins/util/tags.js +7 -0
  73. package/packages/dd-trace/src/plugins/util/test.js +20 -22
  74. package/packages/dd-trace/src/plugins/util/web.js +6 -4
  75. package/packages/dd-trace/src/profiling/profiler.js +24 -14
  76. package/packages/dd-trace/src/profiling/profilers/events.js +3 -3
  77. package/packages/dd-trace/src/profiling/profilers/wall.js +94 -66
  78. package/packages/dd-trace/src/proxy.js +12 -0
  79. package/packages/dd-trace/src/service-naming/schemas/v0/index.js +2 -1
  80. package/packages/dd-trace/src/service-naming/schemas/v0/serverless.js +12 -0
  81. package/packages/dd-trace/src/service-naming/schemas/v1/index.js +2 -1
  82. package/packages/dd-trace/src/service-naming/schemas/v1/serverless.js +12 -0
  83. package/packages/datadog-core/src/storage/async_resource.js +0 -108
  84. package/packages/datadog-core/src/storage/index.js +0 -5
@@ -14,7 +14,6 @@ require,import-in-the-middle,Apache license 2.0,Copyright 2021 Datadog Inc.
14
14
  require,int64-buffer,MIT,Copyright 2015-2016 Yusuke Kawasaki
15
15
  require,istanbul-lib-coverage,BSD-3-Clause,Copyright 2012-2015 Yahoo! Inc.
16
16
  require,jest-docblock,MIT,Copyright Meta Platforms, Inc. and affiliates.
17
- require,jsonpath-plus,MIT,Copyright (c) 2011-2019 Stefan Goessner, Subbu Allamaraju, Mike Brevoort, Robert Krahn, Brett Zamir, Richard Schneider
18
17
  require,koalas,MIT,Copyright 2013-2017 Brian Woodward
19
18
  require,limiter,MIT,Copyright 2011 John Hurliman
20
19
  require,lodash.sortby,MIT,Copyright JS Foundation and other contributors
package/ext/types.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  declare const types: {
2
2
  HTTP: 'http'
3
+ SERVERLESS: 'serverless'
3
4
  WEB: 'web'
4
5
  }
5
6
 
package/ext/types.js CHANGED
@@ -2,5 +2,6 @@
2
2
 
3
3
  module.exports = {
4
4
  HTTP: 'http',
5
+ SERVERLESS: 'serverless',
5
6
  WEB: 'web'
6
7
  }
package/index.d.ts CHANGED
@@ -147,7 +147,9 @@ interface Plugins {
147
147
  "amqp10": tracer.plugins.amqp10;
148
148
  "amqplib": tracer.plugins.amqplib;
149
149
  "apollo": tracer.plugins.apollo;
150
+ "avsc": tracer.plugins.avsc;
150
151
  "aws-sdk": tracer.plugins.aws_sdk;
152
+ "azure-functions": tracer.plugins.azure_functions;
151
153
  "bunyan": tracer.plugins.bunyan;
152
154
  "cassandra-driver": tracer.plugins.cassandra_driver;
153
155
  "child_process": tracer.plugins.child_process;
@@ -190,6 +192,7 @@ interface Plugins {
190
192
  "playwright": tracer.plugins.playwright;
191
193
  "pg": tracer.plugins.pg;
192
194
  "pino": tracer.plugins.pino;
195
+ "protobufjs": tracer.plugins.protobufjs;
193
196
  "redis": tracer.plugins.redis;
194
197
  "restify": tracer.plugins.restify;
195
198
  "rhea": tracer.plugins.rhea;
@@ -1191,6 +1194,12 @@ declare namespace tracer {
1191
1194
  signature?: boolean;
1192
1195
  }
1193
1196
 
1197
+ /**
1198
+ * This plugin automatically patches the [avsc](https://github.com/mtth/avsc) module
1199
+ * to collect avro message schemas when Datastreams Monitoring is enabled.
1200
+ */
1201
+ interface avsc extends Integration {}
1202
+
1194
1203
  /**
1195
1204
  * This plugin automatically instruments the
1196
1205
  * [aws-sdk](https://github.com/aws/aws-sdk-js) module.
@@ -1229,6 +1238,12 @@ declare namespace tracer {
1229
1238
  [key: string]: boolean | Object | undefined;
1230
1239
  }
1231
1240
 
1241
+ /**
1242
+ * This plugin automatically instruments the
1243
+ * @azure/functions module.
1244
+ */
1245
+ interface azure_functions extends Instrumentation {}
1246
+
1232
1247
  /**
1233
1248
  * This plugin patches the [bunyan](https://github.com/trentm/node-bunyan)
1234
1249
  * to automatically inject trace identifiers in log records when the
@@ -1731,6 +1746,11 @@ declare namespace tracer {
1731
1746
  * on the tracer.
1732
1747
  */
1733
1748
  interface pino extends Integration {}
1749
+ /**
1750
+ * This plugin automatically patches the [protobufjs](https://protobufjs.github.io/protobuf.js/)
1751
+ * to collect protobuf message schemas when Datastreams Monitoring is enabled.
1752
+ */
1753
+ interface protobufjs extends Integration {}
1734
1754
 
1735
1755
  /**
1736
1756
  * This plugin automatically instruments the
@@ -2146,6 +2166,12 @@ declare namespace tracer {
2146
2166
  */
2147
2167
  maxContextOperations?: number,
2148
2168
 
2169
+ /**
2170
+ * Defines the pattern to ignore cookie names in the vulnerability hash calculation
2171
+ * @default ".{32,}"
2172
+ */
2173
+ cookieFilterPattern?: string,
2174
+
2149
2175
  /**
2150
2176
  * Whether to enable vulnerability deduplication
2151
2177
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dd-trace",
3
- "version": "5.23.1",
3
+ "version": "5.24.0",
4
4
  "description": "Datadog APM tracing client for JavaScript",
5
5
  "main": "index.js",
6
6
  "typings": "index.d.ts",
@@ -20,8 +20,8 @@
20
20
  "test:appsec:ci": "nyc --no-clean --include \"packages/dd-trace/src/appsec/**/*.js\" --exclude \"packages/dd-trace/test/appsec/**/*.plugin.spec.js\" -- npm run test:appsec",
21
21
  "test:appsec:plugins": "mocha -r \"packages/dd-trace/test/setup/mocha.js\" \"packages/dd-trace/test/appsec/**/*.@($(echo $PLUGINS)).plugin.spec.js\"",
22
22
  "test:appsec:plugins:ci": "yarn services && nyc --no-clean --include \"packages/dd-trace/src/appsec/**/*.js\" -- npm run test:appsec:plugins",
23
- "test:debugger": "tap packages/dd-trace/test/debugger/**/*.spec.js",
24
- "test:debugger:ci": "npm run test:debugger -- --coverage --nyc-arg=--include=\"packages/dd-trace/src/debugger/**/*.js\"",
23
+ "test:debugger": "mocha -r 'packages/dd-trace/test/setup/mocha.js' 'packages/dd-trace/test/debugger/**/*.spec.js'",
24
+ "test:debugger:ci": "nyc --no-clean --include 'packages/dd-trace/src/debugger/**/*.js' -- npm run test:debugger",
25
25
  "test:trace:core": "tap packages/dd-trace/test/*.spec.js \"packages/dd-trace/test/{ci-visibility,datastreams,encode,exporters,opentelemetry,opentracing,plugins,service-naming,telemetry}/**/*.spec.js\"",
26
26
  "test:trace:core:ci": "npm run test:trace:core -- --coverage --nyc-arg=--include=\"packages/dd-trace/src/**/*.js\"",
27
27
  "test:instrumentations": "mocha -r 'packages/dd-trace/test/setup/mocha.js' 'packages/datadog-instrumentations/test/**/*.spec.js'",
@@ -77,7 +77,7 @@
77
77
  },
78
78
  "dependencies": {
79
79
  "@datadog/native-appsec": "8.1.1",
80
- "@datadog/native-iast-rewriter": "2.4.1",
80
+ "@datadog/native-iast-rewriter": "2.5.0",
81
81
  "@datadog/native-iast-taint-tracking": "3.1.0",
82
82
  "@datadog/native-metrics": "^2.0.0",
83
83
  "@datadog/pprof": "5.3.0",
@@ -91,7 +91,6 @@
91
91
  "int64-buffer": "^0.1.9",
92
92
  "istanbul-lib-coverage": "3.2.0",
93
93
  "jest-docblock": "^29.7.0",
94
- "jsonpath-plus": "^9.0.0",
95
94
  "koalas": "^1.0.2",
96
95
  "limiter": "1.1.5",
97
96
  "lodash.sortby": "^4.7.0",
@@ -114,7 +113,7 @@
114
113
  "aws-sdk": "^2.1446.0",
115
114
  "axios": "^1.7.4",
116
115
  "benchmark": "^2.1.4",
117
- "body-parser": "^1.20.2",
116
+ "body-parser": "^1.20.3",
118
117
  "chai": "^4.3.7",
119
118
  "chalk": "^5.3.0",
120
119
  "checksum": "^1.0.0",
@@ -140,7 +139,7 @@
140
139
  "nyc": "^15.1.0",
141
140
  "proxyquire": "^1.8.0",
142
141
  "rimraf": "^3.0.0",
143
- "sinon": "^15.2.0",
142
+ "sinon": "^16.1.3",
144
143
  "sinon-chai": "^3.7.0",
145
144
  "tap": "^16.3.7",
146
145
  "tiktoken": "^1.0.15"
@@ -0,0 +1,38 @@
1
+ 'use strict'
2
+
3
+ const { getUserLandFrames } = require('../dd-trace/src/plugins/util/stacktrace')
4
+
5
+ const limit = Number(process.env._DD_CODE_ORIGIN_MAX_USER_FRAMES) || 8
6
+
7
+ module.exports = {
8
+ entryTag,
9
+ exitTag
10
+ }
11
+
12
+ function entryTag (topOfStackFunc) {
13
+ return tag('entry', topOfStackFunc)
14
+ }
15
+
16
+ function exitTag (topOfStackFunc) {
17
+ return tag('exit', topOfStackFunc)
18
+ }
19
+
20
+ function tag (type, topOfStackFunc) {
21
+ const frames = getUserLandFrames(topOfStackFunc, limit)
22
+ const tags = {
23
+ '_dd.code_origin.type': type
24
+ }
25
+ for (let i = 0; i < frames.length; i++) {
26
+ const frame = frames[i]
27
+ tags[`_dd.code_origin.frames.${i}.file`] = frame.file
28
+ tags[`_dd.code_origin.frames.${i}.line`] = String(frame.line)
29
+ tags[`_dd.code_origin.frames.${i}.column`] = String(frame.column)
30
+ if (frame.method) {
31
+ tags[`_dd.code_origin.frames.${i}.method`] = frame.method
32
+ }
33
+ if (frame.type) {
34
+ tags[`_dd.code_origin.frames.${i}.type`] = frame.type
35
+ }
36
+ }
37
+ return tags
38
+ }
@@ -1,7 +1,7 @@
1
1
  'use strict'
2
2
 
3
- const LocalStorage = require('./src/storage')
3
+ const { AsyncLocalStorage } = require('async_hooks')
4
4
 
5
- const storage = new LocalStorage()
5
+ const storage = new AsyncLocalStorage()
6
6
 
7
7
  module.exports = { storage }
@@ -0,0 +1,37 @@
1
+ const shimmer = require('../../datadog-shimmer')
2
+ const { addHook } = require('./helpers/instrument')
3
+
4
+ const dc = require('dc-polyfill')
5
+ const serializeChannel = dc.channel('apm:avsc:serialize-start')
6
+ const deserializeChannel = dc.channel('apm:avsc:deserialize-end')
7
+
8
+ function wrapSerialization (Type) {
9
+ shimmer.wrap(Type.prototype, 'toBuffer', original => function () {
10
+ if (!serializeChannel.hasSubscribers) {
11
+ return original.apply(this, arguments)
12
+ }
13
+ serializeChannel.publish({ messageClass: this })
14
+ return original.apply(this, arguments)
15
+ })
16
+ }
17
+
18
+ function wrapDeserialization (Type) {
19
+ shimmer.wrap(Type.prototype, 'fromBuffer', original => function () {
20
+ if (!deserializeChannel.hasSubscribers) {
21
+ return original.apply(this, arguments)
22
+ }
23
+ const result = original.apply(this, arguments)
24
+ deserializeChannel.publish({ messageClass: result })
25
+ return result
26
+ })
27
+ }
28
+
29
+ addHook({
30
+ name: 'avsc',
31
+ versions: ['>=5.0.0']
32
+ }, avro => {
33
+ wrapDeserialization(avro.Type)
34
+ wrapSerialization(avro.Type)
35
+
36
+ return avro
37
+ })
@@ -0,0 +1,48 @@
1
+ 'use strict'
2
+
3
+ const {
4
+ addHook
5
+ } = require('./helpers/instrument')
6
+ const shimmer = require('../../datadog-shimmer')
7
+ const dc = require('dc-polyfill')
8
+
9
+ const azureFunctionsChannel = dc.tracingChannel('datadog:azure-functions:invoke')
10
+
11
+ addHook({ name: '@azure/functions', versions: ['>=4'] }, azureFunction => {
12
+ const { app } = azureFunction
13
+
14
+ shimmer.wrap(app, 'deleteRequest', wrapHandler)
15
+ shimmer.wrap(app, 'http', wrapHandler)
16
+ shimmer.wrap(app, 'get', wrapHandler)
17
+ shimmer.wrap(app, 'patch', wrapHandler)
18
+ shimmer.wrap(app, 'post', wrapHandler)
19
+ shimmer.wrap(app, 'put', wrapHandler)
20
+
21
+ return azureFunction
22
+ })
23
+
24
+ // The http methods are overloaded so we need to check which type of argument was passed in order to wrap the handler
25
+ // The arguments are either an object with a handler property or the handler function itself
26
+ function wrapHandler (method) {
27
+ return function (name, arg) {
28
+ if (typeof arg === 'object' && arg.hasOwnProperty('handler')) {
29
+ const options = arg
30
+ shimmer.wrap(options, 'handler', handler => traceHandler(handler, name, method.name))
31
+ } else if (typeof arg === 'function') {
32
+ const handler = arg
33
+ arguments[1] = shimmer.wrapFunction(handler, handler => traceHandler(handler, name, method.name))
34
+ }
35
+ return method.apply(this, arguments)
36
+ }
37
+ }
38
+
39
+ function traceHandler (handler, functionName, methodName) {
40
+ return function (...args) {
41
+ const httpRequest = args[0]
42
+ const invocationContext = args[1]
43
+ return azureFunctionsChannel.tracePromise(
44
+ handler,
45
+ { functionName, httpRequest, invocationContext, methodName },
46
+ this, ...args)
47
+ }
48
+ }
@@ -61,14 +61,17 @@ function wrapChildProcessSyncMethod (shell = false) {
61
61
 
62
62
  const childProcessInfo = normalizeArgs(arguments, shell)
63
63
 
64
- return childProcessChannel.traceSync(
65
- childProcessMethod,
66
- {
67
- command: childProcessInfo.command,
68
- shell: childProcessInfo.shell
69
- },
70
- this,
71
- ...arguments)
64
+ const innerResource = new AsyncResource('bound-anonymous-fn')
65
+ return innerResource.runInAsyncScope(() => {
66
+ return childProcessChannel.traceSync(
67
+ childProcessMethod,
68
+ {
69
+ command: childProcessInfo.command,
70
+ shell: childProcessInfo.shell
71
+ },
72
+ this,
73
+ ...arguments)
74
+ })
72
75
  }
73
76
  }
74
77
  }
@@ -101,6 +104,12 @@ function wrapChildProcessAsyncMethod (shell = false) {
101
104
 
102
105
  const childProcessInfo = normalizeArgs(arguments, shell)
103
106
 
107
+ const cb = arguments[arguments.length - 1]
108
+ if (typeof cb === 'function') {
109
+ const callbackResource = new AsyncResource('bound-anonymous-fn')
110
+ arguments[arguments.length - 1] = callbackResource.bind(cb)
111
+ }
112
+
104
113
  const innerResource = new AsyncResource('bound-anonymous-fn')
105
114
  return innerResource.runInAsyncScope(() => {
106
115
  childProcessChannel.start.publish({ command: childProcessInfo.command, shell: childProcessInfo.shell })
@@ -3,6 +3,7 @@
3
3
  const { createWrapRouterMethod } = require('./router')
4
4
  const shimmer = require('../../datadog-shimmer')
5
5
  const { addHook, channel } = require('./helpers/instrument')
6
+ const tracingChannel = require('dc-polyfill').tracingChannel
6
7
 
7
8
  const handleChannel = channel('apm:express:request:handle')
8
9
 
@@ -35,6 +36,27 @@ function wrapResponseJson (json) {
35
36
  }
36
37
  }
37
38
 
39
+ const responseRenderChannel = tracingChannel('datadog:express:response:render')
40
+
41
+ function wrapResponseRender (render) {
42
+ return function wrappedRender (view, options, callback) {
43
+ if (!responseRenderChannel.start.hasSubscribers) {
44
+ return render.apply(this, arguments)
45
+ }
46
+
47
+ return responseRenderChannel.traceSync(
48
+ render,
49
+ {
50
+ req: this.req,
51
+ view,
52
+ options
53
+ },
54
+ this,
55
+ ...arguments
56
+ )
57
+ }
58
+ }
59
+
38
60
  addHook({ name: 'express', versions: ['>=4'] }, express => {
39
61
  shimmer.wrap(express.application, 'handle', wrapHandle)
40
62
  shimmer.wrap(express.Router, 'use', wrapRouterMethod)
@@ -42,6 +64,7 @@ addHook({ name: 'express', versions: ['>=4'] }, express => {
42
64
 
43
65
  shimmer.wrap(express.response, 'json', wrapResponseJson)
44
66
  shimmer.wrap(express.response, 'jsonp', wrapResponseJson)
67
+ shimmer.wrap(express.response, 'render', wrapResponseRender)
45
68
 
46
69
  return express
47
70
  })
@@ -79,11 +102,21 @@ addHook({
79
102
  })
80
103
 
81
104
  const processParamsStartCh = channel('datadog:express:process_params:start')
82
- const wrapProcessParamsMethod = (requestPositionInArguments) => {
83
- return (original) => {
84
- return function () {
105
+ function wrapProcessParamsMethod (requestPositionInArguments) {
106
+ return function wrapProcessParams (original) {
107
+ return function wrappedProcessParams () {
85
108
  if (processParamsStartCh.hasSubscribers) {
86
- processParamsStartCh.publish({ req: arguments[requestPositionInArguments] })
109
+ const req = arguments[requestPositionInArguments]
110
+ const abortController = new AbortController()
111
+
112
+ processParamsStartCh.publish({
113
+ req,
114
+ res: req?.res,
115
+ abortController,
116
+ params: req?.params
117
+ })
118
+
119
+ if (abortController.signal.aborted) return
87
120
  }
88
121
 
89
122
  return original.apply(this, arguments)
@@ -5,6 +5,7 @@ const { addHook, channel, AsyncResource } = require('./helpers/instrument')
5
5
 
6
6
  const errorChannel = channel('apm:fastify:middleware:error')
7
7
  const handleChannel = channel('apm:fastify:request:handle')
8
+ const routeAddedChannel = channel('apm:fastify:route:added')
8
9
 
9
10
  const parsingResources = new WeakMap()
10
11
 
@@ -16,6 +17,7 @@ function wrapFastify (fastify, hasParsingEvents) {
16
17
 
17
18
  if (!app || typeof app.addHook !== 'function') return app
18
19
 
20
+ app.addHook('onRoute', onRoute)
19
21
  app.addHook('onRequest', onRequest)
20
22
  app.addHook('preHandler', preHandler)
21
23
 
@@ -86,8 +88,9 @@ function onRequest (request, reply, done) {
86
88
 
87
89
  const req = getReq(request)
88
90
  const res = getRes(reply)
91
+ const routeConfig = getRouteConfig(request)
89
92
 
90
- handleChannel.publish({ req, res })
93
+ handleChannel.publish({ req, res, routeConfig })
91
94
 
92
95
  return done()
93
96
  }
@@ -142,6 +145,10 @@ function getRes (reply) {
142
145
  return reply && (reply.raw || reply.res || reply)
143
146
  }
144
147
 
148
+ function getRouteConfig (request) {
149
+ return request?.routeOptions?.config
150
+ }
151
+
145
152
  function publishError (error, req) {
146
153
  if (error) {
147
154
  errorChannel.publish({ error, req })
@@ -150,6 +157,10 @@ function publishError (error, req) {
150
157
  return error
151
158
  }
152
159
 
160
+ function onRoute (routeOptions) {
161
+ routeAddedChannel.publish({ routeOptions, onRoute })
162
+ }
163
+
153
164
  addHook({ name: 'fastify', versions: ['>=3'] }, fastify => {
154
165
  const wrapped = shimmer.wrapFunction(fastify, fastify => wrapFastify(fastify, true))
155
166
 
@@ -266,24 +266,44 @@ function createWrapFunction (prefix = '', override = '') {
266
266
  const lastIndex = arguments.length - 1
267
267
  const cb = typeof arguments[lastIndex] === 'function' && arguments[lastIndex]
268
268
  const innerResource = new AsyncResource('bound-anonymous-fn')
269
- const message = getMessage(method, getMethodParamsRelationByPrefix(prefix)[operation], arguments, this)
269
+ const params = getMethodParamsRelationByPrefix(prefix)[operation]
270
+ const abortController = new AbortController()
271
+ const message = { ...getMessage(method, params, arguments, this), abortController }
272
+
273
+ const finish = innerResource.bind(function (error) {
274
+ if (error !== null && typeof error === 'object') { // fs.exists receives a boolean
275
+ errorChannel.publish(error)
276
+ }
277
+ finishChannel.publish()
278
+ })
270
279
 
271
280
  if (cb) {
272
281
  const outerResource = new AsyncResource('bound-anonymous-fn')
273
282
 
274
283
  arguments[lastIndex] = shimmer.wrapFunction(cb, cb => innerResource.bind(function (e) {
275
- if (e !== null && typeof e === 'object') { // fs.exists receives a boolean
276
- errorChannel.publish(e)
277
- }
278
-
279
- finishChannel.publish()
280
-
284
+ finish(e)
281
285
  return outerResource.runInAsyncScope(() => cb.apply(this, arguments))
282
286
  }))
283
287
  }
284
288
 
285
289
  return innerResource.runInAsyncScope(() => {
286
290
  startChannel.publish(message)
291
+
292
+ if (abortController.signal.aborted) {
293
+ const error = abortController.signal.reason || new Error('Aborted')
294
+
295
+ if (prefix === 'promises.') {
296
+ finish(error)
297
+ return Promise.reject(error)
298
+ } else if (name.includes('Sync') || !cb) {
299
+ finish(error)
300
+ throw error
301
+ } else if (cb) {
302
+ arguments[lastIndex](error)
303
+ return
304
+ }
305
+ }
306
+
287
307
  try {
288
308
  const result = original.apply(this, arguments)
289
309
  if (cb) return result
@@ -5,6 +5,7 @@ module.exports = {
5
5
  '@apollo/gateway': () => require('../apollo'),
6
6
  'apollo-server-core': () => require('../apollo-server-core'),
7
7
  '@aws-sdk/smithy-client': () => require('../aws-sdk'),
8
+ '@azure/functions': () => require('../azure-functions'),
8
9
  '@cucumber/cucumber': () => require('../cucumber'),
9
10
  '@playwright/test': () => require('../playwright'),
10
11
  '@elastic/elasticsearch': () => require('../elasticsearch'),
@@ -27,6 +28,7 @@ module.exports = {
27
28
  aerospike: () => require('../aerospike'),
28
29
  amqp10: () => require('../amqp10'),
29
30
  amqplib: () => require('../amqplib'),
31
+ avsc: () => require('../avsc'),
30
32
  'aws-sdk': () => require('../aws-sdk'),
31
33
  bluebird: () => require('../bluebird'),
32
34
  'body-parser': () => require('../body-parser'),
@@ -100,6 +102,7 @@ module.exports = {
100
102
  playwright: () => require('../playwright'),
101
103
  'promise-js': () => require('../promise-js'),
102
104
  promise: () => require('../promise'),
105
+ protobufjs: () => require('../protobufjs'),
103
106
  q: () => require('../q'),
104
107
  qs: () => require('../qs'),
105
108
  redis: () => require('../redis'),
@@ -850,7 +850,8 @@ addHook({
850
850
  }, jestConfigSyncWrapper)
851
851
 
852
852
  const LIBRARIES_BYPASSING_JEST_REQUIRE_ENGINE = [
853
- 'selenium-webdriver'
853
+ 'selenium-webdriver',
854
+ 'winston'
854
855
  ]
855
856
 
856
857
  function shouldBypassJestRequireEngine (moduleName) {
@@ -1,6 +1,6 @@
1
1
  const { addHook, channel } = require('../helpers/instrument')
2
2
  const shimmer = require('../../../datadog-shimmer')
3
- const { getCallSites } = require('../../../dd-trace/src/plugins/util/test')
3
+ const { getCallSites } = require('../../../dd-trace/src/plugins/util/stacktrace')
4
4
  const { testToStartLine } = require('./utils')
5
5
 
6
6
  const parameterizedTestCh = channel('ci:mocha:test:parameterize')