dd-trace 2.3.1 → 2.4.2
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/ci/init.js +26 -2
- package/index.d.ts +51 -0
- package/package.json +2 -2
- package/packages/datadog-instrumentations/index.js +10 -0
- package/packages/datadog-instrumentations/src/amqp10.js +70 -0
- package/packages/datadog-instrumentations/src/amqplib.js +58 -0
- package/packages/datadog-instrumentations/src/cassandra-driver.js +191 -0
- package/packages/datadog-instrumentations/src/cucumber.js +27 -12
- package/packages/datadog-instrumentations/src/helpers/hook.js +44 -0
- package/packages/datadog-instrumentations/src/helpers/instrument.js +31 -58
- package/packages/datadog-instrumentations/src/http/client.js +170 -0
- package/packages/datadog-instrumentations/src/http/server.js +61 -0
- package/packages/datadog-instrumentations/src/http.js +4 -0
- package/packages/datadog-instrumentations/src/mocha.js +139 -0
- package/packages/datadog-instrumentations/src/mongodb-core.js +179 -0
- package/packages/datadog-instrumentations/src/net.js +117 -0
- package/packages/datadog-instrumentations/src/pg.js +75 -0
- package/packages/datadog-instrumentations/src/rhea.js +224 -0
- package/packages/datadog-instrumentations/src/tedious.js +66 -0
- package/packages/datadog-plugin-amqp10/src/index.js +79 -122
- package/packages/datadog-plugin-amqplib/src/index.js +77 -142
- package/packages/datadog-plugin-cassandra-driver/src/index.js +52 -224
- package/packages/datadog-plugin-cucumber/src/index.js +3 -1
- package/packages/datadog-plugin-elasticsearch/src/index.js +4 -2
- package/packages/datadog-plugin-http/src/client.js +112 -252
- package/packages/datadog-plugin-http/src/index.js +29 -3
- package/packages/datadog-plugin-http/src/server.js +54 -32
- package/packages/datadog-plugin-jest/src/jest-environment.js +3 -3
- package/packages/datadog-plugin-jest/src/jest-jasmine2.js +5 -3
- package/packages/datadog-plugin-mocha/src/index.js +96 -207
- package/packages/datadog-plugin-mongodb-core/src/index.js +119 -3
- package/packages/datadog-plugin-net/src/index.js +65 -121
- package/packages/datadog-plugin-next/src/index.js +10 -10
- package/packages/datadog-plugin-pg/src/index.js +32 -69
- package/packages/datadog-plugin-rhea/src/index.js +59 -225
- package/packages/datadog-plugin-tedious/src/index.js +38 -86
- package/packages/dd-trace/lib/version.js +1 -1
- package/packages/dd-trace/src/appsec/recommended.json +235 -315
- package/packages/dd-trace/src/config.js +6 -0
- package/packages/dd-trace/src/iitm.js +5 -1
- package/packages/dd-trace/src/loader.js +6 -4
- package/packages/dd-trace/src/noop/tracer.js +4 -0
- package/packages/dd-trace/src/opentracing/propagation/text_map.js +34 -1
- package/packages/dd-trace/src/opentracing/span.js +34 -0
- package/packages/dd-trace/src/plugin_manager.js +4 -0
- package/packages/dd-trace/src/plugins/plugin.js +3 -1
- package/packages/dd-trace/src/plugins/util/web.js +99 -93
- package/packages/dd-trace/src/proxy.js +4 -0
- package/packages/dd-trace/src/ritm.js +60 -25
- package/packages/dd-trace/src/tracer.js +16 -0
- package/packages/datadog-plugin-mongodb-core/src/legacy.js +0 -59
- package/packages/datadog-plugin-mongodb-core/src/unified.js +0 -138
- package/packages/datadog-plugin-mongodb-core/src/util.js +0 -143
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
const { instrument } = require('./util')
|
|
4
|
-
|
|
5
|
-
function createWrapCommand (tracer, config, name) {
|
|
6
|
-
return function wrapCommand (command) {
|
|
7
|
-
return function commandWithTrace (ns, ops) {
|
|
8
|
-
return instrument(command, this, arguments, this, ns, ops, tracer, config, { name })
|
|
9
|
-
}
|
|
10
|
-
}
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
function createWrapQuery (tracer, config) {
|
|
14
|
-
return function wrapQuery (query) {
|
|
15
|
-
return function queryWithTrace () {
|
|
16
|
-
const pool = this.server.s.pool
|
|
17
|
-
const ns = this.ns
|
|
18
|
-
const ops = this.cmd
|
|
19
|
-
|
|
20
|
-
return instrument(query, this, arguments, pool, ns, ops, tracer, config)
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
function createWrapCursor (tracer, config, name) {
|
|
26
|
-
return function wrapCursor (cursor) {
|
|
27
|
-
return function cursorWithTrace () {
|
|
28
|
-
const pool = this.server.s.pool
|
|
29
|
-
const ns = this.ns
|
|
30
|
-
|
|
31
|
-
return instrument(cursor, this, arguments, pool, ns, {}, tracer, config, { name })
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
module.exports = [
|
|
37
|
-
{
|
|
38
|
-
name: 'mongodb-core',
|
|
39
|
-
versions: ['2 - 3.1.9'],
|
|
40
|
-
patch ({ Cursor, Server }, tracer, config) {
|
|
41
|
-
this.wrap(Server.prototype, 'command', createWrapCommand(tracer, config))
|
|
42
|
-
this.wrap(Server.prototype, 'insert', createWrapCommand(tracer, config, 'insert'))
|
|
43
|
-
this.wrap(Server.prototype, 'update', createWrapCommand(tracer, config, 'update'))
|
|
44
|
-
this.wrap(Server.prototype, 'remove', createWrapCommand(tracer, config, 'remove'))
|
|
45
|
-
this.wrap(Cursor.prototype, '_getmore', createWrapCursor(tracer, config, 'getMore'))
|
|
46
|
-
this.wrap(Cursor.prototype, '_find', createWrapQuery(tracer, config))
|
|
47
|
-
this.wrap(Cursor.prototype, 'kill', createWrapCursor(tracer, config, 'killCursors'))
|
|
48
|
-
},
|
|
49
|
-
unpatch ({ Cursor, Server }) {
|
|
50
|
-
this.unwrap(Server.prototype, 'command')
|
|
51
|
-
this.unwrap(Server.prototype, 'insert')
|
|
52
|
-
this.unwrap(Server.prototype, 'update')
|
|
53
|
-
this.unwrap(Server.prototype, 'remove')
|
|
54
|
-
this.unwrap(Cursor.prototype, '_getmore')
|
|
55
|
-
this.unwrap(Cursor.prototype, '_find')
|
|
56
|
-
this.unwrap(Cursor.prototype, 'kill')
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
]
|
|
@@ -1,138 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
const { instrument } = require('./util')
|
|
4
|
-
|
|
5
|
-
function createWrapConnectionCommand (tracer, config, name) {
|
|
6
|
-
return function wrapCommand (command) {
|
|
7
|
-
return function commandWithTrace (ns, ops) {
|
|
8
|
-
const hostParts = typeof this.address === 'string' ? this.address.split(':') : ''
|
|
9
|
-
const options = hostParts.length === 2
|
|
10
|
-
? { host: hostParts[0], port: hostParts[1] }
|
|
11
|
-
: {} // no port means the address is a random UUID so no host either
|
|
12
|
-
const topology = { s: { options } }
|
|
13
|
-
|
|
14
|
-
ns = `${ns.db}.${ns.collection}`
|
|
15
|
-
|
|
16
|
-
return instrument(command, this, arguments, topology, ns, ops, tracer, config, { name })
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
function createWrapCommand (tracer, config, name) {
|
|
22
|
-
return function wrapCommand (command) {
|
|
23
|
-
return function commandWithTrace (server, ns, ops) {
|
|
24
|
-
return instrument(command, this, arguments, server, ns, ops, tracer, config, { name })
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
function createWrapMaybePromise (tracer, config) {
|
|
30
|
-
return function wrapMaybePromise (maybePromise) {
|
|
31
|
-
return function maybePromiseWithTrace (parent, callback, fn) {
|
|
32
|
-
const callbackIndex = arguments.length - 2
|
|
33
|
-
|
|
34
|
-
callback = arguments[callbackIndex]
|
|
35
|
-
|
|
36
|
-
if (typeof callback === 'function') {
|
|
37
|
-
arguments[callbackIndex] = tracer.scope().bind(callback)
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
return maybePromise.apply(this, arguments)
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
function patch (wp, tracer, config) {
|
|
46
|
-
this.wrap(wp, 'command', createWrapCommand(tracer, config))
|
|
47
|
-
this.wrap(wp, 'insert', createWrapCommand(tracer, config, 'insert'))
|
|
48
|
-
this.wrap(wp, 'update', createWrapCommand(tracer, config, 'update'))
|
|
49
|
-
this.wrap(wp, 'remove', createWrapCommand(tracer, config, 'remove'))
|
|
50
|
-
this.wrap(wp, 'query', createWrapCommand(tracer, config))
|
|
51
|
-
this.wrap(wp, 'getMore', createWrapCommand(tracer, config, 'getMore'))
|
|
52
|
-
this.wrap(wp, 'killCursors', createWrapCommand(tracer, config, 'killCursors'))
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
function unpatch (wp) {
|
|
56
|
-
this.unwrap(wp, 'command')
|
|
57
|
-
this.unwrap(wp, 'insert')
|
|
58
|
-
this.unwrap(wp, 'update')
|
|
59
|
-
this.unwrap(wp, 'remove')
|
|
60
|
-
this.unwrap(wp, 'query')
|
|
61
|
-
this.unwrap(wp, 'getMore')
|
|
62
|
-
this.unwrap(wp, 'killCursors')
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
function patchConnection ({ Connection }, tracer, config) {
|
|
66
|
-
const proto = Connection.prototype
|
|
67
|
-
|
|
68
|
-
this.wrap(proto, 'command', createWrapConnectionCommand(tracer, config))
|
|
69
|
-
this.wrap(proto, 'query', createWrapConnectionCommand(tracer, config))
|
|
70
|
-
this.wrap(proto, 'getMore', createWrapConnectionCommand(tracer, config, 'getMore'))
|
|
71
|
-
this.wrap(proto, 'killCursors', createWrapConnectionCommand(tracer, config, 'killCursors'))
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
function unpatchConnection ({ Connection }) {
|
|
75
|
-
const proto = Connection.prototype
|
|
76
|
-
|
|
77
|
-
this.unwrap(proto, 'command')
|
|
78
|
-
this.unwrap(proto, 'query')
|
|
79
|
-
this.unwrap(proto, 'getMore')
|
|
80
|
-
this.unwrap(proto, 'killCursors')
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
function patchClass (WireProtocol, tracer, config) {
|
|
84
|
-
this.wrap(WireProtocol.prototype, 'command', createWrapCommand(tracer, config))
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
function unpatchClass (WireProtocol) {
|
|
88
|
-
this.unwrap(WireProtocol.prototype, 'command')
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
module.exports = [
|
|
92
|
-
{
|
|
93
|
-
name: 'mongodb',
|
|
94
|
-
versions: ['>=4'],
|
|
95
|
-
file: 'lib/cmap/connection.js',
|
|
96
|
-
patch: patchConnection,
|
|
97
|
-
unpatch: unpatchConnection
|
|
98
|
-
},
|
|
99
|
-
{
|
|
100
|
-
name: 'mongodb',
|
|
101
|
-
versions: ['>=3.5.4'],
|
|
102
|
-
file: 'lib/utils.js',
|
|
103
|
-
patch (util, tracer, config) {
|
|
104
|
-
this.wrap(util, 'maybePromise', createWrapMaybePromise(tracer, config))
|
|
105
|
-
},
|
|
106
|
-
unpatch (util) {
|
|
107
|
-
this.unwrap(util, 'maybePromise')
|
|
108
|
-
}
|
|
109
|
-
},
|
|
110
|
-
{
|
|
111
|
-
name: 'mongodb',
|
|
112
|
-
versions: ['>=3.3 <4'],
|
|
113
|
-
file: 'lib/core/wireprotocol/index.js',
|
|
114
|
-
patch,
|
|
115
|
-
unpatch
|
|
116
|
-
},
|
|
117
|
-
{
|
|
118
|
-
name: 'mongodb-core',
|
|
119
|
-
versions: ['>=3.2'],
|
|
120
|
-
file: 'lib/wireprotocol/index.js',
|
|
121
|
-
patch,
|
|
122
|
-
unpatch
|
|
123
|
-
},
|
|
124
|
-
{
|
|
125
|
-
name: 'mongodb-core',
|
|
126
|
-
versions: ['~3.1.10'],
|
|
127
|
-
file: 'lib/wireprotocol/3_2_support.js',
|
|
128
|
-
patch: patchClass,
|
|
129
|
-
unpatch: unpatchClass
|
|
130
|
-
},
|
|
131
|
-
{
|
|
132
|
-
name: 'mongodb-core',
|
|
133
|
-
versions: ['~3.1.10'],
|
|
134
|
-
file: 'lib/wireprotocol/2_6_support.js',
|
|
135
|
-
patch: patchClass,
|
|
136
|
-
unpatch: unpatchClass
|
|
137
|
-
}
|
|
138
|
-
]
|
|
@@ -1,143 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
const analyticsSampler = require('../../dd-trace/src/analytics_sampler')
|
|
4
|
-
|
|
5
|
-
function instrument (command, ctx, args, server, ns, ops, tracer, config, options = {}) {
|
|
6
|
-
const name = options.name || (ops && Object.keys(ops)[0])
|
|
7
|
-
const index = args.length - 1
|
|
8
|
-
const callback = args[index]
|
|
9
|
-
|
|
10
|
-
if (typeof callback !== 'function') return command.apply(ctx, args)
|
|
11
|
-
|
|
12
|
-
const span = startSpan(tracer, config, ns, ops, server, name)
|
|
13
|
-
|
|
14
|
-
if (name !== 'getMore' && name !== 'killCursors') {
|
|
15
|
-
analyticsSampler.sample(span, config.measured)
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
args[index] = wrapCallback(tracer, span, callback)
|
|
19
|
-
|
|
20
|
-
return tracer.scope().bind(command, span).apply(ctx, args)
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
function startSpan (tracer, config, ns, ops, server, name) {
|
|
24
|
-
const scope = tracer.scope()
|
|
25
|
-
const childOf = scope.active()
|
|
26
|
-
const span = tracer.startSpan('mongodb.query', { childOf })
|
|
27
|
-
|
|
28
|
-
addTags(span, tracer, config, ns, ops, server, name)
|
|
29
|
-
|
|
30
|
-
return span
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
function wrapCallback (tracer, span, done) {
|
|
34
|
-
return tracer.scope().bind((err, res) => {
|
|
35
|
-
if (err) {
|
|
36
|
-
span.addTags({
|
|
37
|
-
'error.type': err.name,
|
|
38
|
-
'error.msg': err.message,
|
|
39
|
-
'error.stack': err.stack
|
|
40
|
-
})
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
span.finish()
|
|
44
|
-
|
|
45
|
-
if (done) {
|
|
46
|
-
done(err, res)
|
|
47
|
-
}
|
|
48
|
-
})
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
function addTags (span, tracer, config, ns, cmd, topology, operationName) {
|
|
52
|
-
const query = getQuery(cmd)
|
|
53
|
-
const resource = getResource(ns, query, operationName)
|
|
54
|
-
|
|
55
|
-
span.addTags({
|
|
56
|
-
'service.name': config.service || `${tracer._service}-mongodb`,
|
|
57
|
-
'resource.name': resource,
|
|
58
|
-
'span.type': 'mongodb',
|
|
59
|
-
'span.kind': 'client',
|
|
60
|
-
'db.name': ns
|
|
61
|
-
})
|
|
62
|
-
|
|
63
|
-
if (query) {
|
|
64
|
-
span.setTag('mongodb.query', query)
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
addHost(span, topology)
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
function addHost (span, topology) {
|
|
71
|
-
const options = topology && topology.s && topology.s.options
|
|
72
|
-
|
|
73
|
-
if (options && options.host && options.port) {
|
|
74
|
-
span.addTags({
|
|
75
|
-
'out.host': topology.s.options.host,
|
|
76
|
-
'out.port': topology.s.options.port
|
|
77
|
-
})
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
function getQuery (cmd) {
|
|
82
|
-
if (!cmd || typeof cmd !== 'object' || Array.isArray(cmd)) return
|
|
83
|
-
if (cmd.query) return JSON.stringify(sanitize(cmd.query))
|
|
84
|
-
if (cmd.filter) return JSON.stringify(sanitize(cmd.filter))
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
function getResource (ns, query, operationName) {
|
|
88
|
-
const parts = [operationName, ns]
|
|
89
|
-
|
|
90
|
-
if (query) {
|
|
91
|
-
parts.push(query)
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
return parts.join(' ')
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
function shouldHide (input) {
|
|
98
|
-
return !isObject(input) || Buffer.isBuffer(input) || isBSON(input)
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
function sanitize (input) {
|
|
102
|
-
if (shouldHide(input)) return '?'
|
|
103
|
-
|
|
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
|
-
}
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
return output
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
function isObject (val) {
|
|
136
|
-
return typeof val === 'object' && val !== null && !(val instanceof Array)
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
function isBSON (val) {
|
|
140
|
-
return val && val._bsontype
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
module.exports = { instrument }
|