Get Started with OpenTelemetry

Describes how to send data to Opik using OpenTelemetry

Opik provides native support for OpenTelemetry (OTel), allowing you to instrument your ML/AI applications with distributed tracing. This guide will show you how to directly integrate OpenTelemetry SDKs with Opik.

OpenTelemetry integration in Opik currently supports HTTP transport. We’re actively working on expanding the feature set - stay tuned for updates!

OpenTelemetry Endpoint Configuration

Base Endpoint

To start sending traces to Opik, configure your OpenTelemetry exporter with one of these endpoints:

$# For Comet-hosted installations
>export OTEL_EXPORTER_OTLP_ENDPOINT="https://<COMET-SERVER>/api/v1/private/otel"
>export OTEL_EXPORTER_OTLP_HEADERS="Authorization=<your-api-key>,projectName=<your-project-name>,Comet-Workspace=<your-workspace-name>"
>
># For standalone or self-hosted Opik
>export OTEL_EXPORTER_OTLP_ENDPOINT="http://<YOUR-OPIK-INSTANCE>/api/v1/private/otel"
>
># For localhost
>export OTEL_EXPORTER_OTLP_ENDPOINT="http://localhost:5173/api/v1/private/otel"

Signal-Specific Endpoint

If your OpenTelemetry setup requires signal-specific configuration, you can use the traces endpoint. This is particularly useful when different signals (traces, metrics, logs) need to be sent to different endpoints:

$export OTEL_EXPORTER_OTLP_TRACES_ENDPOINT="http://<YOUR-OPIK-INSTANCE>/api/v1/private/otel/v1/traces"

Custom via OpenTelemetry SDKs

You can use any OpenTelemetry SDK to send traces directly to Opik. OpenTelemetry provides SDKs for many languages (C++, .NET, Erlang/Elixir, Go, Java, JavaScript, PHP, Python, Ruby, Rust, Swift). This extends Opik’s language support beyond the official SDKs (Python and TypeScript). For more instructions, visit the OpenTelemetry documentation.

Here’s a Python example showing how to set up OpenTelemetry with Opik:

1from opentelemetry import trace
2from opentelemetry.exporter.otlp.proto.http.trace_exporter import OTLPSpanExporter
3from opentelemetry.sdk.trace import TracerProvider
4from opentelemetry.sdk.trace.export import BatchSpanProcessor
5
6# For Comet-hosted installations
7OPIK_ENDPOINT = "https://<COMET-SERVER>/api/v1/private/otel/v1/traces"
8API_KEY = "<your-api-key>"
9PROJECT_NAME = "<your-project-name>"
10WORKSPACE_NAME = "<your-workspace-name>"
11
12# Initialize the trace provider
13provider = TracerProvider()
14processor = BatchSpanProcessor(
15 OTLPSpanExporter(
16 endpoint=OPIK_ENDPOINT,
17 headers={
18 "Authorization": API_KEY,
19 "projectName": PROJECT_NAME,
20 "Comet-Workspace": WORKSPACE_NAME
21 }
22 )
23)
24provider.add_span_processor(processor)
25trace.set_tracer_provider(provider)