This package provides OpenInference Core utilities for LLM Traces, including tracing helpers, decorators, and context attribute propagation.
If you are tracing into Phoenix, @arizeai/phoenix-otel re-exports this package’s helpers, context utilities, attribute builders, and OITracer from a single import path alongside Phoenix registration. The wrappers resolve the default tracer when the wrapped function runs, which is useful for experiments and other workflows that swap providers.
Installation#
Tracing Helpers#
This package provides convenient helpers to instrument your functions, agents, and LLM operations with OpenInference spans.
withSpan#
Wraps any function (sync or async) with OpenTelemetry tracing:
traceChain#
Convenience wrapper for tracing workflow sequences:
traceAgent#
Convenience wrapper for tracing autonomous agents:
traceTool#
Convenience wrapper for tracing external tools:
Additional Span-Kind Wrappers#
The remaining OpenInference span kinds each have a matching wrapper. Like traceChain/traceAgent/traceTool, each is a shorthand for withSpan(fn, { ...options, kind }) and accepts the same options minus kind. These wrappers are marked @experimental and may change in a future release.
| Wrapper | Span kind | Use it for |
|---|---|---|
traceLLM | LLM | Language-model invocations — chat/text completions and other inference calls |
traceRetriever | RETRIEVER | Fetching documents from a knowledge base, vector store, or search index (RAG) |
traceReranker | RERANKER | Reordering or scoring candidate documents by relevance |
traceEmbedding | EMBEDDING | Converting text or data into vector representations |
traceGuardrail | GUARDRAIL | Safety, validation, or policy checks (moderation, PII, compliance) |
traceEvaluator | EVALUATOR | Scoring output quality — relevance, correctness, or LLM-as-a-judge |
tracePrompt | PROMPT | Constructing, rendering, or templating a prompt before a model call |
Decorators#
@observe#
Decorator for automatically tracing class methods:
Customizing Spans#
The package offers utilities to track important application metadata using context attribute propagation:
| Function | Description |
|---|---|
setSession | Specify a session ID to track and group multi-turn conversations |
setUser | Specify a user ID to track different conversations with a given user |
setMetadata | Add custom metadata for operational needs |
setTags | Add tags to filter spans on specific keywords |
setPromptTemplate | Track prompt template used, with version and variables |
setAttributes | Add multiple custom attributes at once |
All @arizeai/openinference auto instrumentation packages will pull attributes off of context and add them to spans.
Example: setSession#
Chaining Setters#
Each setter function returns a new active context, so they can be chained together:
Manual Span Context Propagation#
If you are creating spans manually and want to propagate context attributes, use the getAttributesFromContext utility:
Attribute Helpers#
Generate properly formatted attributes for common LLM operations.
getLLMAttributes#
Generate attributes for LLM operations:
getEmbeddingAttributes#
Generate attributes for embedding operations:
getRetrieverAttributes#
Generate attributes for document retrieval:
getToolAttributes#
Generate attributes for tool definitions:
Trace Config#
Control settings like data privacy and payload sizes. You may want to keep sensitive information from being logged for security reasons, or limit the size of base64 encoded images.
These values can also be controlled via environment variables. See the configuration spec for more information.

