dd-trace 2.0.0-appsec-beta.4 → 2.0.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/MIGRATING.md +65 -0
- package/ci/init.js +5 -1
- package/ci/jest/env.js +5 -1
- package/index.d.ts +31 -44
- package/package.json +5 -2
- package/packages/datadog-instrumentations/index.js +6 -0
- package/packages/datadog-instrumentations/src/bluebird.js +26 -0
- package/packages/datadog-instrumentations/src/dns.js +2 -2
- package/packages/datadog-instrumentations/src/helpers/instrument.js +24 -25
- package/packages/datadog-instrumentations/src/helpers/promise.js +29 -0
- package/packages/datadog-instrumentations/src/memcached.js +3 -5
- 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 +21 -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 +1 -1
- package/packages/datadog-plugin-fs/src/index.js +7 -3
- package/packages/datadog-plugin-http/src/client.js +9 -24
- 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-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-router/src/index.js +28 -3
- package/packages/datadog-plugin-winston/src/index.js +30 -12
- 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 +4 -7
- package/packages/dd-trace/src/appsec/gateway/als.js +1 -0
- package/packages/dd-trace/src/appsec/gateway/channels.js +3 -0
- package/packages/dd-trace/src/appsec/gateway/engine/engine.js +20 -30
- package/packages/dd-trace/src/appsec/gateway/engine/runner.js +2 -0
- package/packages/dd-trace/src/appsec/index.js +41 -25
- package/packages/dd-trace/src/appsec/recommended.json +5708 -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 +0 -2
- package/packages/dd-trace/src/exporters/agent/request.js +8 -0
- package/packages/dd-trace/src/format.js +14 -39
- 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 +46 -47
- package/packages/dd-trace/src/opentracing/span.js +2 -7
- package/packages/dd-trace/src/opentracing/span_context.js +0 -3
- package/packages/dd-trace/src/opentracing/tracer.js +5 -23
- package/packages/dd-trace/src/plugins/index.js +1 -5
- package/packages/dd-trace/src/plugins/plugin.js +7 -1
- package/packages/dd-trace/src/plugins/util/test.js +9 -4
- package/packages/dd-trace/src/plugins/util/web.js +3 -3
- package/packages/dd-trace/src/profiling/config.js +5 -1
- package/packages/dd-trace/src/profiling/exporters/agent.js +33 -32
- package/packages/dd-trace/src/profiling/profiler.js +15 -6
- package/packages/dd-trace/src/profiling/profilers/cpu.js +1 -1
- package/packages/dd-trace/src/profiling/profilers/heap.js +3 -2
- package/packages/dd-trace/src/proxy.js +35 -35
- 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 +7 -0
- package/scripts/publish_docs.js +1 -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/appsec/gateway/dc_block.js +0 -68
- package/packages/dd-trace/src/plugins/util/promise.js +0 -31
- package/packages/dd-trace/src/profiling/mapper.js +0 -91
- package/packages/dd-trace/src/scope/noop/scope_manager.js +0 -28
|
@@ -7,21 +7,17 @@ const Reference = opentracing.Reference
|
|
|
7
7
|
const Span = require('./span')
|
|
8
8
|
const SpanContext = require('./span_context')
|
|
9
9
|
const SpanProcessor = require('../span_processor')
|
|
10
|
-
const Sampler = require('../sampler')
|
|
11
10
|
const PrioritySampler = require('../priority_sampler')
|
|
12
11
|
const TextMapPropagator = require('./propagation/text_map')
|
|
13
12
|
const HttpPropagator = require('./propagation/http')
|
|
14
13
|
const BinaryPropagator = require('./propagation/binary')
|
|
15
14
|
const LogPropagator = require('./propagation/log')
|
|
16
|
-
const NoopSpan = require('../noop/span')
|
|
17
15
|
const formats = require('../../../../ext/formats')
|
|
18
16
|
|
|
19
17
|
const log = require('../log')
|
|
20
|
-
const constants = require('../constants')
|
|
21
18
|
const metrics = require('../metrics')
|
|
22
19
|
const getExporter = require('../exporter')
|
|
23
20
|
|
|
24
|
-
const REFERENCE_NOOP = constants.REFERENCE_NOOP
|
|
25
21
|
const REFERENCE_CHILD_OF = opentracing.REFERENCE_CHILD_OF
|
|
26
22
|
const REFERENCE_FOLLOWS_FROM = opentracing.REFERENCE_FOLLOWS_FROM
|
|
27
23
|
|
|
@@ -37,12 +33,10 @@ class DatadogTracer extends Tracer {
|
|
|
37
33
|
this._tags = config.tags
|
|
38
34
|
this._logInjection = config.logInjection
|
|
39
35
|
this._debug = config.debug
|
|
40
|
-
this._internalErrors = config.experimental.internalErrors
|
|
41
36
|
this._prioritySampler = new PrioritySampler(config.env, config.experimental.sampler)
|
|
42
37
|
this._exporter = new Exporter(config, this._prioritySampler)
|
|
43
38
|
this._processor = new SpanProcessor(this._exporter, this._prioritySampler)
|
|
44
39
|
this._url = this._exporter._url
|
|
45
|
-
this._sampler = new Sampler(config.sampleRate)
|
|
46
40
|
this._enableGetRumData = config.experimental.enableGetRumData
|
|
47
41
|
this._propagators = {
|
|
48
42
|
[formats.TEXT_MAP]: new TextMapPropagator(config),
|
|
@@ -57,20 +51,16 @@ class DatadogTracer extends Tracer {
|
|
|
57
51
|
|
|
58
52
|
_startSpan (name, fields) {
|
|
59
53
|
const reference = getParent(fields.references)
|
|
60
|
-
const type = reference && reference.type()
|
|
61
54
|
const parent = reference && reference.referencedContext()
|
|
62
|
-
return this._startSpanInternal(name, fields, parent
|
|
55
|
+
return this._startSpanInternal(name, fields, parent)
|
|
63
56
|
}
|
|
64
57
|
|
|
65
|
-
_startSpanInternal (name, fields = {}, parent
|
|
66
|
-
if (parent && parent._noop) return parent._noop
|
|
67
|
-
if (!isSampled(this._sampler, parent, type)) return new NoopSpan(this, parent)
|
|
68
|
-
|
|
58
|
+
_startSpanInternal (name, fields = {}, parent) {
|
|
69
59
|
const tags = {
|
|
70
60
|
'service.name': this._service
|
|
71
61
|
}
|
|
72
62
|
|
|
73
|
-
const span = new Span(this, this._processor, this.
|
|
63
|
+
const span = new Span(this, this._processor, this._prioritySampler, {
|
|
74
64
|
operationName: fields.operationName || name,
|
|
75
65
|
parent,
|
|
76
66
|
tags,
|
|
@@ -121,12 +111,12 @@ function getParent (references = []) {
|
|
|
121
111
|
const spanContext = ref.referencedContext()
|
|
122
112
|
const type = ref.type()
|
|
123
113
|
|
|
124
|
-
if (
|
|
114
|
+
if (spanContext && !(spanContext instanceof SpanContext)) {
|
|
125
115
|
log.error(() => `Expected ${spanContext} to be an instance of SpanContext`)
|
|
126
116
|
continue
|
|
127
117
|
}
|
|
128
118
|
|
|
129
|
-
if (type === REFERENCE_CHILD_OF
|
|
119
|
+
if (type === REFERENCE_CHILD_OF) {
|
|
130
120
|
parent = ref
|
|
131
121
|
break
|
|
132
122
|
} else if (type === REFERENCE_FOLLOWS_FROM) {
|
|
@@ -139,12 +129,4 @@ function getParent (references = []) {
|
|
|
139
129
|
return parent
|
|
140
130
|
}
|
|
141
131
|
|
|
142
|
-
function isSampled (sampler, parent, type) {
|
|
143
|
-
if (type === REFERENCE_NOOP) return false
|
|
144
|
-
if (parent && !parent._traceFlags.sampled) return false
|
|
145
|
-
if (!parent && !sampler.isSampled()) return false
|
|
146
|
-
|
|
147
|
-
return true
|
|
148
|
-
}
|
|
149
|
-
|
|
150
132
|
module.exports = DatadogTracer
|
|
@@ -4,7 +4,6 @@ module.exports = {
|
|
|
4
4
|
'amqp10': require('../../../datadog-plugin-amqp10/src'),
|
|
5
5
|
'amqplib': require('../../../datadog-plugin-amqplib/src'),
|
|
6
6
|
'aws-sdk': require('../../../datadog-plugin-aws-sdk/src'),
|
|
7
|
-
'bluebird': require('../../../datadog-plugin-bluebird/src'),
|
|
8
7
|
'bunyan': require('../../../datadog-plugin-bunyan/src'),
|
|
9
8
|
'cassandra-driver': require('../../../datadog-plugin-cassandra-driver/src'),
|
|
10
9
|
'connect': require('../../../datadog-plugin-connect/src'),
|
|
@@ -32,6 +31,7 @@ module.exports = {
|
|
|
32
31
|
'memcached': require('../../../datadog-plugin-memcached/src'),
|
|
33
32
|
'microgateway-core': require('../../../datadog-plugin-microgateway-core/src'),
|
|
34
33
|
'mocha': require('../../../datadog-plugin-mocha/src'),
|
|
34
|
+
'moleculer': require('../../../datadog-plugin-moleculer/src'),
|
|
35
35
|
'mongodb-core': require('../../../datadog-plugin-mongodb-core/src'),
|
|
36
36
|
'mongoose': require('../../../datadog-plugin-mongoose/src'),
|
|
37
37
|
'mysql': require('../../../datadog-plugin-mysql/src'),
|
|
@@ -42,15 +42,11 @@ module.exports = {
|
|
|
42
42
|
'paperplane': require('../../../datadog-plugin-paperplane/src'),
|
|
43
43
|
'pg': require('../../../datadog-plugin-pg/src'),
|
|
44
44
|
'pino': require('../../../datadog-plugin-pino/src'),
|
|
45
|
-
'promise': require('../../../datadog-plugin-promise/src'),
|
|
46
|
-
'promise-js': require('../../../datadog-plugin-promise-js/src'),
|
|
47
|
-
'q': require('../../../datadog-plugin-q/src'),
|
|
48
45
|
'redis': require('../../../datadog-plugin-redis/src'),
|
|
49
46
|
'restify': require('../../../datadog-plugin-restify/src'),
|
|
50
47
|
'rhea': require('../../../datadog-plugin-rhea/src'),
|
|
51
48
|
'router': require('../../../datadog-plugin-router/src'),
|
|
52
49
|
'sharedb': require('../../../datadog-plugin-sharedb/src'),
|
|
53
50
|
'tedious': require('../../../datadog-plugin-tedious/src'),
|
|
54
|
-
'when': require('../../../datadog-plugin-when/src'),
|
|
55
51
|
'winston': require('../../../datadog-plugin-winston/src')
|
|
56
52
|
}
|
|
@@ -6,7 +6,13 @@ const { storage } = require('../../../datadog-core')
|
|
|
6
6
|
class Subscription {
|
|
7
7
|
constructor (event, handler) {
|
|
8
8
|
this._channel = dc.channel(event)
|
|
9
|
-
this._handler =
|
|
9
|
+
this._handler = (message, name) => {
|
|
10
|
+
const store = storage.getStore()
|
|
11
|
+
|
|
12
|
+
if (!store || !store.noop) {
|
|
13
|
+
handler(message, name)
|
|
14
|
+
}
|
|
15
|
+
}
|
|
10
16
|
}
|
|
11
17
|
|
|
12
18
|
enable () {
|
|
@@ -24,6 +24,7 @@ const TEST_SUITE = 'test.suite'
|
|
|
24
24
|
const TEST_STATUS = 'test.status'
|
|
25
25
|
const TEST_PARAMETERS = 'test.parameters'
|
|
26
26
|
const TEST_SKIP_REASON = 'test.skip_reason'
|
|
27
|
+
const TEST_IS_RUM_ACTIVE = 'test.is_rum_active'
|
|
27
28
|
|
|
28
29
|
const ERROR_TYPE = 'error.type'
|
|
29
30
|
const ERROR_MESSAGE = 'error.msg'
|
|
@@ -43,6 +44,7 @@ module.exports = {
|
|
|
43
44
|
TEST_STATUS,
|
|
44
45
|
TEST_PARAMETERS,
|
|
45
46
|
TEST_SKIP_REASON,
|
|
47
|
+
TEST_IS_RUM_ACTIVE,
|
|
46
48
|
ERROR_TYPE,
|
|
47
49
|
ERROR_MESSAGE,
|
|
48
50
|
ERROR_STACK,
|
|
@@ -54,7 +56,7 @@ module.exports = {
|
|
|
54
56
|
getTestSuitePath
|
|
55
57
|
}
|
|
56
58
|
|
|
57
|
-
function getTestEnvironmentMetadata (testFramework) {
|
|
59
|
+
function getTestEnvironmentMetadata (testFramework, config) {
|
|
58
60
|
// TODO: eventually these will come from the tracer (generally available)
|
|
59
61
|
const ciMetadata = getCIMetadata()
|
|
60
62
|
const {
|
|
@@ -83,13 +85,17 @@ function getTestEnvironmentMetadata (testFramework) {
|
|
|
83
85
|
|
|
84
86
|
const runtimeAndOSMetadata = getRuntimeAndOSMetadata()
|
|
85
87
|
|
|
86
|
-
|
|
88
|
+
const metadata = {
|
|
87
89
|
[TEST_FRAMEWORK]: testFramework,
|
|
88
90
|
...gitMetadata,
|
|
89
91
|
...ciMetadata,
|
|
90
92
|
...userProvidedGitMetadata,
|
|
91
93
|
...runtimeAndOSMetadata
|
|
92
94
|
}
|
|
95
|
+
if (config && config.service) {
|
|
96
|
+
metadata['service.name'] = config.service
|
|
97
|
+
}
|
|
98
|
+
return metadata
|
|
93
99
|
}
|
|
94
100
|
|
|
95
101
|
function getTestParametersString (parametersByTestName, testName) {
|
|
@@ -118,8 +124,7 @@ function finishAllTraceSpans (span) {
|
|
|
118
124
|
function getTestParentSpan (tracer) {
|
|
119
125
|
return tracer.extract('text_map', {
|
|
120
126
|
'x-datadog-trace-id': id().toString(10),
|
|
121
|
-
'x-datadog-parent-id': '0000000000000000'
|
|
122
|
-
'x-datadog-sampled': 1
|
|
127
|
+
'x-datadog-parent-id': '0000000000000000'
|
|
123
128
|
})
|
|
124
129
|
}
|
|
125
130
|
/**
|
|
@@ -23,6 +23,7 @@ const HTTP_STATUS_CODE = tags.HTTP_STATUS_CODE
|
|
|
23
23
|
const HTTP_ROUTE = tags.HTTP_ROUTE
|
|
24
24
|
const HTTP_REQUEST_HEADERS = tags.HTTP_REQUEST_HEADERS
|
|
25
25
|
const HTTP_RESPONSE_HEADERS = tags.HTTP_RESPONSE_HEADERS
|
|
26
|
+
const MANUAL_DROP = tags.MANUAL_DROP
|
|
26
27
|
|
|
27
28
|
const HTTP2_HEADER_AUTHORITY = ':authority'
|
|
28
29
|
const HTTP2_HEADER_SCHEME = ':scheme'
|
|
@@ -54,9 +55,8 @@ const web = {
|
|
|
54
55
|
|
|
55
56
|
const span = startSpan(tracer, config, req, res, name)
|
|
56
57
|
|
|
57
|
-
// TODO: replace this with a REFERENCE_NOOP after we split http/express/etc
|
|
58
58
|
if (!config.filter(req.url)) {
|
|
59
|
-
span.
|
|
59
|
+
span.setTag(MANUAL_DROP, true)
|
|
60
60
|
}
|
|
61
61
|
|
|
62
62
|
if (config.service) {
|
|
@@ -310,7 +310,7 @@ function addAllowHeaders (req, headers) {
|
|
|
310
310
|
const contextHeaders = [
|
|
311
311
|
'x-datadog-origin',
|
|
312
312
|
'x-datadog-parent-id',
|
|
313
|
-
'x-datadog-sampled',
|
|
313
|
+
'x-datadog-sampled', // Deprecated, but still accept it in case it's sent.
|
|
314
314
|
'x-datadog-sampling-priority',
|
|
315
315
|
'x-datadog-trace-id'
|
|
316
316
|
]
|
|
@@ -20,7 +20,8 @@ const {
|
|
|
20
20
|
DD_TRACE_AGENT_URL,
|
|
21
21
|
DD_AGENT_HOST,
|
|
22
22
|
DD_TRACE_AGENT_PORT,
|
|
23
|
-
DD_PROFILING_UPLOAD_TIMEOUT
|
|
23
|
+
DD_PROFILING_UPLOAD_TIMEOUT,
|
|
24
|
+
DD_PROFILING_SOURCE_MAP
|
|
24
25
|
} = process.env
|
|
25
26
|
|
|
26
27
|
class Config {
|
|
@@ -34,6 +35,8 @@ class Config {
|
|
|
34
35
|
const flushInterval = coalesce(options.interval, 65 * 1000)
|
|
35
36
|
const uploadTimeout = coalesce(options.uploadTimeout,
|
|
36
37
|
DD_PROFILING_UPLOAD_TIMEOUT, 60 * 1000)
|
|
38
|
+
const sourceMap = coalesce(options.sourceMap,
|
|
39
|
+
DD_PROFILING_SOURCE_MAP, true)
|
|
37
40
|
|
|
38
41
|
this.enabled = String(enabled) !== 'false'
|
|
39
42
|
this.service = service
|
|
@@ -49,6 +52,7 @@ class Config {
|
|
|
49
52
|
this.logger = ensureLogger(options.logger)
|
|
50
53
|
this.flushInterval = flushInterval
|
|
51
54
|
this.uploadTimeout = uploadTimeout
|
|
55
|
+
this.sourceMap = sourceMap
|
|
52
56
|
|
|
53
57
|
const hostname = coalesce(options.hostname, DD_AGENT_HOST, 'localhost')
|
|
54
58
|
const port = coalesce(options.port, DD_TRACE_AGENT_PORT, 8126)
|
|
@@ -55,7 +55,6 @@ class AgentExporter {
|
|
|
55
55
|
}
|
|
56
56
|
|
|
57
57
|
export ({ profiles, start, end, tags }) {
|
|
58
|
-
const form = new FormData()
|
|
59
58
|
const types = Object.keys(profiles)
|
|
60
59
|
|
|
61
60
|
const fields = [
|
|
@@ -75,10 +74,6 @@ class AgentExporter {
|
|
|
75
74
|
...Object.entries(tags).map(([key, value]) => ['tags[]', `${key}:${value}`])
|
|
76
75
|
]
|
|
77
76
|
|
|
78
|
-
for (const [key, value] of fields) {
|
|
79
|
-
form.append(key, value)
|
|
80
|
-
}
|
|
81
|
-
|
|
82
77
|
this._logger.debug(() => {
|
|
83
78
|
const body = fields.map(([key, value]) => ` ${key}: ${value}`).join('\n')
|
|
84
79
|
return `Building agent export report: ${'\n' + body}`
|
|
@@ -93,36 +88,14 @@ class AgentExporter {
|
|
|
93
88
|
return `Adding ${type} profile to agent export: ` + bytes
|
|
94
89
|
})
|
|
95
90
|
|
|
96
|
-
|
|
97
|
-
|
|
91
|
+
fields.push([`types[${index}]`, type])
|
|
92
|
+
fields.push([`data[${index}]`, buffer, {
|
|
98
93
|
filename: `${type}.pb.gz`,
|
|
99
94
|
contentType: 'application/octet-stream',
|
|
100
95
|
knownLength: buffer.length
|
|
101
|
-
})
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
const options = {
|
|
105
|
-
method: 'POST',
|
|
106
|
-
path: '/profiling/v1/input',
|
|
107
|
-
headers: form.getHeaders()
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
if (containerId) {
|
|
111
|
-
options.headers['Datadog-Container-ID'] = containerId
|
|
96
|
+
}])
|
|
112
97
|
}
|
|
113
98
|
|
|
114
|
-
if (this._url.protocol === 'unix:') {
|
|
115
|
-
options.socketPath = this._url.pathname
|
|
116
|
-
} else {
|
|
117
|
-
options.protocol = this._url.protocol
|
|
118
|
-
options.hostname = this._url.hostname
|
|
119
|
-
options.port = this._url.port
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
this._logger.debug(() => {
|
|
123
|
-
return `Submitting agent report to: ${JSON.stringify(options)}`
|
|
124
|
-
})
|
|
125
|
-
|
|
126
99
|
return new Promise((resolve, reject) => {
|
|
127
100
|
const operation = retry.operation({
|
|
128
101
|
randomize: true,
|
|
@@ -131,8 +104,36 @@ class AgentExporter {
|
|
|
131
104
|
})
|
|
132
105
|
|
|
133
106
|
operation.attempt((attempt) => {
|
|
134
|
-
const
|
|
135
|
-
|
|
107
|
+
const form = new FormData()
|
|
108
|
+
|
|
109
|
+
for (const [key, value, options] of fields) {
|
|
110
|
+
form.append(key, value, options)
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
const options = {
|
|
114
|
+
method: 'POST',
|
|
115
|
+
path: '/profiling/v1/input',
|
|
116
|
+
headers: form.getHeaders(),
|
|
117
|
+
timeout: this._backoffTime * Math.pow(2, attempt)
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
if (containerId) {
|
|
121
|
+
options.headers['Datadog-Container-ID'] = containerId
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
if (this._url.protocol === 'unix:') {
|
|
125
|
+
options.socketPath = this._url.pathname
|
|
126
|
+
} else {
|
|
127
|
+
options.protocol = this._url.protocol
|
|
128
|
+
options.hostname = this._url.hostname
|
|
129
|
+
options.port = this._url.port
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
this._logger.debug(() => {
|
|
133
|
+
return `Submitting profiler agent report attempt #${attempt} to: ${JSON.stringify(options)}`
|
|
134
|
+
})
|
|
135
|
+
|
|
136
|
+
sendRequest(options, form, (err, response) => {
|
|
136
137
|
if (operation.retry(err)) {
|
|
137
138
|
this._logger.error(`Error from the agent: ${err.message}`)
|
|
138
139
|
return
|
|
@@ -2,7 +2,15 @@
|
|
|
2
2
|
|
|
3
3
|
const { EventEmitter } = require('events')
|
|
4
4
|
const { Config } = require('./config')
|
|
5
|
-
|
|
5
|
+
|
|
6
|
+
function maybeSourceMap (sourceMap) {
|
|
7
|
+
if (!sourceMap) return
|
|
8
|
+
|
|
9
|
+
const { SourceMapper } = require('@datadog/pprof')
|
|
10
|
+
return SourceMapper.create([
|
|
11
|
+
process.cwd()
|
|
12
|
+
])
|
|
13
|
+
}
|
|
6
14
|
|
|
7
15
|
class Profiler extends EventEmitter {
|
|
8
16
|
constructor () {
|
|
@@ -15,18 +23,21 @@ class Profiler extends EventEmitter {
|
|
|
15
23
|
}
|
|
16
24
|
|
|
17
25
|
start (options) {
|
|
26
|
+
this._start(options).catch(() => {})
|
|
27
|
+
return this
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
async _start (options) {
|
|
18
31
|
if (this._enabled) return
|
|
19
32
|
|
|
20
33
|
const config = this._config = new Config(options)
|
|
21
|
-
|
|
22
34
|
if (!config.enabled) return
|
|
23
35
|
|
|
24
36
|
this._logger = config.logger
|
|
25
|
-
|
|
26
37
|
this._enabled = true
|
|
27
38
|
|
|
28
39
|
try {
|
|
29
|
-
const mapper = config.sourceMap
|
|
40
|
+
const mapper = await maybeSourceMap(config.sourceMap)
|
|
30
41
|
|
|
31
42
|
for (const profiler of config.profilers) {
|
|
32
43
|
// TODO: move this out of Profiler when restoring sourcemap support
|
|
@@ -39,8 +50,6 @@ class Profiler extends EventEmitter {
|
|
|
39
50
|
this._logger.error(e)
|
|
40
51
|
this.stop()
|
|
41
52
|
}
|
|
42
|
-
|
|
43
|
-
return this
|
|
44
53
|
}
|
|
45
54
|
|
|
46
55
|
stop () {
|
|
@@ -8,13 +8,14 @@ class NativeHeapProfiler {
|
|
|
8
8
|
this._pprof = undefined
|
|
9
9
|
}
|
|
10
10
|
|
|
11
|
-
start () {
|
|
11
|
+
start ({ mapper } = {}) {
|
|
12
|
+
this._mapper = mapper
|
|
12
13
|
this._pprof = require('@datadog/pprof')
|
|
13
14
|
this._pprof.heap.start(this._samplingInterval, this._stackDepth)
|
|
14
15
|
}
|
|
15
16
|
|
|
16
17
|
profile () {
|
|
17
|
-
return this._pprof.heap.profile()
|
|
18
|
+
return this._pprof.heap.profile(undefined, this._mapper)
|
|
18
19
|
}
|
|
19
20
|
|
|
20
21
|
encode (profile) {
|
|
@@ -8,6 +8,7 @@ const Instrumenter = require('./instrumenter')
|
|
|
8
8
|
const PluginManager = require('./plugin_manager')
|
|
9
9
|
const metrics = require('./metrics')
|
|
10
10
|
const log = require('./log')
|
|
11
|
+
const { isFalse } = require('./util')
|
|
11
12
|
const { setStartupLogInstrumenter } = require('./startup-log')
|
|
12
13
|
|
|
13
14
|
const noop = new NoopTracer()
|
|
@@ -15,6 +16,8 @@ const noop = new NoopTracer()
|
|
|
15
16
|
class Tracer extends BaseTracer {
|
|
16
17
|
constructor () {
|
|
17
18
|
super()
|
|
19
|
+
|
|
20
|
+
this._initialized = false
|
|
18
21
|
this._tracer = noop
|
|
19
22
|
this._instrumenter = new Instrumenter(this)
|
|
20
23
|
this._pluginManager = new PluginManager(this)
|
|
@@ -26,41 +29,43 @@ class Tracer extends BaseTracer {
|
|
|
26
29
|
}
|
|
27
30
|
|
|
28
31
|
init (options) {
|
|
29
|
-
if (
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
log.use(config.logger)
|
|
34
|
-
log.toggle(config.debug, config.logLevel, this)
|
|
35
|
-
|
|
36
|
-
if (config.hasOwnProperty('profiling') && config.profiling.enabled) {
|
|
37
|
-
// do not stop tracer initialization if the profiler fails to be imported
|
|
38
|
-
try {
|
|
39
|
-
const profiler = require('./profiler')
|
|
40
|
-
profiler.start(config)
|
|
41
|
-
} catch (e) {
|
|
42
|
-
log.error(e)
|
|
43
|
-
}
|
|
44
|
-
}
|
|
32
|
+
if (isFalse(process.env.DD_TRACE_ENABLED) || this._initialized) return this
|
|
33
|
+
|
|
34
|
+
this._initialized = true
|
|
45
35
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
metrics.start(config)
|
|
49
|
-
}
|
|
36
|
+
try {
|
|
37
|
+
const config = new Config(options) // TODO: support dynamic config
|
|
50
38
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
require('./appsec').enable(config)
|
|
54
|
-
}
|
|
39
|
+
log.use(config.logger)
|
|
40
|
+
log.toggle(config.debug, config.logLevel, this)
|
|
55
41
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
42
|
+
if (config.profiling.enabled) {
|
|
43
|
+
// do not stop tracer initialization if the profiler fails to be imported
|
|
44
|
+
try {
|
|
45
|
+
const profiler = require('./profiler')
|
|
46
|
+
profiler.start(config)
|
|
47
|
+
} catch (e) {
|
|
48
|
+
log.error(e)
|
|
60
49
|
}
|
|
61
|
-
} catch (e) {
|
|
62
|
-
log.error(e)
|
|
63
50
|
}
|
|
51
|
+
|
|
52
|
+
if (config.runtimeMetrics) {
|
|
53
|
+
metrics.start(config)
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
if (config.tracing) {
|
|
57
|
+
// dirty require for now so zero appsec code is executed unless explicitly enabled
|
|
58
|
+
if (config.appsec.enabled) {
|
|
59
|
+
require('./appsec').enable(config)
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
this._tracer = new DatadogTracer(config)
|
|
63
|
+
this._instrumenter.enable(config)
|
|
64
|
+
this._pluginManager.configure(config)
|
|
65
|
+
setStartupLogInstrumenter(this._instrumenter)
|
|
66
|
+
}
|
|
67
|
+
} catch (e) {
|
|
68
|
+
log.error(e)
|
|
64
69
|
}
|
|
65
70
|
|
|
66
71
|
return this
|
|
@@ -115,11 +120,6 @@ class Tracer extends BaseTracer {
|
|
|
115
120
|
return this._tracer.extract.apply(this._tracer, arguments)
|
|
116
121
|
}
|
|
117
122
|
|
|
118
|
-
scopeManager () {
|
|
119
|
-
this._deprecate('scopeManager')
|
|
120
|
-
return this._tracer.scopeManager.apply(this._tracer, arguments)
|
|
121
|
-
}
|
|
122
|
-
|
|
123
123
|
scope () {
|
|
124
124
|
return this._tracer.scope.apply(this._tracer, arguments)
|
|
125
125
|
}
|
|
@@ -16,13 +16,6 @@ class SpanProcessor {
|
|
|
16
16
|
|
|
17
17
|
if (trace.started.length === trace.finished.length) {
|
|
18
18
|
this._prioritySampler.sample(spanContext)
|
|
19
|
-
|
|
20
|
-
if (spanContext._traceFlags.sampled === false) {
|
|
21
|
-
log.debug(() => `Dropping trace due to user configured filtering: ${trace.started}`)
|
|
22
|
-
this._erase(trace)
|
|
23
|
-
return
|
|
24
|
-
}
|
|
25
|
-
|
|
26
19
|
const formattedSpans = trace.finished.map(format)
|
|
27
20
|
this._exporter.export(formattedSpans)
|
|
28
21
|
this._erase(trace)
|
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
const Tracer = require('./opentracing/tracer')
|
|
4
4
|
const tags = require('../../../ext/tags')
|
|
5
|
-
const ScopeManager = require('./scope/noop/scope_manager')
|
|
6
5
|
const Scope = require('./scope')
|
|
6
|
+
const { storage } = require('../../datadog-core')
|
|
7
7
|
const { isError } = require('./util')
|
|
8
8
|
const { setStartupLogConfig } = require('./startup-log')
|
|
9
9
|
|
|
@@ -16,7 +16,6 @@ class DatadogTracer extends Tracer {
|
|
|
16
16
|
constructor (config) {
|
|
17
17
|
super(config)
|
|
18
18
|
|
|
19
|
-
this._scopeManager = new ScopeManager()
|
|
20
19
|
this._scope = new Scope()
|
|
21
20
|
setStartupLogConfig(config)
|
|
22
21
|
}
|
|
@@ -68,6 +67,10 @@ class DatadogTracer extends Tracer {
|
|
|
68
67
|
const tracer = this
|
|
69
68
|
|
|
70
69
|
return function () {
|
|
70
|
+
const store = storage.getStore()
|
|
71
|
+
|
|
72
|
+
if (store && store.noop) return fn.apply(this, arguments)
|
|
73
|
+
|
|
71
74
|
let optionsObj = options
|
|
72
75
|
if (typeof optionsObj === 'function' && typeof fn === 'function') {
|
|
73
76
|
optionsObj = optionsObj.apply(this, arguments)
|
|
@@ -100,10 +103,6 @@ class DatadogTracer extends Tracer {
|
|
|
100
103
|
this._exporter.setUrl(url)
|
|
101
104
|
}
|
|
102
105
|
|
|
103
|
-
scopeManager () {
|
|
104
|
-
return this._scopeManager
|
|
105
|
-
}
|
|
106
|
-
|
|
107
106
|
scope () {
|
|
108
107
|
return this._scope
|
|
109
108
|
}
|
|
@@ -25,6 +25,13 @@ Object.keys(externals).forEach(external => externals[external].forEach(thing =>
|
|
|
25
25
|
}
|
|
26
26
|
}))
|
|
27
27
|
|
|
28
|
+
fs.readdirSync(path.join(__dirname, '../packages/datadog-instrumentations/src'))
|
|
29
|
+
.filter(file => file.endsWith('js'))
|
|
30
|
+
.forEach(file => {
|
|
31
|
+
file = file.replace('.js', '')
|
|
32
|
+
plugins[file] = { name: file, prototype: Object.create(Plugin.prototype) }
|
|
33
|
+
})
|
|
34
|
+
|
|
28
35
|
run()
|
|
29
36
|
|
|
30
37
|
async function run () {
|
package/scripts/publish_docs.js
CHANGED
|
@@ -18,4 +18,4 @@ exec('git init', { cwd: './docs/out' }) // cloning would overwrite generated doc
|
|
|
18
18
|
exec('git remote add origin git@github.com:DataDog/dd-trace-js.git', { cwd: './docs/out' })
|
|
19
19
|
exec('git add -A', { cwd: './docs/out' })
|
|
20
20
|
exec(`git commit -m "${msg}"`, { cwd: './docs/out' })
|
|
21
|
-
exec('git push -f origin
|
|
21
|
+
exec('git push -f origin main:gh-pages', { cwd: './docs/out' })
|
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
const tx = require('../../dd-trace/src/plugins/util/promise')
|
|
4
|
-
|
|
5
|
-
const DD_LIB_COPIES = '_datadog_library_copies'
|
|
6
|
-
|
|
7
|
-
function createGetNewLibraryCopyWrap (tracer, config, originalLib, shim) {
|
|
8
|
-
return function wrapGetNewLibraryCopy (getNewLibraryCopy) {
|
|
9
|
-
return function getNewLibraryCopyWithTrace () {
|
|
10
|
-
const libraryCopy = getNewLibraryCopy.apply(this, arguments)
|
|
11
|
-
shim.wrap(libraryCopy.prototype, '_then', tx.createWrapThen(tracer, config))
|
|
12
|
-
shim.wrap(libraryCopy, 'getNewLibraryCopy', createGetNewLibraryCopyWrap(tracer, config, originalLib, shim))
|
|
13
|
-
addToLibraryCopies(originalLib, libraryCopy)
|
|
14
|
-
return libraryCopy
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
function addToLibraryCopies (originalLib, libraryCopy) {
|
|
20
|
-
let libraryCopies = originalLib[DD_LIB_COPIES]
|
|
21
|
-
|
|
22
|
-
if (!libraryCopies) {
|
|
23
|
-
libraryCopies = new Set()
|
|
24
|
-
|
|
25
|
-
Object.defineProperty(originalLib, DD_LIB_COPIES, {
|
|
26
|
-
writable: true,
|
|
27
|
-
configurable: true,
|
|
28
|
-
value: libraryCopies
|
|
29
|
-
})
|
|
30
|
-
}
|
|
31
|
-
libraryCopies.add(libraryCopy)
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
function unwrapLibraryCopies (originalLib, shim) {
|
|
35
|
-
const libraryCopies = originalLib[DD_LIB_COPIES]
|
|
36
|
-
|
|
37
|
-
if (libraryCopies) {
|
|
38
|
-
libraryCopies.forEach(libraryCopy => {
|
|
39
|
-
shim.unwrap(libraryCopy.prototype, '_then')
|
|
40
|
-
shim.unwrap(libraryCopy, 'getNewLibraryCopy')
|
|
41
|
-
})
|
|
42
|
-
libraryCopies.clear()
|
|
43
|
-
delete originalLib[DD_LIB_COPIES]
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
module.exports = [
|
|
48
|
-
{
|
|
49
|
-
name: 'bluebird',
|
|
50
|
-
versions: ['^2.11.0', '^3.4.1'],
|
|
51
|
-
patch (Promise, tracer, config) {
|
|
52
|
-
this.wrap(Promise, 'getNewLibraryCopy', createGetNewLibraryCopyWrap(tracer, config, Promise, this))
|
|
53
|
-
},
|
|
54
|
-
unpatch (Promise) {
|
|
55
|
-
this.unwrap(Promise, 'getNewLibraryCopy')
|
|
56
|
-
unwrapLibraryCopies(Promise, this)
|
|
57
|
-
}
|
|
58
|
-
},
|
|
59
|
-
{
|
|
60
|
-
name: 'bluebird',
|
|
61
|
-
versions: ['>=2.0.2'], // 2.0.0 and 2.0.1 were removed from npm
|
|
62
|
-
patch (Promise, tracer, config) {
|
|
63
|
-
this.wrap(Promise.prototype, '_then', tx.createWrapThen(tracer, config))
|
|
64
|
-
},
|
|
65
|
-
unpatch (Promise) {
|
|
66
|
-
this.unwrap(Promise.prototype, '_then')
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
]
|