# @arizeai/openinference-instrumentation-bedrock

**JavaScript · Instrumentation**

OpenInference instrumentation for AWS Bedrock

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

[npm](https://www.npmjs.com/package/@arizeai/openinference-instrumentation-bedrock) · [README](https://github.com/Arize-ai/openinference/blob/main/js/packages/openinference-instrumentation-bedrock/README.md) · [Source](https://github.com/Arize-ai/openinference/tree/main/js/packages/openinference-instrumentation-bedrock)

## Install

```sh
npm install @arizeai/openinference-instrumentation-bedrock
```

## Usage

Register the instrumentation once, at startup, before the library is imported. The [`BedrockInstrumentation`](https://openinf.dev/js/openinference-instrumentation-bedrock.html.md#BedrockInstrumentation) reference below lists its options.

```ts
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()`](https://openinf.dev/js/openinference-instrumentation-bedrock.html.md#BedrockInstrumentation.manuallyInstrument).

## `@arizeai/openinference-instrumentation-bedrock`

### `isPatched`

_function_ · [Source](https://github.com/Arize-ai/openinference/blob/main/js/packages/openinference-instrumentation-bedrock/src/instrumentation.ts#L63)

```typescript
function isPatched(): boolean
```

Type guard that checks if the Bedrock instrumentation is currently enabled

**Returns**

| Type | Description |
| - | - |
| `boolean` | True if instrumentation is active, false otherwise |

### `BedrockInstrumentation`

_class_ · [Source](https://github.com/Arize-ai/openinference/blob/main/js/packages/openinference-instrumentation-bedrock/src/instrumentation.ts#L79)

```typescript
class BedrockInstrumentation extends InstrumentationBase<BedrockModuleExports>
```

An auto instrumentation class for AWS Bedrock that creates [OpenInference](https://github.com/Arize-ai/openinference/blob/main/spec/attributes/semantic-conventions.md) Compliant spans for Bedrock API calls

Supports instrumentation of:

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

> **See also**
>
> - `InstrumentationConfig`
> - [`TraceConfigOptions`](https://openinf.dev/js/openinference-core.html.md#TraceConfigOptions)

**Properties**

| Name | Type |
| - | - |
| [`tracer`](https://openinf.dev/js/openinference-instrumentation-bedrock.html.md#BedrockInstrumentation.tracer) | `Tracer` |

#### `new BedrockInstrumentation`

_constructor_ · [Source](https://github.com/Arize-ai/openinference/blob/main/js/packages/openinference-instrumentation-bedrock/src/instrumentation.ts#L84)

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

**Parameters**

| Name | Type | Description |
| - | - | - |
| `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`

_method_ · [Source](https://github.com/Arize-ai/openinference/blob/main/js/packages/openinference-instrumentation-bedrock/src/instrumentation.ts#L119)

```typescript
manuallyInstrument(module: BedrockModuleExports): void
```

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

#### `setTracerProvider`

_method_ · [Source](https://github.com/Arize-ai/openinference/blob/main/js/packages/openinference-instrumentation-bedrock/src/instrumentation.ts#L145)

```typescript
setTracerProvider(tracerProvider: TracerProvider): void
```

Sets TraceProvider to this plugin
