evalution
    Preparing search index...

    Interface PerTraceTelemetry

    interface PerTraceTelemetry {
        executeLanguageModelCall?: <T>(
            options: Partial<InferTelemetryEvent<LanguageModelCallStartEvent>> & {
                callId: string;
                execute: () => PromiseLike<T>;
            },
        ) => PromiseLike<T>;
        executeTool?: <T>(
            options: Partial<InferTelemetryEvent<WidenedToolExecutionStartEvent>> & {
                callId: string;
                execute: () => PromiseLike<T>;
                toolCallId: string;
            },
        ) => PromiseLike<T>;
        onAbort?: Callback<
            InferTelemetryEvent<GenerateTextAbortEvent<ToolSet, Context>>,
        >;
        onEmbedEnd?: Callback<InferTelemetryEvent<EmbeddingModelCallEndEvent>>;
        onEmbedStart?: Callback<InferTelemetryEvent<EmbeddingModelCallStartEvent>>;
        onEnd?: Callback<InferTelemetryEvent<OperationEndEvent>>;
        onError?: Callback<unknown>;
        onLanguageModelCallEnd?: Callback<
            InferTelemetryEvent<LanguageModelCallEndEvent<ToolSet>>,
        >;
        onLanguageModelCallStart?: Callback<
            InferTelemetryEvent<LanguageModelCallStartEvent>,
        >;
        onObjectStepEnd?: Callback<InferTelemetryEvent<GenerateObjectStepEndEvent>>;
        onObjectStepStart?: Callback<
            InferTelemetryEvent<GenerateObjectStepStartEvent>,
        >;
        onRerankEnd?: Callback<InferTelemetryEvent<RerankingModelCallEndEvent>>;
        onRerankStart?: Callback<InferTelemetryEvent<RerankingModelCallStartEvent>>;
        onStart?: Callback<InferTelemetryEvent<OperationStartEvent>>;
        onStepEnd?: Callback<
            InferTelemetryEvent<GenerateTextStepEndEvent<ToolSet, Context>>,
        >;
        onStepFinish?: Callback<
            InferTelemetryEvent<GenerateTextStepEndEvent<ToolSet, Context>>,
        >;
        onStepStart?: Callback<
            InferTelemetryEvent<
                GenerateTextStepStartEvent<ToolSet, Context, Output<any, any, any>>,
            >,
        >;
        onToolExecutionEnd?: Callback<
            InferTelemetryEvent<WidenedToolExecutionEndEvent>,
        >;
        onToolExecutionStart?: Callback<
            InferTelemetryEvent<WidenedToolExecutionStartEvent>,
        >;
        fail(message: string): Promise<void>;
        withTraceId(traceId: string): PerTraceTelemetry;
    }

    Hierarchy (View Summary)

    Index

    Properties

    executeLanguageModelCall?: <T>(
        options: Partial<InferTelemetryEvent<LanguageModelCallStartEvent>> & {
            callId: string;
            execute: () => PromiseLike<T>;
        },
    ) => PromiseLike<T>

    Optionally runs the language model call in a telemetry-integration-specific context. This enables auto-instrumented model provider requests to become children of the current model-call span.

    The options carry the model-call start-event content as context (the event fields are optional), alongside the always-present callId and the execute function that performs the model call.

    executeTool?: <T>(
        options: Partial<InferTelemetryEvent<WidenedToolExecutionStartEvent>> & {
            callId: string;
            execute: () => PromiseLike<T>;
            toolCallId: string;
        },
    ) => PromiseLike<T>

    Optionally runs the tool execute function in a telemetry-integration-specific context. This enables nested traces — e.g. when a tool's execute function calls generateText, the inner call's spans become children of the tool span.

    The options carry the tool-execution start-event content as context (the event fields are optional), alongside the always-present callId, toolCallId, and the execute function to run.

    onAbort?: Callback<
        InferTelemetryEvent<GenerateTextAbortEvent<ToolSet, Context>>,
    >

    Called when a streaming text generation operation is aborted before it completes.

    onEmbedEnd?: Callback<InferTelemetryEvent<EmbeddingModelCallEndEvent>>

    Called when an individual embedding model call (doEmbed) completes. Contains the embeddings, usage, and any warnings from the model response.

    onEmbedStart?: Callback<InferTelemetryEvent<EmbeddingModelCallStartEvent>>

    Called when an individual embedding model call (doEmbed) begins. For embed, there is one call. For embedMany, there may be multiple calls when values are chunked.

    onEnd?: Callback<InferTelemetryEvent<OperationEndEvent>>

    Called when an operation completes. Fired for text generation (generateText/streamText), object generation (generateObject/streamObject), embedding (embed/embedMany), and reranking operations.

    Use the event shape or operationId to distinguish between operation types.

    onError?: Callback<unknown>

    Called when an unrecoverable error occurs during the generation lifecycle. The error value is untyped — it may be an Error instance, an AISDKError, or any thrown value.

    Use this to record error details on telemetry spans and set error status.

    onLanguageModelCallEnd?: Callback<
        InferTelemetryEvent<LanguageModelCallEndEvent<ToolSet>>,
    >

    Called after the model response has been normalized and parsed, but before any client-side tool execution begins.

    onLanguageModelCallStart?: Callback<
        InferTelemetryEvent<LanguageModelCallStartEvent>,
    >

    Called immediately before the provider model call begins. Unlike onStepStart, this callback is scoped to model work only and excludes any later client-side tool execution.

    onObjectStepEnd?: Callback<InferTelemetryEvent<GenerateObjectStepEndEvent>>

    Called when an object generation step (single LLM invocation) completes, with the raw result before JSON parsing and schema validation.

    onObjectStepStart?: Callback<InferTelemetryEvent<GenerateObjectStepStartEvent>>

    Called when an object generation step (single LLM invocation) begins. For generateObject/streamObject there is always exactly one step.

    onRerankEnd?: Callback<InferTelemetryEvent<RerankingModelCallEndEvent>>

    Called when an individual reranking model call (doRerank) completes. Contains the ranking results from the model response.

    onRerankStart?: Callback<InferTelemetryEvent<RerankingModelCallStartEvent>>

    Called when an individual reranking model call (doRerank) begins. There is one call per rerank invocation.

    onStart?: Callback<InferTelemetryEvent<OperationStartEvent>>

    Called when an operation begins. Fired for text generation (generateText/streamText), object generation (generateObject/streamObject), embedding (embed/embedMany), and reranking operations.

    Use the operationId field to distinguish between operation types.

    onStepEnd?: Callback<
        InferTelemetryEvent<GenerateTextStepEndEvent<ToolSet, Context>>,
    >

    Called when an individual step (single LLM invocation) completes. The event is a StepResult containing the model's response, tool calls and results, usage statistics, finish reason, and optional request/response bodies.

    onStepFinish?: Callback<
        InferTelemetryEvent<GenerateTextStepEndEvent<ToolSet, Context>>,
    >

    Called when an individual step (single LLM invocation) completes.

    Use onStepEnd instead.

    onStepStart?: Callback<
        InferTelemetryEvent<
            GenerateTextStepStartEvent<ToolSet, Context, Output<any, any, any>>,
        >,
    >

    Called when an individual step (single LLM invocation) begins. A generation may consist of multiple steps (e.g. when tool calls trigger follow-up LLM calls). Use this to create per-step spans or record step-level inputs.

    The event includes the step number, accumulated previous step results, and the messages that will be sent to the model.

    onToolExecutionEnd?: Callback<InferTelemetryEvent<WidenedToolExecutionEndEvent>>

    Called when a tool execution completes, either successfully or with an error. The event uses a discriminated union on the success field — check event.success to determine whether output or error is available.

    The event includes execution time (toolExecutionMs) for performance tracking.

    onToolExecutionStart?: Callback<
        InferTelemetryEvent<WidenedToolExecutionStartEvent>,
    >

    Called when a tool execution begins, before the tool's execute function is invoked. Use this to create tool-level spans or log tool invocations.

    Methods

    • Marks this run's trace as failed. Used by executeConfig to surface a generateText rejection that happens before onStart fires (e.g. a bad model id) — without this, the trace pre-created for the route's synchronous response would otherwise hang in running forever. If spans were already opened before the rejection, they are closed as error too.

      Parameters

      • message: string

      Returns Promise<void>