/** * OpenTelemetry metrics emitted by the framework. * * Recorded for every request, independent of the tracking layer's sampling, * so ratio alerts need no extrapolation. Instrument names and attribute keys * are a public contract bound by dashboards and alerts: rename nothing without * a migration plan. */ import type { EngineCredentialOwner } from "../agent/engine/credential-owner.js"; export declare const OBSERVABILITY_FLUSH_TIMEOUT_MS = 2000; export interface HttpServerRequestMetric { method: string; statusCode: number; durationMs: number; /** * A value from the closed set `httpRouteForRequest()` documents, or a * trusted action's declared template. Never a raw path: arbitrary request * paths would mint a series each. */ route?: string; } export declare function recordHttpServerRequest(request: HttpServerRequestMetric): void; export declare function recordHttpServerHandoff(request: HttpServerRequestMetric): void; export interface GenAiChatMetric { requestModel: string; /** The engine name; a closed, registered set. */ providerName?: string; /** Whose key served the call; a closed set. */ credentialOwner?: EngineCredentialOwner; supportedModels?: readonly string[]; durationMs?: number; failed?: boolean; /** The engine's error code for a failed call, bounded before it becomes `error.type`. */ errorCode?: string; inputTokens?: number; outputTokens?: number; } /** One model round trip (`gen_ai.operation.name=chat`). */ export declare function recordGenAiChat(call: GenAiChatMetric): void; export interface AgentRunMetric { status: string; terminalReason: string; requestModel?: string; providerName?: string; supportedModels?: readonly string[]; } export declare function recordAgentRun(run: AgentRunMetric): void; export interface AgentToolCallMetric { toolName: string; /** A bounded failure class; omit on success. */ errorType?: string; } /** App-defined tool names collapse to `other` so they cannot mint series. */ export declare function recordAgentToolCall(call: AgentToolCallMetric): void; export type TraceWriteStage = "spans" | "summary" | "thread_org" | "write"; /** Counted once per failed stage of a run, never per span. */ export declare function recordTraceWriteFailure(stage: TraceWriteStage, error: unknown): void; /** Counted once per write whose durable change marker did not persist. */ export declare function recordActionChangeMarkerFailure(error: unknown): void; export declare function __resetFlushFailureLogForTests(): void; export declare const METRICS_FLUSH_MIN_INTERVAL_MS = 10000; /** * Export buffered telemetry before a serverless function can freeze. Never * delays a request by more than OBSERVABILITY_FLUSH_TIMEOUT_MS; each provider * that times out or fails drops its points and is counted separately on * `agent_native.telemetry.flush_failures`, which the next flush exports. * Metrics export at most once per METRICS_FLUSH_MIN_INTERVAL_MS; spans export * on every call. */ export declare function flushObservability(): Promise;