dd-trace 2.5.0 → 2.7.1

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 -2
  2. package/index.d.ts +17 -8
  3. package/package.json +19 -23
  4. package/packages/datadog-instrumentations/index.js +15 -0
  5. package/packages/datadog-instrumentations/src/aws-sdk.js +104 -0
  6. package/packages/datadog-instrumentations/src/connect.js +111 -0
  7. package/packages/datadog-instrumentations/src/express.js +27 -0
  8. package/packages/datadog-instrumentations/src/fastify.js +187 -0
  9. package/packages/datadog-instrumentations/src/find-my-way.js +30 -0
  10. package/packages/datadog-instrumentations/src/google-cloud-pubsub.js +100 -0
  11. package/packages/datadog-instrumentations/src/http/server.js +1 -1
  12. package/packages/datadog-instrumentations/src/jest.js +175 -0
  13. package/packages/datadog-instrumentations/src/kafkajs.js +112 -0
  14. package/packages/datadog-instrumentations/src/knex.js +20 -0
  15. package/packages/datadog-instrumentations/src/koa.js +159 -0
  16. package/packages/datadog-instrumentations/src/limitd-client.js +21 -0
  17. package/packages/datadog-instrumentations/src/oracledb.js +128 -0
  18. package/packages/datadog-instrumentations/src/paperplane.js +77 -0
  19. package/packages/datadog-instrumentations/src/pg.js +2 -2
  20. package/packages/datadog-instrumentations/src/restify.js +58 -0
  21. package/packages/datadog-instrumentations/src/rhea.js +1 -1
  22. package/packages/datadog-instrumentations/src/router.js +177 -0
  23. package/packages/datadog-plugin-aws-sdk/src/base.js +146 -0
  24. package/packages/datadog-plugin-aws-sdk/src/index.js +16 -106
  25. package/packages/datadog-plugin-aws-sdk/src/services/cloudwatchlogs.js +4 -2
  26. package/packages/datadog-plugin-aws-sdk/src/services/default.js +7 -0
  27. package/packages/datadog-plugin-aws-sdk/src/services/dynamodb.js +3 -1
  28. package/packages/datadog-plugin-aws-sdk/src/services/eventbridge.js +5 -4
  29. package/packages/datadog-plugin-aws-sdk/src/services/index.js +12 -0
  30. package/packages/datadog-plugin-aws-sdk/src/services/kinesis.js +4 -3
  31. package/packages/datadog-plugin-aws-sdk/src/services/lambda.js +4 -3
  32. package/packages/datadog-plugin-aws-sdk/src/services/redshift.js +3 -1
  33. package/packages/datadog-plugin-aws-sdk/src/services/s3.js +3 -1
  34. package/packages/datadog-plugin-aws-sdk/src/services/sns.js +4 -3
  35. package/packages/datadog-plugin-aws-sdk/src/services/sqs.js +45 -6
  36. package/packages/datadog-plugin-connect/src/index.js +10 -114
  37. package/packages/datadog-plugin-cucumber/src/index.js +9 -21
  38. package/packages/datadog-plugin-cypress/src/plugin.js +6 -17
  39. package/packages/datadog-plugin-dns/src/index.js +12 -1
  40. package/packages/datadog-plugin-express/src/index.js +11 -25
  41. package/packages/datadog-plugin-fastify/src/index.js +17 -4
  42. package/packages/datadog-plugin-find-my-way/src/index.js +20 -0
  43. package/packages/datadog-plugin-fs/src/index.js +2 -0
  44. package/packages/datadog-plugin-google-cloud-pubsub/src/index.js +56 -111
  45. package/packages/datadog-plugin-http/src/server.js +2 -10
  46. package/packages/datadog-plugin-jest/src/index.js +101 -3
  47. package/packages/datadog-plugin-jest/src/util.js +1 -29
  48. package/packages/datadog-plugin-kafkajs/src/index.js +64 -90
  49. package/packages/datadog-plugin-koa/src/index.js +12 -164
  50. package/packages/datadog-plugin-mocha/src/index.js +5 -15
  51. package/packages/datadog-plugin-oracledb/src/index.js +34 -100
  52. package/packages/datadog-plugin-paperplane/src/index.js +14 -100
  53. package/packages/datadog-plugin-paperplane/src/logger.js +11 -0
  54. package/packages/datadog-plugin-paperplane/src/server.js +24 -0
  55. package/packages/datadog-plugin-restify/src/index.js +13 -75
  56. package/packages/datadog-plugin-router/src/index.js +67 -164
  57. package/packages/datadog-plugin-web/src/index.js +20 -0
  58. package/packages/dd-trace/lib/version.js +1 -1
  59. package/packages/dd-trace/src/appsec/callbacks/ddwaf.js +31 -11
  60. package/packages/dd-trace/src/appsec/index.js +7 -3
  61. package/packages/dd-trace/src/appsec/reporter.js +33 -3
  62. package/packages/dd-trace/src/appsec/rule_manager.js +2 -2
  63. package/packages/dd-trace/src/config.js +25 -3
  64. package/packages/dd-trace/src/format.js +9 -5
  65. package/packages/dd-trace/src/plugin_manager.js +13 -7
  66. package/packages/dd-trace/src/plugins/index.js +1 -2
  67. package/packages/dd-trace/src/plugins/log_plugin.js +8 -4
  68. package/packages/dd-trace/src/plugins/plugin.js +8 -0
  69. package/packages/dd-trace/src/plugins/util/test.js +20 -1
  70. package/packages/dd-trace/src/plugins/util/web.js +41 -12
  71. package/packages/dd-trace/src/profiling/config.js +8 -8
  72. package/packages/dd-trace/src/profiling/index.js +4 -4
  73. package/packages/dd-trace/src/profiling/profilers/{heap.js → space.js} +2 -2
  74. package/packages/dd-trace/src/profiling/profilers/{cpu.js → wall.js} +3 -3
  75. package/packages/dd-trace/src/span_processor.js +4 -1
  76. package/scripts/install_plugin_modules.js +1 -0
  77. package/packages/datadog-plugin-aws-sdk/src/helpers.js +0 -103
  78. package/packages/datadog-plugin-fastify/src/fastify.js +0 -198
  79. package/packages/datadog-plugin-fastify/src/find-my-way.js +0 -37
  80. package/packages/datadog-plugin-jest/src/jest-environment.js +0 -272
  81. package/packages/datadog-plugin-jest/src/jest-jasmine2.js +0 -185
  82. package/packages/datadog-plugin-knex/src/index.js +0 -23
  83. package/packages/datadog-plugin-limitd-client/src/index.js +0 -30
  84. package/scripts/postpublish.js +0 -24
@@ -56,6 +56,14 @@ module.exports = class Plugin {
56
56
  this._subscriptions.push(new Subscription(channelName, handler))
57
57
  }
58
58
 
59
+ addError (error) {
60
+ const store = storage.getStore()
61
+
62
+ if (!store || !store.span) return
63
+
64
+ store.span.setTag('error', error)
65
+ }
66
+
59
67
  configure (config) {
60
68
  if (typeof config === 'boolean') {
61
69
  config = { enabled: config }
@@ -19,6 +19,10 @@ const {
19
19
  } = require('./tags')
20
20
  const id = require('../../id')
21
21
 
22
+ const { SPAN_TYPE, RESOURCE_NAME, SAMPLING_PRIORITY } = require('../../../../../ext/tags')
23
+ const { SAMPLING_RULE_DECISION } = require('../../constants')
24
+ const { AUTO_KEEP } = require('../../../../../ext/priority')
25
+
22
26
  const TEST_FRAMEWORK = 'test.framework'
23
27
  const TEST_FRAMEWORK_VERSION = 'test.framework_version'
24
28
  const TEST_TYPE = 'test.type'
@@ -60,7 +64,8 @@ module.exports = {
60
64
  getTestParentSpan,
61
65
  getTestSuitePath,
62
66
  getCodeOwnersFileEntries,
63
- getCodeOwnersForFilename
67
+ getCodeOwnersForFilename,
68
+ getTestCommonTags
64
69
  }
65
70
 
66
71
  function getTestEnvironmentMetadata (testFramework, config) {
@@ -134,6 +139,20 @@ function getTestParentSpan (tracer) {
134
139
  'x-datadog-parent-id': '0000000000000000'
135
140
  })
136
141
  }
142
+
143
+ function getTestCommonTags (name, suite, version) {
144
+ return {
145
+ [SPAN_TYPE]: 'test',
146
+ [TEST_TYPE]: 'test',
147
+ [SAMPLING_RULE_DECISION]: 1,
148
+ [SAMPLING_PRIORITY]: AUTO_KEEP,
149
+ [TEST_NAME]: name,
150
+ [TEST_SUITE]: suite,
151
+ [RESOURCE_NAME]: `${suite}.${name}`,
152
+ [TEST_FRAMEWORK_VERSION]: version
153
+ }
154
+ }
155
+
137
156
  /**
138
157
  * We want to make sure that test suites are reported the same way for
139
158
  * every OS, so we replace `path.sep` by `/`
@@ -52,10 +52,38 @@ const web = {
52
52
  })
53
53
  },
54
54
 
55
- startSpan (tracer, config, req, res, name) {
55
+ setFramework (req, name, config) {
56
56
  const context = this.patch(req)
57
+ const span = context.span
58
+
59
+ if (!span) return
60
+
61
+ span.context()._name = `${name}.request`
62
+
63
+ web.setConfig(req, config)
64
+ },
65
+
66
+ setConfig (req, config) {
67
+ const context = contexts.get(req)
68
+ const span = context.span
69
+
57
70
  context.config = config
58
71
 
72
+ if (!config.filter(req.url)) {
73
+ span.setTag(MANUAL_DROP, true)
74
+ span.context()._trace.isRecording = false
75
+ }
76
+
77
+ if (config.service) {
78
+ span.setTag(SERVICE_NAME, config.service)
79
+ }
80
+
81
+ analyticsSampler.sample(span, config.measured, true)
82
+ },
83
+
84
+ startSpan (tracer, config, req, res, name) {
85
+ const context = this.patch(req)
86
+
59
87
  let span
60
88
 
61
89
  if (context.span) {
@@ -69,6 +97,8 @@ const web = {
69
97
  context.span = span
70
98
  context.res = res
71
99
 
100
+ this.setConfig(req, config)
101
+
72
102
  return span
73
103
  },
74
104
  wrap (req) {
@@ -83,16 +113,6 @@ const web = {
83
113
  instrument (tracer, config, req, res, name, callback) {
84
114
  const span = this.startSpan(tracer, config, req, res, name)
85
115
 
86
- if (!config.filter(req.url)) {
87
- span.setTag(MANUAL_DROP, true)
88
- }
89
-
90
- if (config.service) {
91
- span.setTag(SERVICE_NAME, config.service)
92
- }
93
-
94
- analyticsSampler.sample(span, config.measured, true)
95
-
96
116
  this.wrap(req)
97
117
 
98
118
  return callback && tracer.scope().activate(span, () => callback(span))
@@ -110,6 +130,14 @@ const web = {
110
130
  }
111
131
  },
112
132
 
133
+ setRoute (req, path) {
134
+ const context = contexts.get(req)
135
+
136
+ if (!context) return
137
+
138
+ context.paths = [path]
139
+ },
140
+
113
141
  // Remove the current route segment.
114
142
  exitRoute (req) {
115
143
  contexts.get(req).paths.pop()
@@ -231,8 +259,9 @@ const web = {
231
259
  const context = contexts.get(req)
232
260
  const span = context.span
233
261
  const error = context.error
262
+ const hasMiddlewareError = span.context()._tags['error'] || span.context()._tags['error.msg']
234
263
 
235
- if (!context.config.validateStatus(statusCode)) {
264
+ if (!hasMiddlewareError && !context.config.validateStatus(statusCode)) {
236
265
  span.setTag(ERROR, error || true)
237
266
  }
238
267
  },
@@ -6,8 +6,8 @@ const { URL } = require('url')
6
6
  const { AgentExporter } = require('./exporters/agent')
7
7
  const { FileExporter } = require('./exporters/file')
8
8
  const { ConsoleLogger } = require('./loggers/console')
9
- const CpuProfiler = require('./profilers/cpu')
10
- const HeapProfiler = require('./profilers/heap')
9
+ const WallProfiler = require('./profilers/wall')
10
+ const SpaceProfiler = require('./profilers/space')
11
11
  const { tagger } = require('./tagger')
12
12
 
13
13
  const {
@@ -64,8 +64,8 @@ class Config {
64
64
  ], this)
65
65
 
66
66
  const profilers = coalesce(options.profilers, DD_PROFILING_PROFILERS, [
67
- new CpuProfiler(),
68
- new HeapProfiler()
67
+ new WallProfiler(),
68
+ new SpaceProfiler()
69
69
  ])
70
70
 
71
71
  this.profilers = ensureProfilers(profilers, this)
@@ -100,10 +100,10 @@ function ensureExporters (exporters, options) {
100
100
 
101
101
  function getProfiler (name, options) {
102
102
  switch (name) {
103
- case 'cpu':
104
- return new CpuProfiler(options)
105
- case 'heap':
106
- return new HeapProfiler(options)
103
+ case 'wall':
104
+ return new WallProfiler(options)
105
+ case 'space':
106
+ return new SpaceProfiler(options)
107
107
  default:
108
108
  options.logger.error(`Unknown profiler "${name}"`)
109
109
  }
@@ -1,8 +1,8 @@
1
1
  'use strict'
2
2
 
3
3
  const { Profiler } = require('./profiler')
4
- const CpuProfiler = require('./profilers/cpu')
5
- const HeapProfiler = require('./profilers/heap')
4
+ const WallProfiler = require('./profilers/wall')
5
+ const SpaceProfiler = require('./profilers/space')
6
6
  const { AgentExporter } = require('./exporters/agent')
7
7
  const { FileExporter } = require('./exporters/file')
8
8
  const { ConsoleLogger } = require('./loggers/console')
@@ -13,7 +13,7 @@ module.exports = {
13
13
  profiler,
14
14
  AgentExporter,
15
15
  FileExporter,
16
- CpuProfiler,
17
- HeapProfiler,
16
+ WallProfiler,
17
+ SpaceProfiler,
18
18
  ConsoleLogger
19
19
  }
@@ -1,6 +1,6 @@
1
1
  'use strict'
2
2
 
3
- class NativeHeapProfiler {
3
+ class NativeSpaceProfiler {
4
4
  constructor (options = {}) {
5
5
  this.type = 'space'
6
6
  this._samplingInterval = options.samplingInterval || 512 * 1024
@@ -27,4 +27,4 @@ class NativeHeapProfiler {
27
27
  }
28
28
  }
29
29
 
30
- module.exports = NativeHeapProfiler
30
+ module.exports = NativeSpaceProfiler
@@ -1,9 +1,9 @@
1
1
  'use strict'
2
2
 
3
- class NativeCpuProfiler {
3
+ class NativeWallProfiler {
4
4
  constructor (options = {}) {
5
5
  this.type = 'wall'
6
- this._samplingInterval = options.samplingInterval || 10 * 1000
6
+ this._samplingInterval = options.samplingInterval || 1e6 / 99 // 99hz
7
7
  this._mapper = undefined
8
8
  this._pprof = undefined
9
9
  }
@@ -43,4 +43,4 @@ class NativeCpuProfiler {
43
43
  }
44
44
  }
45
45
 
46
- module.exports = NativeCpuProfiler
46
+ module.exports = NativeWallProfiler
@@ -32,7 +32,10 @@ class SpanProcessor {
32
32
  }
33
33
  }
34
34
 
35
- this._exporter.export(formatted)
35
+ if (formatted.length !== 0 && trace.isRecording !== false) {
36
+ this._exporter.export(formatted)
37
+ }
38
+
36
39
  this._erase(trace, active)
37
40
  }
38
41
  }
@@ -186,6 +186,7 @@ const requirePackageJson = require('${requirePackageJsonPath}')
186
186
 
187
187
  module.exports = {
188
188
  get (id) { return require(id || '${name}') },
189
+ getPath (id) { return require.resolve(id || '${name}' ) },
189
190
  version () { return requirePackageJson('${name}', module).version }
190
191
  }
191
192
  `
@@ -1,103 +0,0 @@
1
- 'use strict'
2
-
3
- const Tags = require('opentracing').Tags
4
-
5
- const services = {
6
- cloudwatchlogs: getService(require('./services/cloudwatchlogs')),
7
- dynamodb: getService(require('./services/dynamodb')),
8
- kinesis: getService(require('./services/kinesis')),
9
- lambda: getService(require('./services/lambda')),
10
- s3: getService(require('./services/s3')),
11
- redshift: getService(require('./services/redshift')),
12
- sns: getService(require('./services/sns')),
13
- sqs: getService(require('./services/sqs')),
14
- eventbridge: getService(require('./services/eventbridge'))
15
- }
16
-
17
- function getService (Service) {
18
- return new Service()
19
- }
20
-
21
- const helpers = {
22
- finish (config, span, response, err) {
23
- if (err) {
24
- span.setTag('error', err)
25
-
26
- if (err.requestId) {
27
- span.addTags({ 'aws.response.request_id': err.requestId })
28
- }
29
- }
30
-
31
- config.hooks.request(span, response)
32
-
33
- span.finish()
34
- },
35
-
36
- isEnabled (serviceIdentifier, config, request) {
37
- if (typeof config === 'boolean') {
38
- return config
39
- } else if (!config || typeof config !== 'object' || !services[serviceIdentifier]) {
40
- return true
41
- }
42
-
43
- return services[serviceIdentifier].isEnabled
44
- ? services[serviceIdentifier].isEnabled(config, request)
45
- : true
46
- },
47
-
48
- addResponseTags (span, response, serviceName) {
49
- if (!span) return
50
-
51
- if (response.request) {
52
- this.addServicesTags(span, response, serviceName)
53
- }
54
- },
55
-
56
- addServicesTags (span, response, serviceName) {
57
- if (!span) return
58
-
59
- const params = response.request.params
60
- const operation = response.request.operation
61
- const extraTags = services[serviceName] ? services[serviceName].generateTags(params, operation, response) : {}
62
- const tags = Object.assign({
63
- 'aws.response.request_id': response.requestId,
64
- 'resource.name': operation,
65
- 'span.kind': 'client'
66
- }, extraTags)
67
-
68
- span.addTags(tags)
69
- },
70
-
71
- responseExtract (serviceName, request, response, tracer) {
72
- if (services[serviceName] && services[serviceName].responseExtract) {
73
- const params = request.params
74
- const operation = request.operation
75
- return services[serviceName].responseExtract(params, operation, response, tracer)
76
- }
77
- },
78
-
79
- requestInject (span, request, serviceName, tracer) {
80
- if (!span) return
81
-
82
- const service = services[serviceName] && services[serviceName]
83
- if (service && service.requestInject) service.requestInject(span, request, tracer)
84
- },
85
-
86
- wrapCb (cb, serviceName, tags, request, tracer, childOf) {
87
- const awsHelpers = this
88
- return function wrappedCb (err, resp) {
89
- const maybeChildOf = awsHelpers.responseExtract(serviceName, request, resp, tracer)
90
- if (maybeChildOf) {
91
- const options = {
92
- childOf: maybeChildOf,
93
- tags: Object.assign({}, tags, { [Tags.SPAN_KIND]: 'server' })
94
- }
95
- return tracer.wrap('aws.response', options, cb).apply(this, arguments)
96
- } else {
97
- return tracer.scope().bind(cb, childOf).apply(this, arguments)
98
- }
99
- }
100
- }
101
- }
102
-
103
- module.exports = helpers
@@ -1,198 +0,0 @@
1
- 'use strict'
2
-
3
- const methods = require('methods').concat('all')
4
- const web = require('../../dd-trace/src/plugins/util/web')
5
-
6
- function createWrapFastify (tracer, config) {
7
- config = web.normalizeConfig(config)
8
-
9
- return function wrapFastify (fastify) {
10
- if (typeof fastify !== 'function') return fastify
11
-
12
- return function fastifyWithTrace () {
13
- const app = fastify.apply(this, arguments)
14
-
15
- if (!app) return app
16
-
17
- if (typeof app.addHook === 'function') {
18
- app.addHook('onRequest', createOnRequest(tracer, config))
19
- app.addHook('preHandler', preHandler)
20
- app.addHook = createWrapAddHook(tracer, config)(app.addHook)
21
- }
22
-
23
- methods.forEach(method => {
24
- app[method] = wrapMethod(app[method])
25
- })
26
-
27
- app.route = wrapRoute(app.route)
28
-
29
- return app
30
- }
31
- }
32
- }
33
-
34
- function createWrapAddHook (tracer, config) {
35
- return function wrapAddHook (addHook) {
36
- return function addHookWithTrace (name, fn) {
37
- fn = arguments[arguments.length - 1]
38
-
39
- if (typeof fn !== 'function') return addHook.apply(this, arguments)
40
-
41
- arguments[arguments.length - 1] = safeWrap(fn, function (request, reply, done) {
42
- const req = getReq(request)
43
-
44
- if (!req) return fn.apply(this, arguments)
45
-
46
- done = arguments[arguments.length - 1]
47
-
48
- try {
49
- if (typeof done === 'function') {
50
- arguments[arguments.length - 1] = function (err) {
51
- web.addError(req, err)
52
- return done.apply(this, arguments)
53
- }
54
-
55
- return fn.apply(this, arguments)
56
- } else {
57
- const promise = fn.apply(this, arguments)
58
-
59
- if (promise && typeof promise.catch === 'function') {
60
- return promise.catch(err => {
61
- web.addError(req, err)
62
- throw err
63
- })
64
- }
65
-
66
- return promise
67
- }
68
- } catch (e) {
69
- web.addError(req, e)
70
- throw e
71
- }
72
- })
73
-
74
- return addHook.apply(this, arguments)
75
- }
76
- }
77
- }
78
-
79
- function createOnRequest (tracer, config) {
80
- return function onRequest (request, reply, next) {
81
- if (typeof next !== 'function') return
82
-
83
- const req = getReq(request)
84
- const res = getRes(reply)
85
- const name = 'fastify.request'
86
-
87
- return web.instrument(tracer, config, req, res, name, () => next())
88
- }
89
- }
90
-
91
- function preHandler (request, reply, next) {
92
- if (typeof next !== 'function') return
93
- if (!reply || typeof reply.send !== 'function') return next()
94
-
95
- reply.send = wrapSend(reply.send)
96
-
97
- next()
98
- }
99
-
100
- function wrapSend (send) {
101
- return function sendWithTrace (payload) {
102
- const req = getReq(this && this.request)
103
-
104
- web.addError(req, payload)
105
-
106
- return send.apply(this, arguments)
107
- }
108
- }
109
-
110
- function wrapRoute (route) {
111
- if (typeof route !== 'function') return route
112
-
113
- return function routeWithTrace (opts) {
114
- opts.handler = wrapHandler(opts.handler)
115
-
116
- return route.apply(this, arguments)
117
- }
118
- }
119
-
120
- function wrapMethod (method) {
121
- if (typeof method !== 'function') return method
122
-
123
- return function methodWithTrace (url, opts, handler) {
124
- const lastIndex = arguments.length - 1
125
-
126
- handler = arguments[lastIndex]
127
-
128
- if (typeof handler === 'function') {
129
- arguments[lastIndex] = wrapHandler(handler)
130
- } else if (handler) {
131
- arguments[lastIndex].handler = wrapHandler(handler.handler)
132
- }
133
-
134
- return method.apply(this, arguments)
135
- }
136
- }
137
-
138
- function wrapHandler (handler) {
139
- if (!handler || typeof handler !== 'function' || handler.name === 'handlerWithTrace') {
140
- return handler
141
- }
142
-
143
- return function handlerWithTrace (request, reply) {
144
- const req = getReq(request)
145
-
146
- return web.reactivate(req, () => handler.apply(this, arguments))
147
- }
148
- }
149
-
150
- // TODO: move this to a common util
151
- function safeWrap (fn, wrapper) {
152
- Object.defineProperty(wrapper, 'length', Object.getOwnPropertyDescriptor(fn, 'length'))
153
-
154
- return wrapper
155
- }
156
-
157
- function getReq (request) {
158
- return request && (request.raw || request.req || request)
159
- }
160
-
161
- function getRes (reply) {
162
- return reply && (reply.raw || reply.res || reply)
163
- }
164
-
165
- module.exports = [
166
- {
167
- name: 'fastify',
168
- versions: ['>=3'],
169
- patch (fastify, tracer, config) {
170
- // `fastify` is a function so we return a wrapper that will replace its export.
171
- const wrapped = this.wrapExport(fastify, createWrapFastify(tracer, config)(fastify))
172
-
173
- wrapped.fastify = wrapped
174
- wrapped.default = wrapped
175
-
176
- return wrapped
177
- },
178
- unpatch (fastify) {
179
- const unwrapped = this.unwrapExport(fastify)
180
-
181
- unwrapped.fastify = unwrapped
182
- unwrapped.default = unwrapped
183
-
184
- return unwrapped
185
- }
186
- },
187
- {
188
- name: 'fastify',
189
- versions: ['1 - 2'],
190
- patch (fastify, tracer, config) {
191
- // `fastify` is a function so we return a wrapper that will replace its export.
192
- return this.wrapExport(fastify, createWrapFastify(tracer, config)(fastify))
193
- },
194
- unpatch (fastify) {
195
- this.unwrapExport(fastify)
196
- }
197
- }
198
- ]
@@ -1,37 +0,0 @@
1
- 'use strict'
2
-
3
- const web = require('../../dd-trace/src/plugins/util/web')
4
-
5
- function createWrapOn () {
6
- return function wrapOn (on) {
7
- return function onWithTrace (method, path, opts) {
8
- const index = typeof opts === 'function' ? 2 : 3
9
- const handler = arguments[index]
10
- const wrapper = function (req) {
11
- web.patch(req)
12
- web.enterRoute(req, path)
13
-
14
- return handler.apply(this, arguments)
15
- }
16
-
17
- if (typeof handler === 'function') {
18
- arguments[index] = wrapper
19
- }
20
-
21
- return on.apply(this, arguments)
22
- }
23
- }
24
- }
25
-
26
- module.exports = [
27
- {
28
- name: 'find-my-way',
29
- versions: ['>=1'],
30
- patch (Router, tracer, config) {
31
- this.wrap(Router.prototype, 'on', createWrapOn(tracer, config))
32
- },
33
- unpatch (Router) {
34
- this.unwrap(Router.prototype, 'on')
35
- }
36
- }
37
- ]