Skip to main content
This module provides automatic instrumentation for the Anthropic SDK which may be used in conjunction with OpenTelemetry.

Installation

Install the instrumentation package:

Quickstart

Install required packages:
Set up instrumentation in your application:

Configuration

The AnthropicInstrumentation constructor accepts the following options:
  • instrumentationConfig: Standard OpenTelemetry instrumentation configuration
  • traceConfig: OpenInference-specific trace configuration for masking/redacting sensitive information
  • tracerProvider: Optional custom tracer provider

Supported Features

  • Messages API: Full support for anthropic.messages.create()
  • Streaming: Automatic handling of streaming responses
  • Tool Use: Captures tool/function calling information
  • Token Usage: Records input/output token counts when available
  • Error Handling: Proper error recording and span status management

Semantic Conventions

This instrumentation follows the OpenInference semantic conventions for LLM observability, capturing:
  • Model name and provider information
  • Input/output messages and content
  • Token usage statistics
  • Tool calling details
  • Invocation parameters

Resources