Skip to main content

@arizeai/phoenix-otel re-exports the OpenInference tracing helpers from @arizeai/openinference-core, so you can configure Phoenix export and author traced functions from one package path.

Why These Re-Exports Matter#

@arizeai/phoenix-otel adds Phoenix registration and export. The tracing helpers themselves come from @arizeai/openinference-core.

Those helpers resolve the default tracer when the wrapped function is invoked, not when the wrapper is created. That means:

  • functions wrapped at module load continue following later global provider changes
  • experiment-scoped providers still receive spans from previously defined helpers
  • you can keep using the same wrappers when moving between standalone tracing and experiment workflows

API Reference#

withSpan(fn, options?)#

The general-purpose wrapper. All other helper wrappers build on it.

Options (SpanTraceOptions):

FieldTypeDefaultDescription
namestringfn.nameSpan name. Falls back to the function name.
kindOpenInferenceSpanKindCHAINOpenInference span kind such as CHAIN, AGENT, TOOL, LLM, or RETRIEVER.
tracerTracerdefault tracerOverride the tracer instance. When omitted, the default tracer is resolved when the wrapper runs.
attributesAttributes—Base attributes merged into every span.
processInput(...args) => AttributesdefaultProcessInputCustom function to extract span attributes from input arguments.
processOutput(result) => AttributesdefaultProcessOutputCustom function to extract span attributes from the return value.
openTelemetrySpanKindSpanKindSpanKind.INTERNALUnderlying OpenTelemetry span kind.

Behavior:

  • wraps both sync and async functions
  • records input and output attributes automatically
  • records exceptions, marks the span as ERROR, closes the span, and re-throws
  • preserves the call-time this value

traceChain(fn, options?)#

Shorthand for withSpan(fn, { ...options, kind: OpenInferenceSpanKind.CHAIN }).

traceAgent(fn, options?)#

Shorthand for withSpan(fn, { ...options, kind: OpenInferenceSpanKind.AGENT }).

traceTool(fn, options?)#

Shorthand for withSpan(fn, { ...options, kind: OpenInferenceSpanKind.TOOL }).

Additional Span-Kind Wrappers#

Alongside traceChain, traceAgent, and traceTool, the following wrappers cover the remaining OpenInference span kinds. Each is a shorthand for withSpan(fn, { ...options, kind }) with the listed span kind pre-configured, accepts the same SpanTraceOptions (minus kind), and resolves the default tracer at invocation time.

Note
These wrappers are marked @experimental in @arizeai/openinference-core and may change in a future release.
WrapperSpan kindUse it for
traceLLM(fn, options?)LLMInvocations of a large language model — chat or text completions and other foundation-model inference calls.
traceRetriever(fn, options?)RETRIEVERFetching documents or context from a knowledge base, vector store, or search index (RAG).
traceReranker(fn, options?)RERANKERReordering or scoring candidate documents by relevance before passing them to a model.
traceEmbedding(fn, options?)EMBEDDINGConverting text or other data into vector representations for semantic search and retrieval.
traceGuardrail(fn, options?)GUARDRAILSafety, validation, or policy checks such as content moderation, PII detection, or compliance enforcement.
traceEvaluator(fn, options?)EVALUATORAssessing or scoring output quality — relevance scoring, correctness checks, or LLM-as-a-judge evaluations.
tracePrompt(fn, options?)PROMPTConstructing, rendering, or templating a prompt before it is sent to a model.

observe(options?)#

Decorator factory for class methods. Use TypeScript 5+ standard decorators.

observe preserves method this context and uses the method name as the default span name unless you pass name.

Input / Output Processing#

By default, withSpan serializes function arguments into input.value and the return value into output.value. Override this with processInput and processOutput when you want richer OpenInference attributes.

The same customization pattern works with every span-kind wrapper (traceChain, traceAgent, traceTool, traceLLM, traceRetriever, traceReranker, traceEmbedding, traceGuardrail, traceEvaluator, and tracePrompt), since they all delegate to withSpan.

Combining Helpers With Context Attributes#

Tracing helpers compose naturally with context attributes. Wrap a call in context.with() to propagate session IDs, metadata, or tags to all child spans.

Use With Experiments#

When you run experiments with @arizeai/phoenix-client, the experiment framework can attach a per-run global provider. Because the wrappers resolve the default tracer at invocation time, traced functions defined at module scope still route spans to the active provider.