# @arizeai/openinference-instrumentation-typesafe

**JavaScript · Instrumentation**

OpenInference instrumentation for the TypeSafe AI SDK

- **Version**: 0.4.7
- **Node.js**: >=20
- **Instruments**: `@typesafe-ai/sdk >=0.6.0`

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

## Install

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

## Usage

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

```ts
import { registerInstrumentations } from "@opentelemetry/instrumentation";
import { NodeTracerProvider } from "@opentelemetry/sdk-trace-node";
import { TypeSafeInstrumentation } from "@arizeai/openinference-instrumentation-typesafe";

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

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

If the library is imported first (as ES modules often are), patch it directly with [`manuallyInstrument()`](https://openinf.dev/js/openinference-instrumentation-typesafe.html.md#TypeSafeInstrumentation.manuallyInstrument).

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

### `TypeSafeInstrumentation`

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

```typescript
class TypeSafeInstrumentation extends InstrumentationBase<TypeSafeModule>
```

OpenInference instrumentation for `@typesafe-ai/sdk`.

Emits one OpenInference `DECISION` span per `TypeSafeClient.systemOne` call, including SDK retries. Does not instrument `models.list`. Request and response bodies are recorded as JSON on `input.value` / `output.value`.

Automatic patching covers CommonJS `require` loads. For ESM, bundlers, or late imports, call [`TypeSafeInstrumentation.manuallyInstrument`](https://openinf.dev/js/openinference-instrumentation-typesafe.html.md#TypeSafeInstrumentation.manuallyInstrument).

> **See also**
>
> [OpenInference semantic conventions](https://github.com/Arize-ai/openinference/blob/main/spec/attributes/semantic-conventions.md)

#### `new TypeSafeInstrumentation`

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

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

**Parameters**

| Name | Type | Description |
| - | - | - |
| `options?` | `{ instrumentationConfig?: InstrumentationConfig; traceConfig?: TraceConfigOptions; tracerProvider?: TracerProvider }` | Optional instrumentor configuration. |
| `options.instrumentationConfig?` | `InstrumentationConfig` | OpenTelemetry instrumentation config. |
| `options.traceConfig?` | `TraceConfigOptions` | OpenInference [`TraceConfigOptions`](https://openinf.dev/js/openinference-core.html.md#TraceConfigOptions). |
| `options.tracerProvider?` | `TracerProvider` | Tracer provider used to create spans. |

#### `setTracerProvider`

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

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

Rebinds the instrumentor to a new tracer provider.

**Parameters**

| Name | Type | Description |
| - | - | - |
| `provider` | `TracerProvider` | Tracer provider used for subsequent spans. |

#### `manuallyInstrument`

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

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

Patches an already-imported `@typesafe-ai/sdk` namespace.

Use this for ESM loads, bundlers, or modules imported before the instrumentor was enabled. Safe to call for both CommonJS and ESM builds in the same process.

**Parameters**

| Name | Type | Description |
| - | - | - |
| `module` | `__module` | The imported `@typesafe-ai/sdk` module namespace. |

#### `enable`

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

```typescript
enable(): void
```

#### `disable`

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

```typescript
disable(): void
```
