Integrate OpenTelemetry with LangWatch to collect LLM spans from any language for unified AI agent evaluation data.
OpenTelemetry is a vendor-neutral standard for observability that provides a unified way to capture traces, metrics, and logs. LangWatch is fully compatible with OpenTelemetry, allowing you to use any OpenTelemetry-compatible library in any programming language to capture your LLM traces and send them to LangWatch.This guide shows you how to set up OpenTelemetry instrumentation in any language and configure it to export traces to LangWatch’s OTEL API endpoint.
Protip: wanna to get started even faster? Copy our llms.txt and ask an AI to do this integration
using OpenTelemetry;using OpenTelemetry.Resources;using OpenTelemetry.Trace;public class Program{ public static void Main(string[] args) { var builder = Sdk.CreateTracerProviderBuilder() .SetResourceBuilder(ResourceBuilder.CreateDefault() .AddService(serviceName: "my-service")) .AddOtlpExporter(opts => opts .Endpoint = new Uri("https://app.langwatch.ai/api/otel/v1/traces") .Headers = "Authorization=Bearer " + Environment.GetEnvironmentVariable("LANGWATCH_API_KEY")) .Build(); }}
3
Instrument your LLM calls
using OpenTelemetry.Trace;public class LLMService{ private readonly Tracer _tracer = TracerProvider.Default.GetTracer("my-service"); public async Task<string> CallLLMAsync() { using var span = _tracer.StartActiveSpan("llm-call"); // Your LLM call here return "response"; }}
Spring AI: Spring AI provides built-in observability support for AI applications, including OpenTelemetry integration for tracing LLM calls and AI operations
OpenTelemetry Java SDK: Use OpenTelemetry Java SDK with custom spans
Azure Monitor OpenTelemetry: Azure Monitor OpenTelemetry provides comprehensive OpenTelemetry support for .NET applications, including automatic instrumentation and Azure-specific features
OpenTelemetry .NET SDK: Use OpenTelemetry .NET SDK with custom instrumentation
Set these environment variables for authentication:
export LANGWATCH_API_KEY="your-api-key-here"export LANGWATCH_PROJECT_ID="your-project-id-here" # Required for service API keys
LANGWATCH_PROJECT_ID is required when using a service API key (e.g. for CI/CD or multi-project setups). Project API keys obtained from the project settings page already have the project context built in.