bland-toddler-43562
09/18/2025, 6:08 AMtall-airline-16756
09/18/2025, 6:08 AMtall-airline-16756
09/18/2025, 6:09 AMsession.chat_ctx, which holds all messages, function calls, and outputs.
• Then, use the _chat_ctx_to_otel_events utility to convert the chat context into OpenTelemetry events.
• Attach these events to spans by using trace.get_current_span() and span.add_event().
• Make sure to enable tracing with a provider using set_tracer_provider(), and you can also add helpful metadata like session or user IDs.
• For real-time updates, the conversation_item_added event is great for capturing incremental changes.
• If you’re working with models like OpenAI Realtime, just enable the tracing parameter in the model options for smooth automatic integration.
We also have a complete example integration with LangFuse available here. It walks you through setting up a tracer provider, sending chat messages as events, and capturing session-level spans.
If you’d like, I’m here to assist you with setting up a specific tracing backend or integrating with any particular LLM provider. Just let me know how I can help!
Sources: Workflows | LiveKit Docs | livekit-plugins/livekit-plugins-openai/livekit/plugins/openai/realtime/real... | Logs, metrics, and telemetry | LiveKit Docsbland-toddler-43562
09/18/2025, 6:48 AMtall-airline-16756
09/18/2025, 6:48 AMbland-toddler-43562
09/18/2025, 6:49 AMtall-airline-16756
09/18/2025, 6:50 AMsession.chat_ctx. This holds all your messages, function calls, and outputs.
2. Next, use the _chat_ctx_to_otel_events utility to transform that chat context into OpenTelemetry events.
3. Then, attach these events to the current span by calling span.add_event(). For example:
from opentelemetry import trace
span = trace.get_current_span()
chat_events = _chat_ctx_to_otel_events(session.chat_ctx)
for name, attrs in chat_events:
span.add_event(name, attrs)
Doing this will make sure your chat history and outputs are neatly logged as part of your tracing data.
If you’d like, I’m here to walk you through the implementation in your setup—just let me know!bland-toddler-43562
09/18/2025, 8:28 AMtall-airline-16756
09/18/2025, 8:29 AMbland-toddler-43562
09/18/2025, 8:35 AMtall-airline-16756
09/18/2025, 8:35 AMfrom opentelemetry import trace
from opentelemetry.trace import TracerProvider
from opentelemetry.sdk.trace import TracerProvider
from opentelemetry.sdk.trace.export import SimpleSpanProcessor, ConsoleSpanExporter
# Set up the tracer provider
provider = TracerProvider()
trace.set_tracer_provider(provider)
provider.add_span_processor(SimpleSpanProcessor(ConsoleSpanExporter()))
# Get a tracer instance
tracer = trace.get_tracer(__name__)
# Start a span with a custom name
with tracer.start_as_current_span("custom_trace_name") as span:
span.set_attribute("key", "value")
# Add your logic here
Just swap out "custom_trace_name" with whatever name you'd like your trace to have. This way, your trace will show up with your chosen name in the tracing backend, making it easier to identify.
If you have any questions or if you’re working with a different language or framework, please don’t hesitate to ask. I’m here to help you every step of the way!