Skip to content

@flarelog/sdk


@flarelog/sdk / flarelogAI

Function: flarelogAI()

flarelogAI(logger, config?): AIInstrumentationHandle

Defined in: ai/index.ts:76

Enable AI inference observability on a FlareLog instance.

By default, this:

  • Patches globalThis.fetch to intercept calls to OpenAI, Anthropic, and any user-configured extra hosts.
  • Injects the W3C traceparent header on outgoing AI calls so they correlate with the parent request span.
  • Captures token usage, latency (TTFB + total), cost in USD, tool calls, and errors.
  • Emits a structured log entry per call with flarelog.kind: "ai_call".

The instrumentation is global — calling flarelogAI(logger) twice with different loggers is undefined. Use one logger per process.

Parameters

logger

FlareLog

config?

AIInstrumentationConfig = {}

Returns

AIInstrumentationHandle

a handle with a .dispose() method to remove instrumentation.

Released under the MIT License.