If you use a framework that supports
OpenTelemetry (OTel), you can export traces
directly to Openlayer without needing to use Openlayer’s SDKs. See the
OpenTelemetry integration for more details.

How to set up tracing
You must use one of Openlayer’s SDKs to trace your system. After installing the SDK in your language of choice, follow the steps:If you prefer, feel free to refer to a notebook
example.
Our templates gallery also has complete sample projects
that show how tracing works for development and monitoring.
1
Set environment variables
Openlayer needs to know where to upload the traces to. This information
is in the following environment variables:
Shell
2
Annotate the code you want to trace
Annotate all the functions you want to trace with Openlayer’s SDK.The traced
generate_answer
function in the example above uses an OpenAI LLM.
However, tracing also works for other LLM providers. If you set up any of the
streamlined approaches described in the Publishing data
guide, it will get added to the trace as well.3
Use the annotated code
All data that goes through the decorated code is automatically
streamed to the Openlayer platform, where your tests and alerts are defined.In the example above, if we call the resulting trace would be:
The
main
:
main
function has two nested steps: retrieve_context
, and
generate_answer
. The generate_answer
has a chat completion call within it. The cost,
number of tokens, latency, and other metadata are all computed automatically behind the
scenes.Updating Trace Metadata and Custom Inference IDs
These features are available in Openlayer Python SDK v0.2.0a91+ and enable
advanced request correlation scenarios and dynamic metadata enrichment.
update_current_trace()
- Updates trace-level metadata and inference IDsupdate_current_step()
- Updates current step/span metadata
Setting Custom Inference IDs
By default, Openlayer automatically generates unique UUIDs for each trace. However, you can set custom inference IDs to enable request correlation with external systems, batch processing, and audit trails. To set a custom inference ID, use theupdate_current_trace
function within any traced function:
Common Use Cases for Custom Inference IDs
- Request Correlation: Link traces with external API request IDs or session identifiers
- Batch Processing: Group related requests with consistent correlation patterns
- System Integration: Use existing request identifiers from upstream systems
- Audit Trails: Maintain consistent identifiers across distributed systems
- Debugging: Easily correlate logs and traces using familiar identifiers
Setting Trace-Level Metadata
You can enrich traces with contextual information like user IDs, session variables, or custom tags usingupdate_current_trace()
:
Setting Step-Level Metadata
You can also add metadata specific to individual steps usingupdate_current_step()
:
Common Use Cases
- Custom Inference IDs: Request correlation, batch processing, external system integration, audit trails, user feedback collection
- Trace Metadata: User context, session tracking, A/B testing flags, environment information, business metrics
- Step Metadata: Performance metrics, model parameters, intermediate results, error details, retry information
Using Custom Inference IDs for User Feedback and Signals
Custom inference IDs are particularly powerful when combined with Openlayer’s data updating capabilities. By setting meaningful inference IDs, you can easily add user feedback, ground truth labels, and other signals after the initial request:- Collect user ratings and satisfaction scores after interaction
- Add ground truth labels after expert review or verification
- Update with business signals like conversion rates or success metrics
- Enrich with contextual data discovered after the initial request
Trace metadata is set at the trace level and applies to all steps within that trace.Step metadata is specific to the current function/step being executed.Custom inference IDs are set at the trace level - if you don’t set one, Openlayer automatically generates a unique UUID.Metadata merging - calling
update_current_trace()
or update_current_step()
multiple times will merge the new metadata with existing values.