import { Attributes } from "@opentelemetry/api"; import { ViewOptions } from "@opentelemetry/sdk-metrics"; //#region src/metrics.d.ts /** * Duration buckets for GenAI operations, in **seconds**. Matches the spec's * advice for `gen_ai.client.operation.duration` and the streaming-timing * metrics (`time_to_first_chunk`, `time_per_output_chunk`). */ export declare const GEN_AI_DURATION_BUCKETS_SECONDS: readonly number[]; /** * Token-count buckets for `gen_ai.client.token.usage`. Matches the spec's * published advice — tiny prompts through million-token context windows. */ export declare const GEN_AI_TOKEN_USAGE_BUCKETS: readonly number[]; /** * USD cost buckets. Sub-cent resolution at the low end (fractions of a cent per * small call) up to tens of dollars (batch jobs, Opus/o-series runs). */ export declare const GEN_AI_COST_USD_BUCKETS: readonly number[]; /** Histogram bucket family. */ export type GenAiHistogramKind = 'duration' | 'tokens' | 'cost'; /** * Instrument-level advice object for `createHistogram(name, advice)`. Use when * you control instrument creation (e.g. custom business GenAI metrics); * {@link genAiMetricViews} is better when the metric comes from a plugin. */ export declare function llmHistogramAdvice(kind: GenAiHistogramKind): { advice: { explicitBucketBoundaries: number[]; }; }; /** * Returns `View`s that re-bucket the standard OpenTelemetry GenAI histograms. * Pass the result to your `MeterProvider`'s `views` option. * * Covers the canonical GenAI instruments: * - `gen_ai.client.operation.duration` * - `gen_ai.client.operation.time_to_first_chunk` * - `gen_ai.client.operation.time_per_output_chunk` * - `gen_ai.client.token.usage` * - `gen_ai.invoke_workflow.duration` * - `gen_ai.client.cost.usd` (autotel extension; no-op if not emitted) * * Add more instrument patterns via `extra` if you emit custom GenAI metrics. */ export declare function genAiMetricViews(extra?: { instrumentName: string; kind: GenAiHistogramKind; }[]): ViewOptions[]; /** One completed GenAI operation, as {@link recordGenAiMetrics} needs it. */ export interface GenAiMetricInput { /** Wall-clock seconds for the operation. */ durationSeconds: number; /** Attributes shared by every instrument: operation, provider, model. */ attributes: Attributes; inputTokens?: number; outputTokens?: number; costUsd?: number; timeToFirstChunk?: number; } /** * Drop the cached instruments so the next record rebuilds them against the * current `MeterProvider`. * * @internal Exported for tests that swap providers between cases. Production * code registers one provider in `init()` and never needs this. */ export declare function resetGenAiInstruments(): void; /** * Record the canonical GenAI metrics for one completed operation. * * Called by `traceGenAI`; you only need it when instrumenting a GenAI call * some other way. Without a registered `MeterProvider` every call is a no-op, * so this costs nothing in a traces-only setup. */ export declare function recordGenAiMetrics(input: GenAiMetricInput): void; //#endregion