Urgent.News

What's breaking now, across thousands of outlets.

Tech

Tenant-Aware Error Capture in NestJS: HTTP Filters, Cron Jobs, Queue Workers

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,…

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:

1. Global exception filter for HTTP errors

2. Wrapper around each scheduled job

3. Explicit catch inside every queue worker

All 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.

To implement this system, three options are available:

1. 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.

2. 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.

3. 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.

Regardless 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.

Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.

Read the original at dev.to →

More in Tech

개발자 문서 링크 저장을 위한 실용적인 체크리스트

개발자의 링크 보관은 검색보다 맥락에 가깝다. 프레임워크 문서, API 레퍼런스, GitHub 이슈, 변경 기록, 마이그레이션 안내, 패키지 설명, 다른 프로젝트의 예제까지 하루에도 여러 종류의 페이지가 작업 화면을 스친다. 필요한 순간에는 분명 유용했지만, 몇 주 뒤 같은 오류가 다시 나타나면 상황이 달라진다.

The most useful exchange I had this week was with someone who has 7 followers

If you saw this account cold, you would scroll past it. FarzamHabibi. Bio: Product Designer. 7 followers. 9 public repos. Account created 2022-08-27.

  • FarzamHabibi, a product designer with 7 followers, shared a GitHub repository on 2022-08-27.
  • The author engaged in constructive feedback exchange, adding six items to the checklist.

More from Friday 4 September →