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

  1. Install Dependencies

    Ensure you have the necessary packages installed:

    1uv pip install kern-ai openai traceloop-sdk
  2. Setup Traceloop Account

  3. 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 Traceloop
2from kern.agent import Agent
3from kern.models.openai import OpenAIResponses
4
5# Initialize Traceloop - must be called before creating agents
6Traceloop.init(app_name="agno_agent")
7
8# Create and configure the agent
9agent = Agent(
10 name="Assistant",
11 model=OpenAIResponses(id="gpt-5.2"),
12 description="A helpful assistant",
13 instructions=["Be concise and helpful"],
14)
15
16# Agent execution is automatically traced
17response = 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 Traceloop
2from kern.agent import Agent
3from kern.models.openai import OpenAIResponses
4
5# Disable batching for immediate trace visibility during development
6Traceloop.init(app_name="agno_dev", disable_batch=True)
7
8# Create and configure the agent
9agent = Agent(
10 name="DevAgent",
11 model=OpenAIResponses(id="gpt-5.2"),
12)
13
14agent.print_response("Hello, world!")
  • Example: Multi-Agent Team Tracing

Team execution is automatically traced, showing the coordination between multiple agents:

1from traceloop.sdk import Traceloop
2from kern.agent import Agent
3from kern.models.openai import OpenAIResponses
4from kern.team import Team
5
6Traceloop.init(app_name="agno_team")
7
8researcher = 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)
15
16writer = 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)
23
24team = Team(
25 name="ContentTeam",
26 members=[researcher, writer],
27 model=OpenAIResponses(id="gpt-5.2"),
28 debug_mode=True,
29)
30
31# Team execution creates parent span with child spans for each agent
32result = 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 Traceloop
2from traceloop.sdk.decorators import workflow
3from kern.agent import Agent
4from kern.models.openai import OpenAIResponses
5
6Traceloop.init(app_name="agno_workflows")
7
8agent = Agent(
9 name="AnalysisAgent",
10 model=OpenAIResponses(id="gpt-5.2"),
11 debug_mode=True,
12)
13
14@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.content
19
20# The workflow decorator creates a parent span
21result = 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 asyncio
2from traceloop.sdk import Traceloop
3from kern.agent import Agent
4from kern.models.openai import OpenAIResponses
5
6Traceloop.init(app_name="agno_async")
7
8def get_weather(city: str) -> str:
9 """Get the weather for a city."""
10 return f"The weather in {city} is sunny, 72°F"
11
12agent = Agent(
13 name="WeatherAgent",
14 model=OpenAIResponses(id="gpt-5.2"),
15 tools=[get_weather],
16 debug_mode=True,
17)
18
19async def main():
20 # Async execution is automatically traced
21 response = await agent.arun("What's the weather in San Francisco?")
22 print(response.content)
23
24asyncio.run(main())

Notes

  • Initialization: Call Traceloop.init() before creating any agents to ensure proper instrumentation.
  • Development Mode: Use disable_batch=True during development for immediate trace visibility.
  • Async Support: Both sync (run()) and async (arun()) methods are fully instrumented.
  • Privacy Control: Set TRACELOOP_TRACE_CONTENT=false to disable logging of prompts and completions.