dd-trace 5.0.0-pre-069b62a → 5.0.0-pre-e2df7ec
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 +1 -0
- package/index.d.ts +5 -0
- package/package.json +4 -3
- package/packages/datadog-instrumentations/src/apollo-server-core.js +41 -0
- package/packages/datadog-instrumentations/src/apollo-server.js +83 -0
- package/packages/datadog-instrumentations/src/child-process.js +4 -5
- package/packages/datadog-instrumentations/src/crypto.js +2 -1
- package/packages/datadog-instrumentations/src/dns.js +2 -1
- package/packages/datadog-instrumentations/src/graphql.js +18 -4
- package/packages/datadog-instrumentations/src/helpers/hooks.js +9 -2
- package/packages/datadog-instrumentations/src/helpers/instrument.js +8 -3
- package/packages/datadog-instrumentations/src/helpers/register.js +18 -2
- package/packages/datadog-instrumentations/src/http/client.js +4 -16
- package/packages/datadog-instrumentations/src/http/server.js +7 -4
- package/packages/datadog-instrumentations/src/http2/client.js +3 -1
- package/packages/datadog-instrumentations/src/http2/server.js +3 -1
- package/packages/datadog-instrumentations/src/jest.js +1 -1
- package/packages/datadog-instrumentations/src/kafkajs.js +27 -0
- package/packages/datadog-instrumentations/src/net.js +10 -2
- package/packages/datadog-instrumentations/src/next.js +15 -5
- package/packages/datadog-instrumentations/src/restify.js +1 -1
- package/packages/datadog-instrumentations/src/rhea.js +15 -9
- package/packages/datadog-plugin-cucumber/src/index.js +34 -2
- package/packages/datadog-plugin-cypress/src/plugin.js +60 -8
- package/packages/datadog-plugin-graphql/src/resolve.js +26 -18
- package/packages/datadog-plugin-http/src/client.js +1 -1
- package/packages/datadog-plugin-jest/src/index.js +38 -4
- package/packages/datadog-plugin-kafkajs/src/consumer.js +51 -0
- package/packages/datadog-plugin-kafkajs/src/producer.js +55 -0
- package/packages/datadog-plugin-mocha/src/index.js +32 -1
- package/packages/datadog-plugin-next/src/index.js +32 -6
- package/packages/datadog-plugin-playwright/src/index.js +17 -1
- package/packages/dd-trace/src/appsec/activation.js +29 -0
- package/packages/dd-trace/src/appsec/addresses.js +1 -0
- package/packages/dd-trace/src/appsec/api_security_sampler.js +48 -0
- package/packages/dd-trace/src/appsec/blocked_templates.js +4 -1
- package/packages/dd-trace/src/appsec/blocking.js +95 -43
- package/packages/dd-trace/src/appsec/channels.js +4 -1
- package/packages/dd-trace/src/appsec/graphql.js +146 -0
- package/packages/dd-trace/src/appsec/iast/analyzers/header-injection-analyzer.js +16 -7
- package/packages/dd-trace/src/appsec/index.js +29 -40
- package/packages/dd-trace/src/appsec/recommended.json +1395 -2
- package/packages/dd-trace/src/appsec/remote_config/capabilities.js +6 -1
- package/packages/dd-trace/src/appsec/remote_config/index.js +40 -15
- package/packages/dd-trace/src/appsec/reporter.js +2 -4
- package/packages/dd-trace/src/appsec/sdk/user_blocking.js +1 -1
- package/packages/dd-trace/src/appsec/waf/waf_context_wrapper.js +25 -13
- package/packages/dd-trace/src/ci-visibility/exporters/agentless/coverage-writer.js +30 -1
- package/packages/dd-trace/src/ci-visibility/exporters/agentless/writer.js +30 -1
- package/packages/dd-trace/src/ci-visibility/exporters/git/git_metadata.js +36 -4
- package/packages/dd-trace/src/ci-visibility/intelligent-test-runner/get-itr-configuration.js +18 -1
- package/packages/dd-trace/src/ci-visibility/intelligent-test-runner/get-skippable-suites.js +26 -1
- package/packages/dd-trace/src/ci-visibility/telemetry.js +130 -0
- package/packages/dd-trace/src/config.js +110 -56
- package/packages/dd-trace/src/datastreams/processor.js +107 -12
- package/packages/dd-trace/src/encode/agentless-ci-visibility.js +14 -1
- package/packages/dd-trace/src/encode/coverage-ci-visibility.js +14 -0
- package/packages/dd-trace/src/exporters/common/agent-info-exporter.js +4 -0
- package/packages/dd-trace/src/exporters/common/form-data.js +4 -0
- package/packages/dd-trace/src/opentracing/span.js +2 -0
- package/packages/dd-trace/src/opentracing/tracer.js +2 -2
- package/packages/dd-trace/src/plugins/ci_plugin.js +44 -8
- package/packages/dd-trace/src/plugins/index.js +5 -0
- package/packages/dd-trace/src/plugins/util/exec.js +23 -2
- package/packages/dd-trace/src/plugins/util/git.js +94 -19
- package/packages/dd-trace/src/plugins/util/user-provided-git.js +3 -2
- package/packages/dd-trace/src/profiling/exporters/agent.js +1 -0
- package/packages/dd-trace/src/profiling/profiler.js +7 -6
- package/packages/dd-trace/src/profiling/profilers/events.js +19 -51
- package/packages/dd-trace/src/profiling/profilers/shared.js +34 -4
- package/packages/dd-trace/src/profiling/profilers/space.js +2 -1
- package/packages/dd-trace/src/profiling/profilers/wall.js +17 -12
- package/packages/dd-trace/src/proxy.js +14 -0
- package/packages/dd-trace/src/spanleak.js +98 -0
- package/packages/dd-trace/src/telemetry/index.js +43 -5
- package/packages/dd-trace/src/tracer.js +4 -0
|
@@ -7,13 +7,12 @@ const { HTTP_METHOD, HTTP_ROUTE, RESOURCE_NAME, SPAN_TYPE } = require('../../../
|
|
|
7
7
|
const { WEB } = require('../../../../../ext/types')
|
|
8
8
|
const runtimeMetrics = require('../../runtime_metrics')
|
|
9
9
|
const telemetryMetrics = require('../../telemetry/metrics')
|
|
10
|
-
const {
|
|
10
|
+
const { END_TIMESTAMP_LABEL, getThreadLabels } = require('./shared')
|
|
11
11
|
|
|
12
12
|
const beforeCh = dc.channel('dd-trace:storage:before')
|
|
13
13
|
const enterCh = dc.channel('dd-trace:storage:enter')
|
|
14
14
|
const spanFinishCh = dc.channel('dd-trace:span:finish')
|
|
15
15
|
const profilerTelemetryMetrics = telemetryMetrics.manager.namespace('profilers')
|
|
16
|
-
const threadName = `${threadNamePrefix} Event Loop`
|
|
17
16
|
|
|
18
17
|
const MemoizedWebTags = Symbol('NativeWallProfiler.MemoizedWebTags')
|
|
19
18
|
|
|
@@ -96,12 +95,9 @@ class NativeWallProfiler {
|
|
|
96
95
|
this._enter = this._enter.bind(this)
|
|
97
96
|
this._spanFinished = this._spanFinished.bind(this)
|
|
98
97
|
}
|
|
99
|
-
this._generateLabels = this._generateLabels.bind(this)
|
|
100
|
-
} else {
|
|
101
|
-
// Explicitly assigning, to express the intent that this is meant to be
|
|
102
|
-
// undefined when passed to pprof.time.stop() when not using sample contexts.
|
|
103
|
-
this._generateLabels = undefined
|
|
104
98
|
}
|
|
99
|
+
this._generateLabels = this._generateLabels.bind(this)
|
|
100
|
+
|
|
105
101
|
this._logger = options.logger
|
|
106
102
|
this._started = false
|
|
107
103
|
}
|
|
@@ -239,12 +235,21 @@ class NativeWallProfiler {
|
|
|
239
235
|
return profile
|
|
240
236
|
}
|
|
241
237
|
|
|
242
|
-
_generateLabels (
|
|
243
|
-
|
|
244
|
-
|
|
238
|
+
_generateLabels (context) {
|
|
239
|
+
if (context == null) {
|
|
240
|
+
// generateLabels is also called for samples without context.
|
|
241
|
+
// In that case just return thread labels.
|
|
242
|
+
return getThreadLabels()
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
const labels = { ...getThreadLabels() }
|
|
246
|
+
|
|
247
|
+
const { context: { spanId, rootSpanId, webTags, endpoint }, timestamp } = context
|
|
248
|
+
|
|
249
|
+
if (this._timelineEnabled) {
|
|
245
250
|
// Incoming timestamps are in microseconds, we emit nanos.
|
|
246
|
-
[
|
|
247
|
-
}
|
|
251
|
+
labels[END_TIMESTAMP_LABEL] = timestamp * 1000n
|
|
252
|
+
}
|
|
248
253
|
|
|
249
254
|
if (spanId) {
|
|
250
255
|
labels['span id'] = spanId
|
|
@@ -10,6 +10,7 @@ const PluginManager = require('./plugin_manager')
|
|
|
10
10
|
const remoteConfig = require('./appsec/remote_config')
|
|
11
11
|
const AppsecSdk = require('./appsec/sdk')
|
|
12
12
|
const dogstatsd = require('./dogstatsd')
|
|
13
|
+
const spanleak = require('./spanleak')
|
|
13
14
|
|
|
14
15
|
class Tracer extends NoopProxy {
|
|
15
16
|
constructor () {
|
|
@@ -35,6 +36,19 @@ class Tracer extends NoopProxy {
|
|
|
35
36
|
setInterval(() => {
|
|
36
37
|
this.dogstatsd.flush()
|
|
37
38
|
}, 10 * 1000).unref()
|
|
39
|
+
|
|
40
|
+
process.once('beforeExit', () => {
|
|
41
|
+
this.dogstatsd.flush()
|
|
42
|
+
})
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
if (config.spanLeakDebug > 0) {
|
|
46
|
+
if (config.spanLeakDebug === spanleak.MODES.LOG) {
|
|
47
|
+
spanleak.enableLogging()
|
|
48
|
+
} else if (config.spanLeakDebug === spanleak.MODES.GC_AND_LOG) {
|
|
49
|
+
spanleak.enableGarbageCollection()
|
|
50
|
+
}
|
|
51
|
+
spanleak.startScrubber()
|
|
38
52
|
}
|
|
39
53
|
|
|
40
54
|
if (config.remoteConfig.enabled && !config.isCiVisibility) {
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
/* eslint-disable no-console */
|
|
4
|
+
|
|
5
|
+
const SortedSet = require('tlhunter-sorted-set')
|
|
6
|
+
|
|
7
|
+
const INTERVAL = 1000 // look for expired spans every 1s
|
|
8
|
+
const LIFETIME = 60 * 1000 // all spans have a max lifetime of 1m
|
|
9
|
+
|
|
10
|
+
const MODES = {
|
|
11
|
+
DISABLED: 0,
|
|
12
|
+
// METRICS_ONLY
|
|
13
|
+
LOG: 1,
|
|
14
|
+
GC_AND_LOG: 2
|
|
15
|
+
// GC
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
module.exports.MODES = MODES
|
|
19
|
+
|
|
20
|
+
const spans = new SortedSet()
|
|
21
|
+
|
|
22
|
+
// TODO: should these also be delivered as runtime metrics?
|
|
23
|
+
|
|
24
|
+
// const registry = new FinalizationRegistry(name => {
|
|
25
|
+
// spans.del(span) // there is no span
|
|
26
|
+
// })
|
|
27
|
+
|
|
28
|
+
let interval
|
|
29
|
+
let mode = MODES.DISABLED
|
|
30
|
+
|
|
31
|
+
module.exports.disable = function () {
|
|
32
|
+
mode = MODES.DISABLED
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
module.exports.enableLogging = function () {
|
|
36
|
+
mode = MODES.LOG
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
module.exports.enableGarbageCollection = function () {
|
|
40
|
+
mode = MODES.GC_AND_LOG
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
module.exports.startScrubber = function () {
|
|
44
|
+
if (!isEnabled()) return
|
|
45
|
+
|
|
46
|
+
interval = setInterval(() => {
|
|
47
|
+
const now = Date.now()
|
|
48
|
+
const expired = spans.rangeByScore(0, now)
|
|
49
|
+
|
|
50
|
+
if (!expired.length) return
|
|
51
|
+
|
|
52
|
+
const gc = isGarbageCollecting()
|
|
53
|
+
|
|
54
|
+
const expirationsByType = Object.create(null) // { [spanType]: count }
|
|
55
|
+
|
|
56
|
+
for (const wrapped of expired) {
|
|
57
|
+
spans.del(wrapped)
|
|
58
|
+
const span = wrapped.deref()
|
|
59
|
+
|
|
60
|
+
if (!span) continue // span has already been garbage collected
|
|
61
|
+
|
|
62
|
+
// TODO: Should we also do things like record the route to help users debug leaks?
|
|
63
|
+
if (!expirationsByType[span._name]) expirationsByType[span._name] = 0
|
|
64
|
+
expirationsByType[span._name]++
|
|
65
|
+
|
|
66
|
+
if (!gc) continue // everything after this point is related to manual GC
|
|
67
|
+
|
|
68
|
+
// TODO: what else can we do to alleviate memory usage
|
|
69
|
+
span.context()._tags = Object.create(null)
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
console.log('expired spans:' +
|
|
73
|
+
Object.keys(expirationsByType).reduce((a, c) => `${a} ${c}: ${expirationsByType[c]}`, ''))
|
|
74
|
+
}, INTERVAL)
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
module.exports.stopScrubber = function () {
|
|
78
|
+
clearInterval(interval)
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
module.exports.addSpan = function (span) {
|
|
82
|
+
if (!isEnabled()) return
|
|
83
|
+
|
|
84
|
+
const now = Date.now()
|
|
85
|
+
const expiration = now + LIFETIME
|
|
86
|
+
// eslint-disable-next-line no-undef
|
|
87
|
+
const wrapped = new WeakRef(span)
|
|
88
|
+
spans.add(wrapped, expiration)
|
|
89
|
+
// registry.register(span, span._name)
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
function isEnabled () {
|
|
93
|
+
return mode > MODES.DISABLED
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
function isGarbageCollecting () {
|
|
97
|
+
return mode >= MODES.GC_AND_LOG
|
|
98
|
+
}
|
|
@@ -112,11 +112,26 @@ function flatten (input, result = [], prefix = [], traversedObjects = null) {
|
|
|
112
112
|
return result
|
|
113
113
|
}
|
|
114
114
|
|
|
115
|
+
function getInstallSignature (config) {
|
|
116
|
+
const { installSignature: sig } = config
|
|
117
|
+
if (sig && (sig.id || sig.time || sig.type)) {
|
|
118
|
+
return {
|
|
119
|
+
install_id: sig.id,
|
|
120
|
+
install_time: sig.time,
|
|
121
|
+
install_type: sig.type
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
115
126
|
function appStarted (config) {
|
|
116
127
|
const app = {
|
|
117
128
|
products: getProducts(config),
|
|
118
129
|
configuration: flatten(config)
|
|
119
130
|
}
|
|
131
|
+
const installSignature = getInstallSignature(config)
|
|
132
|
+
if (installSignature) {
|
|
133
|
+
app.install_signature = installSignature
|
|
134
|
+
}
|
|
120
135
|
// TODO: add app.error with correct error codes
|
|
121
136
|
// if (errors.agentError) {
|
|
122
137
|
// app.error = errors.agentError
|
|
@@ -129,6 +144,10 @@ function onBeforeExit () {
|
|
|
129
144
|
process.removeListener('beforeExit', onBeforeExit)
|
|
130
145
|
const { reqType, payload } = createPayload('app-closing')
|
|
131
146
|
sendData(config, application, host, reqType, payload)
|
|
147
|
+
// we flush before shutting down. Only in CI Visibility
|
|
148
|
+
if (config.isCiVisibility) {
|
|
149
|
+
metricsManager.send(config, application, host)
|
|
150
|
+
}
|
|
132
151
|
}
|
|
133
152
|
|
|
134
153
|
function createAppObject (config) {
|
|
@@ -286,11 +305,30 @@ function updateConfig (changes, config) {
|
|
|
286
305
|
const application = createAppObject(config)
|
|
287
306
|
const host = createHostObject()
|
|
288
307
|
|
|
289
|
-
const
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
308
|
+
const names = {
|
|
309
|
+
sampleRate: 'DD_TRACE_SAMPLE_RATE',
|
|
310
|
+
logInjection: 'DD_LOG_INJECTION',
|
|
311
|
+
headerTags: 'DD_TRACE_HEADER_TAGS',
|
|
312
|
+
tags: 'DD_TAGS'
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
const configuration = []
|
|
316
|
+
|
|
317
|
+
for (const change of changes) {
|
|
318
|
+
if (!names.hasOwnProperty(change.name)) continue
|
|
319
|
+
|
|
320
|
+
const name = names[change.name]
|
|
321
|
+
const { origin, value } = change
|
|
322
|
+
const entry = { name, origin, value }
|
|
323
|
+
|
|
324
|
+
if (Array.isArray(value)) {
|
|
325
|
+
entry.value = value.join(',')
|
|
326
|
+
} else if (name === 'DD_TAGS') {
|
|
327
|
+
entry.value = Object.entries(value).map(([key, value]) => `${key}:${value}`)
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
configuration.push(entry)
|
|
331
|
+
}
|
|
294
332
|
|
|
295
333
|
const { reqType, payload } = createPayload('app-client-configuration-change', { configuration })
|
|
296
334
|
|