Skip to main content
This module provides automatic instrumentation for the OpenAI Node.js SDK. which may be used in conjunction with @opentelemetry/sdk-trace-node.

Install

Setup

To instrument your application, import and enable OpenAIInstrumentation Create the instrumentation.js file:

Run OpenAI

Import the instrumentation.js file first, then use OpenAI as usual.

Observe

After setting up instrumentation and running your OpenAI application, traces will appear in the Phoenix UI for visualization and analysis. Chat completions, completions, the Responses API, embeddings, and decisions are instrumented.

Decisions API

The OpenAI Decisions API (openai.decisions.create) asks a decision model a fixed set of typed questions about text or images. It returns one typed, probabilistic answer per question instead of generated text, which makes it a good fit for routing, classification, and scoring inside your application. Requires openai >= 7.30.0 and @arizeai/openinference-instrumentation-openai >= 4.4.0. Calls are traced with the setup above, with no extra configuration:
Each call shows up in Phoenix as a DECISION span named OpenAI Decisions, rather than an LLM span, containing:
  • input.value: the request body (model, input, questions) as JSON
  • output.value: the response body (answers, model, usage) as JSON
  • decision.system and decision.provider: both openai
  • decision.request.model_name, decision.response.model_name, and decision.model_name
  • decision.token_count.input and decision.token_count.output, from the response’s usage
Phoenix names the decision model in the span’s input card. The model and its usage are recorded under decision.* rather than llm.*, so decision-model calls stay out of Phoenix’s LLM token and cost reporting. The questions and answers live only in input.value and output.value, so the hideInputs and hideOutputs trace config options redact them completely.

Custom Tracer Provider

You can specify a custom tracer provider for OpenAI instrumentation in multiple ways:

Method 1: Pass tracerProvider on instantiation

Method 2: Set tracerProvider after instantiation

Method 3: Pass tracerProvider to registerInstrumentations

Resources