Class AISDKExporter

OpenTelemetry trace exporter for Vercel AI SDK.

import { AISDKExporter } from "langsmith/vercel";
import { Client } from "langsmith";

import { generateText } from "ai";
import { openai } from "@ai-sdk/openai";

import { NodeSDK } from "@opentelemetry/sdk-node";
import { getNodeAutoInstrumentations } from "@opentelemetry/auto-instrumentations-node";

const client = new Client();

const sdk = new NodeSDK({
traceExporter: new AISDKExporter({ client }),
instrumentations: [getNodeAutoInstrumentations()],
});

sdk.start();

const res = await generateText({
model: openai("gpt-4o-mini"),
messages: [
{
role: "user",
content: "What color is the sky?",
},
],
experimental_telemetry: AISDKExporter.getSettings({
runName: "langsmith_traced_call",
metadata: { userId: "123", language: "english" },
}),
});

await sdk.shutdown();

Constructors

Methods

  • Parameters

    • spans: unknown[]
    • resultCallback: (result: { code: 0 | 1; error?: Error }) => void

    Returns void

  • Parameters

    Returns {
        isEnabled: boolean;
        metadata: { [key: string]: AttributeValue };
        functionId?: string;
        recordInputs?: boolean;
        recordOutputs?: boolean;
        tracer?: Tracer;
    }

    • isEnabled: boolean
    • metadata: { [key: string]: AttributeValue }
    • OptionalfunctionId?: string

      Identifier for this function. Used to group telemetry data by function.

    • OptionalrecordInputs?: boolean

      Enable or disable input recording. Enabled by default.

      You might want to disable input recording to avoid recording sensitive information, to reduce data transfers, or to increase performance.

    • OptionalrecordOutputs?: boolean

      Enable or disable output recording. Enabled by default.

      You might want to disable output recording to avoid recording sensitive information, to reduce data transfers, or to increase performance.

    • Optionaltracer?: Tracer

      A custom tracer to use for the telemetry data.

  • Parameters

    • ...args: [message?: any, ...optionalParams: any[]]

    Returns void