{
  "id": 5490830,
  "title": "Tenant-Aware Error Capture in NestJS: HTTP Filters, Cron Jobs, Queue Workers",
  "url": "https://urgent.news/2026/09/04/tenant-aware-error-capture-in-nestjs-http-filters-cron-jobs-queue",
  "topic": "tech",
  "section": "Tech",
  "published": "2026-09-04T04:46:42.000Z",
  "source": {
    "name": "Dev.to",
    "slug": "dev-to",
    "url": "https://dev.to/iversonblake8417/tenant-aware-error-capture-in-nestjs-http-filters-cron-jobs-queue-workers-38p2"
  },
  "original_language": "en",
  "account": "When running a support SaaS that experiments with AI-generated first replies for tenants, capturing errors accurately is crucial. The issue arises when HTTP exceptions, cron jobs, and queue workers all contribute to the same error bucket, making it difficult to discern which error is more significant. To address this, a three-layer capture system can be implemented:\n\n1. Global exception filter for HTTP errors\n2. Wrapper around each scheduled job\n3. Explicit catch inside every queue worker\n\nAll three entry points should append the tenant ID and experiment cohort information to the event before it leaves the Node.js process. This approach ensures that the error data is accurate and can be trusted for further analysis and comparison.\n\nTo implement this system, three options are available:\n\n1. Sentry: The default choice for many, Sentry provides SDKs for NestJS and Node.js, allowing for easy tagging of events with release and scope information. It offers robust error tracking and can be integrated with Grafana Loki for visualization.\n\n2. OpenTelemetry with Grafana Loki or Tempo: This option combines OpenTelemetry, a portable observability framework, with Loki or Tempo for logging and visualization. It is ideal when errors are just one signal among many, as it provides deep stack triage capabilities.\n\n3. Infrai: Infrai offers a simple REST API for capturing errors across various components, such as HTTP requests, cron jobs, and queue workers. It eliminates the need for SDKs and provides a single contract for error capture, making it easy to manage across different services.\n\nRegardless of the chosen option, the key to accurate error comparison lies in consistent error tagging with tenant ID and cohort information. This ensures that errors from different sources can be accurately compared, even when multiple errors occur simultaneously. By following this capture layer strategy, a NestJS backend can effectively handle errors from HTTP requests, scheduled jobs, and queue workers, providing a reliable foundation for error analysis and experiment evaluation.",
  "summary": "An error-tracking setup for a NestJS backend has one hard problem, and it isn't which vendor you sign up with: HTTP exceptions arrive by the thousand, cron jobs and queue workers arrive by the handful, and if both land in the same bucket the noisy one wins every chart you draw. Use one capture layer with three entry points — a global exception filter for HTTP, a wrapper around each scheduled job,…",
  "key_points": [
    "Implement three-layer error capture system: global HTTP filter, cron job wrapper, queue worker catch",
    "Append tenant ID and experiment cohort to error data at each entry point",
    "Choose between Sentry, OpenTelemetry, or Infrai for consistent error tagging"
  ],
  "editors_take": "Implementing a multi-layer error capture system that tags errors with tenant ID and cohort information enables accurate comparison and analysis of errors from different sources in a NestJS backend.",
  "illustration": null,
  "coverage": {
    "outlets": 1,
    "also_reported_by": []
  },
  "ai_generated": true,
  "disclaimer": "Summaries, key points and the editor’s take are written by software from other outlets’ reporting and may contain errors — always check the linked original."
}