Skip to main content

Respan instrumentation plugin for the Claude Agent SDK

Project description

respan-instrumentation-claude-agent-sdk

Respan instrumentation plugin for the Claude Agent SDK.

This package enables the Claude Agent SDK's native OpenTelemetry emission and normalizes those spans into the Respan/Traceloop conventions used by the OTLP pipeline.

Configuration

1. Install

pip install respan-instrumentation-claude-agent-sdk

2. Set Environment Variables

Variable Required Description
RESPAN_API_KEY Yes Your Respan API key. Authenticates both proxy and tracing.
RESPAN_BASE_URL No Defaults to https://api.respan.ai/api.

All vendor-specific variables (for example ANTHROPIC_API_KEY) are derived from these in your application code.

Quickstart

3. Run Script

import asyncio
import os

import claude_agent_sdk
from claude_agent_sdk import ClaudeAgentOptions, ResultMessage
from respan import Respan
from respan_instrumentation_claude_agent_sdk import ClaudeAgentSDKInstrumentor

respan_api_key = os.environ["RESPAN_API_KEY"]
respan_base_url = os.getenv("RESPAN_BASE_URL", "https://api.respan.ai/api")

os.environ["ANTHROPIC_API_KEY"] = respan_api_key
os.environ["ANTHROPIC_AUTH_TOKEN"] = respan_api_key
os.environ["ANTHROPIC_BASE_URL"] = f"{respan_base_url}/anthropic"

respan = Respan(
    api_key=respan_api_key,
    base_url=respan_base_url,
    instrumentations=[ClaudeAgentSDKInstrumentor(capture_content=True)],
)


async def main() -> None:
    options = ClaudeAgentOptions(
        model="sonnet",
        max_turns=1,
        permission_mode="bypassPermissions",
        cwd=os.getcwd(),
        env={
            "ANTHROPIC_API_KEY": respan_api_key,
            "ANTHROPIC_AUTH_TOKEN": respan_api_key,
            "ANTHROPIC_BASE_URL": f"{respan_base_url}/anthropic",
        },
    )

    async for message in claude_agent_sdk.query(
        prompt="Reply with exactly hello_from_claude_sdk.",
        options=options,
    ):
        if isinstance(message, ResultMessage):
            print(message.result)


asyncio.run(main())
respan.flush()

4. View Dashboard

After running the script, traces appear on your Respan dashboard.

Further Reading

See the python/tracing/claude-agent-sdk example for a runnable end-to-end workflow that covers tool use, multi-turn sessions, and edge cases.

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

Built Distribution

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

File details

Details for the file respan_instrumentation_claude_agent_sdk-0.1.2.tar.gz.

File metadata

File hashes

Hashes for respan_instrumentation_claude_agent_sdk-0.1.2.tar.gz
Algorithm Hash digest
SHA256 36555db21c7f31fb8b9f918d79a6f0de907c139459bb84e3a6251055e68c5aed
MD5 6bff39bc27cde367f6c4df56b6db8105
BLAKE2b-256 e7b723f74c33c5497536e05519434810214b1fad8e28424e1bea56814cc3d59b

See more details on using hashes here.

Provenance

The following attestation bundles were made for respan_instrumentation_claude_agent_sdk-0.1.2.tar.gz:

Publisher: publish.yml on respanai/respan

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file respan_instrumentation_claude_agent_sdk-0.1.2-py3-none-any.whl.

File metadata

File hashes

Hashes for respan_instrumentation_claude_agent_sdk-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 c002d6fb5f415b91cc04279572ea8064965a21a2b9fa3999360752699d37d0bf
MD5 182b0391a2aa3dccbf6083f5e73aba83
BLAKE2b-256 9a3e1013a42cfc297b1c1a8f356044924467052cc77c27b2116fc26317d6b0c0

See more details on using hashes here.

Provenance

The following attestation bundles were made for respan_instrumentation_claude_agent_sdk-0.1.2-py3-none-any.whl:

Publisher: publish.yml on respanai/respan

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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