traceStart() function
Starts a named span for tracing a block of code that no decorator can wrap, to be closed later by traceEnd() with the same name.
Signature:
export declare function traceStart(name: string, tags?: TraceAttributes, tracerName?: string): void;
Parameters
|
Parameter |
Type |
Description |
|---|---|---|
|
name |
string |
span name, and the key traceEnd() will close it by |
|
tags |
(Optional) attributes to set on the span at creation; values must be strings | |
|
tracerName |
string |
(Optional) tracer to create the span with, |
Returns:
void
Exceptions
TypeError if a span under this name is already open
Remarks
Spans started here are held in a module-level registry keyed by name, which is what lets traceEnd() find one from an unrelated call site. Two consequences follow, and both matter:
- A name may have only ONE span open at a time. Starting a second under a live name throws rather than silently replacing it, since replacing would leak the first span forever. - A span left unclosed is never exported. Prefer traced(), or a
try/finallyaround the traceEnd() call, wherever the block can throw.
The span is created standalone, NOT as a child of whatever span is currently active, and it is not made active for the code in between. Use it to time a region, not to parent the spans that region creates.
Example
import {
traceStart,
traceEnd,
} from '@imqueue/opentelemetry';
traceStart('import-batch', { 'batch.size': String(rows.length) });
try {
await importRows(rows);
} finally {
traceEnd('import-batch');
}
Read this page as plain markdown — no HTML, no navigation. For pasting into an LLM, or for an agent to fetch.