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
-
Install Dependencies
Ensure you have the necessary packages installed:
1uv pip install kern-ai openai openlit -
Deploy OpenLIT
OpenLIT is open-source and self-hosted. Quick start with Docker:
1git clone https://github.com/openlit/openlit2cd openlit3docker-compose up -dAccess the dashboard at
http://127.0.0.1:3000with 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
-
Set Environment Variables (Optional)
Configure the OTLP endpoint based on your deployment:
1# Local deployment2export OTEL_EXPORTER_OTLP_ENDPOINT="http://127.0.0.1:4318"34# Self-hosted on your infrastructure5export 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 openlit2from kern.agent import Agent3from kern.models.openai import OpenAIResponses4from kern.tools.yfinance import YFinanceTools56# Initialize OpenLIT instrumentation7openlit.init(8 otlp_endpoint="http://127.0.0.1:4318" # Your OpenLIT OTLP endpoint9)1011# Create and configure the agent12agent = 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)1920# Use the agent - all calls are automatically traced21agent.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 openlit2from kern.agent import Agent3from kern.models.openai import OpenAIResponses4from kern.tools.hackernews import HackerNewsTools56# Initialize OpenLIT without OTLP endpoint for console output7openlit.init()89# Create and configure the agent10agent = 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)1718# Use the agent - traces will be printed to console19agent.print_response("What are the latest developments in AI agents?")Example: Multi-Agent Team Tracing
OpenLIT automatically traces complex multi-agent workflows:
1import openlit2from kern.agent import Agent3from kern.team import Team4from kern.models.openai import OpenAIResponses5from kern.tools.hackernews import HackerNewsTools6from kern.tools.yfinance import YFinanceTools78# Initialize OpenLIT instrumentation9openlit.init(otlp_endpoint="http://127.0.0.1:4318")1011# Research Agent12research_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)1819# Financial Analysis Agent20finance_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)2627# Coordinated Team28finance_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)3738# Execute team workflow - all agent interactions are traced39finance_team.print_response("Analyze Apple (AAPL) investment potential")Example: Custom Tracer Configuration
For advanced use cases with custom OpenTelemetry configuration:
1import openlit2from opentelemetry import trace3from opentelemetry.sdk.trace import TracerProvider4from opentelemetry.sdk.trace.export import SimpleSpanProcessor5from opentelemetry.exporter.otlp.proto.http.trace_exporter import OTLPSpanExporter6from kern.agent import Agent7from kern.models.openai import OpenAIResponses8from kern.tools.hackernews import HackerNewsTools910# Configure custom tracer provider11trace_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)1819# Initialize OpenLIT with custom tracer20openlit.init(21 tracer=trace.get_tracer(__name__),22 disable_batch=True23)2425# Create and configure the agent26agent = Agent(27 model=OpenAIResponses(id="gpt-5.2"),28 tools=[HackerNewsTools()],29 markdown=True,30)3132# Use the agent33agent.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
Configuration Options
The openlit.init() function accepts several parameters:
1openlit.init(2 otlp_endpoint="http://127.0.0.1:4318", # OTLP collector endpoint3 tracer=None, # Custom OpenTelemetry tracer4 disable_batch=False, # Disable batch span processing5 environment="production", # Environment name for filtering6 application_name="my-agent", # Application identifier7)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.pyThis 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 theopenlit-instrumentCLI 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.