effect-io-ai

Package: @effect/ai
Module: Telemetry

Telemetry.SpanTransformer

A function that can transform OpenTelemetry spans based on AI operation data.

Span transformers receive the complete request/response context from AI operations and can add custom telemetry attributes, metrics, or other observability data.

Example

import { Telemetry } from "@effect/ai"

const customTransformer: Telemetry.SpanTransformer = (options) => {
  // Add custom attributes based on the response
  const textParts = options.response.filter(part => part.type === "text")
  const totalTextLength = textParts.reduce((sum, part) =>
    sum + (part.type === "text" ? part.text.length : 0), 0
  )

  // Add custom metrics
  console.log(`Generated ${totalTextLength} characters of text`)
}

Signature

export interface SpanTransformer {
  (
    options: ProviderOptions & {
      /**
       * Array of response parts generated by the AI model.
       */
      readonly response: ReadonlyArray<Response.AllParts<any>>
    }
  ): void
}

Source

Since v1.0.0