Traceloop
Integrate Kern with Traceloop to send traces and gain insights into your agent's performance.
Integrating Kern with Traceloop
Traceloop provides an LLM observability platform built on OpenLLMetry, an open-source OpenTelemetry extension. By integrating Kern with Traceloop, you can automatically trace agent execution, team workflows, tool calls, and token usage metrics.
Prerequisites
-
Install Dependencies
Ensure you have the necessary packages installed:
1uv pip install kern-ai openai traceloop-sdk -
Setup Traceloop Account
- Sign up for an account at Traceloop.
- Obtain your API key from Settings > API Keys.
-
Set Environment Variables
Configure your environment with the Traceloop API key:
1export TRACELOOP_API_KEY=<your-api-key>
Sending Traces to Traceloop
-
Example: Basic Agent Instrumentation
Initialize Traceloop at the start of your application. The SDK automatically instruments Kern agent execution.
1from traceloop.sdk import Traceloop2from kern.agent import Agent3from kern.models.openai import OpenAIResponses45# Initialize Traceloop - must be called before creating agents6Traceloop.init(app_name="agno_agent")78# Create and configure the agent9agent = Agent(10 name="Assistant",11 model=OpenAIResponses(id="gpt-5.2"),12 description="A helpful assistant",13 instructions=["Be concise and helpful"],14)1516# Agent execution is automatically traced17response = agent.run("What is the capital of France?")18print(response.content)-
Example: Development Mode (Disable Batching)
For local development, disable batching to see traces immediately:
1from traceloop.sdk import Traceloop2from kern.agent import Agent3from kern.models.openai import OpenAIResponses45# Disable batching for immediate trace visibility during development6Traceloop.init(app_name="agno_dev", disable_batch=True)78# Create and configure the agent9agent = Agent(10 name="DevAgent",11 model=OpenAIResponses(id="gpt-5.2"),12)1314agent.print_response("Hello, world!")-
Example: Multi-Agent Team Tracing
Team execution is automatically traced, showing the coordination between multiple agents:
1from traceloop.sdk import Traceloop2from kern.agent import Agent3from kern.models.openai import OpenAIResponses4from kern.team import Team56Traceloop.init(app_name="agno_team")78researcher = Agent(9 name="Researcher",10 role="Research Specialist",11 model=OpenAIResponses(id="gpt-5.2"),12 instructions=["Research topics thoroughly and provide factual information"],13 debug_mode=True,14)1516writer = Agent(17 name="Writer",18 role="Content Writer",19 model=OpenAIResponses(id="gpt-5.2"),20 instructions=["Write clear, engaging content based on research"],21 debug_mode=True,22)2324team = Team(25 name="ContentTeam",26 members=[researcher, writer],27 model=OpenAIResponses(id="gpt-5.2"),28 debug_mode=True,29)3031# Team execution creates parent span with child spans for each agent32result = team.run("Write a brief overview of OpenTelemetry observability")33print(result.content)-
Example: Using Workflow Decorators
Use the @workflow decorator to create custom spans for organizing your traces:
1from traceloop.sdk import Traceloop2from traceloop.sdk.decorators import workflow3from kern.agent import Agent4from kern.models.openai import OpenAIResponses56Traceloop.init(app_name="agno_workflows")78agent = Agent(9 name="AnalysisAgent",10 model=OpenAIResponses(id="gpt-5.2"),11 debug_mode=True,12)1314@workflow(name="data_analysis_pipeline")15def analyze_data(query: str) -> str:16 """Custom workflow that wraps agent execution."""17 response = agent.run(query)18 return response.content1920# The workflow decorator creates a parent span21result = analyze_data("Analyze the benefits of observability in AI systems")22print(result)-
Example: Async Agent with Tools
Async agent execution is fully supported with automatic tool call tracing:
1import asyncio2from traceloop.sdk import Traceloop3from kern.agent import Agent4from kern.models.openai import OpenAIResponses56Traceloop.init(app_name="agno_async")78def get_weather(city: str) -> str:9 """Get the weather for a city."""10 return f"The weather in {city} is sunny, 72°F"1112agent = Agent(13 name="WeatherAgent",14 model=OpenAIResponses(id="gpt-5.2"),15 tools=[get_weather],16 debug_mode=True,17)1819async def main():20 # Async execution is automatically traced21 response = await agent.arun("What's the weather in San Francisco?")22 print(response.content)2324asyncio.run(main())Notes
- Initialization: Call
Traceloop.init()before creating any agents to ensure proper instrumentation. - Development Mode: Use
disable_batch=Trueduring development for immediate trace visibility. - Async Support: Both sync (
run()) and async (arun()) methods are fully instrumented. - Privacy Control: Set
TRACELOOP_TRACE_CONTENT=falseto disable logging of prompts and completions.