Anthropic (JS/TS)
Trace Anthropic Claude calls from JavaScript/TypeScript using OpenTelemetry instrumentation and Muster.
This guide demonstrates how to combine Anthropic's JavaScript/TypeScript SDK with Muster for comprehensive AI application observability. The approach uses OpenTelemetry instrumentation to automatically capture and monitor Anthropic SDK interactions.
Setup
Installation
npm install @anthropic-ai/sdk @arizeai/openinference-instrumentation-anthropic @langfuse/otel @opentelemetry/sdk-nodeEnvironment Configuration
Set credentials for both Anthropic and Muster:
ANTHROPIC_API_KEY="sk-ant-..."
LANGFUSE_PUBLIC_KEY="pk-lf-..."
LANGFUSE_SECRET_KEY="sk-lf-..."
LANGFUSE_BASE_URL="https://app.getmuster.io" # or your self-hosted Muster URLAnthropic API keys are issued from the Anthropic Console. Muster API keys are issued from your project's Settings → API Keys page.
OpenTelemetry Initialization
import Anthropic from "@anthropic-ai/sdk";
import { NodeSDK } from "@opentelemetry/sdk-node";
import { LangfuseSpanProcessor } from "@langfuse/otel";
import { AnthropicInstrumentation } from "@arizeai/openinference-instrumentation-anthropic";
const instrumentation = new AnthropicInstrumentation();
instrumentation.manuallyInstrument(Anthropic);
const sdk = new NodeSDK({
spanProcessors: [new LangfuseSpanProcessor()],
instrumentations: [instrumentation],
});
sdk.start();After initialization, every call you make through the Anthropic SDK is captured automatically as a span and forwarded to your Muster project.
const client = new Anthropic();
const message = await client.messages.create({
model: "claude-opus-4-20250514",
max_tokens: 1024,
messages: [{ role: "user", content: "Hello, Claude" }],
});
console.log(message);Advanced Integration Features
The integration supports deeper customization through:
- Context Managers — wrap instrumented code to add attributes and establish observation hierarchies.
observewrapper — decorate existing functions for automatic span creation without code modification.- Attribute propagation — distribute
userId,sessionId,metadata,tags, andversioninformation across child observations.
See the JS/TS SDK reference for the full API.
Troubleshooting
Enable debug logging to diagnose tracing issues:
LANGFUSE_LOG_LEVEL="DEBUG"Other things to check:
- In short-lived environments, call
await langfuseSpanProcessor.forceFlush()before exit so spans are not dropped. - Filter unwanted OpenTelemetry spans from unrelated libraries — they still count toward your billable units.
See also
- Anthropic (Python)
- Upstream Langfuse Anthropic JS/TS docs for the latest examples