dd-trace 2.2.0 → 2.2.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.
- package/LICENSE-3rdparty.csv +0 -2
- package/index.d.ts +0 -12
- package/package.json +3 -5
- package/packages/datadog-instrumentations/index.js +8 -0
- package/packages/datadog-instrumentations/src/bunyan.js +22 -0
- package/packages/datadog-instrumentations/src/elasticsearch.js +6 -1
- package/packages/datadog-instrumentations/src/generic-pool.js +48 -0
- package/packages/datadog-instrumentations/src/ioredis.js +49 -0
- package/packages/datadog-instrumentations/src/mongoose.js +30 -0
- package/packages/datadog-instrumentations/src/pino.js +105 -0
- package/packages/datadog-instrumentations/src/redis.js +118 -0
- package/packages/datadog-instrumentations/src/sharedb.js +78 -0
- package/packages/datadog-instrumentations/src/winston.js +57 -0
- package/packages/datadog-plugin-bunyan/src/index.js +5 -22
- package/packages/datadog-plugin-fastify/src/find-my-way.js +0 -1
- package/packages/datadog-plugin-google-cloud-pubsub/src/index.js +8 -6
- package/packages/datadog-plugin-graphql/src/index.js +34 -28
- package/packages/datadog-plugin-grpc/src/client.js +20 -6
- package/packages/datadog-plugin-http2/src/server.js +2 -0
- package/packages/datadog-plugin-ioredis/src/index.js +5 -35
- package/packages/datadog-plugin-jest/src/jest-environment.js +26 -30
- package/packages/datadog-plugin-koa/src/index.js +6 -2
- package/packages/datadog-plugin-microgateway-core/src/index.js +1 -3
- package/packages/datadog-plugin-mocha/src/index.js +5 -3
- package/packages/datadog-plugin-mongodb-core/src/util.js +31 -7
- package/packages/datadog-plugin-next/src/index.js +9 -4
- package/packages/datadog-plugin-oracledb/src/index.js +10 -7
- package/packages/datadog-plugin-pino/src/index.js +5 -158
- package/packages/datadog-plugin-redis/src/index.js +96 -80
- package/packages/datadog-plugin-restify/src/index.js +18 -3
- package/packages/datadog-plugin-rhea/src/index.js +8 -5
- package/packages/datadog-plugin-router/src/index.js +23 -14
- package/packages/datadog-plugin-sharedb/src/index.js +47 -87
- package/packages/datadog-plugin-winston/src/index.js +5 -113
- package/packages/datadog-shimmer/src/shimmer.js +1 -1
- package/packages/dd-trace/lib/version.js +1 -1
- package/packages/dd-trace/src/appsec/index.js +2 -1
- package/packages/dd-trace/src/appsec/reporter.js +3 -2
- package/packages/dd-trace/src/constants.js +1 -6
- package/packages/dd-trace/src/opentracing/propagation/text_map.js +0 -34
- package/packages/dd-trace/src/plugins/index.js +0 -2
- package/packages/dd-trace/src/plugins/log_plugin.js +44 -0
- package/packages/dd-trace/src/plugins/plugin.js +7 -0
- package/packages/dd-trace/src/plugins/util/web.js +102 -84
- package/packages/dd-trace/src/priority_sampler.js +1 -49
- package/packages/dd-trace/src/scope.js +47 -23
- package/packages/datadog-plugin-generic-pool/src/index.js +0 -52
- package/packages/datadog-plugin-mongoose/src/index.js +0 -51
|
@@ -1,164 +1,11 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
|
-
const
|
|
3
|
+
const LogPlugin = require('../../dd-trace/src/plugins/log_plugin')
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
return
|
|
8
|
-
const instance = pino.apply(this, arguments)
|
|
9
|
-
|
|
10
|
-
Object.defineProperty(instance, symbol, {
|
|
11
|
-
configurable: true,
|
|
12
|
-
enumerable: true,
|
|
13
|
-
writable: true,
|
|
14
|
-
value: wrapper(tracer, config)(instance[symbol])
|
|
15
|
-
})
|
|
16
|
-
|
|
17
|
-
return instance
|
|
18
|
-
}
|
|
5
|
+
class PinoPlugin extends LogPlugin {
|
|
6
|
+
static get name () {
|
|
7
|
+
return 'pino'
|
|
19
8
|
}
|
|
20
9
|
}
|
|
21
10
|
|
|
22
|
-
|
|
23
|
-
return function wrapAsJson (asJson) {
|
|
24
|
-
return function asJsonWithTrace (obj, msg, num, time) {
|
|
25
|
-
const span = tracer.scope().active()
|
|
26
|
-
|
|
27
|
-
obj = arguments[0] = obj || {}
|
|
28
|
-
|
|
29
|
-
tracer.inject(span, LOG, obj)
|
|
30
|
-
|
|
31
|
-
const json = asJson.apply(this, arguments)
|
|
32
|
-
|
|
33
|
-
obj && delete obj.dd
|
|
34
|
-
|
|
35
|
-
return json
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
function createWrapMixin (tracer, config) {
|
|
41
|
-
return function wrapMixin (mixin) {
|
|
42
|
-
return function mixinWithTrace () {
|
|
43
|
-
let obj = {}
|
|
44
|
-
|
|
45
|
-
if (mixin) {
|
|
46
|
-
obj = mixin.apply(this, arguments)
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
const span = tracer.scope().active()
|
|
50
|
-
|
|
51
|
-
tracer.inject(span, LOG, obj)
|
|
52
|
-
|
|
53
|
-
return obj
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
function createWrapPrettifyObject (tracer, config) {
|
|
59
|
-
return function wrapPrettifyObject (prettifyObject) {
|
|
60
|
-
return function prettifyObjectWithTrace (input) {
|
|
61
|
-
const span = tracer.scope().active()
|
|
62
|
-
|
|
63
|
-
tracer.inject(span, LOG, input.input)
|
|
64
|
-
|
|
65
|
-
return prettifyObject.apply(this, arguments)
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
function createWrapPrettyFactory (tracer, config) {
|
|
71
|
-
return function wrapPrettyFactory (prettyFactory) {
|
|
72
|
-
return function prettyFactoryWithTrace () {
|
|
73
|
-
const pretty = prettyFactory.apply(this, arguments)
|
|
74
|
-
|
|
75
|
-
return function prettyWithTrace (obj) {
|
|
76
|
-
const span = tracer.scope().active()
|
|
77
|
-
|
|
78
|
-
tracer.inject(span, LOG, obj)
|
|
79
|
-
|
|
80
|
-
return pretty.apply(this, arguments)
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
module.exports = [
|
|
87
|
-
{
|
|
88
|
-
name: 'pino',
|
|
89
|
-
versions: ['2 - 3', '4', '>=5 <5.14.0'],
|
|
90
|
-
patch (pino, tracer, config) {
|
|
91
|
-
if (!tracer._logInjection) return
|
|
92
|
-
|
|
93
|
-
const asJsonSym = (pino.symbols && pino.symbols.asJsonSym) || 'asJson'
|
|
94
|
-
|
|
95
|
-
return this.wrapExport(pino, createWrapPino(tracer, config, asJsonSym, createWrapAsJson)(pino))
|
|
96
|
-
},
|
|
97
|
-
unpatch (pino) {
|
|
98
|
-
return this.unwrapExport(pino)
|
|
99
|
-
}
|
|
100
|
-
},
|
|
101
|
-
{
|
|
102
|
-
name: 'pino',
|
|
103
|
-
versions: ['>=5.14.0 <6.8.0'],
|
|
104
|
-
patch (pino, tracer, config) {
|
|
105
|
-
if (!tracer._logInjection) return
|
|
106
|
-
|
|
107
|
-
const mixinSym = pino.symbols.mixinSym
|
|
108
|
-
|
|
109
|
-
return this.wrapExport(pino, createWrapPino(tracer, config, mixinSym, createWrapMixin)(pino))
|
|
110
|
-
},
|
|
111
|
-
unpatch (pino) {
|
|
112
|
-
return this.unwrapExport(pino)
|
|
113
|
-
}
|
|
114
|
-
},
|
|
115
|
-
{
|
|
116
|
-
name: 'pino',
|
|
117
|
-
versions: ['>=6.8.0'],
|
|
118
|
-
patch (pino, tracer, config) {
|
|
119
|
-
if (!tracer._logInjection) return
|
|
120
|
-
|
|
121
|
-
const mixinSym = pino.symbols.mixinSym
|
|
122
|
-
|
|
123
|
-
const wrapped = this.wrapExport(pino, createWrapPino(tracer, config, mixinSym, createWrapMixin)(pino))
|
|
124
|
-
|
|
125
|
-
wrapped.pino = wrapped
|
|
126
|
-
wrapped.default = wrapped
|
|
127
|
-
|
|
128
|
-
return wrapped
|
|
129
|
-
},
|
|
130
|
-
unpatch (pino) {
|
|
131
|
-
const unwrapped = this.unwrapExport(pino)
|
|
132
|
-
|
|
133
|
-
unwrapped.pino = unwrapped
|
|
134
|
-
unwrapped.default = unwrapped
|
|
135
|
-
|
|
136
|
-
return unwrapped
|
|
137
|
-
}
|
|
138
|
-
},
|
|
139
|
-
{
|
|
140
|
-
name: 'pino-pretty',
|
|
141
|
-
versions: ['>=3'], // will only work starting from pino@5.0.0 as previous versions are not using pino-pretty
|
|
142
|
-
file: 'lib/utils.js',
|
|
143
|
-
patch (utils, tracer, config) {
|
|
144
|
-
if (!tracer._logInjection) return
|
|
145
|
-
|
|
146
|
-
this.wrap(utils, 'prettifyObject', createWrapPrettifyObject(tracer, config))
|
|
147
|
-
},
|
|
148
|
-
unpatch (utils) {
|
|
149
|
-
this.unwrap(utils, 'prettifyObject')
|
|
150
|
-
}
|
|
151
|
-
},
|
|
152
|
-
{
|
|
153
|
-
name: 'pino-pretty',
|
|
154
|
-
versions: ['1 - 2'],
|
|
155
|
-
patch (prettyFactory, tracer, config) {
|
|
156
|
-
if (!tracer._logInjection) return
|
|
157
|
-
|
|
158
|
-
return this.wrapExport(prettyFactory, createWrapPrettyFactory(tracer, config)(prettyFactory))
|
|
159
|
-
},
|
|
160
|
-
unpatch (prettyFactory) {
|
|
161
|
-
return this.unwrapExport(prettyFactory)
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
]
|
|
11
|
+
module.exports = PinoPlugin
|
|
@@ -1,104 +1,120 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
const Plugin = require('../../dd-trace/src/plugins/plugin')
|
|
4
|
+
const { storage } = require('../../datadog-core')
|
|
5
|
+
const analyticsSampler = require('../../dd-trace/src/analytics_sampler')
|
|
6
|
+
const urlFilter = require('../../dd-trace/src/plugins/util/urlfilter')
|
|
7
|
+
|
|
8
|
+
class RedisPlugin extends Plugin {
|
|
9
|
+
static get name () {
|
|
10
|
+
return 'redis'
|
|
11
|
+
}
|
|
4
12
|
|
|
5
|
-
|
|
13
|
+
constructor (...args) {
|
|
14
|
+
super(...args)
|
|
6
15
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
16
|
+
this.addSub(`apm:${this.constructor.name}:command:start`, (
|
|
17
|
+
{ db, command, args, connectionOptions, connectionName }
|
|
18
|
+
) => {
|
|
19
|
+
if (!this.config.filter(command)) {
|
|
20
|
+
return this.skip()
|
|
21
|
+
}
|
|
22
|
+
const store = storage.getStore()
|
|
23
|
+
const childOf = store ? store.span : store
|
|
24
|
+
const span = this.tracer.startSpan('redis.command', {
|
|
25
|
+
childOf,
|
|
26
|
+
tags: {
|
|
27
|
+
'span.kind': 'client',
|
|
28
|
+
'resource.name': command,
|
|
29
|
+
'span.type': 'redis',
|
|
30
|
+
'db.type': 'redis',
|
|
31
|
+
'db.name': db || '0',
|
|
32
|
+
'redis.raw_command': formatCommand(command, args)
|
|
33
|
+
}
|
|
34
|
+
})
|
|
35
|
+
|
|
36
|
+
span.setTag('service.name', this.config.service || `${span.context()._tags['service.name']}-redis`)
|
|
37
|
+
|
|
38
|
+
analyticsSampler.sample(span, this.config.measured)
|
|
39
|
+
|
|
40
|
+
if (connectionOptions) {
|
|
41
|
+
span.addTags({
|
|
42
|
+
'out.host': connectionOptions.host,
|
|
43
|
+
'out.port': connectionOptions.port
|
|
44
|
+
})
|
|
45
|
+
}
|
|
12
46
|
|
|
13
|
-
if (
|
|
47
|
+
if (this.config.splitByInstance && connectionName) {
|
|
48
|
+
const service = this.config.service
|
|
49
|
+
? `${this.config.service}-${connectionName}`
|
|
50
|
+
: connectionName
|
|
14
51
|
|
|
15
|
-
|
|
16
|
-
|
|
52
|
+
span.setTag('service.name', service)
|
|
53
|
+
}
|
|
17
54
|
|
|
18
|
-
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
}
|
|
55
|
+
this.enter(span, store)
|
|
56
|
+
})
|
|
22
57
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
if (!config.filter(options.command)) return internalSendCommand.apply(this, arguments)
|
|
58
|
+
this.addSub(`apm:${this.constructor.name}:command:end`, () => {
|
|
59
|
+
this.exit()
|
|
60
|
+
})
|
|
27
61
|
|
|
28
|
-
|
|
29
|
-
const span =
|
|
62
|
+
this.addSub(`apm:${this.constructor.name}:command:error`, err => {
|
|
63
|
+
const span = storage.getStore().span
|
|
64
|
+
span.setTag('error', err)
|
|
65
|
+
})
|
|
30
66
|
|
|
31
|
-
|
|
67
|
+
this.addSub(`apm:${this.constructor.name}:command:async-end`, () => {
|
|
68
|
+
const span = storage.getStore().span
|
|
69
|
+
span.finish()
|
|
70
|
+
})
|
|
71
|
+
}
|
|
32
72
|
|
|
33
|
-
|
|
34
|
-
|
|
73
|
+
configure (config) {
|
|
74
|
+
super.configure(normalizeConfig(config))
|
|
35
75
|
}
|
|
36
76
|
}
|
|
37
77
|
|
|
38
|
-
function
|
|
39
|
-
|
|
40
|
-
return function sendCommandWithTrace (command, args, callback) {
|
|
41
|
-
if (!config.filter(command)) return sendCommand.apply(this, arguments)
|
|
78
|
+
function formatCommand (command, args) {
|
|
79
|
+
command = command.toUpperCase()
|
|
42
80
|
|
|
43
|
-
|
|
44
|
-
const span = startSpan(tracer, config, this, command, args)
|
|
81
|
+
if (!args || command === 'AUTH') return command
|
|
45
82
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
} else {
|
|
51
|
-
arguments[2] = tx.wrap(span)
|
|
52
|
-
}
|
|
83
|
+
for (let i = 0, l = args.length; i < l; i++) {
|
|
84
|
+
if (typeof args[i] === 'function') continue
|
|
85
|
+
|
|
86
|
+
command = `${command} ${formatArg(args[i])}`
|
|
53
87
|
|
|
54
|
-
|
|
55
|
-
|
|
88
|
+
if (command.length > 1000) return trim(command, 1000)
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
return command
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
function formatArg (arg) {
|
|
95
|
+
switch (typeof arg) {
|
|
96
|
+
case 'string':
|
|
97
|
+
case 'number':
|
|
98
|
+
return trim(String(arg), 100)
|
|
99
|
+
default:
|
|
100
|
+
return '?'
|
|
56
101
|
}
|
|
57
102
|
}
|
|
58
103
|
|
|
59
|
-
function
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
104
|
+
function trim (str, maxlen) {
|
|
105
|
+
if (str.length > maxlen) {
|
|
106
|
+
str = str.substr(0, maxlen - 3) + '...'
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
return str
|
|
110
|
+
}
|
|
63
111
|
|
|
64
|
-
|
|
112
|
+
function normalizeConfig (config) {
|
|
113
|
+
const filter = urlFilter.getFilter(config)
|
|
65
114
|
|
|
66
|
-
return
|
|
115
|
+
return Object.assign({}, config, {
|
|
116
|
+
filter
|
|
117
|
+
})
|
|
67
118
|
}
|
|
68
119
|
|
|
69
|
-
module.exports =
|
|
70
|
-
{
|
|
71
|
-
name: '@node-redis/client',
|
|
72
|
-
versions: ['>=1'],
|
|
73
|
-
file: 'dist/lib/client/commands-queue.js',
|
|
74
|
-
patch (redis, tracer, config) {
|
|
75
|
-
config = tx.normalizeConfig(config)
|
|
76
|
-
this.wrap(redis.default.prototype, 'addCommand', createWrapAddCommand(tracer, config))
|
|
77
|
-
},
|
|
78
|
-
unpatch (redis) {
|
|
79
|
-
this.unwrap(redis.default.prototype, 'addCommand')
|
|
80
|
-
}
|
|
81
|
-
},
|
|
82
|
-
{
|
|
83
|
-
name: 'redis',
|
|
84
|
-
versions: ['>=2.6 <4'],
|
|
85
|
-
patch (redis, tracer, config) {
|
|
86
|
-
config = tx.normalizeConfig(config)
|
|
87
|
-
this.wrap(redis.RedisClient.prototype, 'internal_send_command', createWrapInternalSendCommand(tracer, config))
|
|
88
|
-
},
|
|
89
|
-
unpatch (redis) {
|
|
90
|
-
this.unwrap(redis.RedisClient.prototype, 'internal_send_command')
|
|
91
|
-
}
|
|
92
|
-
},
|
|
93
|
-
{
|
|
94
|
-
name: 'redis',
|
|
95
|
-
versions: ['>=0.12 <2.6'],
|
|
96
|
-
patch (redis, tracer, config) {
|
|
97
|
-
config = tx.normalizeConfig(config)
|
|
98
|
-
this.wrap(redis.RedisClient.prototype, 'send_command', createWrapSendCommand(tracer, config))
|
|
99
|
-
},
|
|
100
|
-
unpatch (redis) {
|
|
101
|
-
this.unwrap(redis.RedisClient.prototype, 'send_command')
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
]
|
|
120
|
+
module.exports = RedisPlugin
|
|
@@ -4,14 +4,14 @@ const web = require('../../dd-trace/src/plugins/util/web')
|
|
|
4
4
|
const handlers = ['use', 'pre']
|
|
5
5
|
const methods = ['del', 'get', 'head', 'opts', 'post', 'put', 'patch']
|
|
6
6
|
|
|
7
|
-
function createWrapSetupRequest (tracer, config) {
|
|
7
|
+
function createWrapSetupRequest (tracer, config, withRoute) {
|
|
8
8
|
config = web.normalizeConfig(config)
|
|
9
9
|
|
|
10
10
|
return function wrapSetupRequest (setupRequest) {
|
|
11
11
|
return function setupRequestWithTrace (req, res) {
|
|
12
12
|
return web.instrument(tracer, config, req, res, 'restify.request', () => {
|
|
13
13
|
web.beforeEnd(req, () => {
|
|
14
|
-
if (req.route &&
|
|
14
|
+
if (req.route && withRoute) {
|
|
15
15
|
web.enterRoute(req, req.route.path)
|
|
16
16
|
}
|
|
17
17
|
})
|
|
@@ -55,7 +55,7 @@ function wrapFn (fn) {
|
|
|
55
55
|
module.exports = [
|
|
56
56
|
{
|
|
57
57
|
name: 'restify',
|
|
58
|
-
versions: ['>=
|
|
58
|
+
versions: ['>=7'],
|
|
59
59
|
file: 'lib/server.js',
|
|
60
60
|
patch (Server, tracer, config) {
|
|
61
61
|
this.wrap(Server.prototype, '_setupRequest', createWrapSetupRequest(tracer, config))
|
|
@@ -67,5 +67,20 @@ module.exports = [
|
|
|
67
67
|
this.unwrap(Server.prototype, handlers)
|
|
68
68
|
this.unwrap(Server.prototype, methods)
|
|
69
69
|
}
|
|
70
|
+
},
|
|
71
|
+
{
|
|
72
|
+
name: 'restify',
|
|
73
|
+
versions: ['3 - 6'],
|
|
74
|
+
file: 'lib/server.js',
|
|
75
|
+
patch (Server, tracer, config) {
|
|
76
|
+
this.wrap(Server.prototype, '_setupRequest', createWrapSetupRequest(tracer, config, true))
|
|
77
|
+
this.wrap(Server.prototype, handlers, createWrapHandler(tracer, config))
|
|
78
|
+
this.wrap(Server.prototype, methods, createWrapMethod(tracer, config))
|
|
79
|
+
},
|
|
80
|
+
unpatch (Server) {
|
|
81
|
+
this.unwrap(Server.prototype, '_setupRequest')
|
|
82
|
+
this.unwrap(Server.prototype, handlers)
|
|
83
|
+
this.unwrap(Server.prototype, methods)
|
|
84
|
+
}
|
|
70
85
|
}
|
|
71
86
|
]
|
|
@@ -6,6 +6,8 @@ const dd = Symbol('datadog')
|
|
|
6
6
|
const circularBufferConstructor = Symbol('circularBufferConstructor')
|
|
7
7
|
const inFlightDeliveries = Symbol('inFlightDeliveries')
|
|
8
8
|
|
|
9
|
+
const patched = new WeakSet()
|
|
10
|
+
|
|
9
11
|
function createWrapSend (tracer, config, instrumenter) {
|
|
10
12
|
return function wrapSend (send) {
|
|
11
13
|
return function sendWithTrace (msg, tag, format) {
|
|
@@ -133,9 +135,9 @@ function patchCircularBuffer (proto, instrumenter) {
|
|
|
133
135
|
if (outgoing.deliveries) {
|
|
134
136
|
CircularBuffer = outgoing.deliveries.constructor
|
|
135
137
|
}
|
|
136
|
-
if (CircularBuffer && !CircularBuffer.prototype
|
|
138
|
+
if (CircularBuffer && !patched.has(CircularBuffer.prototype)) {
|
|
137
139
|
instrumenter.wrap(CircularBuffer.prototype, 'pop_if', createWrapCircularBufferPopIf())
|
|
138
|
-
CircularBuffer.prototype
|
|
140
|
+
patched.add(CircularBuffer.prototype)
|
|
139
141
|
const Session = proto.constructor
|
|
140
142
|
if (Session) {
|
|
141
143
|
Session[circularBufferConstructor] = CircularBuffer
|
|
@@ -260,9 +262,10 @@ module.exports = [
|
|
|
260
262
|
patchCircularBuffer(Session.prototype, this)
|
|
261
263
|
},
|
|
262
264
|
unpatch (Session, tracer) {
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
265
|
+
const CircularBuffer = Session[circularBufferConstructor]
|
|
266
|
+
if (CircularBuffer) {
|
|
267
|
+
patched.delete(CircularBuffer.prototype)
|
|
268
|
+
this.unwrap(CircularBuffer.prototype, 'pop_if')
|
|
266
269
|
}
|
|
267
270
|
}
|
|
268
271
|
}
|
|
@@ -5,9 +5,10 @@ const pathToRegExp = require('path-to-regexp')
|
|
|
5
5
|
const shimmer = require('../../datadog-shimmer')
|
|
6
6
|
const web = require('../../dd-trace/src/plugins/util/web')
|
|
7
7
|
|
|
8
|
-
// TODO: clean this up to not use web util internals
|
|
9
8
|
// TODO: stop checking for fast star and fast slash
|
|
10
9
|
|
|
10
|
+
const contexts = new WeakMap()
|
|
11
|
+
const layerMatchers = new WeakMap()
|
|
11
12
|
const regexpCache = Object.create(null)
|
|
12
13
|
|
|
13
14
|
function createWrapHandle (tracer, config) {
|
|
@@ -15,17 +16,17 @@ function createWrapHandle (tracer, config) {
|
|
|
15
16
|
return function handleWithTrace (req, res, done) {
|
|
16
17
|
web.patch(req)
|
|
17
18
|
|
|
18
|
-
if (!req
|
|
19
|
+
if (!contexts.has(req)) {
|
|
19
20
|
const context = {
|
|
20
21
|
route: '',
|
|
21
22
|
stack: []
|
|
22
23
|
}
|
|
23
24
|
|
|
24
25
|
web.beforeEnd(req, () => {
|
|
25
|
-
req
|
|
26
|
+
web.enterRoute(req, context.route)
|
|
26
27
|
})
|
|
27
28
|
|
|
28
|
-
req
|
|
29
|
+
contexts.set(req, context)
|
|
29
30
|
}
|
|
30
31
|
|
|
31
32
|
return handle.apply(this, arguments)
|
|
@@ -78,7 +79,7 @@ function wrapStack (stack, offset, matchers) {
|
|
|
78
79
|
layer.handle = wrapLayerHandle(layer, layer.handle)
|
|
79
80
|
}
|
|
80
81
|
|
|
81
|
-
layer
|
|
82
|
+
layerMatchers.set(layer, matchers)
|
|
82
83
|
|
|
83
84
|
if (layer.route) {
|
|
84
85
|
METHODS.forEach(method => {
|
|
@@ -96,10 +97,12 @@ function wrapNext (layer, req, next) {
|
|
|
96
97
|
if (!next || !web.active(req)) return next
|
|
97
98
|
|
|
98
99
|
const originalNext = next
|
|
100
|
+
const context = contexts.get(req)
|
|
101
|
+
const matchers = layerMatchers.get(layer)
|
|
99
102
|
|
|
100
103
|
return function (error) {
|
|
101
|
-
if (layer.path && !isFastStar(layer) && !isFastSlash(layer)) {
|
|
102
|
-
|
|
104
|
+
if (layer.path && !isFastStar(layer, matchers) && !isFastSlash(layer, matchers)) {
|
|
105
|
+
context.stack.pop()
|
|
103
106
|
}
|
|
104
107
|
|
|
105
108
|
web.finish(req, error)
|
|
@@ -109,13 +112,13 @@ function wrapNext (layer, req, next) {
|
|
|
109
112
|
}
|
|
110
113
|
|
|
111
114
|
function callHandle (layer, handle, req, args) {
|
|
112
|
-
const matchers = layer
|
|
115
|
+
const matchers = layerMatchers.get(layer)
|
|
113
116
|
|
|
114
117
|
if (web.active(req) && matchers) {
|
|
115
118
|
// Try to guess which path actually matched
|
|
116
119
|
for (let i = 0; i < matchers.length; i++) {
|
|
117
120
|
if (matchers[i].test(layer)) {
|
|
118
|
-
const context = req
|
|
121
|
+
const context = contexts.get(req)
|
|
119
122
|
|
|
120
123
|
context.stack.push(matchers[i].path)
|
|
121
124
|
|
|
@@ -145,24 +148,30 @@ function extractMatchers (fn) {
|
|
|
145
148
|
|
|
146
149
|
return arg.map(pattern => ({
|
|
147
150
|
path: pattern instanceof RegExp ? `(${pattern})` : pattern,
|
|
148
|
-
test: layer =>
|
|
151
|
+
test: layer => {
|
|
152
|
+
const matchers = layerMatchers.get(layer)
|
|
153
|
+
|
|
154
|
+
return !isFastStar(layer, matchers) &&
|
|
155
|
+
!isFastSlash(layer, matchers) &&
|
|
156
|
+
cachedPathToRegExp(pattern).test(layer.path)
|
|
157
|
+
}
|
|
149
158
|
}))
|
|
150
159
|
}
|
|
151
160
|
|
|
152
|
-
function isFastStar (layer) {
|
|
161
|
+
function isFastStar (layer, matchers) {
|
|
153
162
|
if (layer.regexp.fast_star !== undefined) {
|
|
154
163
|
return layer.regexp.fast_star
|
|
155
164
|
}
|
|
156
165
|
|
|
157
|
-
return
|
|
166
|
+
return matchers.some(matcher => matcher.path === '*')
|
|
158
167
|
}
|
|
159
168
|
|
|
160
|
-
function isFastSlash (layer) {
|
|
169
|
+
function isFastSlash (layer, matchers) {
|
|
161
170
|
if (layer.regexp.fast_slash !== undefined) {
|
|
162
171
|
return layer.regexp.fast_slash
|
|
163
172
|
}
|
|
164
173
|
|
|
165
|
-
return
|
|
174
|
+
return matchers.some(matcher => matcher.path === '/')
|
|
166
175
|
}
|
|
167
176
|
|
|
168
177
|
function flatten (arr) {
|