Skip to content
GitHubLog inStart free
cetra is not released yet. These docs describe the development version.

Send OpenTelemetry

Use plain OpenTelemetry when your application already has it, or when it is written in a language without a cetra SDK.

Protocol Endpoint
OTLP/HTTP http://<HOST>:8080/v1/traces or http://<HOST>:4318/v1/traces
OTLP/gRPC <HOST>:4317

Authenticate with an API key in a header: Authorization: Bearer sk-cetra-…. cetra accepts protobuf and JSON bodies, and gzip compression.

Install the OpenTelemetry SDK and the OTLP/HTTP exporter:

Terminal window
pip install opentelemetry-sdk opentelemetry-exporter-otlp-proto-http
export CETRA_API_KEY=sk-cetra-<32_LETTERS_OR_DIGITS>
export OTEL_EXPORTER_OTLP_ENDPOINT=http://localhost:8080

The exporter reads the endpoint from OTEL_EXPORTER_OTLP_ENDPOINT and adds /v1/traces itself.

import os
from opentelemetry.exporter.otlp.proto.http.trace_exporter import OTLPSpanExporter
from opentelemetry.sdk.trace import TracerProvider
from opentelemetry.sdk.trace.export import BatchSpanProcessor
provider = TracerProvider()
provider.add_span_processor(
BatchSpanProcessor(
OTLPSpanExporter(headers={"Authorization": f"Bearer {os.environ['CETRA_API_KEY']}"})
)
)
tracer = provider.get_tracer("my-app")
with tracer.start_as_current_span("chat") as span:
span.set_attribute("gen_ai.provider.name", "openai")
span.set_attribute("gen_ai.request.model", "gpt-4o-mini")
span.set_attribute("gen_ai.usage.input_tokens", 12)
span.set_attribute("gen_ai.usage.output_tokens", 3)
provider.shutdown() # flushes the spans before the script ends
Terminal window
npm install @opentelemetry/sdk-trace-node @opentelemetry/exporter-trace-otlp-proto
export CETRA_API_KEY=sk-cetra-<32_LETTERS_OR_DIGITS>
export OTEL_EXPORTER_OTLP_ENDPOINT=http://localhost:8080
import { OTLPTraceExporter } from "@opentelemetry/exporter-trace-otlp-proto";
import { BatchSpanProcessor } from "@opentelemetry/sdk-trace-node";
import { NodeTracerProvider } from "@opentelemetry/sdk-trace-node";
const provider = new NodeTracerProvider({
spanProcessors: [
new BatchSpanProcessor(
new OTLPTraceExporter({ headers: { Authorization: `Bearer ${process.env.CETRA_API_KEY}` } }),
),
],
});
provider.register();
const tracer = provider.getTracer("my-app");
const span = tracer.startSpan("chat");
span.setAttribute("gen_ai.provider.name", "openai");
span.setAttribute("gen_ai.request.model", "gpt-4o-mini");
span.end();
await provider.shutdown();

Use the OTLP/HTTP exporter and set the endpoint and header through the standard variables:

Terminal window
export OTEL_EXPORTER_OTLP_ENDPOINT=http://localhost:8080
export OTEL_EXPORTER_OTLP_HEADERS="Authorization=Bearer sk-cetra-…"
exporter, err := otlptracehttp.New(ctx) // go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp
if err != nil {
log.Fatal(err)
}
provider := sdktrace.NewTracerProvider(sdktrace.WithBatcher(exporter))
defer provider.Shutdown(ctx)
otel.SetTracerProvider(provider)

With the OpenTelemetry Java agent, set the same variables:

Terminal window
export OTEL_EXPORTER_OTLP_ENDPOINT=http://localhost:8080
export OTEL_EXPORTER_OTLP_PROTOCOL=http/protobuf
export OTEL_EXPORTER_OTLP_HEADERS="Authorization=Bearer sk-cetra-…"
java -javaagent:opentelemetry-javaagent.jar -jar app.jar

If your application already sends to a Collector, add an otlphttp exporter with the header:

exporters:
otlphttp/cetra:
endpoint: http://localhost:8080
headers:
Authorization: Bearer ${env:CETRA_API_KEY}
service:
pipelines:
traces:
exporters: [otlphttp/cetra]

cetra reads the OpenTelemetry GenAI attributes (gen_ai.*) and the OpenInference conventions, and records inputs, outputs, token usage and cost from them. Spans without these attributes are stored as they are. See Semantic conventions for every convention cetra reads.