dd-trace 2.1.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 +22 -12
- package/package.json +3 -5
- package/packages/datadog-instrumentations/index.js +13 -3
- package/packages/datadog-instrumentations/src/bunyan.js +22 -0
- package/packages/datadog-instrumentations/src/couchbase.js +143 -0
- package/packages/datadog-instrumentations/src/elasticsearch.js +79 -0
- 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/mysql.js +2 -2
- package/packages/datadog-instrumentations/src/mysql2.js +5 -5
- 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/helpers.js +1 -1
- package/packages/datadog-plugin-bunyan/src/index.js +5 -22
- package/packages/datadog-plugin-couchbase/src/index.js +51 -148
- package/packages/datadog-plugin-elasticsearch/src/index.js +41 -82
- package/packages/datadog-plugin-fastify/src/fastify.js +22 -1
- 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-mysql/src/index.js +4 -5
- package/packages/datadog-plugin-mysql2/src/index.js +11 -0
- 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 -110
- 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 +6 -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 +1 -3
- 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/dd-trace/src/tagger.js +14 -21
- package/packages/dd-trace/src/tracer.js +1 -1
- package/packages/datadog-plugin-generic-pool/src/index.js +0 -52
- package/packages/datadog-plugin-mongoose/src/index.js +0 -51
package/LICENSE-3rdparty.csv
CHANGED
|
@@ -22,8 +22,6 @@ require,path-to-regexp,MIT,Copyright 2014 Blake Embrey
|
|
|
22
22
|
require,performance-now,MIT,Copyright 2013 Braveg1rl
|
|
23
23
|
require,retry,MIT,Copyright 2011 Tim Koschützki Felix Geisendörfer
|
|
24
24
|
require,semver,ISC,Copyright Isaac Z. Schlueter and Contributors
|
|
25
|
-
require,source-map,BSD-3-Clause,Copyright 2009-2011 Mozilla Foundation and contributors
|
|
26
|
-
require,source-map-resolve,MIT,Copyright 2014-2020 Simon Lydell 2019 Jinxiang
|
|
27
25
|
dev,autocannon,MIT,Copyright 2016 Matteo Collina
|
|
28
26
|
dev,axios,MIT,Copyright 2014-present Matt Zabriskie
|
|
29
27
|
dev,benchmark,MIT,Copyright 2010-2016 Mathias Bynens Robert Kieffer John-David Dalton
|
package/index.d.ts
CHANGED
|
@@ -186,18 +186,6 @@ export declare interface SamplingRule {
|
|
|
186
186
|
* List of options available to the tracer.
|
|
187
187
|
*/
|
|
188
188
|
export declare interface TracerOptions {
|
|
189
|
-
/**
|
|
190
|
-
* Whether to enable the tracer.
|
|
191
|
-
* @default true
|
|
192
|
-
*/
|
|
193
|
-
enabled?: boolean;
|
|
194
|
-
|
|
195
|
-
/**
|
|
196
|
-
* Enable debug logging in the tracer.
|
|
197
|
-
* @default false
|
|
198
|
-
*/
|
|
199
|
-
debug?: boolean;
|
|
200
|
-
|
|
201
189
|
/**
|
|
202
190
|
* Whether to enable trace ID injection in log records to be able to correlate
|
|
203
191
|
* traces with logs.
|
|
@@ -406,6 +394,28 @@ export declare interface TracerOptions {
|
|
|
406
394
|
* @default true
|
|
407
395
|
*/
|
|
408
396
|
orphanable?: boolean
|
|
397
|
+
|
|
398
|
+
/**
|
|
399
|
+
* Configuration of the AppSec protection. Can be a boolean as an alias to `appsec.enabled`.
|
|
400
|
+
*/
|
|
401
|
+
appsec?: boolean | {
|
|
402
|
+
/**
|
|
403
|
+
* Whether to enable AppSec.
|
|
404
|
+
* @default false
|
|
405
|
+
*/
|
|
406
|
+
enabled?: boolean,
|
|
407
|
+
|
|
408
|
+
/**
|
|
409
|
+
* Specifies a path to a custom rules file.
|
|
410
|
+
*/
|
|
411
|
+
rules?: string,
|
|
412
|
+
|
|
413
|
+
/**
|
|
414
|
+
* Controls the maximum amount of traces sampled by AppSec attacks, per second.
|
|
415
|
+
* @default 100
|
|
416
|
+
*/
|
|
417
|
+
rateLimit?: number
|
|
418
|
+
};
|
|
409
419
|
}
|
|
410
420
|
|
|
411
421
|
/** @hidden */
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dd-trace",
|
|
3
|
-
"version": "2.1
|
|
3
|
+
"version": "2.2.1",
|
|
4
4
|
"description": "Datadog APM tracing client for JavaScript",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"typings": "index.d.ts",
|
|
@@ -69,7 +69,7 @@
|
|
|
69
69
|
"crypto-randomuuid": "^1.0.0",
|
|
70
70
|
"diagnostics_channel": "^1.1.0",
|
|
71
71
|
"form-data": "^3.0.0",
|
|
72
|
-
"import-in-the-middle": "^1.1
|
|
72
|
+
"import-in-the-middle": "^1.2.1",
|
|
73
73
|
"koalas": "^1.0.2",
|
|
74
74
|
"limiter": "^1.1.4",
|
|
75
75
|
"lodash.kebabcase": "^4.1.1",
|
|
@@ -83,9 +83,7 @@
|
|
|
83
83
|
"path-to-regexp": "^0.1.2",
|
|
84
84
|
"performance-now": "^2.1.0",
|
|
85
85
|
"retry": "^0.10.1",
|
|
86
|
-
"semver": "^5.5.0"
|
|
87
|
-
"source-map": "^0.7.3",
|
|
88
|
-
"source-map-resolve": "^0.6.0"
|
|
86
|
+
"semver": "^5.5.0"
|
|
89
87
|
},
|
|
90
88
|
"devDependencies": {
|
|
91
89
|
"autocannon": "^4.5.2",
|
|
@@ -1,11 +1,21 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
|
+
require('./src/bluebird')
|
|
4
|
+
require('./src/bunyan')
|
|
5
|
+
require('./src/couchbase')
|
|
3
6
|
require('./src/dns')
|
|
7
|
+
require('./src/elasticsearch')
|
|
8
|
+
require('./src/generic-pool')
|
|
9
|
+
require('./src/ioredis')
|
|
4
10
|
require('./src/memcached')
|
|
11
|
+
require('./src/mongoose')
|
|
5
12
|
require('./src/mysql')
|
|
6
13
|
require('./src/mysql2')
|
|
7
|
-
require('./src/
|
|
8
|
-
require('./src/when')
|
|
14
|
+
require('./src/pino')
|
|
9
15
|
require('./src/promise')
|
|
10
|
-
require('./src/q')
|
|
11
16
|
require('./src/promise-js')
|
|
17
|
+
require('./src/q')
|
|
18
|
+
require('./src/redis')
|
|
19
|
+
require('./src/sharedb')
|
|
20
|
+
require('./src/when')
|
|
21
|
+
require('./src/winston')
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
const {
|
|
4
|
+
channel,
|
|
5
|
+
addHook
|
|
6
|
+
} = require('./helpers/instrument')
|
|
7
|
+
const shimmer = require('../../datadog-shimmer')
|
|
8
|
+
|
|
9
|
+
addHook({ name: 'bunyan', versions: ['>=1'] }, Logger => {
|
|
10
|
+
const logCh = channel('apm:bunyan:log')
|
|
11
|
+
shimmer.wrap(Logger.prototype, '_emit', emit => {
|
|
12
|
+
return function wrappedEmit (rec) {
|
|
13
|
+
if (logCh.hasSubscribers) {
|
|
14
|
+
const payload = { message: rec }
|
|
15
|
+
logCh.publish(payload)
|
|
16
|
+
arguments[0] = payload.message
|
|
17
|
+
}
|
|
18
|
+
return emit.apply(this, arguments)
|
|
19
|
+
}
|
|
20
|
+
})
|
|
21
|
+
return Logger
|
|
22
|
+
})
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
const {
|
|
4
|
+
channel,
|
|
5
|
+
addHook,
|
|
6
|
+
AsyncResource
|
|
7
|
+
} = require('./helpers/instrument')
|
|
8
|
+
const shimmer = require('../../datadog-shimmer')
|
|
9
|
+
|
|
10
|
+
addHook({ name: 'couchbase', file: 'lib/bucket.js', versions: ['^2.6.5'] }, Bucket => {
|
|
11
|
+
const startCh = channel('apm:couchbase:query:start')
|
|
12
|
+
const asyncEndCh = channel('apm:couchbase:query:async-end')
|
|
13
|
+
const endCh = channel('apm:couchbase:query:end')
|
|
14
|
+
const errorCh = channel('apm:couchbase:query:error')
|
|
15
|
+
|
|
16
|
+
Bucket.prototype._maybeInvoke = wrapMaybeInvoke(Bucket.prototype._maybeInvoke)
|
|
17
|
+
Bucket.prototype.query = wrapQuery(Bucket.prototype.query)
|
|
18
|
+
|
|
19
|
+
shimmer.wrap(Bucket.prototype, '_n1qlReq', _n1qlReq => function (host, q, adhoc, emitter) {
|
|
20
|
+
if (!startCh.hasSubscribers) {
|
|
21
|
+
return _n1qlReq.apply(this, arguments)
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
if (!emitter || !emitter.once) return _n1qlReq.apply(this, arguments)
|
|
25
|
+
|
|
26
|
+
const n1qlQuery = q && q.statement
|
|
27
|
+
|
|
28
|
+
startCh.publish({ resource: n1qlQuery, bucket: this })
|
|
29
|
+
|
|
30
|
+
emitter.once('rows', AsyncResource.bind(() => {
|
|
31
|
+
asyncEndCh.publish(undefined)
|
|
32
|
+
}))
|
|
33
|
+
|
|
34
|
+
emitter.once('error', AsyncResource.bind((error) => {
|
|
35
|
+
errorCh.publish(error)
|
|
36
|
+
asyncEndCh.publish(undefined)
|
|
37
|
+
}))
|
|
38
|
+
|
|
39
|
+
try {
|
|
40
|
+
return _n1qlReq.apply(this, arguments)
|
|
41
|
+
} catch (err) {
|
|
42
|
+
err.stack // trigger getting the stack at the original throwing point
|
|
43
|
+
errorCh.publish(err)
|
|
44
|
+
|
|
45
|
+
throw err
|
|
46
|
+
} finally {
|
|
47
|
+
endCh.publish(undefined)
|
|
48
|
+
}
|
|
49
|
+
})
|
|
50
|
+
|
|
51
|
+
Bucket.prototype.upsert = wrap('apm:couchbase:upsert', Bucket.prototype.upsert)
|
|
52
|
+
Bucket.prototype.insert = wrap('apm:couchbase:insert', Bucket.prototype.insert)
|
|
53
|
+
Bucket.prototype.replace = wrap('apm:couchbase:replace', Bucket.prototype.replace)
|
|
54
|
+
Bucket.prototype.append = wrap('apm:couchbase:append', Bucket.prototype.append)
|
|
55
|
+
Bucket.prototype.prepend = wrap('apm:couchbase:prepend', Bucket.prototype.prepend)
|
|
56
|
+
|
|
57
|
+
return Bucket
|
|
58
|
+
})
|
|
59
|
+
|
|
60
|
+
addHook({ name: 'couchbase', file: 'lib/cluster.js', versions: ['^2.6.5'] }, Cluster => {
|
|
61
|
+
Cluster.prototype._maybeInvoke = wrapMaybeInvoke(Cluster.prototype._maybeInvoke)
|
|
62
|
+
Cluster.prototype.query = wrapQuery(Cluster.prototype.query)
|
|
63
|
+
|
|
64
|
+
return Cluster
|
|
65
|
+
})
|
|
66
|
+
|
|
67
|
+
function findCallbackIndex (args) {
|
|
68
|
+
for (let i = args.length - 1; i >= 2; i--) {
|
|
69
|
+
if (typeof args[i] === 'function') return i
|
|
70
|
+
}
|
|
71
|
+
return -1
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function wrapMaybeInvoke (_maybeInvoke) {
|
|
75
|
+
const wrapped = function (fn, args) {
|
|
76
|
+
if (!Array.isArray(args)) return _maybeInvoke.apply(this, arguments)
|
|
77
|
+
|
|
78
|
+
const callbackIndex = args.length - 1
|
|
79
|
+
const callback = args[callbackIndex]
|
|
80
|
+
|
|
81
|
+
if (callback instanceof Function) {
|
|
82
|
+
args[callbackIndex] = AsyncResource.bind(callback)
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
return _maybeInvoke.apply(this, arguments)
|
|
86
|
+
}
|
|
87
|
+
return shimmer.wrap(_maybeInvoke, wrapped)
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
function wrapQuery (query) {
|
|
91
|
+
const wrapped = function (q, params, callback) {
|
|
92
|
+
callback = AsyncResource.bind(arguments[arguments.length - 1])
|
|
93
|
+
|
|
94
|
+
if (typeof callback === 'function') {
|
|
95
|
+
arguments[arguments.length - 1] = callback
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
const res = query.apply(this, arguments)
|
|
99
|
+
return res
|
|
100
|
+
}
|
|
101
|
+
return shimmer.wrap(query, wrapped)
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
function wrap (prefix, fn) {
|
|
105
|
+
const startCh = channel(prefix + ':start')
|
|
106
|
+
const endCh = channel(prefix + ':end')
|
|
107
|
+
const asyncEndCh = channel(prefix + ':async-end')
|
|
108
|
+
const errorCh = channel(prefix + ':error')
|
|
109
|
+
|
|
110
|
+
const wrapped = function (key, value, options, callback) {
|
|
111
|
+
if (!startCh.hasSubscribers) {
|
|
112
|
+
return fn.apply(this, arguments)
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
const callbackIndex = findCallbackIndex(arguments)
|
|
116
|
+
|
|
117
|
+
if (callbackIndex < 0) return fn.apply(this, arguments)
|
|
118
|
+
|
|
119
|
+
const cb = arguments[callbackIndex]
|
|
120
|
+
|
|
121
|
+
startCh.publish({ bucket: this })
|
|
122
|
+
|
|
123
|
+
arguments[callbackIndex] = function (error, result) {
|
|
124
|
+
if (error) {
|
|
125
|
+
errorCh.publish(error)
|
|
126
|
+
}
|
|
127
|
+
asyncEndCh.publish(result)
|
|
128
|
+
return cb.apply(this, arguments)
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
try {
|
|
132
|
+
return fn.apply(this, arguments)
|
|
133
|
+
} catch (error) {
|
|
134
|
+
error.stack // trigger getting the stack at the original throwing point
|
|
135
|
+
errorCh.publish(error)
|
|
136
|
+
|
|
137
|
+
throw error
|
|
138
|
+
} finally {
|
|
139
|
+
endCh.publish(undefined)
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
return shimmer.wrap(fn, wrapped)
|
|
143
|
+
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
const {
|
|
4
|
+
channel,
|
|
5
|
+
addHook,
|
|
6
|
+
AsyncResource
|
|
7
|
+
} = require('./helpers/instrument')
|
|
8
|
+
const shimmer = require('../../datadog-shimmer')
|
|
9
|
+
|
|
10
|
+
const startCh = channel('apm:elasticsearch:query:start')
|
|
11
|
+
const asyncEndCh = channel('apm:elasticsearch:query:async-end')
|
|
12
|
+
const endCh = channel('apm:elasticsearch:query:end')
|
|
13
|
+
const errorCh = channel('apm:elasticsearch:query:error')
|
|
14
|
+
|
|
15
|
+
addHook({ name: '@elastic/transport', file: 'lib/Transport.js', versions: ['>=8'] }, (exports) => {
|
|
16
|
+
shimmer.wrap(exports.default.prototype, 'request', wrapRequest)
|
|
17
|
+
return exports
|
|
18
|
+
})
|
|
19
|
+
|
|
20
|
+
addHook({ name: '@elastic/elasticsearch', file: 'lib/Transport.js', versions: ['>=5.6.16 <8', '>=8'] }, Transport => {
|
|
21
|
+
shimmer.wrap(Transport.prototype, 'request', wrapRequest)
|
|
22
|
+
return Transport
|
|
23
|
+
})
|
|
24
|
+
|
|
25
|
+
addHook({ name: 'elasticsearch', file: 'src/lib/transport.js', versions: ['>=10'] }, Transport => {
|
|
26
|
+
shimmer.wrap(Transport.prototype, 'request', wrapRequest)
|
|
27
|
+
return Transport
|
|
28
|
+
})
|
|
29
|
+
|
|
30
|
+
function wrapRequest (request) {
|
|
31
|
+
return function (params, options, cb) {
|
|
32
|
+
if (!startCh.hasSubscribers) {
|
|
33
|
+
return request.apply(this, arguments)
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
if (!params) return request.apply(this, arguments)
|
|
37
|
+
|
|
38
|
+
const asyncResource = new AsyncResource('bound-anonymous-fn')
|
|
39
|
+
|
|
40
|
+
startCh.publish({ params })
|
|
41
|
+
|
|
42
|
+
try {
|
|
43
|
+
const lastIndex = arguments.length - 1
|
|
44
|
+
cb = arguments[lastIndex]
|
|
45
|
+
|
|
46
|
+
if (typeof cb === 'function') {
|
|
47
|
+
cb = asyncResource.bind(cb)
|
|
48
|
+
|
|
49
|
+
arguments[lastIndex] = AsyncResource.bind(function (error) {
|
|
50
|
+
finish(params, error)
|
|
51
|
+
return cb.apply(null, arguments)
|
|
52
|
+
})
|
|
53
|
+
return request.apply(this, arguments)
|
|
54
|
+
} else {
|
|
55
|
+
const promise = request.apply(this, arguments)
|
|
56
|
+
if (promise && typeof promise.then === 'function') {
|
|
57
|
+
promise.then(() => finish(params), e => finish(params, e))
|
|
58
|
+
} else {
|
|
59
|
+
finish(params)
|
|
60
|
+
}
|
|
61
|
+
return promise
|
|
62
|
+
}
|
|
63
|
+
} catch (err) {
|
|
64
|
+
err.stack // trigger getting the stack at the original throwing point
|
|
65
|
+
errorCh.publish(err)
|
|
66
|
+
|
|
67
|
+
throw err
|
|
68
|
+
} finally {
|
|
69
|
+
endCh.publish(undefined)
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function finish (params, error) {
|
|
75
|
+
if (error) {
|
|
76
|
+
errorCh.publish(error)
|
|
77
|
+
}
|
|
78
|
+
asyncEndCh.publish({ params })
|
|
79
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
const { addHook, AsyncResource } = require('./helpers/instrument')
|
|
4
|
+
const shimmer = require('../../datadog-shimmer')
|
|
5
|
+
|
|
6
|
+
function createWrapAcquire () {
|
|
7
|
+
return function wrapAcquire (acquire) {
|
|
8
|
+
return function acquireWithTrace (callback, priority) {
|
|
9
|
+
if (typeof callback === 'function') {
|
|
10
|
+
arguments[0] = AsyncResource.bind(callback)
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
return acquire.apply(this, arguments)
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function createWrapPool () {
|
|
19
|
+
return function wrapPool (Pool) {
|
|
20
|
+
if (typeof Pool !== 'function') return Pool
|
|
21
|
+
|
|
22
|
+
return function PoolWithTrace (factory) {
|
|
23
|
+
const pool = Pool.apply(this, arguments)
|
|
24
|
+
|
|
25
|
+
if (pool && typeof pool.acquire === 'function') {
|
|
26
|
+
shimmer.wrap(pool, 'acquire', createWrapAcquire())
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
return pool
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
addHook({
|
|
35
|
+
name: 'generic-pool',
|
|
36
|
+
versions: ['^2.4']
|
|
37
|
+
}, genericPool => {
|
|
38
|
+
shimmer.wrap(genericPool.Pool.prototype, 'acquire', createWrapAcquire())
|
|
39
|
+
return genericPool
|
|
40
|
+
})
|
|
41
|
+
|
|
42
|
+
addHook({
|
|
43
|
+
name: 'generic-pool',
|
|
44
|
+
versions: ['2 - 2.3']
|
|
45
|
+
}, genericPool => {
|
|
46
|
+
shimmer.wrap(genericPool, 'Pool', createWrapPool())
|
|
47
|
+
return genericPool
|
|
48
|
+
})
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
const {
|
|
4
|
+
channel,
|
|
5
|
+
addHook
|
|
6
|
+
} = require('./helpers/instrument')
|
|
7
|
+
const shimmer = require('../../datadog-shimmer')
|
|
8
|
+
|
|
9
|
+
const startCh = channel('apm:ioredis:command:start')
|
|
10
|
+
const asyncEndCh = channel('apm:ioredis:command:async-end')
|
|
11
|
+
const endCh = channel('apm:ioredis:command:end')
|
|
12
|
+
const errorCh = channel('apm:ioredis:command:error')
|
|
13
|
+
|
|
14
|
+
addHook({ name: 'ioredis', versions: ['>=2'] }, Redis => {
|
|
15
|
+
shimmer.wrap(Redis.prototype, 'sendCommand', sendCommand => function (command, stream) {
|
|
16
|
+
if (!startCh.hasSubscribers) return sendCommand.apply(this, arguments)
|
|
17
|
+
|
|
18
|
+
if (!command || !command.promise) return sendCommand.apply(this, arguments)
|
|
19
|
+
|
|
20
|
+
const options = this.options || {}
|
|
21
|
+
const connectionName = options.connectionName
|
|
22
|
+
const db = options.db
|
|
23
|
+
const connectionOptions = { host: options.host, port: options.port }
|
|
24
|
+
startCh.publish({ db, command: command.name, args: command.args, connectionOptions, connectionName })
|
|
25
|
+
|
|
26
|
+
command.promise.then(
|
|
27
|
+
() => finish(asyncEndCh, errorCh),
|
|
28
|
+
err => finish(asyncEndCh, errorCh, err)
|
|
29
|
+
)
|
|
30
|
+
|
|
31
|
+
try {
|
|
32
|
+
return sendCommand.apply(this, arguments)
|
|
33
|
+
} catch (err) {
|
|
34
|
+
errorCh.publish(err)
|
|
35
|
+
|
|
36
|
+
throw err
|
|
37
|
+
} finally {
|
|
38
|
+
endCh.publish(undefined)
|
|
39
|
+
}
|
|
40
|
+
})
|
|
41
|
+
return Redis
|
|
42
|
+
})
|
|
43
|
+
|
|
44
|
+
function finish (asyncEndCh, errorCh, error) {
|
|
45
|
+
if (error) {
|
|
46
|
+
errorCh.publish(error)
|
|
47
|
+
}
|
|
48
|
+
asyncEndCh.publish(undefined)
|
|
49
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
const { addHook } = require('./helpers/instrument')
|
|
4
|
+
const { wrapThen } = require('./helpers/promise')
|
|
5
|
+
const { AsyncResource } = require('./helpers/instrument')
|
|
6
|
+
const shimmer = require('../../datadog-shimmer')
|
|
7
|
+
|
|
8
|
+
function wrapAddQueue (addQueue) {
|
|
9
|
+
return function addQueueWithTrace (name) {
|
|
10
|
+
if (typeof name === 'function') {
|
|
11
|
+
arguments[0] = AsyncResource.bind(name)
|
|
12
|
+
} else if (typeof this[name] === 'function') {
|
|
13
|
+
arguments[0] = AsyncResource.bind((...args) => this[name](...args))
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
return addQueue.apply(this, arguments)
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
addHook({
|
|
21
|
+
name: 'mongoose',
|
|
22
|
+
versions: ['>=4.6.4']
|
|
23
|
+
}, mongoose => {
|
|
24
|
+
if (mongoose.Promise !== global.Promise) {
|
|
25
|
+
shimmer.wrap(mongoose.Promise.prototype, 'then', wrapThen)
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
shimmer.wrap(mongoose.Collection.prototype, 'addQueue', wrapAddQueue)
|
|
29
|
+
return mongoose
|
|
30
|
+
})
|
|
@@ -20,9 +20,9 @@ addHook({ name: 'mysql', file: 'lib/Connection.js', versions: ['>=2'] }, Connect
|
|
|
20
20
|
}
|
|
21
21
|
|
|
22
22
|
const sql = arguments[0].sql ? arguments[0].sql : arguments[0]
|
|
23
|
-
const
|
|
23
|
+
const conf = this.config
|
|
24
24
|
|
|
25
|
-
startCh.publish(
|
|
25
|
+
startCh.publish({ sql, conf })
|
|
26
26
|
|
|
27
27
|
try {
|
|
28
28
|
const res = query.apply(this, arguments)
|
|
@@ -8,10 +8,10 @@ const {
|
|
|
8
8
|
const shimmer = require('../../datadog-shimmer')
|
|
9
9
|
|
|
10
10
|
addHook({ name: 'mysql2', file: 'lib/connection.js', versions: ['>=1'] }, Connection => {
|
|
11
|
-
const startCh = channel('apm:
|
|
12
|
-
const asyncEndCh = channel('apm:
|
|
13
|
-
const endCh = channel('apm:
|
|
14
|
-
const errorCh = channel('apm:
|
|
11
|
+
const startCh = channel('apm:mysql2:query:start')
|
|
12
|
+
const asyncEndCh = channel('apm:mysql2:query:async-end')
|
|
13
|
+
const endCh = channel('apm:mysql2:query:end')
|
|
14
|
+
const errorCh = channel('apm:mysql2:query:error')
|
|
15
15
|
|
|
16
16
|
shimmer.wrap(Connection.prototype, 'addCommand', addCommand => function (cmd) {
|
|
17
17
|
if (!startCh.hasSubscribers) return addCommand.apply(this, arguments)
|
|
@@ -45,7 +45,7 @@ addHook({ name: 'mysql2', file: 'lib/connection.js', versions: ['>=1'] }, Connec
|
|
|
45
45
|
return asyncResource.bind(function executeWithTrace (packet, connection) {
|
|
46
46
|
const sql = cmd.statement ? cmd.statement.query : cmd.sql
|
|
47
47
|
|
|
48
|
-
startCh.publish(
|
|
48
|
+
startCh.publish({ sql, conf: config })
|
|
49
49
|
|
|
50
50
|
if (this.onResult) {
|
|
51
51
|
const onResult = asyncResource.bind(this.onResult)
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
const {
|
|
4
|
+
channel,
|
|
5
|
+
addHook
|
|
6
|
+
} = require('./helpers/instrument')
|
|
7
|
+
const shimmer = require('../../datadog-shimmer')
|
|
8
|
+
|
|
9
|
+
function wrapPino (symbol, wrapper, pino) {
|
|
10
|
+
return function pinoWithTrace () {
|
|
11
|
+
const instance = pino.apply(this, arguments)
|
|
12
|
+
|
|
13
|
+
Object.defineProperty(instance, symbol, {
|
|
14
|
+
configurable: true,
|
|
15
|
+
enumerable: true,
|
|
16
|
+
writable: true,
|
|
17
|
+
value: wrapper(instance[symbol])
|
|
18
|
+
})
|
|
19
|
+
|
|
20
|
+
return instance
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function wrapAsJson (asJson) {
|
|
25
|
+
const ch = channel('apm:pino:log')
|
|
26
|
+
return function asJsonWithTrace (obj, msg, num, time) {
|
|
27
|
+
obj = arguments[0] = obj || {}
|
|
28
|
+
|
|
29
|
+
const payload = { message: obj }
|
|
30
|
+
ch.publish(payload)
|
|
31
|
+
arguments[0] = payload.message
|
|
32
|
+
|
|
33
|
+
return asJson.apply(this, arguments)
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function wrapMixin (mixin) {
|
|
38
|
+
const ch = channel('apm:pino:log')
|
|
39
|
+
return function mixinWithTrace () {
|
|
40
|
+
let obj = {}
|
|
41
|
+
|
|
42
|
+
if (mixin) {
|
|
43
|
+
obj = mixin.apply(this, arguments)
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const payload = { message: obj }
|
|
47
|
+
ch.publish(payload)
|
|
48
|
+
|
|
49
|
+
return payload.message
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function wrapPrettifyObject (prettifyObject) {
|
|
54
|
+
const ch = channel('apm:pino:log')
|
|
55
|
+
return function prettifyObjectWithTrace (input) {
|
|
56
|
+
const payload = { message: input.input }
|
|
57
|
+
ch.publish(payload)
|
|
58
|
+
input.input = payload.message
|
|
59
|
+
return prettifyObject.apply(this, arguments)
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function wrapPrettyFactory (prettyFactory) {
|
|
64
|
+
const ch = channel('apm:pino:log')
|
|
65
|
+
return function prettyFactoryWithTrace () {
|
|
66
|
+
const pretty = prettyFactory.apply(this, arguments)
|
|
67
|
+
return function prettyWithTrace (obj) {
|
|
68
|
+
const payload = { message: obj }
|
|
69
|
+
ch.publish(payload)
|
|
70
|
+
arguments[0] = payload.message
|
|
71
|
+
return pretty.apply(this, arguments)
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
addHook({ name: 'pino', versions: ['2 - 3', '4', '>=5 <5.14.0'] }, pino => {
|
|
77
|
+
const asJsonSym = (pino.symbols && pino.symbols.asJsonSym) || 'asJson'
|
|
78
|
+
|
|
79
|
+
return shimmer.wrap(pino, wrapPino(asJsonSym, wrapAsJson, pino))
|
|
80
|
+
})
|
|
81
|
+
|
|
82
|
+
addHook({ name: 'pino', versions: ['>=5.14.0 <6.8.0'] }, pino => {
|
|
83
|
+
const mixinSym = pino.symbols.mixinSym
|
|
84
|
+
|
|
85
|
+
return shimmer.wrap(pino, wrapPino(mixinSym, wrapMixin, pino))
|
|
86
|
+
})
|
|
87
|
+
|
|
88
|
+
addHook({ name: 'pino', versions: ['>=6.8.0'] }, pino => {
|
|
89
|
+
const mixinSym = pino.symbols.mixinSym
|
|
90
|
+
|
|
91
|
+
const wrapped = shimmer.wrap(pino, wrapPino(mixinSym, wrapMixin, pino))
|
|
92
|
+
wrapped.pino = wrapped
|
|
93
|
+
wrapped.default = wrapped
|
|
94
|
+
|
|
95
|
+
return wrapped
|
|
96
|
+
})
|
|
97
|
+
|
|
98
|
+
addHook({ name: 'pino-pretty', file: 'lib/utils.js', versions: ['>=3'] }, utils => {
|
|
99
|
+
shimmer.wrap(utils, 'prettifyObject', wrapPrettifyObject)
|
|
100
|
+
return utils
|
|
101
|
+
})
|
|
102
|
+
|
|
103
|
+
addHook({ name: 'pino-pretty', versions: ['1 - 2'] }, prettyFactory => {
|
|
104
|
+
return shimmer.wrap(prettyFactory, wrapPrettyFactory(prettyFactory))
|
|
105
|
+
})
|