-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstrumentation.ts
More file actions
20 lines (16 loc) · 919 Bytes
/
Copy pathinstrumentation.ts
File metadata and controls
20 lines (16 loc) · 919 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
import Anthropic from "@anthropic-ai/sdk";
import { AnthropicInstrumentation } from "@arizeai/openinference-instrumentation-anthropic";
import { LangfuseSpanProcessor } from "@langfuse/otel";
import { NodeSDK } from "@opentelemetry/sdk-node";
export const langfuseSpanProcessor = new LangfuseSpanProcessor();
// Official best-practice for the Anthropic JS/TS SDK: auto-instrument via OpenInference
// (prefer integration over manual wrapping). Under ESM/tsx the auto-patch does not fire,
// so manuallyInstrument(Anthropic) is required. Captures model, tokens, input/output and
// the correct generation observation type automatically on every Anthropic call.
const anthropicInstrumentation = new AnthropicInstrumentation();
anthropicInstrumentation.manuallyInstrument(Anthropic);
const sdk = new NodeSDK({
spanProcessors: [langfuseSpanProcessor],
instrumentations: [anthropicInstrumentation],
});
sdk.start();