I'm working on setting up *Langfuse* for the LiveK...
# agents
d
I'm working on setting up Langfuse for the LiveKit agent. While the traces are appearing, the input and output fields for the traces are completely empty. Has anyone else managed to resolve this issue? I'm using the code provided in the langfuse example
Copy code
def setup_langfuse(
    metadata: dict[str, AttributeValue] | None = None,
    *,
    host: str | None = None,
    public_key: str | None = None,
    secret_key: str | None = None,
) -> TracerProvider:
    from opentelemetry.exporter.otlp.proto.http.trace_exporter import OTLPSpanExporter
    from opentelemetry.sdk.trace.export import BatchSpanProcessor

    public_key = public_key or os.getenv("LANGFUSE_PUBLIC_KEY")
    secret_key = secret_key or os.getenv("LANGFUSE_SECRET_KEY")
    host = host or os.getenv("LANGFUSE_HOST")

    if not public_key or not secret_key or not host:
        raise ValueError("LANGFUSE_PUBLIC_KEY, LANGFUSE_SECRET_KEY, and LANGFUSE_HOST must be set")

    langfuse_auth = base64.b64encode(f"{public_key}:{secret_key}".encode()).decode()
    os.environ["OTEL_EXPORTER_OTLP_ENDPOINT"] = f"{host.rstrip('/')}/api/public/otel"
    os.environ["OTEL_EXPORTER_OTLP_HEADERS"] = f"Authorization=Basic {langfuse_auth}"

    trace_provider = TracerProvider()
    trace_provider.add_span_processor(BatchSpanProcessor(OTLPSpanExporter()))
    set_tracer_provider(trace_provider, metadata=metadata)
    return trace_provider

def setup_tracing(ctx: JobContext, logger: logging.Logger):
    trace_provider = setup_langfuse(
        logger=logger,
        # metadata will be set as attributes on all spans created by the tracer
        metadata={
            "langfuse.session.id": ctx.room.name,
        }
    )

    # (optional) add a shutdown callback to flush the trace before process exit
    async def flush_trace():
        try:
            trace_provider.force_flush()
        except Exception as e:
            logger.error(f"Error flushing trace: {e}")

    ctx.add_shutdown_callback(flush_trace)


async def entrypoint(ctx: JobContext):
    setup_tracing(ctx=ctx, logger=logger)
f
Maybe not entirely related but there's also this feature request for langfuse https://github.com/livekit/agents/issues/3008#issuecomment-3179456016
r