Supercharge your AI agents with data from the web and beyond. Building the library for superintelligence. 🔥
TypeScript aiai-agentsai-crawlerai-scrapingai-searchcrawlerdata-extractionhtml-to-markdownllmmarkdownscraperscrapingweb-crawlerweb-dataweb-data-extractionweb-scraperweb-scrapingweb-searchwebscraping
Ignore Cancelled Jobs on Sentry (#2614)
Abimael Martelle712b9795cc6
diff --git a/apps/api/src/lib/error.ts b/apps/api/src/lib/error.tsindex 6076748b9..fe59dd281 100644--- a/apps/api/src/lib/error.ts+++ b/apps/api/src/lib/error.ts@@ -172,3 +172,14 @@ export class CrawlDenialError extends TransportableError {return x;}}++/**+ * Error thrown when a job is cancelled (expected flow control, not a real error)+ * This should not be sent to Sentry as it's expected behavior when a crawl/batch is cancelled+ */+export class JobCancelledError extends Error {+ constructor() {+ super("Parent crawl/batch scrape was cancelled");+ this.name = "JobCancelledError";+ }+}diff --git a/apps/api/src/lib/otel-tracer.ts b/apps/api/src/lib/otel-tracer.tsindex 59bf7c0b7..bca592fe1 100644--- a/apps/api/src/lib/otel-tracer.ts+++ b/apps/api/src/lib/otel-tracer.ts@@ -92,10 +92,6 @@ export async function withSpan<T>(message: error instanceof Error ? error.message : String(error),});- if (error instanceof Error) {- Sentry.captureException(error);- }-throw error;}},diff --git a/apps/api/src/services/sentry.ts b/apps/api/src/services/sentry.tsindex 39b40b3d5..681f95e17 100644--- a/apps/api/src/services/sentry.ts+++ b/apps/api/src/services/sentry.ts@@ -7,6 +7,7 @@ import {EngineError,} from "../scraper/scrapeURL/error";import { AbortManagerThrownError } from "../scraper/scrapeURL/lib/abortManager";+import { JobCancelledError } from "../lib/error";type CaptureContext = {tags?: Record<string, string>;@@ -63,7 +64,8 @@ if (config.SENTRY_DSN) {error instanceof AddFeatureError ||error instanceof RemoveFeatureError ||error instanceof AbortManagerThrownError ||- error instanceof EngineError+ error instanceof EngineError ||+ error instanceof JobCancelledError) {return null;}@@ -74,6 +76,15 @@ if (config.SENTRY_DSN) {const errorCodeFromField = "code" in error ? String(error.code) : "";const errorMessage =error instanceof Error ? String(error.message || "") : "";++ // Ignore cancellation errors (fallback for serialized errors)+ if (+ errorMessage === "Parent crawl/batch scrape was cancelled" ||+ errorMessage.includes("Parent crawl/batch scrape was cancelled")+ ) {+ return null;+ }+const errorCodeFromMessage =errorCodeFromField ||(errorMessage.includes("|") ? errorMessage.split("|", 1)[0] : "");diff --git a/apps/api/src/services/worker/scrape-worker.ts b/apps/api/src/services/worker/scrape-worker.tsindex 776c13852..20aa1bbbd 100644--- a/apps/api/src/services/worker/scrape-worker.ts+++ b/apps/api/src/services/worker/scrape-worker.ts@@ -53,6 +53,7 @@ import { getBillingQueue } from "../queue-service";import type { Logger } from "winston";import {CrawlDenialError,+ JobCancelledError,RacedRedirectError,ScrapeJobTimeoutError,TransportableError,@@ -197,7 +198,7 @@ async function processJob(job: NuQJob<ScrapeJobSingleUrls>) {if (job.data.crawl_id) {const sc = (await getCrawl(job.data.crawl_id)) as StoredCrawl;if (sc && sc.cancelled) {- throw new Error("Parent crawl/batch scrape was cancelled");+ throw new JobCancelledError();}}@@ -591,9 +592,7 @@ async function processJob(job: NuQJob<ScrapeJobSingleUrls>) {}const isEarlyTimeout = error instanceof ScrapeJobTimeoutError;- const isCancelled =- error instanceof Error &&- error.message === "Parent crawl/batch scrape was cancelled";+ const isCancelled = error instanceof JobCancelledError;if (isEarlyTimeout) {logger.error(`🐂 Job timed out ${job.id}`);@@ -1198,8 +1197,15 @@ async function processJobWithTracing(job: NuQJob<ScrapeJobData>, logger: any) {} catch (error) {logger.warn("Job failed", { error });- // Filter out TransportableErrors (flow control)- if (!(error instanceof TransportableError)) {+ // Filter out expected errors (flow control, not real errors)+ if (+ error instanceof TransportableError ||+ error instanceof JobCancelledError ||+ error instanceof RacedRedirectError ||+ error instanceof ScrapeJobTimeoutError+ ) {+ // These are expected flow control errors, don't send to Sentry+ } else {captureExceptionWithZdrCheck(error, {extra: { zeroDataRetention: job.data.zeroDataRetention ?? false },});