OpenLIT

Integrate Kern with OpenLIT for OpenTelemetry-native observability, tracing, and monitoring of your AI agents.

Integrating Kern with OpenLIT

OpenLIT is an open-source, self-hosted, OpenTelemetry-native platform for a continuous feedback loop for testing, tracing, and fixing AI agents. By integrating Kern with OpenLIT, you can automatically instrument your agents to gain full visibility into LLM calls, tool usage, costs, performance metrics, and errors.

Prerequisites

  1. Install Dependencies

    Ensure you have the necessary packages installed:

    1uv pip install kern-ai openai openlit
  2. Deploy OpenLIT

    OpenLIT is open-source and self-hosted. Quick start with Docker:

    1git clone https://github.com/openlit/openlit
    2cd openlit
    3docker-compose up -d

    Access the dashboard at http://127.0.0.1:3000 with default credentials (username: user@openlit.io, password: openlituser).

    Other Deployment Options:

    For production deployments, Kubernetes with Helm, or other infrastructure setups, see the OpenLIT Installation Guide for detailed instructions on:

    • Kubernetes deployment with Helm charts
    • Custom Docker configurations
    • Reusing existing ClickHouse or OpenTelemetry Collector infrastructure
    • OpenLIT Operator for zero-code instrumentation in Kubernetes
  3. Set Environment Variables (Optional)

    Configure the OTLP endpoint based on your deployment:

    1# Local deployment
    2export OTEL_EXPORTER_OTLP_ENDPOINT="http://127.0.0.1:4318"
    3
    4# Self-hosted on your infrastructure
    5export OTEL_EXPORTER_OTLP_ENDPOINT="http://your-openlit-host:4318"

Sending Traces to OpenLIT

Example: Basic Agent Setup

This example demonstrates how to instrument your Kern agent with OpenLIT for automatic tracing.

1import openlit
2from kern.agent import Agent
3from kern.models.openai import OpenAIResponses
4from kern.tools.yfinance import YFinanceTools
5
6# Initialize OpenLIT instrumentation
7openlit.init(
8 otlp_endpoint="http://127.0.0.1:4318" # Your OpenLIT OTLP endpoint
9)
10
11# Create and configure the agent
12agent = Agent(
13 name="Stock Price Agent",
14 model=OpenAIResponses(id="gpt-5.2"),
15 tools=[YFinanceTools(stock_price=True, analyst_recommendations=True)],
16 instructions="You are a stock price agent. Answer questions in the style of a stock analyst.",
17 show_tool_calls=True,
18)
19
20# Use the agent - all calls are automatically traced
21agent.print_response("What is the current price of Tesla and what do analysts recommend?")

Example: Development Mode (Console Output)

For local development without a collector, OpenLIT can output traces directly to the console:

1import openlit
2from kern.agent import Agent
3from kern.models.openai import OpenAIResponses
4from kern.tools.hackernews import HackerNewsTools
5
6# Initialize OpenLIT without OTLP endpoint for console output
7openlit.init()
8
9# Create and configure the agent
10agent = Agent(
11 name="Web Search Agent",
12 model=OpenAIResponses(id="gpt-5.2"),
13 tools=[HackerNewsTools()],
14 instructions="Search the web and provide comprehensive answers.",
15 markdown=True,
16)
17
18# Use the agent - traces will be printed to console
19agent.print_response("What are the latest developments in AI agents?")

Example: Multi-Agent Team Tracing

OpenLIT automatically traces complex multi-agent workflows:

1import openlit
2from kern.agent import Agent
3from kern.team import Team
4from kern.models.openai import OpenAIResponses
5from kern.tools.hackernews import HackerNewsTools
6from kern.tools.yfinance import YFinanceTools
7
8# Initialize OpenLIT instrumentation
9openlit.init(otlp_endpoint="http://127.0.0.1:4318")
10
11# Research Agent
12research_agent = Agent(
13 name="Market Research Agent",
14 model=OpenAIResponses(id="gpt-5.2"),
15 tools=[HackerNewsTools()],
16 instructions="Research current market conditions and news",
17)
18
19# Financial Analysis Agent
20finance_agent = Agent(
21 name="Financial Analyst",
22 model=OpenAIResponses(id="gpt-5.2"),
23 tools=[YFinanceTools(stock_price=True, company_info=True)],
24 instructions="Perform quantitative financial analysis",
25)
26
27# Coordinated Team
28finance_team = Team(
29 name="Finance Research Team",
30 model=OpenAIResponses(id="gpt-5.2"),
31 members=[research_agent, finance_agent],
32 instructions=[
33 "Collaborate to provide comprehensive financial insights",
34 "Consider both fundamental analysis and market sentiment",
35 ],
36)
37
38# Execute team workflow - all agent interactions are traced
39finance_team.print_response("Analyze Apple (AAPL) investment potential")

Example: Custom Tracer Configuration

For advanced use cases with custom OpenTelemetry configuration:

1import openlit
2from opentelemetry import trace
3from opentelemetry.sdk.trace import TracerProvider
4from opentelemetry.sdk.trace.export import SimpleSpanProcessor
5from opentelemetry.exporter.otlp.proto.http.trace_exporter import OTLPSpanExporter
6from kern.agent import Agent
7from kern.models.openai import OpenAIResponses
8from kern.tools.hackernews import HackerNewsTools
9
10# Configure custom tracer provider
11trace_provider = TracerProvider()
12trace_provider.add_span_processor(
13 SimpleSpanProcessor(
14 OTLPSpanExporter(endpoint="http://127.0.0.1:4318/v1/traces")
15 )
16)
17trace.set_tracer_provider(trace_provider)
18
19# Initialize OpenLIT with custom tracer
20openlit.init(
21 tracer=trace.get_tracer(__name__),
22 disable_batch=True
23)
24
25# Create and configure the agent
26agent = Agent(
27 model=OpenAIResponses(id="gpt-5.2"),
28 tools=[HackerNewsTools()],
29 markdown=True,
30)
31
32# Use the agent
33agent.print_response("What is currently trending on Twitter?")

OpenLIT Dashboard Features

Once your agents are instrumented, you can access the OpenLIT dashboard to:

  • View Traces: Visualize complete execution flows including agent runs, tool calls, and LLM requests
  • Monitor Performance: Track latency, token usage, and throughput metrics
  • Analyze Costs: Monitor API costs across different models and providers
  • Track Errors: Identify and debug exceptions with detailed stack traces
  • Compare Models: Evaluate different LLM providers based on performance and cost
OpenLIT Trace Details

Configuration Options

The openlit.init() function accepts several parameters:

1openlit.init(
2 otlp_endpoint="http://127.0.0.1:4318", # OTLP collector endpoint
3 tracer=None, # Custom OpenTelemetry tracer
4 disable_batch=False, # Disable batch span processing
5 environment="production", # Environment name for filtering
6 application_name="my-agent", # Application identifier
7)

CLI-Based Instrumentation

For true zero-code instrumentation, you can use the openlit-instrument CLI command to run your application without modifying any code:

1openlit-instrument \
2 --service-name my-ai-app \
3 --environment production \
4 --otlp-endpoint http://127.0.0.1:4318 \
5 python your_app.py

This approach is particularly useful for:

  • Adding observability to existing applications without code changes
  • CI/CD pipelines where you want to instrument automatically
  • Testing observability before committing to code modifications

Notes

  • Automatic Instrumentation: OpenLIT automatically instruments supported LLM providers (OpenAI, Anthropic, etc.) and frameworks
  • Zero Code Changes: Use either openlit.init() in your code or the openlit-instrument CLI to trace all LLM calls without modifications
  • OpenTelemetry Native: OpenLIT uses standard OpenTelemetry protocols, ensuring compatibility with other observability tools
  • Open-Source & Self-Hosted: OpenLIT is fully open-source and runs on your own infrastructure for complete data privacy and control

Integration with Other Platforms

OpenLIT can export traces to other observability platforms like Grafana Cloud, New Relic and more. See the Langfuse integration guide for an example of using OpenLIT with Langfuse.