Skip to main content
Requires Node.js 18 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.
apiKey
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.
skipDefaultInstrumentations
boolean
default:"false"
Disable automatic tracing of AI providers. See Instrumentations for details.
instrumentations
array
Custom OpenTelemetry instrumentors. See Instrumentations for details.

trace()

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
object
Additional attributes to attach to the span.

interaction()

Tracks a user interaction. Propagates user context to all nested traces.
userId
string
Identifier for the user.
sessionId
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:

taskSpan()

Creates a task span with explicit input/output recording.
name
string
required
The name of the task span.
attributes
object
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