JavaScript · Integration
@arizeai/openinference-genai
OpenInference utilities for converting OpenTelemetry GenAI span attributes to OpenInference span attributes
- Version
- 0.4.4
- Peer dependencies
@opentelemetry/api >=1.9.0, @opentelemetry/semantic-conventions >=1.41.1
Install
npm install @arizeai/openinference-genai@arizeai/openinference-genai
convertGenAISpanAttributesToOpenInferenceSpanAttributes
constantSource ↗const convertGenAISpanAttributesToOpenInferenceSpanAttributes: SafeFunction<(spanAttributes: Attributes) => Attributes>@arizeai/openinference-genai/attributes
GenAIInputMessage
type aliasSource ↗type GenAIInputMessage = ChatMessageGenAIInputMessagePart
type aliasSource ↗type GenAIInputMessagePart = ChatMessage["parts"][number]GenAIOutputMessage
type aliasSource ↗type GenAIOutputMessage = OutputMessage & { text?: string }GenAIOutputMessagePart
type aliasSource ↗type GenAIOutputMessagePart = OutputMessage["parts"][number]convertGenAISpanAttributesToOpenInferenceSpanAttributes
functionSource ↗function convertGenAISpanAttributesToOpenInferenceSpanAttributes(
spanAttributes: Attributes,
): AttributesConvert GenAI span attributes to OpenInference span attributes
Parameters
| Name | Type | Description |
|---|---|---|
spanAttributes | Attributes | The span attributes containing GenAI span attributes to convert |
Returns
| Type | Description |
|---|---|
Attributes | The converted OpenInference span attributes |
mapProviderAndSystem
functionSource ↗function mapProviderAndSystem(spanAttributes: Attributes): AttributesMap provider and system to openinference attributes
Parameters
| Name | Type | Description |
|---|---|---|
spanAttributes | Attributes | The span attributes containing provider and system to map |
TODO: add some heuristics that can map incoming provider names to the correct OpenInference provider name
Returns
| Type | Description |
|---|---|
Attributes | The mapped provider and system attributes |
mapAgentAttributes
functionSource ↗function mapAgentAttributes(spanAttributes: Attributes): AttributesMap GenAI agent attributes to OpenInference agent attributes.
Currently only gen_ai.agent.name -> agent.name. gen_ai.agent.id and gen_ai.agent.description (which also drive AGENT span-kind detection in mapSpanKind) are intentionally not mapped, as OpenInference has no corresponding agent attributes for them.
Parameters
| Name | Type | Description |
|---|---|---|
spanAttributes | Attributes | The GenAI span attributes to read agent attributes from |
Returns
| Type | Description |
|---|---|
Attributes | The mapped OpenInference agent attributes |
mapConversationId
functionSource ↗function mapConversationId(spanAttributes: Attributes): AttributesMap the GenAI conversation id to the OpenInference session id.
gen_ai.conversation.id identifies the conversation (session or thread) a span belongs to, which is what session.id represents in OpenInference. An explicit session.id takes precedence.
Parameters
| Name | Type | Description |
|---|---|---|
spanAttributes | Attributes | The GenAI span attributes to read the conversation id from |
Returns
| Type | Description |
|---|---|
Attributes | The mapped OpenInference session attributes |
mapModels
functionSource ↗function mapModels(spanAttributes: Attributes): AttributesMap model name to openinference attributes
Parameters
| Name | Type | Description |
|---|---|---|
spanAttributes | Attributes | The span attributes containing model name to map |
Returns
| Type | Description |
|---|---|
Attributes | The mapped model name attributes |
mapFinishReason
functionSource ↗function mapFinishReason(spanAttributes: Attributes): AttributesMap GenAI response finish reasons to the OpenInference LLM finish reason attribute.
Parameters
| Name | Type | Description |
|---|---|---|
spanAttributes | Attributes | The span attributes containing the finish reasons to map |
Returns
| Type | Description |
|---|---|
Attributes | The mapped finish reason attribute |
mapSpanKind
functionSource ↗function mapSpanKind(spanAttributes: Attributes): AttributesMap span kind to openinference attributes
Parameters
| Name | Type | Description |
|---|---|---|
spanAttributes | Attributes | The span attributes containing span kind to map |
Returns
| Type | Description |
|---|---|
Attributes | The mapped span kind attributes |
mapInvocationParameters
functionSource ↗function mapInvocationParameters(spanAttributes: Attributes): AttributesMap invocation parameters to openinference attributes
Parameters
| Name | Type | Description |
|---|---|---|
spanAttributes | Attributes | The span attributes containing invocation parameters to map |
Returns
| Type | Description |
|---|---|
Attributes | The mapped invocation parameters attributes |
mapInputValue
functionSource ↗function mapInputValue(spanAttributes: Attributes): AttributesMap input value to openinference attributes
Parameters
| Name | Type | Description |
|---|---|---|
spanAttributes | Attributes | The span attributes containing input value to map |
Returns
| Type | Description |
|---|---|
Attributes | The mapped input value attributes |
mapOutputValue
functionSource ↗function mapOutputValue(spanAttributes: Attributes): AttributesMap output value to openinference attributes
Parameters
| Name | Type | Description |
|---|---|---|
spanAttributes | Attributes | The span attributes containing output value to map |
Returns
| Type | Description |
|---|---|
Attributes | The mapped output value attributes |
mapAgent
functionSource ↗function mapAgent(spanAttributes: Attributes): AttributesMap GenAI agent attributes to OpenInference attributes.
Parameters
| Name | Type | Description |
|---|---|---|
spanAttributes | Attributes | The span attributes containing agent details |
Returns
| Type | Description |
|---|---|
Attributes | The mapped agent attributes |
mapSystemInstructions
functionSource ↗function mapSystemInstructions(spanAttributes: Attributes): AttributesMap GenAI system instructions into metadata for preservation.
Parameters
| Name | Type | Description |
|---|---|---|
spanAttributes | Attributes | The span attributes containing system instructions |
Returns
| Type | Description |
|---|---|
Attributes | The mapped metadata attributes |
mapToolDefinitions
functionSource ↗function mapToolDefinitions(spanAttributes: Attributes): AttributesMap GenAI tool definitions to OpenInference LLM tool schema attributes.
Parameters
| Name | Type | Description |
|---|---|---|
spanAttributes | Attributes | The span attributes containing tool definitions |
Returns
| Type | Description |
|---|---|
Attributes | The mapped tool schema attributes |
mapInputMessages
functionSource ↗function mapInputMessages(spanAttributes: Attributes): AttributesMap input messages to openinference attributes
Parameters
| Name | Type | Description |
|---|---|---|
spanAttributes | Attributes | The span attributes containing input messages to map |
Returns
| Type | Description |
|---|---|
Attributes | The mapped input messages attributes |
mapOutputMessages
functionSource ↗function mapOutputMessages(spanAttributes: Attributes): AttributesMap output messages to openinference attributes
Parameters
| Name | Type | Description |
|---|---|---|
spanAttributes | Attributes | The span attributes containing output messages to map |
Returns
| Type | Description |
|---|---|
Attributes | The mapped output messages attributes |
mapTokenCounts
functionSource ↗function mapTokenCounts(spanAttributes: Attributes): AttributesMap usage token counts to openinference attributes
Parameters
| Name | Type | Description |
|---|---|---|
spanAttributes | Attributes | The span attributes containing usage token counts to map |
Returns
| Type | Description |
|---|---|
Attributes | The mapped usage token counts attributes |
mapToolExecution
functionSource ↗function mapToolExecution(spanAttributes: Attributes): AttributesMap tool execution to openinference attributes
Parameters
| Name | Type | Description |
|---|---|---|
spanAttributes | Attributes | The span attributes containing tool execution to map |
Returns
| Type | Description |
|---|---|
Attributes | The mapped tool execution attributes |
@arizeai/openinference-genai/utils
safelyJSONStringify
functionSource ↗function safelyJSONStringify(value: unknown): string | nullgetNumber
functionSource ↗function getNumber(value: unknown): number | undefinedgetString
functionSource ↗function getString(value: unknown): string | undefinedgetStringArray
functionSource ↗function getStringArray(value: unknown): string[] | undefinedsafelyParseJSON
functionSource ↗function safelyParseJSON(value: unknown): unknowngetMimeType
functionSource ↗function getMimeType(value: unknown): MimeTypeset
functionSource ↗function set(
attrs: Attributes,
key: string,
value?: AttributeValue | null,
): voidAssign attribute value to attributes object if value is not undefined or null This mutates the attrs object
Parameters
| Name | Type | Description |
|---|---|---|
attrs | Attributes | The attributes object to assign the value to |
key | string | The key to assign the value to |
value? | AttributeValue | null | The value to assign to the key |
merge
functionSource ↗function merge(...groups: Attributes[]): AttributesMerge multiple attributes objects into a single attributes object This mutates the first attributes object
Parameters
| Name | Type | Description |
|---|---|---|
...groups | Attributes[] | The groups of attributes to merge |
Returns
| Type | Description |
|---|---|
Attributes | The merged attributes |
toStringContent
functionSource ↗function toStringContent(value: unknown): stringConvert a value to a string. If the value is already a string, return it. If the value can be jsonified, jsonify it. Otherwise, return the string representation of the value.
Parameters
| Name | Type | Description |
|---|---|---|
value | unknown | The value to convert to a string |
Returns
| Type | Description |
|---|---|
string | The string representation of the value |
withSafety
functionSource ↗function withSafety<T extends GenericFunction>(
fn: { fn: T; onError?: (error: unknown) => void },
): SafeFunction<T>Wraps a function with a try-catch block to catch and log any errors.
Parameters
| Name | Type | Description |
|---|---|---|
fn | { fn: T; onError?: (error: unknown) => void } | A function to wrap with a try-catch block. |
fn.fn | T | |
fn.onError? | (error: unknown) => void |
Returns
| Type | Description |
|---|---|
SafeFunction<T> | A function that returns null if an error is thrown. |
@arizeai/openinference-genai/types
Mutable
type aliasSource ↗type Mutable<T> = { -readonly [P in keyof T]: T[P] }DeeplyMutable
type aliasSource ↗type DeeplyMutable<T> = { -readonly [P in keyof T]: T[P] extends object ? DeeplyMutable<T[P]> : T[P] }GenericFunction
type aliasSource ↗type GenericFunction = (...args: any[]) => anySafeFunction
type aliasSource ↗type SafeFunction<T extends GenericFunction> = (...args: Parameters<T>) => ReturnType<T> | null