traceAI-livekit
OpenTelemetry instrumentation for LiveKit agents integrated with Future AGI.
This package provides automatic attribute mapping from LiveKit's native OpenTelemetry instrumentation to Future AGI's semantic conventions, ensuring rich and structured traces in your dashboard.
Installation
pip install traceai-livekit
Quick Start
To instrument your LiveKit agent, simply initialize fi-instrumentation and enable the attribute mapping inside your agent's entrypoint.
from livekit.agents import AgentServer, JobContext
from fi_instrumentation.otel import register, ProjectType
from traceai_livekit import enable_http_attribute_mapping
server = AgentServer()
@server.rtc_session()
async def entrypoint(ctx: JobContext):
# 1. Initialize TraceAI (inside entrypoint for multiprocessing safety)
register(
project_name="My LiveKit Agent",
project_type=ProjectType.OBSERVE,
set_global_tracer_provider=True,
)
# 2. Enable LiveKit attribute mapping
# This automatically hooks into LiveKit's telemetry system
enable_http_attribute_mapping()
# ... rest of your agent logic ...
await ctx.connect()
if __name__ == "__main__":
server.run()
enable_http_attribute_mapping() (or enable_grpc_attribute_mapping()) hands the provider to LiveKit for you. If you call
LiveKit's set_tracer_provider yourself on the provider register() returned, call it after enable_*: before it, the call
drops the Future AGI exporter. LiveKit installs its privacy filter once per provider, so an allow_pii passed in a later call is
ignored. To keep conversation content out of your traces, set LIVEKIT_TELEMETRY_ALLOW_PII=false before calling enable_*
(livekit-agents 1.8 and later).
Flushing at the end of a job
On Linux a LiveKit job process ends without running atexit, and LiveKit flushes only its own processors, so the spans
still queued when a job ends, such as the root agent_session span, used to never reach Future AGI. enable_* now sends
them twice over:
- When the job shuts down, if
enable_*runs inside a job (the usual place, the entrypoint): this sends the voice trace,agent_sessionincluded, as soon as the call ends. - When the process exits, just before it stops: this sends what LiveKit ends after the shutdown callbacks, its own
job_shutdownspan, and the job's rootjob_entrypointspan when tracing is set up before the job starts. With set-up inside the entrypoint, LiveKit startsjob_entrypointbefore tracing is on, so it is never recorded and the job trace arrives rooted atjob_shutdown.
Each waits at most 3 seconds for the collector, well inside the 10 seconds LiveKit gives a job process to exit, so its own clean-up still runs when the collector is slow.
If you set tracing up outside a job (for example at import time, in the job process), only the process-exit flush runs.
To also send each call's trace as soon as the call ends, call flush_on_job_shutdown() in each job entrypoint:
from traceai_livekit import flush_on_job_shutdown
@server.rtc_session()
async def entrypoint(ctx: JobContext):
flush_on_job_shutdown()
...
Do not pass provider.force_flush to ctx.add_shutdown_callback: LiveKit calls it with the shutdown reason, which
force_flush takes as its timeout, so it fails and nothing is flushed.
Limits:
- A process LiveKit kills (for example when a worker drains and the job overruns its exit time) sends nothing more.
- Before livekit-agents 1.3, LiveKit closes the session at the same time as the job-shutdown flush, so that flush can miss
agent_session; the process-exit flush still sends it. - A second
AgentSessionin one job that is still closing when the shutdown callbacks run is sent by the process-exit flush, not the job-shutdown one. - In LiveKit Cloud observability mode the session's parent span is recorded on LiveKit's own provider and never reaches Future AGI, so the trace has no stored root there.
Compatibility
- livekit-agents: 1.x. 1.8 is the tested version (it needs Python 3.10 or later). Since 1.7, LiveKit names its content
attributes
lk.pii.*(for examplelk.pii.user_input); both those names and the earlier ones are mapped toinput.valueandoutput.value. - fi-instrumentation-otel: 1.1.0 or later (1.0.0 fails inside
register()with OpenTelemetry 1.45, which livekit-agents 1.8.7 and later require). 1.0 moved span attributes from thellm.*names to the OpenTelemetry GenAIgen_ai.*names, and renamed theSpanAttributesconstants with them. Code that only callsregister()is unaffected; if your code sets or reads those attributes directly, see the mapping from the old names.
Features
- Automatic Attribute Mapping: Converts LiveKit attributes (like
lk.user_input,gen_ai.usage.input_tokens) to Future AGI standard attributes (input.value,llm.tokenCount.prompt). - Raw Data Preservation: Keeps original LiveKit attributes and adds
raw.input/raw.outputfor full debugging context. - Multiprocessing Support: Designed to work with LiveKit's worker process model.
- Event Parsing: Extracts LLM outputs from
gen_ai.choiceevents when available.
Examples
Check the examples/ directory for complete working agents:
simple_agent.py: A basic voice assistant agent.egress_agent.py: An agent with call recording (Egress) enabled.
Metadata
Release files for traceAI-livekit 0.1.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| traceai_livekit-0.1.2.tar.gz | 14.5 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| traceai_livekit-0.1.2-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 29.8 kB
Release files / traceai_livekit-0.1.2.tar.gz
| Download URL | traceai_livekit-0.1.2.tar.gz |
|---|---|
| Size | 14.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
4bf06f3cb387862412045db9268d09fbfbb5c5a121c892127654f2f68f2f6b71
|
|
BLAKE2b-256 checksum How to use checksums |
8597648db82f7979e554e0b356bc8f26bbce578b541c9f9fc2184519563fbb42
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/2.0.1 CPython/3.13.3 Darwin/25.6.0
|
Release files / traceai_livekit-0.1.2-py3-none-any.whl
| Download URL | traceai_livekit-0.1.2-py3-none-any.whl |
|---|---|
| Size | 15.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
fa192df872f63c577358db6c78e56a01b0b4ec0dbc6be3bebe5088fc67209ef7
|
|
BLAKE2b-256 checksum How to use checksums |
0469e96f1fad70957d1e21b0b9892b579da7f9975273ac78b02608b7c2a6aca6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/2.0.1 CPython/3.13.3 Darwin/25.6.0
|
Security for traceAI-livekit 0.1.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.