Overview
This guide covers how to integrate Gentrace with complex OpenTelemetry setups. If you are looking for a basic Gentrace setup, start with our quickstart.Core Concepts
OpenTelemetry uses three main components:Language SDKs and APIs that create and manage spans (units of work
in your application)
The OpenTelemetry Collector or in-process processors that batch,
enrich, and filter spans
Modules that send spans to backends via protocols like OTLP/HTTP
- Attributes: Key/value metadata
- Events: Time-stamped messages
- Context propagation: Links spans across services via Baggage
Steps
To send your traces that use LLMs to Gentrace via OpenTelemetry, we need to:1
Instrument your application
Include Gentrace and gen_ai attributes and events in your spans.
2
Export spans to Gentrace
Set up span infrastructure to filter and export spans, so only
relevant spans are sent to Gentrace.
3
View your traces in Gentrace
Head to your Gentrace dashboard to see
your traces.
Instrument your application
Create the spans
Use the following SDK helpers to automatically add Gentrace attributes and events to your spans:- interaction() - for sending agent interactions to Gentrace
- traced() - for tracing functions
Set the baggage for future filtering
For existing OpenTelemetry setups, spans must be filtered before exporting to Gentrace to avoid rate limiting. To facilitate this, add the baggage itemgentrace.sample=true to relevant spans, and then filter in your exporter on the basis of gentrace.sample.
Test span marking
When running experiments, the SDK automatically addsgentrace.in_experiment=true to the baggage to mark test spans.
This prevents production evaluations from running on test data.
You should set this manually in your experiment script:
Export spans to Gentrace
First, choose one of two methods:With the OpenTelemetry Collector
Use OpenTelemetry Collector to filter and route spans
With In-Process Sampling
Use a custom sampler in your application to control which spans
are sent
With the OpenTelemetry Collector
With the OpenTelemetry Collector, setup the following span processing infrastructure to send only relevant spans to Gentrace:1. Map baggage to span attributes
The collector does not receive baggage items, as they are only held in-memory. Use a span processor to mapgentrace.sample and gentrace.in_experiment from the baggage to the span.
For convenience, we provide a span processor that does this for you:
2. Add Gentrace exporter to the collector configuration
3. Configure filtering to only send Gentrace-specific spans
4. Set up pipelines
Point your application’s OTLP exporter to your Collector (e.g.,
http://collector.example.com:4318), which will then forward
filtered spans to Gentrace’s OTLP endpoint at /api/otel/v1/tracesComplete example collector configuration
With In-Process Sampling
With the OpenTelemetry SDK, setup the following span processing infrastructure to send only relevant spans to Gentrace:1. Sample spans based on baggage
Before setting up your exporter, sample spans based ongentrace.sample=true.
For simplicity, we supply the GentraceSampler, which is an in-process sampler that filters spans based on OpenTelemetry baggage.
2. Export spans to Gentrace
Add a Gentrace exporter to your OpenTelemetry SDK configuration:Troubleshooting
If spans aren’t appearing in Gentrace:- Verify filtering: Ensure spans have the
gentrace.sample=trueattribute (set by SDK helpers or manually) - Check collector configuration: Confirm the filter processor isn’t dropping your spans
- Validate API key: Ensure your
GENTRACE_API_KEYis correctly set in the collector - Monitor ingestion:
- Test collector connectivity: Use the OpenTelemetry Collector’s built-in logging to debug connection issues
Next Steps
- OpenTelemetry API Reference - Span attributes and events
- OpenTelemetry SDK setup - Detailed SDK configuration
- interaction() - SDK helper for tracing functions
- experiment() - SDK helper for experiments