Anthropic

messages.create, including streaming and tool use, auto-captures as kind='llm' with full token extraction.

Install the instrumentor and every Claude call inside wrap your agent becomes a span. The provider field is anthropic.

What's captured

CallSpan kindAuto-extracted
client.messages.createllmmodel, input/output tokens, stop_reason, messages, completion
client.messages.streamllmsame, accumulated across deltas
client.messages.count_tokensllmmodel, input tokens

Install

npm install @anthropic-ai/sdk @opentelemetry/instrumentation-anthropic
pip install anthropic opentelemetry-instrumentation-anthropic

Minimal example

import trodo from 'trodo-node';
import Anthropic from '@anthropic-ai/sdk';

trodo.init({ siteId: process.env.TRODO_SITE_ID });
const anthropic = new Anthropic();

await trodo.wrapAgent('summarizer', async (run) => {
  const r = await anthropic.messages.create({
    model: 'claude-3-5-sonnet-20241022',
    max_tokens: 1024,
    messages: [{ role: 'user', content: `Summarize:\n${text}` }],
  });
  run.setOutput(r.content[0].type === 'text' ? r.content[0].text : '');
});
import os, trodo, anthropic

trodo.init(site_id=os.environ['TRODO_SITE_ID'])
client = anthropic.Anthropic()

with trodo.wrap_agent('summarizer') as run:
    r = client.messages.create(
        model='claude-3-5-sonnet-20241022',
        max_tokens=1024,
        messages=[{'role': 'user', 'content': f'Summarize:\n{text}'}],
    )
    run.set_output(r.content[0].text)

On this page