Skip to content

Commit 81a9c72

Browse files
committed
trace_events: respect inspect() depth
This commit causes the Tracing class to account for util.inspect() depth. PR-URL: #28037 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]>
1 parent 39d6da8 commit 81a9c72

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

lib/trace_events.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@ class Tracing {
6161
}
6262

6363
[customInspectSymbol](depth, opts) {
64+
if (typeof depth === 'number' && depth < 0)
65+
return this;
66+
6467
const obj = {
6568
enabled: this.enabled,
6669
categories: this.categories

test/parallel/test-util-inspect.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2519,3 +2519,15 @@ assert.strictEqual(
25192519
assert(i < 2 || line.startsWith('\u001b[90m'));
25202520
});
25212521
}
2522+
2523+
{
2524+
// Tracing class respects inspect depth.
2525+
try {
2526+
const trace = require('trace_events').createTracing({ categories: ['fo'] });
2527+
const actual = util.inspect({ trace }, { depth: 0 });
2528+
assert.strictEqual(actual, '{ trace: [Tracing] }');
2529+
} catch (err) {
2530+
if (err.code !== 'ERR_TRACE_EVENTS_UNAVAILABLE')
2531+
throw err;
2532+
}
2533+
}

0 commit comments

Comments
 (0)