This example demonstrates how to use @queuert/otel for distributed tracing and metrics with OpenTelemetry.
- Setting up OpenTelemetry tracing with OTLP exporter
- Setting up OpenTelemetry metrics with OTLP exporter
- Visualizing traces in otel-tui (terminal UI)
- Trace hierarchy: chain → job → attempt → prepare/complete
- Continuation links between jobs in a workflow
- Retry attempts showing multiple spans per job
Install otel-tui (terminal UI for OpenTelemetry):
# macOS
brew install ymtdzzz/tap/otel-tui
# Or with Go
go install github.com/ymtdzzz/otel-tui@latest# Terminal 1: Start otel-tui (OTLP receiver + viewer)
pnpm --filter example-observability-otel tui
# Terminal 2: Run the example
pnpm --filter example-observability-otel startIn otel-tui:
- Press
Tabto switch between Traces/Logs/Metrics views - Use arrow keys to navigate traces
- Press
Enterto expand trace details
- Basic chain - Single chain with one job (
greet) - Continuations - Chain with 3 jobs linked via continueWith (
order:validate→order:process→order:complete) - Blockers - Main job waits for 2 parallel blocker jobs (
fetch-user+fetch-permissions→process-with-blockers) - Retry - Job that fails first attempt, then succeeds (
might-fail)
If you don't have otel-tui, you can run with console output:
pnpm --filter example-observability-otel start:console| Script | Description |
|---|---|
tui |
Start otel-tui (OTLP receiver) |
start |
Run example (sends traces to otel-tui) |
start:console |
Run example (prints traces to console) |
src/observability.ts- OTEL tracing and metrics setupsrc/index.ts- Demo scenarios
- chain (PRODUCER) - Created when job chain starts
- job (PRODUCER) - Created for each job in the chain
- attempt (CONSUMER) - Created when worker processes job
- prepare (INTERNAL) - Job preparation phase
- complete (INTERNAL) - Job completion phase
- chain (CONSUMER) - Created when chain completes
- Counters: job created, attempt started/completed/failed, worker started/stopped
- Histograms: job duration, attempt duration, chain duration
- Gauges: idle workers, processing jobs per type