Class: Tracer
Prefactor TypeScript SDK / @prefactor/core / Tracer
Class: Tracer
Section titled “Class: Tracer”Defined in: packages/core/src/tracing/tracer.ts:66
Tracer manages the lifecycle of spans.
The tracer is responsible for:
- Creating spans with unique IDs
- Managing span lifecycle (start/end)
- Delegating to the transport layer for span emission
- Handling agent instance lifecycle
Example
Section titled “Example”const tracer = new Tracer(transport);
const span = tracer.startSpan({ name: 'llm-call', spanType: SpanType.LLM, inputs: { prompt: 'Hello' }});
try { // ... do work ... tracer.endSpan(span, { outputs: { response: 'Hi!' } });} catch (error) { tracer.endSpan(span, { error });}Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new Tracer(
transport,partition?):Tracer
Defined in: packages/core/src/tracing/tracer.ts:75
Initialize the tracer.
Parameters
Section titled “Parameters”transport
Section titled “transport”The transport to use for emitting spans
partition?
Section titled “partition?”number
The partition for ID generation. If not provided, a random partition will be generated.
Returns
Section titled “Returns”Tracer
Methods
Section titled “Methods”startSpan()
Section titled “startSpan()”startSpan(
options):Span
Defined in: packages/core/src/tracing/tracer.ts:88
Start a new span
Parameters
Section titled “Parameters”options
Section titled “options”Span configuration options
Returns
Section titled “Returns”The created span
endSpan()
Section titled “endSpan()”endSpan(
span,options?):void
Defined in: packages/core/src/tracing/tracer.ts:128
End a span and emit it to the transport
Parameters
Section titled “Parameters”The span to end
options?
Section titled “options?”End span options (outputs, error, token usage)
Returns
Section titled “Returns”void
close()
Section titled “close()”close():
Promise<void>
Defined in: packages/core/src/tracing/tracer.ts:168
Close the tracer and flush any pending spans
Returns
Section titled “Returns”Promise<void>
Promise that resolves when the tracer is closed
startAgentInstance()
Section titled “startAgentInstance()”startAgentInstance():
void
Defined in: packages/core/src/tracing/tracer.ts:172
Returns
Section titled “Returns”void
finishAgentInstance()
Section titled “finishAgentInstance()”finishAgentInstance():
void
Defined in: packages/core/src/tracing/tracer.ts:180
Returns
Section titled “Returns”void