effect-io-ai

Package: @effect/ai
Module: Telemetry

Telemetry.addGenAIAnnotations

Applies GenAI telemetry attributes to an OpenTelemetry span.

This function adds standardized GenAI attributes to a span following OpenTelemetry semantic conventions. It supports both curried and direct application patterns.

Note: This function mutates the provided span in-place.

Example

import { Telemetry } from "@effect/ai"
import { Effect } from "effect"

const directUsage = Effect.gen(function* () {
  const span = yield* Effect.currentSpan

  Telemetry.addGenAIAnnotations(span, {
    system: "openai",
    request: { model: "gpt-4", temperature: 0.7 },
    usage: { inputTokens: 100, outputTokens: 50 }
  })
})

Signature

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

Source

Since v1.0.0