Skip to content

Commit 7e4b054

Browse files
authored
DNS Lookup event hostname is sometimes not a string (#5067)
1 parent 858b2a1 commit 7e4b054

1 file changed

Lines changed: 17 additions & 1 deletion

File tree

  • packages/dd-trace/src/profiling/profilers

packages/dd-trace/src/profiling/profilers/events.js

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,23 @@ const pprofValueUnit = 'nanoseconds'
1414
const dateOffset = BigInt(Math.round(performance.timeOrigin * MS_TO_NS))
1515

1616
function labelFromStr (stringTable, key, valStr) {
17-
return new Label({ key, str: stringTable.dedup(valStr) })
17+
return new Label({ key, str: stringTable.dedup(safeToString(valStr)) })
18+
}
19+
20+
// We don't want to invoke toString for objects and functions, rather we'll
21+
// provide dummy values. These values are not meant to emulate built-in toString
22+
// behavior.
23+
function safeToString (val) {
24+
switch (typeof val) {
25+
case 'string':
26+
return val
27+
case 'object':
28+
return '[object]'
29+
case 'function':
30+
return '[function]'
31+
default:
32+
return String(val)
33+
}
1834
}
1935

2036
function labelFromStrStr (stringTable, keyStr, valStr) {

0 commit comments

Comments
 (0)