Skip to main content
Requires Python 3.9 or higher.

Installation

Quick Start

That’s it. All your OpenAI, Anthropic, and Google Generative AI calls are now traced automatically.

API Reference

init()

Initializes the Glass SDK. Call this once at application startup.
api_key
string
Your Glass API key. Falls back to GLASS_API_KEY environment variable if not provided.
debug
boolean
default:"False"
Enable console output for local development.
skip_default_instrumentations
boolean
default:"False"
Disable automatic tracing of AI providers. See Instrumentations for details.
instrumentations
list
Custom OpenTelemetry instrumentors. See Instrumentations for details.

@trace()

Decorator that wraps any function with tracing. Automatically records arguments, return values, and exceptions.
Works with async functions too:
name
string
Custom span name. Defaults to the function name.
attributes
dict
Additional attributes to attach to the span.

interaction()

Context manager for tracking user interactions. Propagates user context to all nested traces.
Also works with async:
user_id
string
Identifier for the user.
session_id
string
Session identifier.
project
string
In which project to classify traces.
input
string
The user’s input/query.
service
string
Service name for routing.
Methods on the context:

task_span()

Context manager for creating task spans with explicit input/output recording.
name
string
required
The name of the task span.
attributes
dict
Additional attributes for the span.
Methods on the task:

Full Example: RAG Pipeline

Here’s how the primitives compose together:
This creates a trace hierarchy like:

Environment Variables