function
trace_events.createTracing
Creates and returns a Tracing object for the given set of categories.
import trace_events from 'node:trace_events';
const categories = ['node.perf', 'node.async_hooks'];
const tracing = trace_events.createTracing({ categories });
tracing.enable();
// do stuff
tracing.disable();Referenced types
interface CreateTracingOptions
- categories: string[]
An array of trace category names. Values included in the array are coerced to a string when possible. An error will be thrown if the value cannot be coerced.
interface Tracing
The Tracing object is used to enable or disable tracing for sets of categories. Instances are created using the trace_events.createTracing() method.
When created, the Tracing object is disabled. Calling the tracing.enable() method adds the categories to the set of enabled trace event categories. Calling tracing.disable() will remove the categories from the set of enabled trace event categories.
- readonly categories: string
A comma-separated list of the trace event categories covered by this
Tracingobject. Disables this
Tracingobject.Only trace event categories not covered by other enabled
Tracingobjects and not specified by the--trace-event-categoriesflag will be disabled.import trace_events from 'node:trace_events'; const t1 = trace_events.createTracing({ categories: ['node', 'v8'] }); const t2 = trace_events.createTracing({ categories: ['node.perf', 'node'] }); t1.enable(); t2.enable(); // Prints 'node,node.perf,v8' console.log(trace_events.getEnabledCategories()); t2.disable(); // Will only disable emission of the 'node.perf' category // Prints 'node,v8' console.log(trace_events.getEnabledCategories());Enables this
Tracingobject for the set of categories covered by theTracingobject.