Skip to content

Commit f69bc04

Browse files
szegedirochdev
authored andcommitted
Tag profiles with a sequence number (#6106)
1 parent 748dc59 commit f69bc04

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

integration-tests/profiler/profiler.spec.js

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,16 @@ if (process.platform !== 'win32') {
2222
const TIMEOUT = 30000
2323

2424
function checkProfiles (agent, proc, timeout,
25-
expectedProfileTypes = DEFAULT_PROFILE_TYPES, expectBadExit = false
25+
expectedProfileTypes = DEFAULT_PROFILE_TYPES, expectBadExit = false, expectSeq = true
2626
) {
2727
return Promise.all([
2828
processExitPromise(proc, timeout, expectBadExit),
29-
expectProfileMessagePromise(agent, timeout, expectedProfileTypes)
29+
expectProfileMessagePromise(agent, timeout, expectedProfileTypes, expectSeq)
3030
])
3131
}
3232

3333
function expectProfileMessagePromise (agent, timeout,
34-
expectedProfileTypes = DEFAULT_PROFILE_TYPES
34+
expectedProfileTypes = DEFAULT_PROFILE_TYPES, expectSeq = true
3535
) {
3636
const fileNames = expectedProfileTypes.map(type => `${type}.pprof`)
3737
return agent.assertMessageReceived(({ headers, _, files }) => {
@@ -50,6 +50,9 @@ function expectProfileMessagePromise (agent, timeout,
5050
for (const [index, fileName] of attachments.entries()) {
5151
assert.propertyVal(files[index + 1], 'originalname', fileName)
5252
}
53+
if (expectSeq) {
54+
assert(event.tags_profiler.indexOf(',profile_seq:') !== -1)
55+
}
5356
} catch (e) {
5457
e.message += ` ${JSON.stringify({ headers, files, event })}`
5558
throw e
@@ -560,7 +563,7 @@ describe('profiler', () => {
560563
execArgv: oomExecArgv,
561564
env: oomEnv
562565
})
563-
return checkProfiles(agent, proc, timeout, ['space'], true)
566+
return checkProfiles(agent, proc, timeout, ['space'], true, false)
564567
})
565568

566569
it('sends a heap profile on OOM in worker thread and exits successfully', () => {
@@ -584,7 +587,7 @@ describe('profiler', () => {
584587
DD_PROFILING_EXPERIMENTAL_OOM_MAX_HEAP_EXTENSION_COUNT: 3
585588
}
586589
})
587-
return checkProfiles(agent, proc, timeout, ['space'], false)
590+
return checkProfiles(agent, proc, timeout, ['space'], false, false)
588591
}).retries(3)
589592

590593
it('sends a heap profile on OOM with async callback', () => {

packages/dd-trace/src/profiling/profiler.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ function findWebSpan (startedSpans, spanId) {
4242
}
4343

4444
class Profiler extends EventEmitter {
45+
#profileSeq = 0
46+
4547
constructor () {
4648
super()
4749
this._enabled = false
@@ -123,11 +125,12 @@ class Profiler extends EventEmitter {
123125

124126
try {
125127
const start = new Date()
128+
const nearOOMCallback = this._nearOOMExport.bind(this)
126129
for (const profiler of config.profilers) {
127130
// TODO: move this out of Profiler when restoring sourcemap support
128131
profiler.start({
129132
mapper,
130-
nearOOMCallback: this._nearOOMExport.bind(this)
133+
nearOOMCallback
131134
})
132135
this._logger.debug(`Started ${profiler.type} profiler in ${threadNamePrefix} thread`)
133136
}
@@ -292,6 +295,7 @@ class Profiler extends EventEmitter {
292295
this.endpointCounts.clear()
293296

294297
tags.snapshot = snapshotKind
298+
tags.profile_seq = this.#profileSeq++
295299
const exportSpec = { profiles, start, end, tags, endpointCounts }
296300
const tasks = this._config.exporters.map(exporter =>
297301
exporter.export(exportSpec).catch(err => {

0 commit comments

Comments
 (0)