Guides / Monitoring

How to Log Production Errors as Business Events

3 min read·Monitoring

Error Trackers vs Business Event Logging

Sentry and Datadog catch every error — stack traces, browser exceptions, the works. That's great for debugging.

LogIt is for a different slice: the errors that directly affect your business. A checkout crash. A failed webhook. An email that didn't send. These belong in your business event inbox, not buried in a stack trace dashboard.

Example: checkout crash

ts
import { init } from "logit";
const logit = init({ token: process.env.LOGIT_API_KEY! });

try {
  await processCheckout(userId, priceId);
} catch (err) {
  const error = err instanceof Error ? err : new Error(String(err));

  await logit.now("errors", {
    event: "Checkout failed",
    description: `User ${userId}: ${error.message}`,
    icon: "❌",
    notify: true,
    tags: { component: "checkout", userId },
    metadata: { userId, priceId, message: error.message },
  });

  throw err; // re-throw so Sentry still catches it
}

Express error middleware

ts
import type { Request, Response, NextFunction } from "express";

app.use(async (err: Error, req: Request, res: Response, next: NextFunction) => {
  if (req.path.startsWith("/api/checkout") || req.path.startsWith("/api/webhook")) {
    await logit.now("errors", {
      event: "Revenue-critical error",
      description: `${req.method} ${req.path}: ${err.message}`,
      icon: "❌",
      notify: true,
      tags: { path: req.path, method: req.method },
      metadata: { message: err.message, stack: err.stack },
    });
  }
  next(err);
});

Tip

Only log errors that are revenue-critical or user-facing. Use your error tracker for everything else. Noisy business event inboxes lose their signal fast.

Try LogIt free

7-day trial. No credit card required.

Start free