JavaScript APIbedrock

Core

Instrumentation

Integrations

JavaScript · Instrumentation

@arizeai/openinference-instrumentation-bedrock

OpenInference instrumentation for AWS Bedrock

Version
0.5.10
Instruments
@aws-sdk/client-bedrock-runtime ^3.0.0

Install

npm install @arizeai/openinference-instrumentation-bedrock

Usage

Register the instrumentation once, at startup, before the library is imported. The BedrockInstrumentation reference below lists its options.

import { registerInstrumentations } from "@opentelemetry/instrumentation";
import { NodeTracerProvider } from "@opentelemetry/sdk-trace-node";
import { BedrockInstrumentation } from "@arizeai/openinference-instrumentation-bedrock";

const provider = new NodeTracerProvider({
  // ...a span processor that exports to Phoenix or any OTLP backend.
});
provider.register();

registerInstrumentations({
  instrumentations: [new BedrockInstrumentation()],
});

If the library is imported first (as ES modules often are), patch it directly with manuallyInstrument().

@arizeai/openinference-instrumentation-bedrock

isPatched

functionSource ↗
function isPatched(): boolean

Type guard that checks if the Bedrock instrumentation is currently enabled

Returns

TypeDescription
boolean

True if instrumentation is active, false otherwise

BedrockInstrumentation

classSource ↗
class BedrockInstrumentation extends InstrumentationBase<BedrockModuleExports>

An auto instrumentation class for AWS Bedrock that creates OpenInference Compliant spans for Bedrock API calls

Supports instrumentation of:

  • InvokeModel commands (synchronous)
  • InvokeModelWithResponseStream commands (streaming)
  • Converse commands (conversation API)
  • ConverseStream commands (streaming conversation API)

Properties

NameType
tracerTracer

new BedrockInstrumentation

constructorSource ↗
new BedrockInstrumentation(
  options?: {
    instrumentationConfig?: InstrumentationConfig;
    traceConfig?: TraceConfigOptions;
    tracerProvider?: TracerProvider;
  },
): BedrockInstrumentation

Parameters

NameTypeDescription
instrumentationConfig?InstrumentationConfig

The config for the instrumentation

traceConfig?TraceConfigOptions

The OpenInference trace configuration. Can be used to mask or redact sensitive information on spans.

tracerProvider?TracerProvider

An optional custom trace provider to be used for tracing. If not provided, a tracer will be created using the global tracer provider. This is useful if you want to use a non-global tracer provider.

manuallyInstrument

methodSource ↗
manuallyInstrument(module: BedrockModuleExports): void

Manually instruments the BedrockRuntimeClient, this allows for guaranteed patching of the module when import order is hard to control.

setTracerProvider

methodSource ↗
setTracerProvider(tracerProvider: TracerProvider): void

Sets TraceProvider to this plugin