import type { Metrics } from '../Metrics.js'; import type * as Webhooks from '../Webhooks.js'; import type * as Log from './Log.js'; /** Webhook event type, including the synthetic `ping` carried on test envelopes. */ export type EventType = Webhooks.Envelope['type']; /** Where a delivery attempt originated. */ export type Trigger = 'manual_retry' | 'ping' | 'queue'; /** Bounded step names inside one block-fanout scan, used by `webhook:scan-step`. */ export type ScanStep = 'block_rpc' | 'enrich' | 'finalized_rpc' | 'logs_rpc' | 'match' | 'stage' | 'subscription_read'; /** * A webhook metric event, recorded by the {@link webhooks} sink. The * block-fanout scan path emits head and scan measurements; the delivery path * emits `webhook:delivery`. */ export type WebhookEvent = { /** Tempo chain whose listener was checked. */ chainId: number; /** Heads refused in a row by the monotonic guard; zero on a delivering listener. */ skippedHeads: number; /** Identifies heads received and discarded rather than heads not received. */ type: 'webhook:head-skipped'; } | { chainId: number; /** True once finality has deferred this block at least one round. */ deferred: boolean; /** Rows matched when dispatched; zero otherwise. */ matches: number; /** Block timestamp to scan completion; absent when the block was not read. */ scanLagMs?: number | undefined; /** Block timestamp to head observation; absent without a fresh stamp. */ observationLagMs?: number | undefined; /** How the head that enqueued this block was observed. */ origin: string; /** One scanned block's outcome. */ outcome: 'deferred' | 'dispatched' | 'empty'; /** Head observation to this scan attempt starting; absent without a stamp. */ queueWaitMs?: number | undefined; /** Identifies one block-fanout scan. */ type: 'webhook:scan-block'; /** Wall-clock work inside this scan attempt. */ workMs: number; } | { chainId: number; /** Times this step ran across the batch, so the total can be normalized. */ count: number; /** Wall-clock duration of this step summed across the batch. */ durationMs: number; /** Bounded step name. */ step: ScanStep; /** Identifies per-step scan attribution. */ type: 'webhook:scan-step'; } | { chainId: number; /** Age of the oldest tracked block, absent when none are pending. */ oldestPendingAgeMs?: number | undefined; /** Tracked blocks awaiting completion reports. */ pendingCount: number; /** Identifies the coordinator's tracked-scan backlog. */ type: 'webhook:scan-backlog'; /** Blocks between the chain head and the enqueue watermark. */ watermarkLagBlocks?: number | undefined; } | { chainId: number; /** Blocks between the observed head and the finalized head. */ lagBlocks: number; /** Identifies the finality gate's settling distance. */ type: 'webhook:scan-finality'; } | { /** Atomic ledger claim outcome. */ outcome: 'attempting' | 'claimed' | 'missing' | 'scheduled' | 'terminal'; /** Identifies a delivery-obligation claim. */ type: 'webhook:delivery-job-claim'; } | { /** Obligations represented by this outcome. */ count: number; /** Whether staging created or found the obligation. */ outcome: 'created' | 'existing'; /** Identifies obligation staging ahead of Queue handoff. */ type: 'webhook:delivery-job-ensure'; } | { /** Delivery attempt ordinal: the ledger claim count on the queue path. */ attempt: number; envelope: Webhooks.Envelope; /** Cloudflare Queue delivery attempt, absent outside the Queue path. */ queueAttempt?: number | undefined; result: Webhooks.Result; subscription: Webhooks.Subscription; timings?: { deliveryLogMs?: number | undefined; envelopeToQueueMs?: number | undefined; endToEndMs?: number | undefined; /** Block timestamp to the attempt leaving; the total latency SLI. */ eventToAttemptMs?: number | undefined; eventToEnvelopeMs?: number | undefined; /** Head observation to the attempt leaving; the controllable SLI. */ observedToAttemptMs?: number | undefined; /** Dequeue to the attempt leaving: claim, reads, signing. */ preflightMs?: number | undefined; processingMs?: number | undefined; queueWaitMs?: number | undefined; /** Response headers to bookkeeping complete; occupancy, not latency. */ settleMs?: number | undefined; stateWriteMs?: number | undefined; subscriptionReadMs?: number | undefined; }; trigger: Trigger; type: 'webhook:delivery'; }; /** Records request (HTTP) metrics for one request-log entry. Built by {@link requests}. */ export type RequestSink = (entry: Log.Entry) => void; /** Records webhook reliability metrics. Built by {@link webhooks}. */ export type WebhookSink = { /** Ships buffered metrics (call once per scan batch / delivery). */ flush(): void; /** Records one webhook event. */ record(event: WebhookEvent): void; }; /** * Builds a request (HTTP) metrics sink over `backend`: emits the bounded Worker * metrics derived from one request-log entry, then flushes (one entry == one * request). * * Metric tags deliberately exclude caller ids, organization ids, request ids, * raw paths, and IP-derived identities — those belong in logs or analytics, not * StatsD-style series. */ export declare function requests(backend: Metrics): RequestSink; /** * Builds a webhook delivery-reliability sink over `backend`. Tags stay * low-cardinality (`chain_id`, `event_type`, `destination_type`, `status_class`, * `attempt_bucket`, `failure`, `queue_attempt_bucket`, `outcome`, `stage`) — never subscription/org/event ids, which belong * in logs or analytics, not StatsD-style series. */ export declare function webhooks(backend: Metrics): WebhookSink; //# sourceMappingURL=MetricSink.d.ts.map