@accordkit/tracer - v0.2.1
    Preparing search index...

    Class Tracer

    A lightweight, vendor-agnostic tracer that emits normalized AccordKit events to a pluggable Sink. Middlewares can be used to transform or drop events before they are sent to the sink.

    If the provided sink implements the BufferedSink interface, the flush() and close() methods will be proxied to allow for graceful delivery of events on shutdown.

    Index

    Constructors

    Properties

    sessionId: string

    The logical session ID used to partition trace logs.

    Methods

    • Emits a message event, which can be from the system, user, assistant, or a tool.

      Parameters

      • e: Omit<MessageEvent, "sessionId" | "type" | "ts" | "level" | "ctx"> & {
            ctx?: TraceContext;
        }

        The message event to emit.

      Returns Promise<unknown>

      A promise that resolves when the event has been sent to the sink.

    • Emits a tool_call event, which represents a call to a tool.

      Parameters

      • e: Omit<ToolCallEvent, "sessionId" | "type" | "ts" | "level" | "ctx"> & {
            ctx?: TraceContext;
        }

        The tool call event to emit.

      Returns Promise<unknown>

      A promise that resolves when the event has been sent to the sink.

    • Emits a tool_result event, which represents the result of a tool call.

      Parameters

      Returns Promise<unknown>

      A promise that resolves when the event has been sent to the sink.

    • Emits a usage event, which contains information about token usage and cost.

      Parameters

      Returns Promise<unknown>

      A promise that resolves when the event has been sent to the sink.

    • Starts a new span and returns a SpanToken that should be passed to spanEnd to complete the span. Any emitted event can reuse token.ctx to relate messages to this span.

      Parameters

      Returns SpanToken

      A SpanToken representing the in-flight span.

    • Finishes a span and emits a span event with the computed duration. The status of the span defaults to 'ok', but can be set to 'error' if the operation failed.

      Parameters

      • token: SpanToken

        The SpanToken returned from spanStart.

      • Optionalend: { status?: "error" | "ok"; attrs?: Record<string, unknown> }

        An optional object containing the status and attributes to add to the span.

      Returns Promise<void>

      A promise that resolves when the span event has been sent to the sink.

    • If the underlying sink is buffered, this method flushes any queued events to durable storage. This is a no-op for sinks that write immediately.

      Returns Promise<void>

      A promise that resolves when the flush is complete.

    • If the underlying sink is buffered, this method closes any open timers and flushes any remaining events. This is a no-op for sinks that write immediately.

      Returns Promise<void>

      A promise that resolves when the close operation is complete.