dd-trace 2.2.0 → 2.3.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 +6 -12
- package/package.json +3 -5
- package/packages/datadog-instrumentations/index.js +9 -0
- package/packages/datadog-instrumentations/src/bunyan.js +22 -0
- package/packages/datadog-instrumentations/src/cucumber.js +116 -0
- package/packages/datadog-instrumentations/src/elasticsearch.js +15 -5
- package/packages/datadog-instrumentations/src/generic-pool.js +48 -0
- package/packages/datadog-instrumentations/src/ioredis.js +52 -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-aws-sdk/src/services/sns.js +2 -2
- package/packages/datadog-plugin-bunyan/src/index.js +5 -22
- package/packages/datadog-plugin-cucumber/src/index.js +83 -128
- 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/config.js +7 -1
- 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/opentracing/tracer.js +1 -1
- package/packages/dd-trace/src/plugins/index.js +0 -2
- package/packages/dd-trace/src/plugins/log_plugin.js +49 -0
- package/packages/dd-trace/src/plugins/plugin.js +7 -0
- package/packages/dd-trace/src/plugins/util/git.js +1 -1
- 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/dd-trace/src/span_processor.js +22 -7
- package/packages/datadog-plugin-generic-pool/src/index.js +0 -52
- package/packages/datadog-plugin-mongoose/src/index.js +0 -51
|
@@ -7,6 +7,9 @@ const { ERROR } = require('../../../ext/tags')
|
|
|
7
7
|
const kinds = require('./kinds')
|
|
8
8
|
const { addMethodTags, addMetadataTags, getFilter } = require('./util')
|
|
9
9
|
|
|
10
|
+
const patched = new WeakSet()
|
|
11
|
+
const instances = new WeakMap()
|
|
12
|
+
|
|
10
13
|
function createWrapMakeRequest (tracer, config, methodKind) {
|
|
11
14
|
const filter = getFilter(config, 'metadata')
|
|
12
15
|
|
|
@@ -80,7 +83,7 @@ function wrapClientConstructor (tracer, config, ServiceClient, methods) {
|
|
|
80
83
|
}
|
|
81
84
|
|
|
82
85
|
function wrapMethod (tracer, config, method, path, methodKind) {
|
|
83
|
-
if (typeof method !== 'function' || method
|
|
86
|
+
if (typeof method !== 'function' || patched.has(method)) {
|
|
84
87
|
return method
|
|
85
88
|
}
|
|
86
89
|
|
|
@@ -94,7 +97,7 @@ function wrapMethod (tracer, config, method, path, methodKind) {
|
|
|
94
97
|
|
|
95
98
|
Object.assign(methodWithTrace, method)
|
|
96
99
|
|
|
97
|
-
methodWithTrace
|
|
100
|
+
patched.add(methodWithTrace)
|
|
98
101
|
|
|
99
102
|
return methodWithTrace
|
|
100
103
|
}
|
|
@@ -186,7 +189,9 @@ function startSpan (tracer, config, path, methodKind) {
|
|
|
186
189
|
}
|
|
187
190
|
|
|
188
191
|
function ensureMetadata (client, args, index) {
|
|
189
|
-
|
|
192
|
+
const grpc = getGrpc(client)
|
|
193
|
+
|
|
194
|
+
if (!client || !grpc) return args
|
|
190
195
|
|
|
191
196
|
const meta = args[index]
|
|
192
197
|
const normalized = []
|
|
@@ -196,7 +201,7 @@ function ensureMetadata (client, args, index) {
|
|
|
196
201
|
}
|
|
197
202
|
|
|
198
203
|
if (!meta || !meta.constructor || meta.constructor.name !== 'Metadata') {
|
|
199
|
-
normalized.push(new
|
|
204
|
+
normalized.push(new grpc.Metadata())
|
|
200
205
|
}
|
|
201
206
|
|
|
202
207
|
if (meta) {
|
|
@@ -238,6 +243,15 @@ function getMethodKind (definition) {
|
|
|
238
243
|
return kinds.unary
|
|
239
244
|
}
|
|
240
245
|
|
|
246
|
+
function getGrpc (client) {
|
|
247
|
+
let proto = client
|
|
248
|
+
|
|
249
|
+
do {
|
|
250
|
+
const instance = instances.get(proto)
|
|
251
|
+
if (instance) return instance
|
|
252
|
+
} while ((proto = Object.getPrototypeOf(proto)))
|
|
253
|
+
}
|
|
254
|
+
|
|
241
255
|
function patch (grpc, tracer, config) {
|
|
242
256
|
if (config.client === false) return
|
|
243
257
|
|
|
@@ -245,7 +259,7 @@ function patch (grpc, tracer, config) {
|
|
|
245
259
|
|
|
246
260
|
const proto = grpc.Client.prototype
|
|
247
261
|
|
|
248
|
-
proto
|
|
262
|
+
instances.set(proto, grpc)
|
|
249
263
|
|
|
250
264
|
this.wrap(proto, 'makeBidiStreamRequest', createWrapMakeRequest(tracer, config, kinds.bidi))
|
|
251
265
|
this.wrap(proto, 'makeClientStreamRequest', createWrapMakeRequest(tracer, config, kinds.clientStream))
|
|
@@ -256,7 +270,7 @@ function patch (grpc, tracer, config) {
|
|
|
256
270
|
function unpatch (grpc) {
|
|
257
271
|
const proto = grpc.Client.prototype
|
|
258
272
|
|
|
259
|
-
delete
|
|
273
|
+
instances.delete(proto)
|
|
260
274
|
|
|
261
275
|
this.unwrap(proto, 'makeBidiStreamRequest')
|
|
262
276
|
this.unwrap(proto, 'makeClientStreamRequest')
|
|
@@ -1,41 +1,11 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
|
-
const
|
|
3
|
+
const RedisPlugin = require('../../datadog-plugin-redis/src')
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
return
|
|
8
|
-
if (!command || !command.promise || !config.filter(command.name)) return sendCommand.apply(this, arguments)
|
|
9
|
-
|
|
10
|
-
const options = this.options || {}
|
|
11
|
-
const connectionName = this.options.connectionName
|
|
12
|
-
const db = options.db
|
|
13
|
-
const span = tx.instrument(tracer, config, db, command.name, command.args)
|
|
14
|
-
|
|
15
|
-
tx.setHost(span, options.host, options.port)
|
|
16
|
-
tx.wrap(span, command.promise)
|
|
17
|
-
|
|
18
|
-
if (config.splitByInstance && connectionName) {
|
|
19
|
-
const service = config.service
|
|
20
|
-
? `${config.service}-${connectionName}`
|
|
21
|
-
: connectionName
|
|
22
|
-
|
|
23
|
-
span.setTag('service.name', service)
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
return tracer.scope().bind(sendCommand, span).apply(this, arguments)
|
|
27
|
-
}
|
|
5
|
+
class IORedisPlugin extends RedisPlugin {
|
|
6
|
+
static get name () {
|
|
7
|
+
return 'ioredis'
|
|
28
8
|
}
|
|
29
9
|
}
|
|
30
10
|
|
|
31
|
-
module.exports =
|
|
32
|
-
name: 'ioredis',
|
|
33
|
-
versions: ['>=2'],
|
|
34
|
-
patch (Redis, tracer, config) {
|
|
35
|
-
config = tx.normalizeConfig(config)
|
|
36
|
-
this.wrap(Redis.prototype, 'sendCommand', createWrapSendCommand(tracer, config))
|
|
37
|
-
},
|
|
38
|
-
unpatch (Redis) {
|
|
39
|
-
this.unwrap(Redis.prototype, 'sendCommand')
|
|
40
|
-
}
|
|
41
|
-
}
|
|
11
|
+
module.exports = IORedisPlugin
|
|
@@ -22,6 +22,8 @@ const {
|
|
|
22
22
|
setSuppressedErrors
|
|
23
23
|
} = require('./util')
|
|
24
24
|
|
|
25
|
+
const originals = new WeakMap()
|
|
26
|
+
|
|
25
27
|
function getVmContext (environment) {
|
|
26
28
|
if (typeof environment.getVmContext === 'function') {
|
|
27
29
|
return environment.getVmContext()
|
|
@@ -234,43 +236,37 @@ function createHandleTestEvent (tracer, testEnvironmentMetadata, instrumenter) {
|
|
|
234
236
|
}
|
|
235
237
|
}
|
|
236
238
|
|
|
239
|
+
function patch (Environment, tracer, config) {
|
|
240
|
+
const testEnvironmentMetadata = getTestEnvironmentMetadata('jest', config)
|
|
241
|
+
const proto = Environment.prototype
|
|
242
|
+
|
|
243
|
+
this.wrap(proto, 'teardown', createWrapTeardown(tracer, this))
|
|
244
|
+
|
|
245
|
+
const newHandleTestEvent = createHandleTestEvent(tracer, testEnvironmentMetadata, this)
|
|
246
|
+
originals.set(newHandleTestEvent, proto.handleTestEvent)
|
|
247
|
+
proto.handleTestEvent = newHandleTestEvent
|
|
248
|
+
|
|
249
|
+
return wrapEnvironment(Environment)
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
function unpatch (Environment) {
|
|
253
|
+
const proto = Environment.prototype
|
|
254
|
+
|
|
255
|
+
this.unwrap(Environment.prototype, 'teardown')
|
|
256
|
+
proto.handleTestEvent = originals.get(proto.handleTestEvent)
|
|
257
|
+
}
|
|
258
|
+
|
|
237
259
|
module.exports = [
|
|
238
260
|
{
|
|
239
261
|
name: 'jest-environment-node',
|
|
240
262
|
versions: ['>=24.8.0'],
|
|
241
|
-
patch
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
this.wrap(NodeEnvironment.prototype, 'teardown', createWrapTeardown(tracer, this))
|
|
245
|
-
|
|
246
|
-
const newHandleTestEvent = createHandleTestEvent(tracer, testEnvironmentMetadata, this)
|
|
247
|
-
newHandleTestEvent._dd_original = NodeEnvironment.prototype.handleTestEvent
|
|
248
|
-
NodeEnvironment.prototype.handleTestEvent = newHandleTestEvent
|
|
249
|
-
|
|
250
|
-
return wrapEnvironment(NodeEnvironment)
|
|
251
|
-
},
|
|
252
|
-
unpatch: function (NodeEnvironment) {
|
|
253
|
-
this.unwrap(NodeEnvironment.prototype, 'teardown')
|
|
254
|
-
NodeEnvironment.prototype.handleTestEvent = NodeEnvironment.prototype.handleTestEvent._dd_original
|
|
255
|
-
}
|
|
263
|
+
patch,
|
|
264
|
+
unpatch
|
|
256
265
|
},
|
|
257
266
|
{
|
|
258
267
|
name: 'jest-environment-jsdom',
|
|
259
268
|
versions: ['>=24.8.0'],
|
|
260
|
-
patch
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
this.wrap(JsdomEnvironment.prototype, 'teardown', createWrapTeardown(tracer, this))
|
|
264
|
-
|
|
265
|
-
const newHandleTestEvent = createHandleTestEvent(tracer, testEnvironmentMetadata, this)
|
|
266
|
-
newHandleTestEvent._dd_original = JsdomEnvironment.prototype.handleTestEvent
|
|
267
|
-
JsdomEnvironment.prototype.handleTestEvent = newHandleTestEvent
|
|
268
|
-
|
|
269
|
-
return wrapEnvironment(JsdomEnvironment)
|
|
270
|
-
},
|
|
271
|
-
unpatch: function (JsdomEnvironment) {
|
|
272
|
-
this.unwrap(JsdomEnvironment.prototype, 'teardown')
|
|
273
|
-
JsdomEnvironment.prototype.handleTestEvent = JsdomEnvironment.prototype.handleTestEvent._dd_original
|
|
274
|
-
}
|
|
269
|
+
patch,
|
|
270
|
+
unpatch
|
|
275
271
|
}
|
|
276
272
|
]
|
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
const web = require('../../dd-trace/src/plugins/util/web')
|
|
4
4
|
|
|
5
|
+
const originals = new WeakMap()
|
|
6
|
+
|
|
5
7
|
function createWrapCallback (tracer, config) {
|
|
6
8
|
config = web.normalizeConfig(config)
|
|
7
9
|
|
|
@@ -83,7 +85,9 @@ function wrapStack (layer) {
|
|
|
83
85
|
layer.stack = layer.stack.map(middleware => {
|
|
84
86
|
if (typeof middleware !== 'function') return middleware
|
|
85
87
|
|
|
86
|
-
|
|
88
|
+
const original = originals.get(middleware)
|
|
89
|
+
|
|
90
|
+
middleware = original || middleware
|
|
87
91
|
|
|
88
92
|
const wrappedMiddleware = wrapMiddleware(middleware)
|
|
89
93
|
|
|
@@ -96,7 +100,7 @@ function wrapStack (layer) {
|
|
|
96
100
|
return wrappedMiddleware.apply(this, arguments)
|
|
97
101
|
}
|
|
98
102
|
|
|
99
|
-
handler
|
|
103
|
+
originals.set(handler, middleware)
|
|
100
104
|
|
|
101
105
|
return handler
|
|
102
106
|
})
|
|
@@ -84,9 +84,7 @@ function wrapPluginInit (init) {
|
|
|
84
84
|
return function initWithTrace (config, logging, stats) {
|
|
85
85
|
const handler = init.apply(this, arguments)
|
|
86
86
|
|
|
87
|
-
|
|
88
|
-
wrapListeners(handler)
|
|
89
|
-
}
|
|
87
|
+
wrapListeners(handler)
|
|
90
88
|
|
|
91
89
|
return handler
|
|
92
90
|
}
|
|
@@ -18,6 +18,8 @@ const {
|
|
|
18
18
|
getTestSuitePath
|
|
19
19
|
} = require('../../dd-trace/src/plugins/util/test')
|
|
20
20
|
|
|
21
|
+
const skippedTests = new WeakSet()
|
|
22
|
+
|
|
21
23
|
function getTestSpanMetadata (tracer, test, sourceRoot) {
|
|
22
24
|
const childOf = getTestParentSpan(tracer)
|
|
23
25
|
|
|
@@ -131,12 +133,12 @@ function createWrapRunTests (tracer, testEnvironmentMetadata, sourceRoot) {
|
|
|
131
133
|
// We call `getAllTestsInSuite` with the root suite so every skipped test
|
|
132
134
|
// should already have an associated test span.
|
|
133
135
|
// This function is called with every suite, so we need a way to mark
|
|
134
|
-
// the test as already accounted for. We do this through `
|
|
136
|
+
// the test as already accounted for. We do this through `skippedTests`.
|
|
135
137
|
// If the test is already marked as skipped, we don't create an additional test span.
|
|
136
|
-
if (!isSkipped || test
|
|
138
|
+
if (!isSkipped || skippedTests.has(test)) {
|
|
137
139
|
return
|
|
138
140
|
}
|
|
139
|
-
test
|
|
141
|
+
skippedTests.add(test)
|
|
140
142
|
const { childOf, resource, ...testSpanMetadata } = getTestSpanMetadata(tracer, test, sourceRoot)
|
|
141
143
|
|
|
142
144
|
const testSpan = tracer
|
|
@@ -94,15 +94,39 @@ function getResource (ns, query, operationName) {
|
|
|
94
94
|
return parts.join(' ')
|
|
95
95
|
}
|
|
96
96
|
|
|
97
|
-
function
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
if (!isObject(input) || Buffer.isBuffer(input) || isBSON(input)) return '?'
|
|
97
|
+
function shouldHide (input) {
|
|
98
|
+
return !isObject(input) || Buffer.isBuffer(input) || isBSON(input)
|
|
99
|
+
}
|
|
101
100
|
|
|
102
|
-
|
|
103
|
-
|
|
101
|
+
function sanitize (input) {
|
|
102
|
+
if (shouldHide(input)) return '?'
|
|
104
103
|
|
|
105
|
-
|
|
104
|
+
const output = {}
|
|
105
|
+
const queue = [{
|
|
106
|
+
input,
|
|
107
|
+
output,
|
|
108
|
+
depth: 0
|
|
109
|
+
}]
|
|
110
|
+
|
|
111
|
+
while (queue.length) {
|
|
112
|
+
const {
|
|
113
|
+
input, output, depth
|
|
114
|
+
} = queue.pop()
|
|
115
|
+
const nextDepth = depth + 1
|
|
116
|
+
for (const key in input) {
|
|
117
|
+
if (typeof input[key] === 'function') continue
|
|
118
|
+
|
|
119
|
+
const child = input[key]
|
|
120
|
+
if (depth >= 20 || shouldHide(child)) {
|
|
121
|
+
output[key] = '?'
|
|
122
|
+
} else {
|
|
123
|
+
queue.push({
|
|
124
|
+
input: child,
|
|
125
|
+
output: output[key] = {},
|
|
126
|
+
depth: nextDepth
|
|
127
|
+
})
|
|
128
|
+
}
|
|
129
|
+
}
|
|
106
130
|
}
|
|
107
131
|
|
|
108
132
|
return output
|
|
@@ -4,6 +4,8 @@
|
|
|
4
4
|
|
|
5
5
|
const analyticsSampler = require('../../dd-trace/src/analytics_sampler')
|
|
6
6
|
|
|
7
|
+
const contexts = new WeakMap()
|
|
8
|
+
|
|
7
9
|
function createWrapHandleRequest (tracer, config) {
|
|
8
10
|
return function wrapHandleRequest (handleRequest) {
|
|
9
11
|
return function handleRequestWithTrace (req, res, pathname, query) {
|
|
@@ -92,8 +94,9 @@ function getPageFromPath (page, dynamicRoutes = []) {
|
|
|
92
94
|
|
|
93
95
|
function trace (tracer, config, req, res, handler) {
|
|
94
96
|
const scope = tracer.scope()
|
|
97
|
+
const context = contexts.get(req)
|
|
95
98
|
|
|
96
|
-
if (
|
|
99
|
+
if (context) return scope.activate(context.span, handler)
|
|
97
100
|
|
|
98
101
|
const childOf = scope.active()
|
|
99
102
|
const tags = {
|
|
@@ -107,7 +110,7 @@ function trace (tracer, config, req, res, handler) {
|
|
|
107
110
|
|
|
108
111
|
analyticsSampler.sample(span, config.measured, true)
|
|
109
112
|
|
|
110
|
-
req
|
|
113
|
+
contexts.set(req, { span })
|
|
111
114
|
|
|
112
115
|
const promise = scope.activate(span, handler)
|
|
113
116
|
|
|
@@ -124,9 +127,11 @@ function trace (tracer, config, req, res, handler) {
|
|
|
124
127
|
}
|
|
125
128
|
|
|
126
129
|
function addPage (req, page) {
|
|
127
|
-
|
|
130
|
+
const context = contexts.get(req)
|
|
131
|
+
|
|
132
|
+
if (!context) return
|
|
128
133
|
|
|
129
|
-
|
|
134
|
+
context.span.addTags({
|
|
130
135
|
'resource.name': `${req.method} ${page}`.trim(),
|
|
131
136
|
'next.page': page
|
|
132
137
|
})
|
|
@@ -2,10 +2,13 @@
|
|
|
2
2
|
|
|
3
3
|
const analyticsSampler = require('../../dd-trace/src/analytics_sampler')
|
|
4
4
|
|
|
5
|
+
const connectionAttributes = new WeakMap()
|
|
6
|
+
const poolAttributes = new WeakMap()
|
|
7
|
+
|
|
5
8
|
function createWrapExecute (tracer, config) {
|
|
6
9
|
return function wrapExecute (execute) {
|
|
7
10
|
return function executeWithTrace (dbQuery, ...args) {
|
|
8
|
-
const connAttrs = this
|
|
11
|
+
const connAttrs = connectionAttributes.get(this)
|
|
9
12
|
const service = getServiceName(tracer, config, connAttrs)
|
|
10
13
|
const connectStringObj = new URL('http://' + connAttrs.connectString)
|
|
11
14
|
const tags = {
|
|
@@ -37,7 +40,7 @@ function createWrapGetConnection (tracer, config) {
|
|
|
37
40
|
if (callback) {
|
|
38
41
|
arguments[1] = (err, connection) => {
|
|
39
42
|
if (connection) {
|
|
40
|
-
connection
|
|
43
|
+
connectionAttributes.set(connection, connAttrs)
|
|
41
44
|
}
|
|
42
45
|
callback(err, connection)
|
|
43
46
|
}
|
|
@@ -45,7 +48,7 @@ function createWrapGetConnection (tracer, config) {
|
|
|
45
48
|
getConnection.apply(this, arguments)
|
|
46
49
|
} else {
|
|
47
50
|
return getConnection.apply(this, arguments).then((connection) => {
|
|
48
|
-
connection
|
|
51
|
+
connectionAttributes.set(connection, connAttrs)
|
|
49
52
|
return connection
|
|
50
53
|
})
|
|
51
54
|
}
|
|
@@ -59,7 +62,7 @@ function createWrapCreatePool (tracer, config) {
|
|
|
59
62
|
if (callback) {
|
|
60
63
|
arguments[1] = (err, pool) => {
|
|
61
64
|
if (pool) {
|
|
62
|
-
pool
|
|
65
|
+
poolAttributes.set(pool, poolAttrs)
|
|
63
66
|
}
|
|
64
67
|
callback(err, pool)
|
|
65
68
|
}
|
|
@@ -67,7 +70,7 @@ function createWrapCreatePool (tracer, config) {
|
|
|
67
70
|
createPool.apply(this, arguments)
|
|
68
71
|
} else {
|
|
69
72
|
return createPool.apply(this, arguments).then((pool) => {
|
|
70
|
-
pool
|
|
73
|
+
poolAttributes.set(pool, poolAttrs)
|
|
71
74
|
return pool
|
|
72
75
|
})
|
|
73
76
|
}
|
|
@@ -85,14 +88,14 @@ function createWrapPoolGetConnection (tracer, config) {
|
|
|
85
88
|
if (callback) {
|
|
86
89
|
arguments[arguments.length - 1] = (err, connection) => {
|
|
87
90
|
if (connection) {
|
|
88
|
-
connection.
|
|
91
|
+
connectionAttributes.set(connection, poolAttributes.get(this))
|
|
89
92
|
}
|
|
90
93
|
callback(err, connection)
|
|
91
94
|
}
|
|
92
95
|
getConnection.apply(this, arguments)
|
|
93
96
|
} else {
|
|
94
97
|
return getConnection.apply(this, arguments).then((connection) => {
|
|
95
|
-
connection.
|
|
98
|
+
connectionAttributes.set(connection, poolAttributes.get(this))
|
|
96
99
|
return connection
|
|
97
100
|
})
|
|
98
101
|
}
|
|
@@ -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
|