Skip to main content
@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.ts re-exports the context helpers
  • node_modules/@arizeai/openinference-core/src/trace/contextAttributes.ts implements 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.
ParameterTypeDescription
contextContextThe current OpenTelemetry context.
session{ sessionId: string }The session identifier.

setUser(context, user)

Attaches a user ID. Spans receive the user.id attribute.
ParameterTypeDescription
contextContextThe 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.
ParameterTypeDescription
contextContextThe current OpenTelemetry context.
metadataRecord<string, unknown>Key-value pairs to attach.

setTags(context, tags)

Attaches a list of string tags.
ParameterTypeDescription
contextContextThe current OpenTelemetry context.
tagsstring[]Tags to attach.

setAttributes(context, attributes)

Attaches arbitrary span attributes. Unlike setMetadata, these become individual span attributes rather than a single serialized JSON blob.
ParameterTypeDescription
contextContextThe current OpenTelemetry context.
attributesAttributesValid OpenTelemetry span attribute values.

setPromptTemplate(context, promptTemplate)

Attaches a prompt template and its variable bindings.
ParameterTypeDescription
contextContextThe 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:
  • clearSession
  • clearUser
  • clearMetadata
  • clearTags
  • clearPromptTemplate
  • clearAttributes

Source Map

  • src/index.ts
  • node_modules/@arizeai/openinference-core/src/trace/contextAttributes.ts