Skip to content

AnthropicTelemetry

The AnthropicTelemetry module defines Anthropic-specific telemetry attributes and a helper for adding them to a tracing span. It keeps the standard GenAI telemetry attributes and adds request and response metadata under the gen_ai.anthropic.* OpenTelemetry namespaces.

6 exports Added in v4.0.0 Source

Models

AllAttributes type

Added in v4.0.0 Source

All telemetry attributes which are part of the GenAI specification, including the Anthropic-specific attributes.

Signature

type AllAttributes = Telemetry.AllAttributes & RequestAttributes & ResponseAttributes;

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 AnthropicTelemetryAttributes = Simplify<
Telemetry.GenAITelemetryAttributes &
Telemetry.AttributesWithPrefix<RequestAttributes, "gen_ai.anthropic.request"> &
Telemetry.AttributesWithPrefix<ResponseAttributes, "gen_ai.anthropic.response">
>;

RequestAttributes interface

Added in v4.0.0 Source

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

Signature

interface RequestAttributes {
readonly extendedThinking?: boolean | null;
readonly thinkingBudgetTokens?: number | null;
}

ResponseAttributes interface

Added in v4.0.0 Source

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

Signature

interface ResponseAttributes {
readonly cacheCreationInputTokens?: number | null;
readonly cacheReadInputTokens?: number | null;
readonly stopReason?: string | null;
}

Options

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

Signature

type AnthropicTelemetryAttributeOptions = Telemetry.GenAITelemetryAttributeOptions & {
anthropic?: {
request?: RequestAttributes;
response?: ResponseAttributes;
};
};

Tracing

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

When to use

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

Gotchas

This method mutates the Span in place.

Signature

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