Create a disposable scope for tracing a synchronous operation using JavaScript's explicit resource management (using syntax). The scope automatically publishes start and end events, enters bound stores, and handles cleanup when disposed.
import { boundedChannel } from 'node:diagnostics_channel';
const wc = boundedChannel('my-operation');
const context = { operationId: '123' };
{
using scope = wc.withScope(context);
// Stores are entered, start event is published
// Perform work and set result on context
context.result = 42;
}
// End event is published, stores are restored automatically