diff --git a/packages/dd-trace/src/profiling/profilers/events.js b/packages/dd-trace/src/profiling/profilers/events.js index 8ff1748ceda..d6ae423d36a 100644 --- a/packages/dd-trace/src/profiling/profilers/events.js +++ b/packages/dd-trace/src/profiling/profilers/events.js @@ -14,7 +14,23 @@ const pprofValueUnit = 'nanoseconds' const dateOffset = BigInt(Math.round(performance.timeOrigin * MS_TO_NS)) function labelFromStr (stringTable, key, valStr) { - return new Label({ key, str: stringTable.dedup(valStr) }) + return new Label({ key, str: stringTable.dedup(safeToString(valStr)) }) +} + +// We don't want to invoke toString for objects and functions, rather we'll +// provide dummy values. These values are not meant to emulate built-in toString +// behavior. +function safeToString (val) { + switch (typeof val) { + case 'string': + return val + case 'object': + return '[object]' + case 'function': + return '[function]' + default: + return String(val) + } } function labelFromStrStr (stringTable, keyStr, valStr) {