Overview
Upsonic instruments every agent run with OpenTelemetry spans following the GenAI semantic conventions. Every LLM call, pipeline step, tool execution, and agent run is traced automatically — giving you complete visibility into what your agent did, how long it took, and how much it cost.Install the optional dependencies:
What You Get
When tracing is enabled, each agent run produces a span hierarchy:gen_ai.request.model,gen_ai.response.model— model usedgen_ai.usage.input_tokens,gen_ai.usage.output_tokens— token countsgen_ai.request.temperature,gen_ai.request.max_tokens— request parametersgen_ai.response.id,gen_ai.response.finish_reasons— response metadataupsonic.total_cost,upsonic.execution_time— cost and durationupsonic.model_execution_time,upsonic.framework_overhead_time— timing breakdownupsonic.time_to_first_token— streaming latencyupsonic.tool_call_count— number of tool callsupsonic.tool.name,upsonic.tool.execution_time,upsonic.tool.success— per-tool detailsupsonic.input,upsonic.output— task input/outputupsonic.run_id,upsonic.status— run identification and statusupsonic.agent.name,upsonic.agent.model— agent metadataupsonic.usage.total_tokens,upsonic.usage.cache_read_tokens,upsonic.usage.cache_write_tokens— detailed token usageupsonic.pipeline.total_steps,upsonic.pipeline.executed_steps— pipeline progressupsonic.step.name,upsonic.step.status,upsonic.step.execution_time— per-step detailsuser.id,session.id— user and session tracking
Usage
Environment Variable — Zero Code Change
SetUPSONIC_OTEL_ENABLED=true and every Agent is automatically instrumented — no code changes needed.
UPSONIC_OTEL_ENABLED and calls Agent.instrument_all() with a DefaultTracingProvider under the hood. All agents created in the process are instrumented automatically.
Quick Start — instrument=True
Creates a DefaultTracingProvider from environment variables automatically.
DefaultTracingProvider — Any OTLP Backend
Send traces to Jaeger, Grafana Tempo, Datadog, or any OTLP-compatible collector.DefaultTracingProvider — Full Configuration
Global Instrumentation — Agent.instrument_all()
Instruments every Agent created after the call, without passing instrument each time.
Session & User Tracking
Streaming
Tracing works identically with streaming — no extra setup.Hide Sensitive Content
Advanced — Raw InstrumentationSettings
For testing or custom setups, passInstrumentationSettings directly.
Environment Variables
| Env Var | Description | Default |
|---|---|---|
UPSONIC_OTEL_ENABLED | Set true to auto-instrument all agents on import | — |
UPSONIC_OTEL_ENDPOINT | OTLP collector endpoint | http://localhost:4317 |
UPSONIC_OTEL_SERVICE_NAME | service.name resource attribute | upsonic |
UPSONIC_OTEL_SAMPLE_RATE | Sampling rate (0.0–1.0) | 1.0 |
UPSONIC_OTEL_HEADERS | Comma-separated key=value headers | — |
UPSONIC_OTEL_ENABLED=true triggers automatic OpenTelemetry setup on import and calls Agent.instrument_all().
Lifecycle
All providers setflush_on_exit=True by default — pending spans are flushed automatically when the process exits. You do not need to call shutdown() manually in normal usage.
Call shutdown() explicitly only if you need to flush spans mid-process (e.g., in tests or before a graceful restart).
Troubleshooting
ConnectionError at process exit
- Run a collector — start Jaeger, Grafana Tempo, or any OTLP-compatible backend:
- Use Langfuse instead — no local collector needed, traces go to the cloud:
- Don’t use tracing — simply don’t set
instrumentorUPSONIC_OTEL_ENABLED.

