Skip to content

Commit ab05db8

Browse files
authored
fix(runtime_metrics): fix non-native runtime.node.heap tags (#7628)
The fallback when the runtime metrics is not using the native module would send the wrong tags. This happens more frequent due to having optional dependencies now. Fixes: #7555
1 parent 3913137 commit ab05db8

2 files changed

Lines changed: 13 additions & 5 deletions

File tree

packages/dd-trace/src/runtime_metrics/runtime_metrics.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ function captureHeapSpace () {
238238
const stats = v8.getHeapSpaceStatistics()
239239

240240
for (let i = 0, l = stats.length; i < l; i++) {
241-
const tags = [`space:${stats[i].space_name}`]
241+
const tags = [`heap_space:${stats[i].space_name}`]
242242

243243
client.gauge('runtime.node.heap.size.by.space', stats[i].space_size, tags)
244244
client.gauge('runtime.node.heap.used_size.by.space', stats[i].space_used_size, tags)

packages/dd-trace/test/runtime_metrics.spec.js

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,9 @@ function createGarbage (count = 50) {
292292
const isGC95Percentile = sinon.match((value) => {
293293
return value >= 1e5 && value < 1e8 // In Nanoseconds. 0.1ms to 100ms.
294294
})
295+
const isHeapSpace = sinon.match((metricName) => {
296+
return /^heap_space:[a-z_]+$/.test(metricName)
297+
})
295298

296299
// These return percentages as strings and are tested later.
297300
sinon.assert.calledWith(client.gauge, 'runtime.node.cpu.user')
@@ -349,10 +352,15 @@ function createGarbage (count = 50) {
349352
})
350353
)
351354

352-
sinon.assert.calledWith(client.gauge, 'runtime.node.heap.size.by.space', isFiniteNumber)
353-
sinon.assert.calledWith(client.gauge, 'runtime.node.heap.used_size.by.space', isFiniteNumber)
354-
sinon.assert.calledWith(client.gauge, 'runtime.node.heap.available_size.by.space', isFiniteNumber)
355-
sinon.assert.calledWith(client.gauge, 'runtime.node.heap.physical_size.by.space', isFiniteNumber)
355+
sinon.assert.calledWith(client.gauge, 'runtime.node.heap.size.by.space', isFiniteNumber, isHeapSpace)
356+
sinon.assert.calledWith(client.gauge, 'runtime.node.heap.used_size.by.space', isFiniteNumber, isHeapSpace)
357+
sinon.assert.calledWith(
358+
client.gauge,
359+
'runtime.node.heap.available_size.by.space',
360+
isFiniteNumber,
361+
isHeapSpace
362+
)
363+
sinon.assert.calledWith(client.gauge, 'runtime.node.heap.physical_size.by.space', isFiniteNumber, isHeapSpace)
356364

357365
sinon.assert.called(client.flush)
358366
})

0 commit comments

Comments
 (0)