@arizeai/phoenix-otel re-exports the OpenInference context setters from @arizeai/openinference-core. These functions write values into the OpenTelemetry context so helper-created spans and many instrumented child spans can inherit them automatically.
Available setters:
setSession(context, { sessionId })setUser(context, { userId })setMetadata(context, metadataObject)setTags(context, string[])setPromptTemplate(context, { template, variables?, version? })setAttributes(context, attributes)
Relevant Source Files
src/index.tsre-exports the context helpersnode_modules/@arizeai/openinference-core/src/trace/contextAttributes.tsimplements the setter, getter, and clearer helpers
How Context Propagation Works#
Each setter takes a Context and returns a new Context with the value attached. Activate that context with context.with(). Any span created inside the callback can then inherit the propagated attributes.
Setters compose by chaining because each one returns the updated context:
API Reference#
setSession(context, session)#
Attaches a session ID. Spans receive the session.id attribute.
| Parameter | Type | Description |
|---|---|---|
context | Context | The current OpenTelemetry context. |
session | { sessionId: string } | The session identifier. |
setUser(context, user)#
Attaches a user ID. Spans receive the user.id attribute.
| Parameter | Type | Description |
|---|---|---|
context | Context | The current OpenTelemetry context. |
user | { userId: string } | The user identifier. |
setMetadata(context, metadata)#
Attaches arbitrary key-value metadata. Serialized as JSON on the metadata span attribute.
| Parameter | Type | Description |
|---|---|---|
context | Context | The current OpenTelemetry context. |
metadata | Record<string, unknown> | Key-value pairs to attach. |
setTags(context, tags)#
Attaches a list of string tags.
| Parameter | Type | Description |
|---|---|---|
context | Context | The current OpenTelemetry context. |
tags | string[] | Tags to attach. |
setAttributes(context, attributes)#
Attaches arbitrary span attributes. Unlike setMetadata, these become individual span attributes rather than a single serialized JSON blob.
| Parameter | Type | Description |
|---|---|---|
context | Context | The current OpenTelemetry context. |
attributes | Attributes | Valid OpenTelemetry span attribute values. |
setPromptTemplate(context, promptTemplate)#
Attaches a prompt template and its variable bindings.
| Parameter | Type | Description |
|---|---|---|
context | Context | The current OpenTelemetry context. |
promptTemplate | { template: string; variables?: Record<string, string>; version?: string } | Template text, bound variables, and optional version. |
Manual Span Propagation#
If you create spans manually with a plain OpenTelemetry tracer, copy the propagated attributes onto the span explicitly:
If you use OITracer instead of a plain tracer, it automatically merges context attributes during startSpan() and startActiveSpan().
Combining Multiple Setters#
Build up context incrementally when different parts of your code learn different pieces of request metadata:
Clearing Context Values#
Each setter has a matching clearer:
clearSessionclearUserclearMetadataclearTagsclearPromptTemplateclearAttributes
Source Map
src/index.tsnode_modules/@arizeai/openinference-core/src/trace/contextAttributes.ts

