Skip to main content

OpenTelemetry instrumentation for Anthropic

Project description

Anthropic OpenTelemetry Integration

Overview

This integration provides support for using OpenTelemetry with the Anthropic framework. It enables tracing and monitoring of applications built with Anthropic.

Installation

  1. Install traceAI Anthropic
pip install traceAI-anthropic

Set Environment Variables

Set up your environment variables to authenticate with FutureAGI

import os

os.environ["FI_API_KEY"] = FI_API_KEY
os.environ["FI_SECRET_KEY"] = FI_SECRET_KEY
os.environ["ANTHROPIC_API_KEY"] = ANTHROPIC_API_KEY

Quickstart

Register Tracer Provider

Set up the trace provider to establish the observability pipeline. The trace provider:

from fi_instrumentation import register
from fi_instrumentation.fi_types import ProjectType

trace_provider = register(
    project_type=ProjectType.OBSERVE,
    project_name="anthropic_app"
)

Configure Anthropic Instrumentation

Instrument the Anthropic client to enable telemetry collection. This step ensures that all interactions with the Anthropic SDK are tracked and monitored.

from traceai_anthropic import AnthropicInstrumentor

AnthropicInstrumentor().instrument(tracer_provider=trace_provider)

Create Anthropic Components

Set up your Anthropic client with built-in observability.

client = anthropic.Anthropic()

response = client.messages.create(
    model="claude-3-5-sonnet-20240620",
    max_tokens=1024,
    tools=[
        {
            "name": "get_weather",
            "description": "Get the current weather in a given location",
            "input_schema": {
                "type": "object",
                "properties": {
                    "location": {
                        "type": "string",
                        "description": "The city and state, e.g. San Francisco, CA",
                    },
                    "unit": {
                        "type": "string",
                        "enum": ["celsius", "fahrenheit"],
                        "description": "The unit of temperature, either 'celsius' or 'fahrenheit'",
                    },
                },
                "required": ["location"],
            },
        },
        {
            "name": "get_time",
            "description": "Get the current time in a given time zone",
            "input_schema": {
                "type": "object",
                "properties": {
                    "timezone": {
                        "type": "string",
                        "description": "The IANA time zone name, e.g. America/Los_Angeles",
                    }
                },
                "required": ["timezone"],
            },
        },
    ],
    messages=[
        {
            "role": "user",
            "content": "What is the weather like right now in New York?"
            " Also what time is it there? Use necessary tools simultaneously.",
        }
    ],
)
print(response)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

traceai_anthropic-0.1.9.tar.gz (12.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

traceai_anthropic-0.1.9-py3-none-any.whl (13.8 kB view details)

Uploaded Python 3

File details

Details for the file traceai_anthropic-0.1.9.tar.gz.

File metadata

  • Download URL: traceai_anthropic-0.1.9.tar.gz
  • Upload date:
  • Size: 12.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.0.0 CPython/3.13.0 Darwin/24.1.0

File hashes

Hashes for traceai_anthropic-0.1.9.tar.gz
Algorithm Hash digest
SHA256 06930554e0991a9693f2ea86b3ca05931a937fb4d7f5fc75aa65db71bd595cff
MD5 45e4c6502b9a4ce5c827e17a1dd9642f
BLAKE2b-256 c103967860c09cf9b1acc706f4d80d137e782ff5703bd426173ef93b06661b80

See more details on using hashes here.

File details

Details for the file traceai_anthropic-0.1.9-py3-none-any.whl.

File metadata

  • Download URL: traceai_anthropic-0.1.9-py3-none-any.whl
  • Upload date:
  • Size: 13.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.0.0 CPython/3.13.0 Darwin/24.1.0

File hashes

Hashes for traceai_anthropic-0.1.9-py3-none-any.whl
Algorithm Hash digest
SHA256 482606f9c5e71f7b3ee2e95142bfb3cef2ce1f5421f29361188028b2d1fdf79d
MD5 31e223a36ace3b4ba3ed90825af77f69
BLAKE2b-256 dbc713a19e1ad7709c5436978deb8cb7dc99430722dc3dd8b962dad9af121adf

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page