Skip to main content

Documentation Index

Fetch the complete documentation index at: https://arizeai-433a7140-mikeldking-12899-providers-and-secrets.mintlify.app/llms.txt

Use this file to discover all available pages before exploring further.

This module provides automatic instrumentation for the AWS SDK for JavaScript Bedrock Runtime Client, which may be used in conjunction with @arizeai/phoenix-otel.

Install

npm install @arizeai/openinference-instrumentation-bedrock @aws-sdk/client-bedrock-runtime @arizeai/phoenix-otel

Setup

To instrument your application, use the register function from @arizeai/phoenix-otel and manually instrument the Bedrock SDK. Create the instrumentation.ts file:
import { register } from "@arizeai/phoenix-otel";
import { BedrockRuntimeClient } from "@aws-sdk/client-bedrock-runtime";
import { BedrockInstrumentation } from "@arizeai/openinference-instrumentation-bedrock";

// Initialize Phoenix tracing
const tracerProvider = register({
  projectName: "bedrock-app",
  // If using Phoenix Cloud:
  // url: "https://app.phoenix.arize.com/s/your-space-name",
  // apiKey: process.env.PHOENIX_API_KEY,
  // If using self-hosted Phoenix:
  // url: "http://localhost:6006",
});

// Set up Bedrock instrumentation
const instrumentation = new BedrockInstrumentation();
instrumentation.manuallyInstrument(BedrockRuntimeClient);

console.log("Bedrock instrumentation registered");

Run Bedrock

Import the instrumentation.ts file first, then use Bedrock as usual.
import "./instrumentation.js";
import { BedrockRuntimeClient, InvokeModelCommand } from "@aws-sdk/client-bedrock-runtime";

const client = new BedrockRuntimeClient({ region: "us-east-1" });

async function main() {
  const payload = {
    anthropic_version: "bedrock-2023-05-31",
    max_tokens: 1024,
    messages: [{ role: "user", content: "Write a haiku about clouds." }],
  };

  const command = new InvokeModelCommand({
    modelId: "anthropic.claude-3-sonnet-20240229-v1:0",
    contentType: "application/json",
    body: JSON.stringify(payload),
  });

  const response = await client.send(command);
  const responseBody = JSON.parse(new TextDecoder().decode(response.body));
  console.log(responseBody.content[0].text);
}

main();

Observe

After setting up instrumentation and running your Bedrock application, traces will appear in the Phoenix UI for visualization and analysis.

Resources