diff --git a/lib/trace_events.js b/lib/trace_events.js index 2b154946d86..0d533c76a78 100644 --- a/lib/trace_events.js +++ b/lib/trace_events.js @@ -61,6 +61,9 @@ class Tracing { } [customInspectSymbol](depth, opts) { + if (typeof depth === 'number' && depth < 0) + return this; + const obj = { enabled: this.enabled, categories: this.categories diff --git a/test/parallel/test-util-inspect.js b/test/parallel/test-util-inspect.js index 834b0c0236a..f9566df48a1 100644 --- a/test/parallel/test-util-inspect.js +++ b/test/parallel/test-util-inspect.js @@ -2519,3 +2519,15 @@ assert.strictEqual( assert(i < 2 || line.startsWith('\u001b[90m')); }); } + +{ + // Tracing class respects inspect depth. + try { + const trace = require('trace_events').createTracing({ categories: ['fo'] }); + const actual = util.inspect({ trace }, { depth: 0 }); + assert.strictEqual(actual, '{ trace: [Tracing] }'); + } catch (err) { + if (err.code !== 'ERR_TRACE_EVENTS_UNAVAILABLE') + throw err; + } +}