将 Litefuse 与 Agno 集成
本 notebook 演示如何通过 OpenLIT instrumentation,使用 OpenTelemetry 将 Litefuse 与 Agno 集成。读完本 notebook 后,你将能够使用 Litefuse 对 Agno 应用进行 trace,从而获得更好的可观测性与调试能力。
什么是 Agno? Agno 是一个用于构建和管理 AI Agent 的平台。
什么是 Litefuse? Litefuse 是一个开源的 AI Agent 可观测性与评估平台。它为 LLM 应用提供 tracing 与监控能力,帮助开发者调试、分析并优化其 AI 系统。Litefuse 通过原生集成、OpenTelemetry 以及 API/SDK 与多种工具和框架对接。
快速开始
我们将通过示例演示如何使用 Agno 并将其与 Litefuse 集成。
第 1 步:安装依赖
%pip install agno openai langfuse yfinance openlit第 2 步:设置环境变量
通过注册 Litefuse Cloud 或 自托管 Litefuse 获取你的 Litefuse API Key。同时你还需要 OpenAI API Key。
import os
# Get keys for your project from the project settings page: https://litefuse.cloud
os.environ["LANGFUSE_PUBLIC_KEY"] = "pk-lf-..."
os.environ["LANGFUSE_SECRET_KEY"] = "sk-lf-..."
os.environ["LANGFUSE_BASE_URL"] = "https://litefuse.cloud"
# your openai key
os.environ["OPENAI_API_KEY"] = "sk-proj-..."设置好环境变量后,我们就可以初始化 Langfuse 客户端了。get_client() 会使用环境变量中提供的凭证来初始化 Langfuse 客户端。
from langfuse import get_client
langfuse = get_client()
# Verify connection
if langfuse.auth_check():
print("Langfuse client is authenticated and ready!")
else:
print("Authentication failed. Please check your credentials and host.")第 3 步:向 Litefuse 发送 Trace
本示例演示如何使用 OpenLit instrumentation 库进行接入。
from agno.agent import Agent
from agno.models.openai import OpenAIChat
from agno.tools.duckduckgo import DuckDuckGoTools
# Initialize OpenLIT instrumentation
import openlit
openlit.init(tracer=langfuse._otel_tracer, disable_batch=True)
# Create and configure the agent
agent = Agent(
model=OpenAIChat(id="gpt-4o-mini"),
tools=[DuckDuckGoTools()],
markdown=True,
debug_mode=True,
)
# Use the agent
agent.print_response("What is currently trending on Twitter?")第 4 步:在 Litefuse 中查看 Trace
运行上面的 Agent 示例后,你可以在 Litefuse 中查看 Agno Agent 生成的 trace。

Interoperability with the Python SDK
You can use this integration together with the Litefuse SDKs to add additional attributes to the observation.
The @observe() decorator provides a convenient way to automatically wrap your instrumented code and add additional attributes to the observation.
from langfuse import observe, propagate_attributes, get_client
langfuse = get_client()
@observe()
def my_llm_pipeline(input):
# Add additional attributes (user_id, session_id, metadata, version, tags) to all spans created within this execution scope
with propagate_attributes(
user_id="user_123",
session_id="session_abc",
tags=["agent", "my-observation"],
metadata={"email": "user@litefuse.ai"},
version="1.0.0"
):
# YOUR APPLICATION CODE HERE
result = call_llm(input)
return result
# Run the function
my_llm_pipeline("Hi")Learn more about using the Decorator in the Langfuse SDK instrumentation docs.
Troubleshooting
No observations appearing
First, enable debug mode in the Python SDK:
export LANGFUSE_DEBUG="True"Then run your application and check the debug logs:
- OTel observations appear in the logs: Your application is instrumented correctly but observations are not reaching Litefuse. To resolve this:
- Call
langfuse.flush()at the end of your application to ensure all observations are exported. - Verify that you are using the correct API keys and base URL.
- Call
- No OTel spans in the logs: Your application is not instrumented correctly. Make sure the instrumentation runs before your application code.
Unwanted observations in Litefuse
The Langfuse SDK is based on OpenTelemetry. Other libraries in your application may emit OTel spans that are not relevant to you. These still count toward your billable units, so you should filter them out. See Unwanted spans in Litefuse for details.
Missing attributes
Some attributes may be stored in the metadata object of the observation rather than being mapped to the Litefuse data model. If a mapping or integration does not work as expected, please raise an issue on GitHub.
Next Steps
Once you have instrumented your code, you can manage, evaluate and debug your application: