Skip to content

Supercharge your AI agents with data from the web and beyond. Building the library for superintelligence. 🔥

4.8 KB
Raw Blame
import { Counter, Histogram } from "prom-client";

export const firePdfCacheEventsTotal = new Counter({
  name: "firecrawl_fire_pdf_cache_events_total",
  help: "fire-pdf content-cache events by outcome: hit, stale, miss, bypass_refresh, bypass_refresh_denied, lookup_error, write, write_failed, refused_write",
  labelNames: ["event", "variant"],
});

export const firePdfCacheRefusedWritesTotal = new Counter({
  name: "firecrawl_fire_pdf_cache_refused_writes_total",
  help: "fire-pdf results not written to the content cache, by reason; reasons: failed_pages, degraded_pages, missing_quality, malformed_provenance",
  labelNames: ["reason"],
});

export const firePdfCacheBackgroundRefreshTotal = new Counter({
  name: "firecrawl_fire_pdf_cache_background_refresh_total",
  help: "Background refreshes the fire-pdf cache service granted on a stale answer, by result: submitted, submit_failed, skipped_by_reference, skipped_zdr, skipped_image, skipped_us_only, skipped_reserved_capacity",
  labelNames: ["result"],
});

export type BackgroundRefreshResult =
  | "submitted"
  | "submit_failed"
  | "skipped_by_reference"
  | "skipped_zdr"
  | "skipped_image"
  | "skipped_us_only"
  | "skipped_reserved_capacity";

export type CacheRefusedReason =
  | "failed_pages"
  | "degraded_pages"
  | "missing_quality"
  | "malformed_provenance";

export const firePdfAsyncSubmittedTotal = new Counter({
  name: "firecrawl_fire_pdf_async_submitted_total",
  help: "Count of POST /jobs requests successfully submitted to fire-pdf async",
  labelNames: ["lane"],
});

export const firePdfAsyncCompletedTotal = new Counter({
  name: "firecrawl_fire_pdf_async_completed_total",
  help: "Count of fire-pdf async jobs that reached a terminal status",
  labelNames: ["terminal_status"],
});

export const firePdfAsyncFallbackTotal = new Counter({
  name: "firecrawl_fire_pdf_async_fallback_total",
  help: "Count of requests that left fire-pdf async processing",
  labelNames: ["reason"],
});

export const firePdfRouteDecisionsTotal = new Counter({
  name: "firecrawl_fire_pdf_route_decisions_total",
  help: "Transport chosen for a request's first FirePDF attempt: path=sync (POST /ocr) or async (POST /jobs), by routing reason",
  labelNames: ["source_kind", "path", "reason", "features", "zdr"],
});

export const firePdfRouteRemainingSeconds = new Histogram({
  name: "firecrawl_fire_pdf_route_remaining_seconds",
  help: "Caller time left on the scrape when the FirePDF transport was chosen",
  labelNames: ["source_kind", "path"],
  buckets: [5, 10, 15, 20, 30, 45, 60, 90, 120, 180, 300, 600],
});

export const firePdfAsyncSubmit503Total = new Counter({
  name: "firecrawl_fire_pdf_async_submit_503_total",
  help: "fire-pdf POST /jobs 503s that ended the async attempt, by the error code in the response body (unattributed when the body carried none)",
  labelNames: ["code"],
});

export const firePdfAsyncLongPollTotal = new Counter({
  name: "firecrawl_fire_pdf_async_long_poll_total",
  help: "GET /jobs/:id requests sent with wait_ms, by outcome: terminal (answered with a terminal status), held (non-terminal after holding), not_held (non-terminal answered early; followed by a pause, and by scheduled polling after repeated early answers)",
  labelNames: ["outcome"],
});

export const firePdfAsyncTotalDurationSeconds = new Histogram({
  name: "firecrawl_fire_pdf_async_total_duration_seconds",
  help: "End-to-end duration from 'decide to use async' to 'result available', by origin: interactive (a caller waits on this document) or bulk (a crawl or batch scrape child)",
  labelNames: ["origin"],
  buckets: [0.5, 1, 2.5, 5, 10, 30, 60, 120, 300, 600, 1200, 1800],
});

export const firePdfAsyncSubmitRetriesTotal = new Counter({
  name: "firecrawl_fire_pdf_async_submit_retries_total",
  help: "Count of POST /jobs retries after a transient failure that never reached fire-pdf's handler",
  labelNames: ["trigger"],
});

export const firePdfAsyncAbandonedTotal = new Counter({
  name: "firecrawl_fire_pdf_async_abandoned_total",
  help: "Count of fire-pdf async attempts abandoned because the caller's scrape window closed first",
  labelNames: ["phase"],
});

export const firePdfAsyncPollCount = new Histogram({
  name: "firecrawl_fire_pdf_async_poll_count",
  help: "Number of GET /jobs/:id polls performed per fire-pdf async job",
  buckets: [1, 2, 5, 10, 20, 50, 100, 200, 500],
});

export type SubmitRetryTrigger =
  | "transport_error"
  | "http_503_closing"
  | "http_503_unattributed";

export type AbandonedPhase = "submit" | "poll" | "result";

export type FallbackReason =
  | "http_400"
  | "http_401"
  | "http_404"
  | "http_410"
  | "http_413"
  | "http_502"
  | "http_503"
  | "http_429"
  | "http_5xx"
  | "network_error"
  | "deadline_too_close"
  | "terminal_failed"
  | "terminal_expired"
  | "terminal_cancelled"
  | "polling_timeout"
  | "result_503"
  | "region_unavailable"
  | "reserved_unavailable";