Tracing
Native tracing support for tracking operations and their relationships.
Overview
Vestig includes built-in tracing that lets you:
- Track operations — Measure duration of functions and async operations
- Build relationships — Nested spans automatically become parent-child
- Correlate logs — Spans are linked to logs via shared context
- Export traces — Compatible with OpenTelemetry and W3C Trace Context
Quick Start
typescript
Creating Spans
Async Spans (Recommended)
The span() function handles lifecycle automatically:
typescript
Sync Spans
For synchronous operations:
typescript
Manual Control
When you need explicit control over span lifecycle:
typescript
Nested Spans
Nested spans automatically become children:
typescript
This produces a trace like:
text
Span Attributes
Add metadata to spans:
typescript
Span Events
Record events within a span:
typescript
Span Status
Set the final status of a span:
typescript
Status values:
'unset'— Default, no explicit status'ok'— Operation completed successfully'error'— Operation failed
Getting the Active Span
Access the current span from anywhere:
typescript
Span Options
Configure spans when creating them:
typescript
Integration with Logging
Spans automatically correlate with logs:
typescript
Log output includes trace context:
json
Next Steps
- Spans — Deep dive into span API
- Context Propagation — How context flows through your app
- W3C Trace Context — Interoperability with other systems