Skip to content
Effect 4.0 is here. One ecosystem. Zero dependencies.

OpenAiTelemetry unstable

The OpenAiTelemetry module defines OpenAI-compatible telemetry attributes and a helper for adding them to a tracing span. It keeps the standard GenAI telemetry attributes and adds service tier and system fingerprint under openai.*.

6 exports Since v4.0.0 Source

Models

Since v4.0.0

The attributes used to describe telemetry in the context of Generative Artificial Intelligence (GenAI) Models requests and responses.

Details

These attributes follow the OpenTelemetry generative AI semantic conventions: https://opentelemetry.io/docs/specs/semconv/attributes-registry/gen-ai/

Signature

type OpenAiTelemetryAttributes = Simplify<Telemetry.GenAITelemetryAttributes & Telemetry.AttributesWithPrefix<RequestAttributes, "openai.request"> & Telemetry.AttributesWithPrefix<ResponseAttributes, "openai.response">>

RequestAttributes

interface unstable
Since v4.0.0

OpenAI request metadata, written under openai.request.*.

Signature

interface RequestAttributes {
readonly serviceTier?: string & {} | WellKnownServiceTier | null;
}

ResponseAttributes

interface unstable
Since v4.0.0

Telemetry attributes which are part of the GenAI specification and are namespaced by openai.response.

Signature

interface ResponseAttributes {
readonly serviceTier?: string | null;
readonly systemFingerprint?: string | null;
}
Since v4.0.0

The openai.request.service_tier attribute has a list of well-known values.

Details

If one of them applies, then the respective value MUST be used; otherwise, a custom value MAY be used.

Signature

type WellKnownServiceTier = "auto" | "default"

Options

Options accepted by addGenAIAnnotations, combining standard GenAI telemetry attributes with optional OpenAI-compatible request and response attributes.

Signature

type OpenAiTelemetryAttributeOptions = Telemetry.GenAITelemetryAttributeOptions & {
openai?: {
request?: RequestAttributes;
response?: ResponseAttributes;
};
}

Tracing

Since v4.0.0

Applies the specified OpenAI GenAI telemetry attributes to the provided Span.

When to use

Use to annotate an OpenAI-compatible model span with standard GenAI telemetry attributes and OpenAI-specific request or response metadata.

Details

Standard GenAI attributes are applied first. OpenAI metadata is written under openai.request.* and openai.response.*.

Gotchas

Mutates the supplied Span in place.

Signature

declare const addGenAIAnnotations: {
(options: OpenAiTelemetryAttributeOptions): (span: Span) => void;
(span: Span, options: OpenAiTelemetryAttributeOptions): void;
}