dd-trace 2.11.0 → 2.12.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 -1
- package/index.d.ts +3 -3
- package/package.json +4 -5
- package/packages/datadog-core/src/storage/async_hooks.js +4 -4
- package/packages/datadog-core/src/storage/async_resource.js +14 -4
- package/packages/datadog-instrumentations/src/connect.js +4 -4
- package/packages/datadog-instrumentations/src/couchbase.js +166 -61
- package/packages/datadog-instrumentations/src/fastify.js +12 -25
- package/packages/datadog-instrumentations/src/graphql.js +17 -5
- package/packages/datadog-instrumentations/src/koa.js +4 -4
- package/packages/datadog-instrumentations/src/mocha.js +88 -18
- package/packages/datadog-instrumentations/src/restify.js +4 -8
- package/packages/datadog-instrumentations/src/router.js +4 -4
- package/packages/datadog-plugin-couchbase/src/index.js +8 -10
- package/packages/datadog-plugin-graphql/src/resolve.js +2 -0
- package/packages/datadog-plugin-http/src/server.js +3 -8
- package/packages/datadog-plugin-mocha/src/index.js +80 -3
- package/packages/datadog-plugin-next/src/index.js +1 -1
- package/packages/datadog-plugin-router/src/index.js +39 -10
- package/packages/dd-trace/src/encode/agentless-ci-visibility.js +111 -15
- package/packages/dd-trace/src/plugin_manager.js +49 -33
- package/packages/dd-trace/src/plugins/util/test.js +32 -1
- package/packages/dd-trace/src/plugins/util/web.js +25 -17
- package/packages/dd-trace/src/profiling/config.js +10 -2
- package/packages/dd-trace/src/profiling/exporters/agent.js +1 -2
- package/packages/dd-trace/src/profiling/exporters/form-data.js +53 -0
- package/packages/dd-trace/src/profiling/index.js +2 -0
- package/packages/dd-trace/src/profiling/profiler.js +6 -1
- package/packages/dd-trace/src/profiling/profilers/cpu.js +126 -0
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
const { storage } = require('../../../../datadog-core')
|
|
4
|
+
|
|
5
|
+
const dc = require('diagnostics_channel')
|
|
6
|
+
|
|
7
|
+
const beforeCh = dc.channel('dd-trace:storage:before')
|
|
8
|
+
const afterCh = dc.channel('dd-trace:storage:after')
|
|
9
|
+
|
|
10
|
+
function getActiveSpan () {
|
|
11
|
+
const store = storage.getStore()
|
|
12
|
+
if (!store) return
|
|
13
|
+
return store.span
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
function getStartedSpans (activeSpan) {
|
|
17
|
+
const context = activeSpan.context()
|
|
18
|
+
if (!context) return
|
|
19
|
+
return context._trace.started
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function getSpanContextTags (span) {
|
|
23
|
+
return span._context()._tags
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function isWebServerSpan (tags) {
|
|
27
|
+
return tags['span.type'] === 'web'
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function endpointNameFromTags (tags) {
|
|
31
|
+
return tags['resource.name'] || [
|
|
32
|
+
tags['http.method'],
|
|
33
|
+
tags['http.route']
|
|
34
|
+
].filter(v => v).join(' ')
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
class NativeCpuProfiler {
|
|
38
|
+
constructor (options = {}) {
|
|
39
|
+
this.type = 'cpu'
|
|
40
|
+
this._frequency = options.frequency || 99
|
|
41
|
+
this._mapper = undefined
|
|
42
|
+
this._pprof = undefined
|
|
43
|
+
this._started = false
|
|
44
|
+
this._cpuProfiler = undefined
|
|
45
|
+
this._endpointCollection = options.endpointCollection
|
|
46
|
+
|
|
47
|
+
// Bind to this so the same value can be used to unsubscribe later
|
|
48
|
+
this._enter = this._enter.bind(this)
|
|
49
|
+
this._exit = this._exit.bind(this)
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
_enter () {
|
|
53
|
+
if (!this._cpuProfiler) return
|
|
54
|
+
|
|
55
|
+
const active = getActiveSpan()
|
|
56
|
+
if (!active) return
|
|
57
|
+
|
|
58
|
+
const activeCtx = active._context()
|
|
59
|
+
if (!activeCtx) return
|
|
60
|
+
|
|
61
|
+
const spans = getStartedSpans(active)
|
|
62
|
+
if (!spans || !spans.length) return
|
|
63
|
+
|
|
64
|
+
const firstCtx = spans[0]._context()
|
|
65
|
+
if (!firstCtx) return
|
|
66
|
+
|
|
67
|
+
const labels = {
|
|
68
|
+
'local root span id': firstCtx.toSpanId(),
|
|
69
|
+
'span id': activeCtx.toSpanId()
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
if (this._endpointCollection) {
|
|
73
|
+
const webServerTags = spans
|
|
74
|
+
.map(getSpanContextTags)
|
|
75
|
+
.filter(isWebServerSpan)[0]
|
|
76
|
+
|
|
77
|
+
if (webServerTags) {
|
|
78
|
+
labels['trace endpoint'] = endpointNameFromTags(webServerTags)
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
this._cpuProfiler.labels = labels
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
_exit () {
|
|
86
|
+
if (!this._cpuProfiler) return
|
|
87
|
+
this._cpuProfiler.labels = {}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
start ({ mapper } = {}) {
|
|
91
|
+
if (this._started) return
|
|
92
|
+
this._started = true
|
|
93
|
+
|
|
94
|
+
this._mapper = mapper
|
|
95
|
+
if (!this._pprof) {
|
|
96
|
+
this._pprof = require('@datadog/pprof')
|
|
97
|
+
this._cpuProfiler = new this._pprof.CpuProfiler()
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
this._cpuProfiler.start(this._frequency)
|
|
101
|
+
|
|
102
|
+
this._enter()
|
|
103
|
+
beforeCh.subscribe(this._enter)
|
|
104
|
+
afterCh.subscribe(this._exit)
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
profile () {
|
|
108
|
+
if (!this._started) return
|
|
109
|
+
return this._cpuProfiler.profile()
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
encode (profile) {
|
|
113
|
+
return this._pprof.encode(profile)
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
stop () {
|
|
117
|
+
if (!this._started) return
|
|
118
|
+
this._started = false
|
|
119
|
+
|
|
120
|
+
this._cpuProfiler.stop()
|
|
121
|
+
beforeCh.unsubscribe(this._enter)
|
|
122
|
+
afterCh.unsubscribe(this._exit)
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
module.exports = NativeCpuProfiler
|