Logging — recording events for debugging. Monitoring — tracking errors in production.
Why it matters: In development, you see every error in the console. In production, users encounter bugs silently — and you have no idea unless you have error monitoring in place. A proper logging strategy gives you visibility into what users actually experience, including errors, slow operations, and user behavior patterns.
How monitoring works:
1. Sentry — popular monitoring service:
1npm install @sentry/react
1// src/index.tsx2import * as Sentry from "@sentry/react";34Sentry.init({5 dsn: "https://...@sentry.io/12345",6 integrations: [7 Sentry.browserTracingIntegration(),8 Sentry.replayIntegration(),9 ],10 tracesSampleRate: 0.1, // 10% of transactions11 replaysSessionSampleRate: 0.1,12});1314// Error in code will be sent to Sentry automatically
2. Error Boundary + Sentry:
1import { ErrorBoundary } from "@sentry/react";23<ErrorBoundary fallback={<ErrorPage />}>4 <App />5</ErrorBoundary>
3. Custom logger:
1const logger = {2 info: (message, data) => {3 if (process.env.NODE_ENV === "development") {4 console.log(`[INFO] ${message}`, data);5 }6 // In production — to analytics7 analytics.track("info", { message, ...data });8 },9 error: (error, context) => {10 console.error(`[ERROR]`, error);11 Sentry.captureException(error, { extra: context });12 },13};1415// Usage16logger.info("User clicked button", { buttonId: "submit" });17logger.error(new Error("API failed"), { url: "/api/users" });
Production configuration:
tracesSampleRate low (0.01-0.1) in production to control costs.Sentry alternatives: LogRocket, Datadog, New Relic, Bugsnag.