import type * as Log from './internal/Log.js'; /** Tag values a metric backend accepts. */ export type Tags = Record; /** * The bounded StatsD-style surface the built-in metric sinks emit to, plus an * optional high-cardinality {@link Metrics.analytics} hook. Apps supply a * concrete backend — e.g. {@link cloudflare} — so core carries no metrics-vendor * dependency. Pass it as `metrics` to `App.create` and the webhook poller/queue * handlers. */ export type Metrics = { /** * Optional per-request analytics sink, called once with the request-log entry * for every response. Unlike the StatsD `count`/`gauge`/`histogram` surface * (which stays low-cardinality), this hook carries the full entry — caller * ids, org ids, route, status — for a wide-event store (e.g. ClickHouse). * Attach it via {@link cloudflare}'s `analytics` option (or {@link from} for a * custom backend); omit it to drop analytics. May be async; `App.create` does * not await it. */ analytics?: ((entry: Log.Entry) => Promise | void) | undefined; /** Increments a counter; same name+tags are summed. */ count(name: string, value: number, tags?: Tags): void; /** Ships accumulated metrics. */ flush(): void; /** Sets a gauge; last write wins for the same name+tags. */ gauge(name: string, value: number, tags?: Tags): void; /** Records a histogram observation. */ histogram(name: string, value: number, tags?: Tags): void; }; /** * Creates a {@link Metrics} from a value, type-checking it against the contract. * The escape hatch for bringing your own backend (Datadog, Prometheus, …): * author the implementation inline and have it validated against {@link Metrics}. */ export declare function from(metrics: metrics): metrics; /** Options for the {@link cloudflare} preset and its backend. */ export declare namespace cloudflare { /** Shared context handed to the {@link Options.analytics} factory. */ type Context = { /** Resolved `enabled` flag; the analytics sink should drop events when false. */ enabled: boolean; /** Deployment environment, also added as the `environment` global tag. */ environment?: string | undefined; /** Service name, also added as the `service` global tag. */ service?: string | undefined; }; type Options = { /** * Builds the per-request {@link Metrics.analytics} hook from the shared * {@link Context}, so the sink reuses `enabled`/`environment`/`service` * instead of repeating them. Omit to drop analytics. */ analytics?: ((context: Context) => Metrics['analytics']) | undefined; /** Set false (e.g. in local `wrangler dev`) to drop every metric and analytics event. Default true. */ enabled?: boolean | undefined; /** Deployment environment, added as the `environment` global tag and shared with {@link Options.analytics}. */ environment?: string | undefined; /** Service name, added as the `service` global tag and shared with {@link Options.analytics}. */ service?: string | undefined; }; } /** * A Cloudflare Workers {@link Metrics} — pass it as `metrics` to `App.create` * and the webhook poller/queue handlers. It buffers metrics and emits them on * `flush()` as `cwm-`-prefixed `console.log` lines (one per ≤250 KiB batch) for * a Workers Logs → metrics pipeline to scrape; no external dependency. */ export declare function cloudflare(options?: cloudflare.Options): Metrics; //# sourceMappingURL=Metrics.d.ts.map