Overview
The@arizeai/openinference-core package provides the foundational utilities for OpenInference JavaScript tracing:
- OITracer: OpenTelemetry tracer wrapper with data masking
- Context Attributes: Session ID, user ID, metadata, and tags propagation
- Span Wrappers:
withSpan,traceChain,traceAgent,traceTool - Decorators:
@observefor class methods - Attribute Helpers: Functions to generate OpenInference-compliant attributes
Installation
OITracer
OITracer wraps an OpenTelemetry tracer and can redact sensitive data before writing spans.
Basic Usage
TraceConfig Options
Environment Variables
Configure masking via environment variables:Context Attributes
Propagate request-level attributes across all spans in a context.Available Setters
Context Setter Reference
| Function | Parameters | Description |
|---|---|---|
setSession | { sessionId: string } | Set session ID |
setUser | { userId: string } | Set user ID |
setMetadata | Record<string, unknown> | Set metadata object |
setTags | string[] | Set tags array |
setPromptTemplate | { template, variables?, version? } | Set prompt template info |
setAttributes | Attributes | Set arbitrary attributes |
Retrieving Attributes
Span Wrappers
withSpan
Wrap a function to automatically create spans:withSpan Options
Custom Input/Output Processing
Convenience Wrappers
These wrappers set the span kind automatically:Decorators
The@observe decorator traces class methods (requires TypeScript 5+ standard decorators):
Decorator Options
Attribute Helpers
Generate OpenInference-compliant attributes:getLLMAttributes
getLLMAttributes Parameters
getEmbeddingAttributes
getRetrieverAttributes
getToolAttributes
getInputAttributes / getOutputAttributes
getMetadataAttributes
Utility Functions
withSafety
Wrap a function and returnnull on error:
safelyJSONStringify / safelyJSONParse
Complete Example
Next Steps
Semantic Conventions
Learn about OpenInference semantic conventions
Instrumentations
Auto-instrument LLM frameworks
Examples
View complete examples