Skip to main content Link Search Menu Expand Document (external link)

AiTelemetry.ts overview

Since v1.0.0


Exports Grouped by Category


models

GenAI (namespace)

Source

Since v1.0.0

BaseAttributes (interface)

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

Signature

export interface BaseAttributes {
  /**
   * The Generative AI product as identified by the client or server
   * instrumentation.
   */
  readonly system?: (string & {}) | WellKnownSystem | null | undefined
}

Source

Since v1.0.0

OperationAttributes (interface)

Telemetry attributes which are part of the GenAI specification and are namespaced by gen_ai.operation.

Signature

export interface OperationAttributes {
  readonly name?: (string & {}) | WellKnownOperationName | null | undefined
}

Source

Since v1.0.0

TokenAttributes (interface)

Telemetry attributes which are part of the GenAI specification and are namespaced by gen_ai.token.

Signature

export interface TokenAttributes {
  readonly type?: string | null | undefined
}

Source

Since v1.0.0

UsageAttributes (interface)

Telemetry attributes which are part of the GenAI specification and are namespaced by gen_ai.usage.

Signature

export interface UsageAttributes {
  readonly inputTokens?: number | null | undefined
  readonly outputTokens?: number | null | undefined
}

Source

Since v1.0.0

RequestAttributes (interface)

Telemetry attributes which are part of the GenAI specification and are namespaced by gen_ai.request.

Signature

export interface RequestAttributes {
  /**
   * The name of the GenAI model a request is being made to.
   */
  readonly model?: string | null | undefined
  /**
   * The temperature setting for the GenAI request.
   */
  readonly temperature?: number | null | undefined
  /**
   * The temperature setting for the GenAI request.
   */
  readonly topK?: number | null | undefined
  /**
   * The top_k sampling setting for the GenAI request.
   */
  readonly topP?: number | null | undefined
  /**
   * The top_p sampling setting for the GenAI request.
   */
  readonly maxTokens?: number | null | undefined
  /**
   * The encoding formats requested in an embeddings operation, if specified.
   */
  readonly encodingFormats?: ReadonlyArray<string> | null | undefined
  /**
   * List of sequences that the model will use to stop generating further
   * tokens.
   */
  readonly stopSequences?: ReadonlyArray<string> | null | undefined
  /**
   * The frequency penalty setting for the GenAI request.
   */
  readonly frequencyPenalty?: number | null | undefined
  /**
   * The presence penalty setting for the GenAI request.
   */
  readonly presencePenalty?: number | null | undefined
  /**
   * The seed setting for the GenAI request. Requests with same seed value
   * are more likely to return same result.
   */
  readonly seed?: number | null | undefined
}

Source

Since v1.0.0

ResponseAttributes (interface)

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

Signature

export interface ResponseAttributes {
  /**
   * The unique identifier for the completion.
   */
  readonly id?: string | null | undefined
  /**
   * The name of the model that generated the response.
   */
  readonly model?: string | null | undefined
  /**
   * Array of reasons the model stopped generating tokens, corresponding to
   * each generation received.
   */
  readonly finishReasons?: ReadonlyArray<string> | null | undefined
}

Source

Since v1.0.0

AllAttributes (type alias)

All telemetry attributes which are part of the GenAI specification.

Signature

type AllAttributes = BaseAttributes &
  OperationAttributes &
  TokenAttributes &
  UsageAttributes &
  RequestAttributes &
  ResponseAttributes

Source

Since v1.0.0

WellKnownOperationName (type alias)

The gen_ai.operation.name attribute has the following list of well-known values.

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

Signature

type WellKnownOperationName = "chat" | "embeddings" | "text_completion"

Source

Since v1.0.0

WellKnownSystem (type alias)

The gen_ai.system attribute has the following list of well-known values.

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

Signature

type WellKnownSystem =
  | "anthropic"
  | "aws.bedrock"
  | "az.ai.inference"
  | "az.ai.openai"
  | "cohere"
  | "deepseek"
  | "gemini"
  | "groq"
  | "ibm.watsonx.ai"
  | "mistral_ai"
  | "openai"
  | "perplexity"
  | "vertex_ai"
  | "xai"

Source

Since v1.0.0

AttributesWithPrefix (type alias)

Signature

type AttributesWithPrefix<Attributes, Prefix> = {
  [Name in keyof Attributes as `${Prefix}.${FormatAttributeName<Name>}`]: Attributes[Name]
}

Source

Since v1.0.0

FormatAttributeName (type alias)

Signature

type FormatAttributeName<T> = T extends string
  ? T extends `${infer First}${infer Rest}`
    ? `${First extends Uppercase<First> ? "_" : ""}${Lowercase<First>}${FormatAttributeName<Rest>}`
    : T
  : never

Source

Since v1.0.0

GenAITelemetryAttributes (type alias)

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

{@see https://opentelemetry.io/docs/specs/semconv/attributes-registry/gen-ai/}

Signature

type GenAITelemetryAttributes = Simplify<
  GenAI.AttributesWithPrefix<GenAI.BaseAttributes, "gen_ai"> &
    GenAI.AttributesWithPrefix<GenAI.OperationAttributes, "gen_ai.operation"> &
    GenAI.AttributesWithPrefix<GenAI.TokenAttributes, "gen_ai.token"> &
    GenAI.AttributesWithPrefix<GenAI.UsageAttributes, "gen_ai.usage"> &
    GenAI.AttributesWithPrefix<GenAI.RequestAttributes, "gen_ai.request"> &
    GenAI.AttributesWithPrefix<GenAI.ResponseAttributes, "gen_ai.response">
>

Source

Since v1.0.0

utilities

addSpanAttributes

Signature

declare const addSpanAttributes: (
  keyPrefix: string,
  transformKey: (key: string) => string
) => <Attributes extends Record<string, any>>(span: Span, attributes: Attributes) => void

Source

Since v1.0.0

utils

GenAITelemetryAttributeOptions (type alias)

Signature

type GenAITelemetryAttributeOptions = GenAI.BaseAttributes & {
  readonly operation?: GenAI.OperationAttributes | undefined
  readonly request?: GenAI.RequestAttributes | undefined
  readonly response?: GenAI.ResponseAttributes | undefined
  readonly token?: GenAI.TokenAttributes | undefined
  readonly usage?: GenAI.UsageAttributes | undefined
}

Source

Since v1.0.0, models

addGenAIAnnotations

Applies the specified GenAI telemetry attributes to the provided Span.

NOTE: This method will mutate the Span in-place.

Signature

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

Source

Since v1.0.0, utilities