@@ -17,13 +17,14 @@ const {
17
17
const { isWebServerSpan, endpointNameFromTags, getStartedSpans } = require ( '../webspan-utils' )
18
18
19
19
let beforeCh
20
+ let lastInstance
20
21
const enterCh = dc . channel ( 'dd-trace:storage:enter' )
21
22
const spanFinishCh = dc . channel ( 'dd-trace:span:finish' )
22
23
const profilerTelemetryMetrics = telemetryMetrics . manager . namespace ( 'profilers' )
23
24
24
25
const ProfilingContext = Symbol ( 'NativeWallProfiler.ProfilingContext' )
25
26
26
- let kSampleCount
27
+ let kSampleCount , kCPEDContextCount
27
28
28
29
function getActiveSpan ( ) {
29
30
const store = storage ( 'legacy' ) . getStore ( )
@@ -131,6 +132,7 @@ class NativeWallProfiler {
131
132
132
133
this . _logger = options . logger
133
134
this . _started = false
135
+ lastInstance = this
134
136
}
135
137
136
138
codeHotspotsEnabled ( ) {
@@ -147,6 +149,7 @@ class NativeWallProfiler {
147
149
this . _mapper = mapper
148
150
this . _pprof = require ( '@datadog/pprof' )
149
151
kSampleCount = this . _pprof . time . constants . kSampleCount
152
+ kCPEDContextCount = this . _pprof . time . constants . kCPEDContextCount
150
153
151
154
// pprof otherwise crashes in worker threads
152
155
if ( ! process . _startProfilerIdleNotifier ) {
@@ -274,6 +277,15 @@ class NativeWallProfiler {
274
277
return profilingContext
275
278
}
276
279
280
+ _getSampleContext ( ) {
281
+ const context = this . _pprof . time . getContext ( )
282
+ return this . _useAsyncContextFrame ? context : context . ref
283
+ }
284
+
285
+ _getCPEDContextCount ( ) {
286
+ return this . _profilerState [ kCPEDContextCount ]
287
+ }
288
+
277
289
_setNewContext ( ) {
278
290
this . _pprof . time . setContext (
279
291
this . _currentContext = {
@@ -411,4 +423,24 @@ class NativeWallProfiler {
411
423
}
412
424
}
413
425
426
+ NativeWallProfiler . prototype . getActiveSpan = function ( ) {
427
+ const span = getActiveSpan ( )
428
+ if ( span === undefined ) {
429
+ return { }
430
+ }
431
+ const spanData = lastInstance . _getProfilingContext ( span )
432
+ updateContext ( spanData )
433
+ return { spanId : spanData . spanId , rootSpanId : spanData . rootSpanId }
434
+ }
435
+ NativeWallProfiler . prototype . getSampleContext = function ( ) {
436
+ const ctx = lastInstance . _getSampleContext ( )
437
+ if ( ctx === undefined ) {
438
+ return { }
439
+ }
440
+ updateContext ( ctx )
441
+ return { spanId : ctx . spanId , rootSpanId : ctx . rootSpanId }
442
+ }
443
+ NativeWallProfiler . prototype . getCPEDContextCount = function ( ) {
444
+ return lastInstance . _getCPEDContextCount ( )
445
+ }
414
446
module . exports = NativeWallProfiler
0 commit comments