JavaScript APItypesafe

Core

Instrumentation

Integrations

JavaScript · Instrumentation

@arizeai/openinference-instrumentation-typesafe

OpenInference instrumentation for the TypeSafe AI SDK

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

Install

npm install @arizeai/openinference-instrumentation-typesafe

Usage

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

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().

@arizeai/openinference-instrumentation-typesafe

TypeSafeInstrumentation

classSource ↗
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.

new TypeSafeInstrumentation

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

Parameters

NameTypeDescription
options?{ instrumentationConfig?: InstrumentationConfig; traceConfig?: TraceConfigOptions; tracerProvider?: TracerProvider }

Optional instrumentor configuration.

options.instrumentationConfig?InstrumentationConfig

OpenTelemetry instrumentation config.

options.traceConfig?TraceConfigOptions

OpenInference TraceConfigOptions.

options.tracerProvider?TracerProvider

Tracer provider used to create spans.

setTracerProvider

methodSource ↗
setTracerProvider(provider: TracerProvider): void

Rebinds the instrumentor to a new tracer provider.

Parameters

NameTypeDescription
providerTracerProvider

Tracer provider used for subsequent spans.

manuallyInstrument

methodSource ↗
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

NameTypeDescription
module__module

The imported @typesafe-ai/sdk module namespace.

enable

methodSource ↗
enable(): void

disable

methodSource ↗
disable(): void