dd-trace 2.0.0-appsec-beta.3 → 2.0.0
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/MIGRATING.md +65 -0
- package/NOTICE +4 -0
- package/ci/cypress/plugin.js +3 -0
- package/ci/cypress/support.js +1 -0
- package/ci/init.js +13 -0
- package/ci/jest/env.js +14 -0
- package/index.d.ts +35 -48
- package/package.json +7 -4
- package/packages/datadog-instrumentations/index.js +10 -0
- package/packages/datadog-instrumentations/src/bluebird.js +26 -0
- package/packages/datadog-instrumentations/src/dns.js +94 -0
- package/packages/datadog-instrumentations/src/helpers/instrument.js +120 -0
- package/packages/datadog-instrumentations/src/helpers/promise.js +29 -0
- package/packages/datadog-instrumentations/src/memcached.js +53 -0
- package/packages/datadog-instrumentations/src/mysql.js +67 -0
- package/packages/datadog-instrumentations/src/promise-js.js +15 -0
- package/packages/datadog-instrumentations/src/promise.js +14 -0
- package/packages/datadog-instrumentations/src/q.js +13 -0
- package/packages/datadog-instrumentations/src/when.js +14 -0
- package/packages/datadog-plugin-cucumber/src/index.js +4 -4
- package/packages/datadog-plugin-cypress/src/plugin.js +12 -2
- package/packages/datadog-plugin-cypress/src/support.js +21 -6
- package/packages/datadog-plugin-dns/src/index.js +65 -178
- package/packages/datadog-plugin-fs/src/index.js +7 -3
- package/packages/datadog-plugin-http/src/client.js +9 -24
- package/packages/datadog-plugin-http/src/server.js +5 -0
- package/packages/datadog-plugin-http2/src/client.js +1 -24
- package/packages/datadog-plugin-http2/src/server.js +2 -2
- package/packages/datadog-plugin-jest/src/jest-environment.js +4 -4
- package/packages/datadog-plugin-jest/src/jest-jasmine2.js +2 -2
- package/packages/datadog-plugin-knex/src/index.js +3 -3
- package/packages/datadog-plugin-memcached/src/index.js +41 -63
- package/packages/datadog-plugin-mocha/src/index.js +3 -2
- package/packages/datadog-plugin-moleculer/src/client.js +60 -0
- package/packages/datadog-plugin-moleculer/src/index.js +8 -0
- package/packages/datadog-plugin-moleculer/src/server.js +61 -0
- package/packages/datadog-plugin-moleculer/src/util.js +21 -0
- package/packages/datadog-plugin-mongoose/src/index.js +2 -2
- package/packages/datadog-plugin-mysql/src/index.js +37 -89
- package/packages/datadog-plugin-net/src/index.js +5 -0
- package/packages/datadog-plugin-pino/src/index.js +25 -1
- package/packages/datadog-plugin-redis/src/index.js +31 -1
- package/packages/datadog-plugin-router/src/index.js +28 -3
- package/packages/dd-trace/lib/version.js +1 -1
- package/packages/dd-trace/src/appsec/addresses.js +11 -4
- package/packages/dd-trace/src/appsec/callbacks/ddwaf.js +5 -8
- package/packages/dd-trace/src/{gateway → appsec/gateway}/als.js +1 -0
- package/packages/dd-trace/src/appsec/gateway/channels.js +11 -0
- package/packages/dd-trace/src/{gateway → appsec/gateway}/engine/engine.js +20 -30
- package/packages/dd-trace/src/{gateway → appsec/gateway}/engine/index.js +0 -0
- package/packages/dd-trace/src/{gateway → appsec/gateway}/engine/runner.js +2 -0
- package/packages/dd-trace/src/appsec/index.js +54 -38
- package/packages/dd-trace/src/appsec/recommended.json +1 -1
- package/packages/dd-trace/src/appsec/reporter.js +27 -10
- package/packages/dd-trace/src/config.js +31 -27
- package/packages/dd-trace/src/constants.js +6 -3
- package/packages/dd-trace/src/exporters/agent/request.js +8 -0
- package/packages/dd-trace/src/format.js +26 -39
- package/packages/dd-trace/src/instrumenter.js +6 -1
- package/packages/dd-trace/src/log.js +6 -15
- package/packages/dd-trace/src/noop/span_context.js +0 -1
- package/packages/dd-trace/src/noop/tracer.js +0 -6
- package/packages/dd-trace/src/opentracing/propagation/text_map.js +79 -46
- package/packages/dd-trace/src/opentracing/span.js +2 -7
- package/packages/dd-trace/src/opentracing/span_context.js +2 -4
- package/packages/dd-trace/src/opentracing/tracer.js +5 -23
- package/packages/dd-trace/src/plugin_manager.js +65 -0
- package/packages/dd-trace/src/plugins/index.js +1 -5
- package/packages/dd-trace/src/plugins/plugin.js +63 -0
- package/packages/dd-trace/src/plugins/util/ci.js +13 -4
- package/packages/dd-trace/src/plugins/util/redis.js +0 -2
- package/packages/dd-trace/src/plugins/util/test.js +9 -4
- package/packages/dd-trace/src/plugins/util/user-provided-git.js +17 -2
- package/packages/dd-trace/src/plugins/util/web.js +6 -16
- package/packages/dd-trace/src/priority_sampler.js +71 -19
- package/packages/dd-trace/src/profiling/exporters/agent.js +35 -34
- package/packages/dd-trace/src/proxy.js +39 -35
- package/packages/dd-trace/src/ritm.js +40 -16
- package/packages/dd-trace/src/span_processor.js +0 -7
- package/packages/dd-trace/src/tracer.js +5 -6
- package/scripts/install_plugin_modules.js +30 -1
- package/packages/datadog-plugin-bluebird/src/index.js +0 -69
- package/packages/datadog-plugin-promise/src/index.js +0 -17
- package/packages/datadog-plugin-promise-js/src/index.js +0 -20
- package/packages/datadog-plugin-q/src/index.js +0 -16
- package/packages/datadog-plugin-when/src/index.js +0 -17
- package/packages/dd-trace/src/gateway/channels.js +0 -8
- package/packages/dd-trace/src/gateway/dc_block.js +0 -68
- package/packages/dd-trace/src/plugins/util/ci-app-spec.json +0 -36
- package/packages/dd-trace/src/plugins/util/promise.js +0 -31
- package/packages/dd-trace/src/scope/noop/scope_manager.js +0 -28
|
@@ -1,26 +1,19 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
3
|
const URL = require('url').URL
|
|
4
|
-
const opentracing = require('opentracing')
|
|
5
4
|
const log = require('../../dd-trace/src/log')
|
|
6
|
-
const constants = require('../../dd-trace/src/constants')
|
|
7
5
|
const tags = require('../../../ext/tags')
|
|
8
6
|
const kinds = require('../../../ext/kinds')
|
|
9
7
|
const formats = require('../../../ext/formats')
|
|
10
|
-
const urlFilter = require('../../dd-trace/src/plugins/util/urlfilter')
|
|
11
8
|
const analyticsSampler = require('../../dd-trace/src/analytics_sampler')
|
|
12
9
|
const shimmer = require('../../datadog-shimmer')
|
|
13
10
|
|
|
14
|
-
const Reference = opentracing.Reference
|
|
15
|
-
|
|
16
11
|
const HTTP_HEADERS = formats.HTTP_HEADERS
|
|
17
12
|
const HTTP_STATUS_CODE = tags.HTTP_STATUS_CODE
|
|
18
13
|
const HTTP_REQUEST_HEADERS = tags.HTTP_REQUEST_HEADERS
|
|
19
14
|
const HTTP_RESPONSE_HEADERS = tags.HTTP_RESPONSE_HEADERS
|
|
20
15
|
const SPAN_KIND = tags.SPAN_KIND
|
|
21
16
|
const CLIENT = kinds.CLIENT
|
|
22
|
-
const REFERENCE_CHILD_OF = opentracing.REFERENCE_CHILD_OF
|
|
23
|
-
const REFERENCE_NOOP = constants.REFERENCE_NOOP
|
|
24
17
|
|
|
25
18
|
const HTTP2_HEADER_METHOD = ':method'
|
|
26
19
|
const HTTP2_HEADER_PATH = ':path'
|
|
@@ -91,26 +84,14 @@ function getStatusValidator (config) {
|
|
|
91
84
|
return code => code < 400 || code >= 500
|
|
92
85
|
}
|
|
93
86
|
|
|
94
|
-
function getFilter (tracer, config) {
|
|
95
|
-
const blocklist = tracer._url ? [`${tracer._url.href}/v0.4/traces`] : []
|
|
96
|
-
|
|
97
|
-
config = Object.assign({}, config, {
|
|
98
|
-
blocklist: blocklist.concat(config.blocklist || [])
|
|
99
|
-
})
|
|
100
|
-
|
|
101
|
-
return urlFilter.getFilter(config)
|
|
102
|
-
}
|
|
103
|
-
|
|
104
87
|
function normalizeConfig (tracer, config) {
|
|
105
88
|
config = config.client || config
|
|
106
89
|
|
|
107
90
|
const validateStatus = getStatusValidator(config)
|
|
108
|
-
const filter = getFilter(tracer, config)
|
|
109
91
|
const headers = getHeaders(config)
|
|
110
92
|
|
|
111
93
|
return Object.assign({}, config, {
|
|
112
94
|
validateStatus,
|
|
113
|
-
filter,
|
|
114
95
|
headers
|
|
115
96
|
})
|
|
116
97
|
}
|
|
@@ -165,12 +146,8 @@ function startSpan (tracer, config, headers, sessionDetails) {
|
|
|
165
146
|
const method = headers[HTTP2_HEADER_METHOD] || HTTP2_METHOD_GET
|
|
166
147
|
const url = `${sessionDetails.protocol}//${sessionDetails.host}:${sessionDetails.port}${path}`
|
|
167
148
|
|
|
168
|
-
const type = config.filter(url) ? REFERENCE_CHILD_OF : REFERENCE_NOOP
|
|
169
|
-
|
|
170
149
|
const span = tracer.startSpan('http.request', {
|
|
171
|
-
|
|
172
|
-
new Reference(type, childOf)
|
|
173
|
-
],
|
|
150
|
+
childOf,
|
|
174
151
|
tags: {
|
|
175
152
|
[SPAN_KIND]: CLIENT,
|
|
176
153
|
'service.name': getServiceName(tracer, config, sessionDetails),
|
|
@@ -20,6 +20,7 @@ const HTTP_STATUS_CODE = tags.HTTP_STATUS_CODE
|
|
|
20
20
|
const HTTP_ROUTE = tags.HTTP_ROUTE
|
|
21
21
|
const HTTP_REQUEST_HEADERS = tags.HTTP_REQUEST_HEADERS
|
|
22
22
|
const HTTP_RESPONSE_HEADERS = tags.HTTP_RESPONSE_HEADERS
|
|
23
|
+
const MANUAL_DROP = tags.MANUAL_DROP
|
|
23
24
|
|
|
24
25
|
const HTTP_STATUS_OK = 200
|
|
25
26
|
const HTTP2_HEADER_AUTHORITY = ':authority'
|
|
@@ -73,9 +74,8 @@ function instrumentStream (tracer, config, stream, headers, name, callback) {
|
|
|
73
74
|
|
|
74
75
|
const span = startStreamSpan(tracer, config, stream, headers, name)
|
|
75
76
|
|
|
76
|
-
// TODO: replace this with a REFERENCE_NOOP after we split http/express/etc
|
|
77
77
|
if (!config.filter(headers[HTTP2_HEADER_PATH])) {
|
|
78
|
-
span.
|
|
78
|
+
span.setTag(MANUAL_DROP, true)
|
|
79
79
|
}
|
|
80
80
|
|
|
81
81
|
if (config.service) {
|
|
@@ -238,8 +238,8 @@ module.exports = [
|
|
|
238
238
|
{
|
|
239
239
|
name: 'jest-environment-node',
|
|
240
240
|
versions: ['>=24.8.0'],
|
|
241
|
-
patch: function (NodeEnvironment, tracer) {
|
|
242
|
-
const testEnvironmentMetadata = getTestEnvironmentMetadata('jest')
|
|
241
|
+
patch: function (NodeEnvironment, tracer, config) {
|
|
242
|
+
const testEnvironmentMetadata = getTestEnvironmentMetadata('jest', config)
|
|
243
243
|
|
|
244
244
|
this.wrap(NodeEnvironment.prototype, 'teardown', createWrapTeardown(tracer, this))
|
|
245
245
|
|
|
@@ -257,8 +257,8 @@ module.exports = [
|
|
|
257
257
|
{
|
|
258
258
|
name: 'jest-environment-jsdom',
|
|
259
259
|
versions: ['>=24.8.0'],
|
|
260
|
-
patch: function (JsdomEnvironment, tracer) {
|
|
261
|
-
const testEnvironmentMetadata = getTestEnvironmentMetadata('jest')
|
|
260
|
+
patch: function (JsdomEnvironment, tracer, config) {
|
|
261
|
+
const testEnvironmentMetadata = getTestEnvironmentMetadata('jest', config)
|
|
262
262
|
|
|
263
263
|
this.wrap(JsdomEnvironment.prototype, 'teardown', createWrapTeardown(tracer, this))
|
|
264
264
|
|
|
@@ -169,8 +169,8 @@ module.exports = [
|
|
|
169
169
|
name: 'jest-jasmine2',
|
|
170
170
|
versions: ['>=24.8.0'],
|
|
171
171
|
file: 'build/jasmineAsyncInstall.js',
|
|
172
|
-
patch: function (jasmineAsyncInstallExport, tracer) {
|
|
173
|
-
const testEnvironmentMetadata = getTestEnvironmentMetadata('jest')
|
|
172
|
+
patch: function (jasmineAsyncInstallExport, tracer, config) {
|
|
173
|
+
const testEnvironmentMetadata = getTestEnvironmentMetadata('jest', config)
|
|
174
174
|
return this.wrapExport(
|
|
175
175
|
jasmineAsyncInstallExport.default,
|
|
176
176
|
createWrapJasmineAsyncInstall(tracer, this, testEnvironmentMetadata)(jasmineAsyncInstallExport.default)
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
|
-
const
|
|
3
|
+
const { wrapThen } = require('../../datadog-instrumentations/src/helpers/promise')
|
|
4
4
|
|
|
5
5
|
function createPatch (file) {
|
|
6
6
|
return {
|
|
7
7
|
name: 'knex',
|
|
8
8
|
versions: ['>=0.8.0'],
|
|
9
9
|
file,
|
|
10
|
-
patch (Builder
|
|
11
|
-
this.wrap(Builder.prototype, 'then',
|
|
10
|
+
patch (Builder) {
|
|
11
|
+
this.wrap(Builder.prototype, 'then', wrapThen)
|
|
12
12
|
},
|
|
13
13
|
unpatch (Builder) {
|
|
14
14
|
this.unwrap(Builder.prototype, 'then')
|
|
@@ -1,77 +1,64 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
|
+
const Plugin = require('../../dd-trace/src/plugins/plugin')
|
|
4
|
+
const { storage } = require('../../datadog-core')
|
|
3
5
|
const analyticsSampler = require('../../dd-trace/src/analytics_sampler')
|
|
4
6
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
return
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
7
|
+
class MemcachedPlugin extends Plugin {
|
|
8
|
+
static get name () {
|
|
9
|
+
return 'memcached'
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
constructor (...args) {
|
|
13
|
+
super(...args)
|
|
14
|
+
|
|
15
|
+
this.addSub('apm:memcached:command:start', () => {
|
|
16
|
+
const store = storage.getStore()
|
|
17
|
+
const childOf = store ? store.span : store
|
|
18
|
+
const span = this.tracer.startSpan('memcached.command', {
|
|
11
19
|
childOf,
|
|
12
20
|
tags: {
|
|
13
21
|
'span.kind': 'client',
|
|
14
22
|
'span.type': 'memcached',
|
|
15
|
-
'service.name': config.service || `${tracer._service}-memcached`
|
|
23
|
+
'service.name': this.config.service || `${this.tracer._service}-memcached`
|
|
16
24
|
}
|
|
17
25
|
})
|
|
18
26
|
|
|
19
|
-
analyticsSampler.sample(span, config.measured)
|
|
20
|
-
|
|
21
|
-
arguments[0] = wrapQueryCompiler(queryCompiler, this, server, scope, span)
|
|
22
|
-
|
|
23
|
-
return scope.bind(command, span).apply(this, arguments)
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
function wrapQueryCompiler (original, client, server, scope, span) {
|
|
29
|
-
const parent = scope.active()
|
|
30
|
-
|
|
31
|
-
return function () {
|
|
32
|
-
const query = original.apply(this, arguments)
|
|
33
|
-
const callback = query.callback
|
|
34
|
-
|
|
35
|
-
span.addTags({
|
|
36
|
-
'resource.name': query.type,
|
|
37
|
-
'memcached.command': query.command
|
|
27
|
+
analyticsSampler.sample(span, this.config.measured)
|
|
28
|
+
this.enter(span, store)
|
|
38
29
|
})
|
|
39
30
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
addError(span, err)
|
|
44
|
-
|
|
45
|
-
span.finish()
|
|
31
|
+
this.addSub('apm:memcached:command:end', () => {
|
|
32
|
+
this.exit()
|
|
33
|
+
})
|
|
46
34
|
|
|
47
|
-
|
|
48
|
-
|
|
35
|
+
this.addSub('apm:memcached:command:start:with-args', ({ client, server, query }) => {
|
|
36
|
+
const span = storage.getStore().span
|
|
37
|
+
span.addTags({
|
|
38
|
+
'resource.name': query.type,
|
|
39
|
+
'memcached.command': query.command
|
|
40
|
+
})
|
|
49
41
|
|
|
50
|
-
|
|
51
|
-
}
|
|
52
|
-
}
|
|
42
|
+
const address = getAddress(client, server, query)
|
|
53
43
|
|
|
54
|
-
|
|
55
|
-
|
|
44
|
+
if (address) {
|
|
45
|
+
span.addTags({
|
|
46
|
+
'out.host': address[0],
|
|
47
|
+
'out.port': address[1]
|
|
48
|
+
})
|
|
49
|
+
}
|
|
50
|
+
})
|
|
56
51
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
'out.port': address[1]
|
|
52
|
+
this.addSub('apm:memcached:command:error', err => {
|
|
53
|
+
const span = storage.getStore().span
|
|
54
|
+
span.setTag('error', err)
|
|
61
55
|
})
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
56
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
'error.type': error.name,
|
|
69
|
-
'error.msg': error.message,
|
|
70
|
-
'error.stack': error.stack
|
|
57
|
+
this.addSub('apm:memcached:command:async-end', () => {
|
|
58
|
+
const span = storage.getStore().span
|
|
59
|
+
span.finish()
|
|
71
60
|
})
|
|
72
61
|
}
|
|
73
|
-
|
|
74
|
-
return error
|
|
75
62
|
}
|
|
76
63
|
|
|
77
64
|
function getAddress (client, server, query) {
|
|
@@ -94,13 +81,4 @@ function getAddress (client, server, query) {
|
|
|
94
81
|
return server && server.split(':')
|
|
95
82
|
}
|
|
96
83
|
|
|
97
|
-
module.exports =
|
|
98
|
-
name: 'memcached',
|
|
99
|
-
versions: ['>=2.2'],
|
|
100
|
-
patch (Memcached, tracer, config) {
|
|
101
|
-
this.wrap(Memcached.prototype, 'command', createWrapCommand(tracer, config))
|
|
102
|
-
},
|
|
103
|
-
unpatch (Memcached) {
|
|
104
|
-
this.unwrap(Memcached.prototype, 'command')
|
|
105
|
-
}
|
|
106
|
-
}
|
|
84
|
+
module.exports = MemcachedPlugin
|
|
@@ -122,6 +122,7 @@ function getAllTestsInSuite (root) {
|
|
|
122
122
|
function createWrapRunTests (tracer, testEnvironmentMetadata, sourceRoot) {
|
|
123
123
|
return function wrapRunTests (runTests) {
|
|
124
124
|
return function runTestsWithTrace () {
|
|
125
|
+
this.once('end', () => tracer._exporter._writer.flush())
|
|
125
126
|
runTests.apply(this, arguments)
|
|
126
127
|
const suite = arguments[0]
|
|
127
128
|
const tests = getAllTestsInSuite(suite)
|
|
@@ -239,8 +240,8 @@ module.exports = [
|
|
|
239
240
|
name: 'mocha',
|
|
240
241
|
versions: ['>=5.2.0'],
|
|
241
242
|
file: 'lib/runner.js',
|
|
242
|
-
patch (Runner, tracer) {
|
|
243
|
-
const testEnvironmentMetadata = getTestEnvironmentMetadata('mocha')
|
|
243
|
+
patch (Runner, tracer, config) {
|
|
244
|
+
const testEnvironmentMetadata = getTestEnvironmentMetadata('mocha', config)
|
|
244
245
|
const sourceRoot = process.cwd()
|
|
245
246
|
this.wrap(Runner.prototype, 'runTests', createWrapRunTests(tracer, testEnvironmentMetadata, sourceRoot))
|
|
246
247
|
this.wrap(Runner.prototype, 'runTest', createWrapRunTest(tracer, testEnvironmentMetadata, sourceRoot))
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
const { moleculerTags } = require('./util')
|
|
4
|
+
|
|
5
|
+
function createWrapCall (tracer, config) {
|
|
6
|
+
return function wrapCall (call) {
|
|
7
|
+
return function callWithTrace (actionName, params, opts) {
|
|
8
|
+
const options = {
|
|
9
|
+
service: config.service,
|
|
10
|
+
resource: actionName,
|
|
11
|
+
tags: {
|
|
12
|
+
'span.kind': 'client'
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
opts = arguments[2] = opts || {}
|
|
17
|
+
opts.meta = opts.meta || {}
|
|
18
|
+
|
|
19
|
+
arguments.length = Math.max(3, arguments.length)
|
|
20
|
+
|
|
21
|
+
return tracer.trace('moleculer.call', options, () => {
|
|
22
|
+
const span = tracer.scope().active()
|
|
23
|
+
|
|
24
|
+
tracer.inject(span, 'text_map', opts.meta)
|
|
25
|
+
|
|
26
|
+
const promise = call.apply(this, arguments)
|
|
27
|
+
|
|
28
|
+
if (promise.ctx) {
|
|
29
|
+
const endpoint = promise.ctx.endpoint || {}
|
|
30
|
+
const node = endpoint.node || {}
|
|
31
|
+
|
|
32
|
+
span.addTags({
|
|
33
|
+
'out.host': node.hostname,
|
|
34
|
+
'out.port': node.port,
|
|
35
|
+
...moleculerTags(this, promise.ctx, config)
|
|
36
|
+
})
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
return promise
|
|
40
|
+
})
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
module.exports = [
|
|
46
|
+
{
|
|
47
|
+
name: 'moleculer',
|
|
48
|
+
versions: ['>=0.14'],
|
|
49
|
+
patch ({ ServiceBroker }, tracer, config) {
|
|
50
|
+
if (config.client === false) return
|
|
51
|
+
|
|
52
|
+
config = Object.assign({}, config, config.client)
|
|
53
|
+
|
|
54
|
+
this.wrap(ServiceBroker.prototype, 'call', createWrapCall(tracer, config))
|
|
55
|
+
},
|
|
56
|
+
unpatch ({ ServiceBroker }) {
|
|
57
|
+
this.unwrap(ServiceBroker.prototype, 'call')
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
]
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
const { moleculerTags } = require('./util')
|
|
4
|
+
|
|
5
|
+
function createWrapRegisterMiddlewares (tracer, config) {
|
|
6
|
+
return function wrapRegisterMiddlewares (registerMiddlewares) {
|
|
7
|
+
return function registerMiddlewaresWithTrace (userMiddlewares) {
|
|
8
|
+
if (this.middlewares && this.middlewares.add) {
|
|
9
|
+
this.middlewares.add(createMiddleware(tracer, config))
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
return registerMiddlewares.apply(this, arguments)
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function createMiddleware (tracer, config) {
|
|
18
|
+
return {
|
|
19
|
+
name: 'Datadog',
|
|
20
|
+
|
|
21
|
+
localAction (next, action) {
|
|
22
|
+
const broker = this
|
|
23
|
+
|
|
24
|
+
return function datadogMiddleware (ctx) {
|
|
25
|
+
const childOf = tracer.extract('text_map', ctx.meta)
|
|
26
|
+
const options = {
|
|
27
|
+
service: config.service,
|
|
28
|
+
resource: action.name,
|
|
29
|
+
type: 'web',
|
|
30
|
+
tags: {
|
|
31
|
+
'span.kind': 'server',
|
|
32
|
+
...moleculerTags(broker, ctx, config)
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
if (childOf) {
|
|
37
|
+
options.childOf = childOf
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
return tracer.trace('moleculer.action', options, () => next(ctx))
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
module.exports = [
|
|
47
|
+
{
|
|
48
|
+
name: 'moleculer',
|
|
49
|
+
versions: ['>=0.14'],
|
|
50
|
+
patch ({ ServiceBroker }, tracer, config) {
|
|
51
|
+
if (config.server === false) return
|
|
52
|
+
|
|
53
|
+
config = Object.assign({}, config, config.server)
|
|
54
|
+
|
|
55
|
+
this.wrap(ServiceBroker.prototype, 'registerMiddlewares', createWrapRegisterMiddlewares(tracer, config))
|
|
56
|
+
},
|
|
57
|
+
unpatch ({ ServiceBroker }) {
|
|
58
|
+
this.unwrap(ServiceBroker.prototype, 'registerMiddlewares')
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
]
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
// TODO: add ctx.params when nested object properties are deprecated
|
|
4
|
+
|
|
5
|
+
function moleculerTags (broker, ctx, config) {
|
|
6
|
+
const service = ctx.service || {}
|
|
7
|
+
const action = ctx.action || {}
|
|
8
|
+
const meta = config.meta && ctx.meta
|
|
9
|
+
|
|
10
|
+
return {
|
|
11
|
+
'moleculer.context.action': action.name,
|
|
12
|
+
'moleculer.context.meta': meta,
|
|
13
|
+
'moleculer.context.node_id': ctx.nodeID,
|
|
14
|
+
'moleculer.context.request_id': ctx.requestID,
|
|
15
|
+
'moleculer.context.service': service.name,
|
|
16
|
+
'moleculer.namespace': broker.namespace,
|
|
17
|
+
'moleculer.node_id': broker.nodeID
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
module.exports = { moleculerTags }
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
|
-
const
|
|
3
|
+
const { wrapThen } = require('../../datadog-instrumentations/src/helpers/promise')
|
|
4
4
|
|
|
5
5
|
function createWrapCollectionAddQueue (tracer, config) {
|
|
6
6
|
return function wrapAddQueue (addQueue) {
|
|
@@ -33,7 +33,7 @@ module.exports = [
|
|
|
33
33
|
versions: ['>=4.6.4'],
|
|
34
34
|
patch (mongoose, tracer, config) {
|
|
35
35
|
if (mongoose.Promise !== global.Promise) {
|
|
36
|
-
this.wrap(mongoose.Promise.prototype, 'then',
|
|
36
|
+
this.wrap(mongoose.Promise.prototype, 'then', wrapThen)
|
|
37
37
|
}
|
|
38
38
|
|
|
39
39
|
this.wrap(mongoose.Collection.prototype, 'addQueue', createWrapCollectionAddQueue(tracer, config))
|
|
@@ -1,110 +1,58 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
|
-
const
|
|
3
|
+
const Plugin = require('../../dd-trace/src/plugins/plugin')
|
|
4
|
+
const { storage } = require('../../datadog-core')
|
|
4
5
|
const analyticsSampler = require('../../dd-trace/src/analytics_sampler')
|
|
5
6
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
return
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
7
|
+
class MySQLPlugin extends Plugin {
|
|
8
|
+
static get name () {
|
|
9
|
+
return 'mysql'
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
constructor (...args) {
|
|
13
|
+
super(...args)
|
|
14
|
+
|
|
15
|
+
this.addSub('apm:mysql:query:start', ([sql, conf]) => {
|
|
16
|
+
const store = storage.getStore()
|
|
17
|
+
const childOf = store ? store.span : store
|
|
18
|
+
const span = this.tracer.startSpan('mysql.query', {
|
|
12
19
|
childOf,
|
|
13
20
|
tags: {
|
|
14
|
-
|
|
15
|
-
'service.name': config.service || `${tracer._service}-mysql`,
|
|
21
|
+
'service.name': this.config.service || `${this.tracer._service}-mysql`,
|
|
16
22
|
'span.type': 'sql',
|
|
17
23
|
'span.kind': 'client',
|
|
18
24
|
'db.type': 'mysql',
|
|
19
|
-
'db.user':
|
|
20
|
-
'out.host':
|
|
21
|
-
'out.port':
|
|
25
|
+
'db.user': conf.user,
|
|
26
|
+
'out.host': conf.host,
|
|
27
|
+
'out.port': conf.port,
|
|
28
|
+
'resource.name': sql
|
|
22
29
|
}
|
|
23
30
|
})
|
|
24
31
|
|
|
25
|
-
if (
|
|
26
|
-
span.setTag('db.name',
|
|
32
|
+
if (conf.database) {
|
|
33
|
+
span.setTag('db.name', conf.database)
|
|
27
34
|
}
|
|
28
35
|
|
|
29
|
-
analyticsSampler.sample(span, config.measured)
|
|
36
|
+
analyticsSampler.sample(span, this.config.measured)
|
|
37
|
+
this.enter(span, store)
|
|
38
|
+
})
|
|
30
39
|
|
|
31
|
-
|
|
40
|
+
this.addSub('apm:mysql:query:end', () => {
|
|
41
|
+
this.exit()
|
|
42
|
+
})
|
|
32
43
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
if (sequence._callback) {
|
|
38
|
-
sequence._callback = wrapCallback(tracer, span, childOf, sequence._callback)
|
|
39
|
-
} else {
|
|
40
|
-
sequence.on('end', () => {
|
|
41
|
-
span.finish()
|
|
42
|
-
})
|
|
44
|
+
this.addSub('apm:mysql:query:error', err => {
|
|
45
|
+
if (err) {
|
|
46
|
+
const span = storage.getStore().span
|
|
47
|
+
span.setTag('error', err)
|
|
43
48
|
}
|
|
49
|
+
})
|
|
44
50
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
function createWrapGetConnection (tracer, config) {
|
|
51
|
-
return function wrapGetConnection (getConnection) {
|
|
52
|
-
return function getConnectionWithTrace (cb) {
|
|
53
|
-
const scope = tracer.scope()
|
|
54
|
-
|
|
55
|
-
arguments[0] = scope.bind(cb)
|
|
56
|
-
|
|
57
|
-
return scope.bind(getConnection).apply(this, arguments)
|
|
58
|
-
}
|
|
51
|
+
this.addSub('apm:mysql:query:async-end', () => {
|
|
52
|
+
const span = storage.getStore().span
|
|
53
|
+
span.finish()
|
|
54
|
+
})
|
|
59
55
|
}
|
|
60
56
|
}
|
|
61
57
|
|
|
62
|
-
|
|
63
|
-
return tracer.scope().bind((...args) => {
|
|
64
|
-
const err = args[0]
|
|
65
|
-
if (err) {
|
|
66
|
-
span.addTags({
|
|
67
|
-
'error.type': err.name,
|
|
68
|
-
'error.msg': err.message,
|
|
69
|
-
'error.stack': err.stack
|
|
70
|
-
})
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
span.finish()
|
|
74
|
-
|
|
75
|
-
done(...args)
|
|
76
|
-
}, parent)
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
function patchConnection (Connection, tracer, config) {
|
|
80
|
-
this.wrap(Connection.prototype, 'query', createWrapQuery(tracer, config))
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
function unpatchConnection (Connection) {
|
|
84
|
-
this.unwrap(Connection.prototype, 'query')
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
function patchPool (Pool, tracer, config) {
|
|
88
|
-
this.wrap(Pool.prototype, 'getConnection', createWrapGetConnection(tracer, config))
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
function unpatchPool (Pool) {
|
|
92
|
-
this.unwrap(Pool.prototype, 'getConnection')
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
module.exports = [
|
|
96
|
-
{
|
|
97
|
-
name: 'mysql',
|
|
98
|
-
file: 'lib/Connection.js',
|
|
99
|
-
versions: ['>=2'],
|
|
100
|
-
patch: patchConnection,
|
|
101
|
-
unpatch: unpatchConnection
|
|
102
|
-
},
|
|
103
|
-
{
|
|
104
|
-
name: 'mysql',
|
|
105
|
-
file: 'lib/Pool.js',
|
|
106
|
-
versions: ['>=2'],
|
|
107
|
-
patch: patchPool,
|
|
108
|
-
unpatch: unpatchPool
|
|
109
|
-
}
|
|
110
|
-
]
|
|
58
|
+
module.exports = MySQLPlugin
|
|
@@ -2,10 +2,15 @@
|
|
|
2
2
|
|
|
3
3
|
const tx = require('../../dd-trace/src/plugins/util/tx')
|
|
4
4
|
const analyticsSampler = require('../../dd-trace/src/analytics_sampler')
|
|
5
|
+
const { storage } = require('../../datadog-core')
|
|
5
6
|
|
|
6
7
|
function createWrapConnect (tracer, config) {
|
|
7
8
|
return function wrapConnect (connect) {
|
|
8
9
|
return function connectWithTrace () {
|
|
10
|
+
const store = storage.getStore()
|
|
11
|
+
|
|
12
|
+
if (store && store.noop) return connect.apply(this, arguments)
|
|
13
|
+
|
|
9
14
|
const scope = tracer.scope()
|
|
10
15
|
const options = getOptions(arguments)
|
|
11
16
|
const lastIndex = arguments.length - 1
|
|
@@ -100,7 +100,7 @@ module.exports = [
|
|
|
100
100
|
},
|
|
101
101
|
{
|
|
102
102
|
name: 'pino',
|
|
103
|
-
versions: ['>=5.14.0'],
|
|
103
|
+
versions: ['>=5.14.0 <6.8.0'],
|
|
104
104
|
patch (pino, tracer, config) {
|
|
105
105
|
if (!tracer._logInjection) return
|
|
106
106
|
|
|
@@ -112,6 +112,30 @@ module.exports = [
|
|
|
112
112
|
return this.unwrapExport(pino)
|
|
113
113
|
}
|
|
114
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
|
+
},
|
|
115
139
|
{
|
|
116
140
|
name: 'pino-pretty',
|
|
117
141
|
versions: ['>=3'], // will only work starting from pino@5.0.0 as previous versions are not using pino-pretty
|