Skip to main content
The openinference-instrumentation package provides utilities for manual instrumentation, trace configuration, and context propagation.

Installation

OITracer

The OITracer class wraps an OpenTelemetry tracer with OpenInference-specific functionality, including support for TraceConfig masking and context attribute propagation.

Creating a Tracer

Manual Span Creation

Decorator-Based Tracing

OITracer provides decorators for common span types:

TraceConfig

The TraceConfig class controls data privacy and payload size in traces.

Configuration Options

Environment Variables

Configuration can also be set via environment variables:
When attributes are hidden, they are replaced with "__REDACTED__".

Context Managers

Context managers propagate attributes like session ID, user ID, metadata, and tags across all spans in a context.

using_session

Track multi-turn conversations:

using_user

Track user-specific traces:

using_metadata

Add custom key-value metadata:

using_tags

Add categorical tags for filtering:

using_prompt_template

Track prompt templates with versions:

using_attributes

Combine multiple context attributes:

suppress_tracing

Temporarily disable tracing:

Helper Functions

safe_json_dumps

Safely serialize objects to JSON:

Complete Example