import type { LlmGenerationEvent, LlmRunSpan, LlmStepSpan, LlmToolSpan, LlmToolSpanContext, LlmTraceSink, Logger } from '@cat-factory/kernel'; export interface OtelSinkConfig { /** OTLP/HTTP base URL, e.g. `http://collector:4318` (the `/v1/*` paths are appended). */ endpoint: string; /** * Whether the destination takes `/v1/metrics` as well as `/v1/traces`. Default true. * * Not every OTLP endpoint is a general collector: a trace BACKEND may implement the traces * signal alone (Langfuse does), and posting metrics there earns a 404 per generation. Off means * the metrics payload is never built, rather than built and dropped. */ exportMetrics?: boolean; /** Extra headers merged onto every request (auth tokens, tenant ids, …). */ headers?: Record; /** OTLP resource `service.name`; defaults to `cat-factory`. */ serviceName?: string; /** Optional logger for swallowed errors. */ logger?: Logger; /** Injectable fetch (tests); defaults to the global `fetch`. */ fetchImpl?: typeof fetch; } export declare class OtelTraceSink implements LlmTraceSink { private readonly tracesEndpoint; private readonly metricsEndpoint; private readonly headers; private readonly serviceName; private readonly logger?; private readonly fetchImpl; constructor(config: OtelSinkConfig); private resourceAttributes; recordGeneration(event: LlmGenerationEvent): Promise; recordToolSpans(context: LlmToolSpanContext, spans: LlmToolSpan[]): Promise; /** * The settled run's root + step spans, in ONE POST: they are the parents the run's already * exported generations and tool spans named, so splitting them across requests would let a * partial failure leave a trace whose steps point at a root that never arrives. */ recordRunSpans(run: LlmRunSpan, steps: LlmStepSpan[]): Promise; private sendSpans; private sendMetrics; private send; } /** Build a fetch-based {@link OtelTraceSink}. The workerd-safe opt-in OTLP exporter. */ export declare function createOtelSink(config: OtelSinkConfig): OtelTraceSink; export { PlatformMetricsOtelExporter, type PlatformMetricsOtelExporterConfig, createPlatformMetricsOtelExporter, } from './platform.js'; export { DEFAULT_LOG_BATCH_SIZE, OtelLogExporter, type OtelLogExporterConfig, SELF_LOG_FIELD, createOtelLogExporter, } from './logs.js'; /** * Parse the OTLP `OTEL_EXPORTER_OTLP_HEADERS` convention — comma-separated `key=value` * pairs (e.g. `x-api-key=abc,x-tenant=42`) — into a header map, or undefined when * unset/empty. Shared by every facade so the two transports read headers identically. */ export declare function parseOtlpHeaders(raw: string | undefined): Record | undefined; /** Default platform-metrics sweep interval (Node timer); the Worker is cron-driven. */ export declare const PLATFORM_METRICS_DEFAULT_INTERVAL_MS = 60000; /** The trailing windows the platform-metrics sweep may aggregate over. */ export declare const PLATFORM_METRICS_WINDOWS: readonly ['1h', '24h', '7d']; export type PlatformMetricsWindow = (typeof PLATFORM_METRICS_WINDOWS)[number]; /** * Parse `OTEL_PLATFORM_METRICS_INTERVAL_MS` into a positive integer ms, falling back to * {@link PLATFORM_METRICS_DEFAULT_INTERVAL_MS} for unset / non-numeric / non-positive values. * Shared by every facade so the sweep cadence is parsed identically. */ export declare function parsePlatformMetricsIntervalMs(raw: string | undefined): number; /** * Parse `OTEL_PLATFORM_METRICS_WINDOW` into a valid trailing window, defaulting to `1h` * (the shortest, most operationally useful — the OTel backend builds longer trends from the * gauge series). Shared so both facades default + validate identically. */ export declare function parsePlatformMetricsWindow(raw: string | undefined): PlatformMetricsWindow; /** * Default log-export flush cadence (Node timer). Short enough that a line is queryable while * an operator is still watching the incident that produced it, long enough that a busy * deployment batches rather than posting per line. The Worker flushes per invocation instead, * so this does not apply there. */ export declare const LOG_EXPORT_DEFAULT_FLUSH_INTERVAL_MS = 5000; /** * Parse `OTEL_LOGS_FLUSH_INTERVAL_MS` into a positive integer ms, falling back to * {@link LOG_EXPORT_DEFAULT_FLUSH_INTERVAL_MS} for unset / non-numeric / non-positive values. */ export declare function parseLogExportFlushIntervalMs(raw: string | undefined): number; /** * Parse `OTEL_LOGS_MAX_BATCH_SIZE` into a positive integer, falling back to * {@link DEFAULT_LOG_BATCH_SIZE}. It bounds both the POST size and (with the exporter's queue * multiplier) how much a collector outage may hold in memory, so an operator turning it up * for a chatty deployment is raising both together, deliberately. */ export declare function parseLogExportBatchSize(raw: string | undefined): number; //# sourceMappingURL=index.d.ts.map