dd-trace 4.45.0 → 4.47.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 (153) hide show
  1. package/LICENSE-3rdparty.csv +2 -0
  2. package/index.d.ts +20 -8
  3. package/package.json +11 -5
  4. package/packages/datadog-instrumentations/src/aerospike.js +1 -1
  5. package/packages/datadog-instrumentations/src/apollo-server.js +1 -1
  6. package/packages/datadog-instrumentations/src/aws-sdk.js +4 -4
  7. package/packages/datadog-instrumentations/src/body-parser.js +4 -4
  8. package/packages/datadog-instrumentations/src/cassandra-driver.js +2 -2
  9. package/packages/datadog-instrumentations/src/child_process.js +2 -2
  10. package/packages/datadog-instrumentations/src/connect.js +4 -4
  11. package/packages/datadog-instrumentations/src/cookie-parser.js +4 -4
  12. package/packages/datadog-instrumentations/src/couchbase.js +12 -12
  13. package/packages/datadog-instrumentations/src/cucumber.js +294 -56
  14. package/packages/datadog-instrumentations/src/dns.js +10 -10
  15. package/packages/datadog-instrumentations/src/elasticsearch.js +4 -4
  16. package/packages/datadog-instrumentations/src/express-mongo-sanitize.js +3 -3
  17. package/packages/datadog-instrumentations/src/express.js +4 -4
  18. package/packages/datadog-instrumentations/src/fastify.js +6 -6
  19. package/packages/datadog-instrumentations/src/fetch.js +1 -1
  20. package/packages/datadog-instrumentations/src/find-my-way.js +2 -2
  21. package/packages/datadog-instrumentations/src/fs.js +2 -2
  22. package/packages/datadog-instrumentations/src/google-cloud-pubsub.js +2 -2
  23. package/packages/datadog-instrumentations/src/grpc/client.js +4 -6
  24. package/packages/datadog-instrumentations/src/grpc/server.js +2 -2
  25. package/packages/datadog-instrumentations/src/hapi.js +10 -13
  26. package/packages/datadog-instrumentations/src/helpers/register.js +1 -1
  27. package/packages/datadog-instrumentations/src/http/client.js +3 -3
  28. package/packages/datadog-instrumentations/src/jest.js +8 -5
  29. package/packages/datadog-instrumentations/src/kafkajs.js +67 -31
  30. package/packages/datadog-instrumentations/src/knex.js +2 -2
  31. package/packages/datadog-instrumentations/src/koa.js +5 -5
  32. package/packages/datadog-instrumentations/src/ldapjs.js +1 -1
  33. package/packages/datadog-instrumentations/src/mariadb.js +8 -8
  34. package/packages/datadog-instrumentations/src/memcached.js +2 -2
  35. package/packages/datadog-instrumentations/src/microgateway-core.js +7 -5
  36. package/packages/datadog-instrumentations/src/mocha/common.js +1 -1
  37. package/packages/datadog-instrumentations/src/mocha/main.js +139 -53
  38. package/packages/datadog-instrumentations/src/mocha/utils.js +37 -18
  39. package/packages/datadog-instrumentations/src/mocha/worker.js +29 -1
  40. package/packages/datadog-instrumentations/src/mocha.js +4 -0
  41. package/packages/datadog-instrumentations/src/moleculer/server.js +2 -2
  42. package/packages/datadog-instrumentations/src/mongodb-core.js +7 -7
  43. package/packages/datadog-instrumentations/src/mongoose.js +5 -6
  44. package/packages/datadog-instrumentations/src/mysql.js +3 -3
  45. package/packages/datadog-instrumentations/src/mysql2.js +6 -6
  46. package/packages/datadog-instrumentations/src/net.js +2 -2
  47. package/packages/datadog-instrumentations/src/next.js +5 -5
  48. package/packages/datadog-instrumentations/src/openai.js +62 -71
  49. package/packages/datadog-instrumentations/src/oracledb.js +8 -8
  50. package/packages/datadog-instrumentations/src/passport-http.js +1 -1
  51. package/packages/datadog-instrumentations/src/passport-local.js +1 -1
  52. package/packages/datadog-instrumentations/src/passport-utils.js +1 -1
  53. package/packages/datadog-instrumentations/src/pg.js +60 -5
  54. package/packages/datadog-instrumentations/src/pino.js +4 -4
  55. package/packages/datadog-instrumentations/src/playwright.js +6 -4
  56. package/packages/datadog-instrumentations/src/redis.js +2 -2
  57. package/packages/datadog-instrumentations/src/restify.js +4 -4
  58. package/packages/datadog-instrumentations/src/rhea.js +4 -4
  59. package/packages/datadog-instrumentations/src/router.js +5 -5
  60. package/packages/datadog-instrumentations/src/sharedb.js +2 -2
  61. package/packages/datadog-instrumentations/src/vitest.js +188 -12
  62. package/packages/datadog-instrumentations/src/winston.js +2 -3
  63. package/packages/datadog-plugin-amqplib/src/consumer.js +1 -3
  64. package/packages/datadog-plugin-aws-sdk/src/base.js +33 -0
  65. package/packages/datadog-plugin-aws-sdk/src/services/kinesis.js +1 -1
  66. package/packages/datadog-plugin-aws-sdk/src/services/sns.js +2 -0
  67. package/packages/datadog-plugin-aws-sdk/src/services/sqs.js +1 -1
  68. package/packages/datadog-plugin-cucumber/src/index.js +24 -1
  69. package/packages/datadog-plugin-cypress/src/cypress-plugin.js +39 -10
  70. package/packages/datadog-plugin-cypress/src/support.js +4 -1
  71. package/packages/datadog-plugin-hapi/src/index.js +2 -2
  72. package/packages/datadog-plugin-http/src/client.js +1 -42
  73. package/packages/datadog-plugin-http2/src/client.js +1 -26
  74. package/packages/datadog-plugin-jest/src/index.js +18 -1
  75. package/packages/datadog-plugin-kafkajs/src/batch-consumer.js +20 -0
  76. package/packages/datadog-plugin-kafkajs/src/consumer.js +1 -2
  77. package/packages/datadog-plugin-kafkajs/src/index.js +3 -1
  78. package/packages/datadog-plugin-mocha/src/index.js +18 -0
  79. package/packages/datadog-plugin-openai/src/index.js +85 -65
  80. package/packages/datadog-plugin-playwright/src/index.js +9 -0
  81. package/packages/datadog-plugin-rhea/src/consumer.js +1 -3
  82. package/packages/datadog-plugin-vitest/src/index.js +68 -3
  83. package/packages/datadog-shimmer/src/shimmer.js +144 -10
  84. package/packages/dd-trace/src/appsec/addresses.js +3 -1
  85. package/packages/dd-trace/src/appsec/blocking.js +23 -17
  86. package/packages/dd-trace/src/appsec/channels.js +4 -2
  87. package/packages/dd-trace/src/appsec/graphql.js +3 -1
  88. package/packages/dd-trace/src/appsec/iast/iast-log.js +2 -1
  89. package/packages/dd-trace/src/appsec/rasp/index.js +103 -0
  90. package/packages/dd-trace/src/appsec/rasp/sql_injection.js +86 -0
  91. package/packages/dd-trace/src/appsec/rasp/ssrf.js +37 -0
  92. package/packages/dd-trace/src/appsec/rasp/utils.js +63 -0
  93. package/packages/dd-trace/src/appsec/remote_config/capabilities.js +2 -0
  94. package/packages/dd-trace/src/appsec/remote_config/index.js +16 -7
  95. package/packages/dd-trace/src/appsec/remote_config/manager.js +93 -52
  96. package/packages/dd-trace/src/appsec/rule_manager.js +8 -0
  97. package/packages/dd-trace/src/appsec/telemetry.js +3 -3
  98. package/packages/dd-trace/src/appsec/waf/waf_context_wrapper.js +33 -14
  99. package/packages/dd-trace/src/appsec/waf/waf_manager.js +2 -1
  100. package/packages/dd-trace/src/ci-visibility/exporters/agentless/writer.js +4 -0
  101. package/packages/dd-trace/src/ci-visibility/exporters/ci-visibility-exporter.js +15 -1
  102. package/packages/dd-trace/src/config.js +100 -40
  103. package/packages/dd-trace/src/constants.js +11 -1
  104. package/packages/dd-trace/src/data_streams_context.js +3 -0
  105. package/packages/dd-trace/src/datastreams/fnv.js +23 -0
  106. package/packages/dd-trace/src/datastreams/pathway.js +12 -5
  107. package/packages/dd-trace/src/datastreams/processor.js +35 -0
  108. package/packages/dd-trace/src/datastreams/schemas/schema.js +8 -0
  109. package/packages/dd-trace/src/datastreams/schemas/schema_builder.js +125 -0
  110. package/packages/dd-trace/src/datastreams/schemas/schema_sampler.js +29 -0
  111. package/packages/dd-trace/src/debugger/devtools_client/config.js +24 -0
  112. package/packages/dd-trace/src/debugger/devtools_client/index.js +57 -0
  113. package/packages/dd-trace/src/debugger/devtools_client/inspector_promises_polyfill.js +23 -0
  114. package/packages/dd-trace/src/debugger/devtools_client/remote_config.js +164 -0
  115. package/packages/dd-trace/src/debugger/devtools_client/send.js +28 -0
  116. package/packages/dd-trace/src/debugger/devtools_client/session.js +7 -0
  117. package/packages/dd-trace/src/debugger/devtools_client/state.js +47 -0
  118. package/packages/dd-trace/src/debugger/devtools_client/status.js +109 -0
  119. package/packages/dd-trace/src/debugger/index.js +92 -0
  120. package/packages/dd-trace/src/encode/agentless-ci-visibility.js +29 -2
  121. package/packages/dd-trace/src/exporters/common/request.js +1 -1
  122. package/packages/dd-trace/src/lambda/handler.js +1 -0
  123. package/packages/dd-trace/src/lambda/index.js +12 -1
  124. package/packages/dd-trace/src/opentracing/propagation/text_map.js +1 -6
  125. package/packages/dd-trace/src/payload-tagging/config/aws.json +30 -0
  126. package/packages/dd-trace/src/payload-tagging/config/index.js +30 -0
  127. package/packages/dd-trace/src/payload-tagging/index.js +93 -0
  128. package/packages/dd-trace/src/payload-tagging/tagging.js +83 -0
  129. package/packages/dd-trace/src/plugin_manager.js +11 -10
  130. package/packages/dd-trace/src/plugins/ci_plugin.js +33 -8
  131. package/packages/dd-trace/src/plugins/util/env.js +5 -2
  132. package/packages/dd-trace/src/plugins/util/test.js +24 -4
  133. package/packages/dd-trace/src/profiler.js +15 -5
  134. package/packages/dd-trace/src/profiling/config.js +7 -4
  135. package/packages/dd-trace/src/profiling/exporter_cli.js +13 -1
  136. package/packages/dd-trace/src/profiling/exporters/agent.js +8 -2
  137. package/packages/dd-trace/src/profiling/profiler.js +0 -9
  138. package/packages/dd-trace/src/profiling/profilers/event_plugins/dns.js +13 -0
  139. package/packages/dd-trace/src/profiling/profilers/event_plugins/dns_lookup.js +16 -0
  140. package/packages/dd-trace/src/profiling/profilers/event_plugins/dns_lookupservice.js +16 -0
  141. package/packages/dd-trace/src/profiling/profilers/event_plugins/dns_resolve.js +24 -0
  142. package/packages/dd-trace/src/profiling/profilers/event_plugins/dns_reverse.js +16 -0
  143. package/packages/dd-trace/src/profiling/profilers/event_plugins/event.js +48 -0
  144. package/packages/dd-trace/src/profiling/profilers/event_plugins/net.js +24 -0
  145. package/packages/dd-trace/src/profiling/profilers/events.js +108 -32
  146. package/packages/dd-trace/src/profiling/profilers/shared.js +5 -0
  147. package/packages/dd-trace/src/profiling/profilers/wall.js +9 -3
  148. package/packages/dd-trace/src/profiling/ssi-heuristics.js +59 -60
  149. package/packages/dd-trace/src/proxy.js +31 -24
  150. package/packages/dd-trace/src/span_stats.js +4 -2
  151. package/packages/dd-trace/src/telemetry/index.js +23 -6
  152. package/packages/dd-trace/src/telemetry/logs/index.js +20 -0
  153. package/packages/dd-trace/src/appsec/rasp.js +0 -176
@@ -14,6 +14,7 @@ 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
17
18
  require,koalas,MIT,Copyright 2013-2017 Brian Woodward
18
19
  require,limiter,MIT,Copyright 2011 John Hurliman
19
20
  require,lodash.sortby,MIT,Copyright JS Foundation and other contributors
@@ -26,6 +27,7 @@ require,pprof-format,MIT,Copyright 2022 Stephen Belanger
26
27
  require,protobufjs,BSD-3-Clause,Copyright 2016 Daniel Wirtz
27
28
  require,tlhunter-sorted-set,MIT,Copyright (c) 2023 Datadog Inc.
28
29
  require,retry,MIT,Copyright 2011 Tim Koschützki Felix Geisendörfer
30
+ require,rfdc,MIT,Copyright 2019 David Mark Clements
29
31
  require,semver,ISC,Copyright Isaac Z. Schlueter and Contributors
30
32
  require,shell-quote,mit,Copyright (c) 2013 James Halliday
31
33
  dev,@types/node,MIT,Copyright Authors
package/index.d.ts CHANGED
@@ -729,6 +729,26 @@ declare namespace tracer {
729
729
  * The selection and priority order of context propagation injection and extraction mechanisms.
730
730
  */
731
731
  propagationStyle?: string[] | PropagationStyle
732
+
733
+ /**
734
+ * Cloud payload report as tags
735
+ */
736
+ cloudPayloadTagging?: {
737
+ /**
738
+ * Additional JSONPath queries to replace with `redacted` in request payloads
739
+ * Undefined or invalid JSONPath queries disable the feature for requests.
740
+ */
741
+ request?: string,
742
+ /**
743
+ * Additional JSONPath queries to replace with `redacted` in response payloads
744
+ * Undefined or invalid JSONPath queries disable the feature for responses.
745
+ */
746
+ response?: string,
747
+ /**
748
+ * Maximum depth of payload traversal for tags
749
+ */
750
+ maxDepth?: number
751
+ }
732
752
  }
733
753
 
734
754
  /**
@@ -1010,14 +1030,6 @@ declare namespace tracer {
1010
1030
  * @default code => code < 500
1011
1031
  */
1012
1032
  validateStatus?: (code: number) => boolean;
1013
-
1014
- /**
1015
- * Enable injection of tracing headers into requests signed with AWS IAM headers.
1016
- * Disable this if you get AWS signature errors (HTTP 403).
1017
- *
1018
- * @default false
1019
- */
1020
- enablePropagationWithAmazonHeaders?: boolean;
1021
1033
  }
1022
1034
 
1023
1035
  /** @hidden */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dd-trace",
3
- "version": "4.45.0",
3
+ "version": "4.47.0",
4
4
  "description": "Datadog APM tracing client for JavaScript",
5
5
  "main": "index.js",
6
6
  "typings": "index.d.ts",
@@ -13,12 +13,15 @@
13
13
  "type:doc": "cd docs && yarn && yarn build",
14
14
  "type:test": "cd docs && yarn && yarn test",
15
15
  "lint": "node scripts/check_licenses.js && eslint . && yarn audit --groups dependencies",
16
+ "lint-fix": "node scripts/check_licenses.js && eslint . --fix && yarn audit --groups dependencies",
16
17
  "services": "node ./scripts/install_plugin_modules && node packages/dd-trace/test/setup/services",
17
18
  "test": "SERVICES=* yarn services && mocha --expose-gc 'packages/dd-trace/test/setup/node.js' 'packages/*/test/**/*.spec.js'",
18
19
  "test:appsec": "mocha -r \"packages/dd-trace/test/setup/mocha.js\" --exclude \"packages/dd-trace/test/appsec/**/*.plugin.spec.js\" \"packages/dd-trace/test/appsec/**/*.spec.js\"",
19
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",
20
21
  "test:appsec:plugins": "mocha -r \"packages/dd-trace/test/setup/mocha.js\" \"packages/dd-trace/test/appsec/**/*.@($(echo $PLUGINS)).plugin.spec.js\"",
21
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\"",
22
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\"",
23
26
  "test:trace:core:ci": "npm run test:trace:core -- --coverage --nyc-arg=--include=\"packages/dd-trace/src/**/*.js\"",
24
27
  "test:instrumentations": "mocha -r 'packages/dd-trace/test/setup/mocha.js' 'packages/datadog-instrumentations/test/**/*.spec.js'",
@@ -36,6 +39,7 @@
36
39
  "test:integration:appsec": "mocha --timeout 60000 -r \"packages/dd-trace/test/setup/core.js\" \"integration-tests/appsec/*.spec.js\"",
37
40
  "test:integration:cucumber": "mocha --timeout 60000 -r \"packages/dd-trace/test/setup/core.js\" \"integration-tests/cucumber/*.spec.js\"",
38
41
  "test:integration:cypress": "mocha --timeout 60000 -r \"packages/dd-trace/test/setup/core.js\" \"integration-tests/cypress/*.spec.js\"",
42
+ "test:integration:debugger": "mocha --timeout 60000 -r \"packages/dd-trace/test/setup/core.js\" \"integration-tests/debugger/*.spec.js\"",
39
43
  "test:integration:jest": "mocha --timeout 60000 -r \"packages/dd-trace/test/setup/core.js\" \"integration-tests/jest/*.spec.js\"",
40
44
  "test:integration:mocha": "mocha --timeout 60000 -r \"packages/dd-trace/test/setup/core.js\" \"integration-tests/mocha/*.spec.js\"",
41
45
  "test:integration:playwright": "mocha --timeout 60000 -r \"packages/dd-trace/test/setup/core.js\" \"integration-tests/playwright/*.spec.js\"",
@@ -72,7 +76,7 @@
72
76
  "node": ">=16"
73
77
  },
74
78
  "dependencies": {
75
- "@datadog/native-appsec": "8.0.1",
79
+ "@datadog/native-appsec": "8.1.1",
76
80
  "@datadog/native-iast-rewriter": "2.4.1",
77
81
  "@datadog/native-iast-taint-tracking": "3.1.0",
78
82
  "@datadog/native-metrics": "^2.0.0",
@@ -83,10 +87,11 @@
83
87
  "crypto-randomuuid": "^1.0.0",
84
88
  "dc-polyfill": "^0.1.4",
85
89
  "ignore": "^5.2.4",
86
- "import-in-the-middle": "^1.8.1",
90
+ "import-in-the-middle": "1.11.2",
87
91
  "int64-buffer": "^0.1.9",
88
92
  "istanbul-lib-coverage": "3.2.0",
89
93
  "jest-docblock": "^29.7.0",
94
+ "jsonpath-plus": "^9.0.0",
90
95
  "koalas": "^1.0.2",
91
96
  "limiter": "1.1.5",
92
97
  "lodash.sortby": "^4.7.0",
@@ -94,10 +99,11 @@
94
99
  "module-details-from-path": "^1.0.3",
95
100
  "msgpack-lite": "^0.1.26",
96
101
  "opentracing": ">=0.12.1",
97
- "path-to-regexp": "^0.1.2",
102
+ "path-to-regexp": "^0.1.10",
98
103
  "pprof-format": "^2.1.0",
99
104
  "protobufjs": "^7.2.5",
100
105
  "retry": "^0.13.1",
106
+ "rfdc": "^1.3.1",
101
107
  "semver": "^7.5.4",
102
108
  "shell-quote": "^1.8.1",
103
109
  "tlhunter-sorted-set": "^0.1.0"
@@ -106,7 +112,7 @@
106
112
  "@types/node": ">=16",
107
113
  "autocannon": "^4.5.2",
108
114
  "aws-sdk": "^2.1446.0",
109
- "axios": "^1.6.7",
115
+ "axios": "^1.7.4",
110
116
  "benchmark": "^2.1.4",
111
117
  "body-parser": "^1.20.2",
112
118
  "chai": "^4.3.7",
@@ -43,5 +43,5 @@ addHook({
43
43
  versions: ['^3.16.2', '4', '5']
44
44
  },
45
45
  commandFactory => {
46
- return shimmer.wrap(commandFactory, wrapCreateCommand(commandFactory))
46
+ return shimmer.wrapFunction(commandFactory, f => wrapCreateCommand(f))
47
47
  })
@@ -55,7 +55,7 @@ function apolloExpress4Hook (express4) {
55
55
  return function expressMiddleware (server, options) {
56
56
  const originalMiddleware = originalExpressMiddleware.apply(this, arguments)
57
57
 
58
- return shimmer.wrap(originalMiddleware, function (req, res, next) {
58
+ return shimmer.wrapFunction(originalMiddleware, originalMiddleware => function (req, res, next) {
59
59
  if (!graphqlMiddlewareChannel.start.hasSubscribers) {
60
60
  return originalMiddleware.apply(this, arguments)
61
61
  }
@@ -75,7 +75,7 @@ function wrapSmithySend (send) {
75
75
  })
76
76
 
77
77
  if (typeof cb === 'function') {
78
- args[args.length - 1] = function (err, result) {
78
+ args[args.length - 1] = shimmer.wrapFunction(cb, cb => function (err, result) {
79
79
  const message = getMessage(request, err, result)
80
80
 
81
81
  completeChannel.publish(message)
@@ -89,7 +89,7 @@ function wrapSmithySend (send) {
89
89
  responseFinishChannel.publish(message.response.error)
90
90
  }
91
91
  })
92
- }
92
+ })
93
93
  } else { // always a promise
94
94
  return send.call(this, command, ...args)
95
95
  .then(
@@ -113,7 +113,7 @@ function wrapSmithySend (send) {
113
113
 
114
114
  function wrapCb (cb, serviceName, request, ar) {
115
115
  // eslint-disable-next-line n/handle-callback-err
116
- return function wrappedCb (err, response) {
116
+ return shimmer.wrapFunction(cb, cb => function wrappedCb (err, response) {
117
117
  const obj = { request, response }
118
118
  return ar.runInAsyncScope(() => {
119
119
  channel(`apm:aws:response:start:${serviceName}`).publish(obj)
@@ -141,7 +141,7 @@ function wrapCb (cb, serviceName, request, ar) {
141
141
  throw e
142
142
  }
143
143
  })
144
- }
144
+ })
145
145
  }
146
146
 
147
147
  function getMessage (request, error, result) {
@@ -6,7 +6,7 @@ const { channel, addHook, AsyncResource } = require('./helpers/instrument')
6
6
  const bodyParserReadCh = channel('datadog:body-parser:read:finish')
7
7
 
8
8
  function publishRequestBodyAndNext (req, res, next) {
9
- return function () {
9
+ return shimmer.wrapFunction(next, next => function () {
10
10
  if (bodyParserReadCh.hasSubscribers && req) {
11
11
  const abortController = new AbortController()
12
12
  const body = req.body
@@ -17,7 +17,7 @@ function publishRequestBodyAndNext (req, res, next) {
17
17
  }
18
18
 
19
19
  return next.apply(this, arguments)
20
- }
20
+ })
21
21
  }
22
22
 
23
23
  addHook({
@@ -25,7 +25,7 @@ addHook({
25
25
  file: 'lib/read.js',
26
26
  versions: ['>=1.4.0 <1.20.0']
27
27
  }, read => {
28
- return shimmer.wrap(read, function (req, res, next) {
28
+ return shimmer.wrapFunction(read, read => function (req, res, next) {
29
29
  const nextResource = new AsyncResource('bound-anonymous-fn')
30
30
  arguments[2] = nextResource.bind(publishRequestBodyAndNext(req, res, next))
31
31
  return read.apply(this, arguments)
@@ -37,7 +37,7 @@ addHook({
37
37
  file: 'lib/read.js',
38
38
  versions: ['>=1.20.0']
39
39
  }, read => {
40
- return shimmer.wrap(read, function (req, res, next) {
40
+ return shimmer.wrapFunction(read, read => function (req, res, next) {
41
41
  arguments[2] = publishRequestBodyAndNext(req, res, next)
42
42
  return read.apply(this, arguments)
43
43
  })
@@ -180,12 +180,12 @@ function finish (finishCh, errorCh, error) {
180
180
  }
181
181
 
182
182
  function wrapCallback (finishCh, errorCh, asyncResource, callback) {
183
- return asyncResource.bind(function (err) {
183
+ return shimmer.wrapFunction(callback, callback => asyncResource.bind(function (err) {
184
184
  finish(finishCh, errorCh, err)
185
185
  if (callback) {
186
186
  return callback.apply(this, arguments)
187
187
  }
188
- })
188
+ }))
189
189
  }
190
190
 
191
191
  function isRequestValid (exec, args, length) {
@@ -133,8 +133,8 @@ function wrapChildProcessAsyncMethod (shell = false) {
133
133
 
134
134
  if (childProcessMethod[util.promisify.custom]) {
135
135
  const wrapedChildProcessCustomPromisifyMethod =
136
- shimmer.wrap(childProcessMethod[util.promisify.custom],
137
- wrapChildProcessCustomPromisifyMethod(childProcessMethod[util.promisify.custom]), shell)
136
+ shimmer.wrapFunction(childProcessMethod[util.promisify.custom],
137
+ promisify => wrapChildProcessCustomPromisifyMethod(promisify, shell))
138
138
 
139
139
  // should do it in this way because the original property is readonly
140
140
  const descriptor = Object.getOwnPropertyDescriptor(childProcessMethod, util.promisify.custom)
@@ -59,7 +59,7 @@ function wrapLayerHandle (layer) {
59
59
 
60
60
  const original = layer.handle
61
61
 
62
- return shimmer.wrap(original, function () {
62
+ return shimmer.wrapFunction(original, original => function () {
63
63
  if (!enterChannel.hasSubscribers) return original.apply(this, arguments)
64
64
 
65
65
  const lastIndex = arguments.length - 1
@@ -90,7 +90,7 @@ function wrapLayerHandle (layer) {
90
90
  }
91
91
 
92
92
  function wrapNext (req, next) {
93
- return function (error) {
93
+ return shimmer.wrapFunction(next, next => function (error) {
94
94
  if (error) {
95
95
  errorChannel.publish({ req, error })
96
96
  }
@@ -99,11 +99,11 @@ function wrapNext (req, next) {
99
99
  finishChannel.publish({ req })
100
100
 
101
101
  next.apply(this, arguments)
102
- }
102
+ })
103
103
  }
104
104
 
105
105
  addHook({ name: 'connect', versions: ['>=3'] }, connect => {
106
- return shimmer.wrap(connect, wrapConnect(connect))
106
+ return shimmer.wrapFunction(connect, connect => wrapConnect(connect))
107
107
  })
108
108
 
109
109
  addHook({ name: 'connect', versions: ['2.2.2'] }, connect => {
@@ -6,7 +6,7 @@ const { channel, addHook } = require('./helpers/instrument')
6
6
  const cookieParserReadCh = channel('datadog:cookie-parser:read:finish')
7
7
 
8
8
  function publishRequestCookieAndNext (req, res, next) {
9
- return function cookieParserWrapper () {
9
+ return shimmer.wrapFunction(next, next => function cookieParserWrapper () {
10
10
  if (cookieParserReadCh.hasSubscribers && req) {
11
11
  const abortController = new AbortController()
12
12
 
@@ -18,17 +18,17 @@ function publishRequestCookieAndNext (req, res, next) {
18
18
  }
19
19
 
20
20
  return next.apply(this, arguments)
21
- }
21
+ })
22
22
  }
23
23
 
24
24
  addHook({
25
25
  name: 'cookie-parser',
26
26
  versions: ['>=1.0.0']
27
27
  }, cookieParser => {
28
- return shimmer.wrap(cookieParser, function () {
28
+ return shimmer.wrapFunction(cookieParser, cookieParser => function () {
29
29
  const cookieMiddleware = cookieParser.apply(this, arguments)
30
30
 
31
- return shimmer.wrap(cookieMiddleware, function (req, res, next) {
31
+ return shimmer.wrapFunction(cookieMiddleware, cookieMiddleware => function (req, res, next) {
32
32
  arguments[2] = publishRequestCookieAndNext(req, res, next)
33
33
  return cookieMiddleware.apply(this, arguments)
34
34
  })
@@ -37,7 +37,7 @@ function wrapMaybeInvoke (_maybeInvoke) {
37
37
 
38
38
  return _maybeInvoke.apply(this, arguments)
39
39
  }
40
- return shimmer.wrap(_maybeInvoke, wrapped)
40
+ return wrapped
41
41
  }
42
42
 
43
43
  function wrapQuery (query) {
@@ -51,7 +51,7 @@ function wrapQuery (query) {
51
51
  const res = query.apply(this, arguments)
52
52
  return res
53
53
  }
54
- return shimmer.wrap(query, wrapped)
54
+ return wrapped
55
55
  }
56
56
 
57
57
  function wrap (prefix, fn) {
@@ -76,13 +76,13 @@ function wrap (prefix, fn) {
76
76
 
77
77
  startCh.publish({ bucket: { name: this.name || this._name }, seedNodes: this._dd_hosts })
78
78
 
79
- arguments[callbackIndex] = asyncResource.bind(function (error, result) {
79
+ arguments[callbackIndex] = shimmer.wrapFunction(cb, cb => asyncResource.bind(function (error, result) {
80
80
  if (error) {
81
81
  errorCh.publish(error)
82
82
  }
83
83
  finishCh.publish(result)
84
84
  return cb.apply(this, arguments)
85
- })
85
+ }))
86
86
 
87
87
  try {
88
88
  return fn.apply(this, arguments)
@@ -94,7 +94,7 @@ function wrap (prefix, fn) {
94
94
  }
95
95
  })
96
96
  }
97
- return shimmer.wrap(fn, wrapped)
97
+ return wrapped
98
98
  }
99
99
 
100
100
  // semver >=3
@@ -118,13 +118,13 @@ function wrapCBandPromise (fn, name, startData, thisArg, args) {
118
118
  // v3 offers callback or promises event handling
119
119
  // NOTE: this does not work with v3.2.0-3.2.1 cluster.query, as there is a bug in the couchbase source code
120
120
  const cb = callbackResource.bind(args[cbIndex])
121
- args[cbIndex] = asyncResource.bind(function (error, result) {
121
+ args[cbIndex] = shimmer.wrapFunction(cb, cb => asyncResource.bind(function (error, result) {
122
122
  if (error) {
123
123
  errorCh.publish(error)
124
124
  }
125
125
  finishCh.publish({ result })
126
126
  return cb.apply(thisArg, arguments)
127
- })
127
+ }))
128
128
  }
129
129
  const res = fn.apply(thisArg, args)
130
130
 
@@ -166,8 +166,8 @@ addHook({ name: 'couchbase', file: 'lib/bucket.js', versions: ['^2.6.12'] }, Buc
166
166
  const finishCh = channel('apm:couchbase:query:finish')
167
167
  const errorCh = channel('apm:couchbase:query:error')
168
168
 
169
- Bucket.prototype._maybeInvoke = wrapMaybeInvoke(Bucket.prototype._maybeInvoke)
170
- Bucket.prototype.query = wrapQuery(Bucket.prototype.query)
169
+ shimmer.wrap(Bucket.prototype, '_maybeInvoke', maybeInvoke => wrapMaybeInvoke(maybeInvoke))
170
+ shimmer.wrap(Bucket.prototype, 'query', query => wrapQuery(query))
171
171
 
172
172
  shimmer.wrap(Bucket.prototype, '_n1qlReq', _n1qlReq => function (host, q, adhoc, emitter) {
173
173
  if (!startCh.hasSubscribers) {
@@ -203,15 +203,15 @@ addHook({ name: 'couchbase', file: 'lib/bucket.js', versions: ['^2.6.12'] }, Buc
203
203
  })
204
204
 
205
205
  wrapAllNames(['upsert', 'insert', 'replace', 'append', 'prepend'], name => {
206
- Bucket.prototype[name] = wrap(`apm:couchbase:${name}`, Bucket.prototype[name])
206
+ shimmer.wrap(Bucket.prototype, name, fn => wrap(`apm:couchbase:${name}`, fn))
207
207
  })
208
208
 
209
209
  return Bucket
210
210
  })
211
211
 
212
212
  addHook({ name: 'couchbase', file: 'lib/cluster.js', versions: ['^2.6.12'] }, Cluster => {
213
- Cluster.prototype._maybeInvoke = wrapMaybeInvoke(Cluster.prototype._maybeInvoke)
214
- Cluster.prototype.query = wrapQuery(Cluster.prototype.query)
213
+ shimmer.wrap(Cluster.prototype, '_maybeInvoke', maybeInvoke => wrapMaybeInvoke(maybeInvoke))
214
+ shimmer.wrap(Cluster.prototype, 'query', query => wrapQuery(query))
215
215
 
216
216
  shimmer.wrap(Cluster.prototype, 'openBucket', openBucket => {
217
217
  return function () {