SDK & Framework Guides

Set Up Error Monitoring for Qwik Apps

Qwik error monitoring setup using LightTrace and Sentry SDK. Capture server and client errors with minimal bundle impact for instant-on apps.

Qwik's resumability model gives you instant-on interactivity and minimal JS payloads—but those advantages disappear if unhandled errors break the experience in production. A robust Qwik error monitoring setup framework captures both server and client errors with near-zero bundle overhead, giving you the visibility you need to debug issues without bloating your already-lean bundle.

Unlike traditional frameworks, Qwik's architecture—where execution can resume mid-interaction on any client—requires error tracking that understands serialized state and async task boundaries. This guide walks you through integrating error monitoring with Qwik using the Sentry SDK and LightTrace, covering middleware-based capture, production debugging, and best practices that respect Qwik's performance-first design.

Why Error Monitoring Matters for Qwik

Error tracking in a Qwik app serves the same critical function as in any framework: it alerts you when things break in production and provides the context to fix them fast. But Qwik's unique architecture—relying on resumability and eager hydration avoidance—introduces subtle failure modes:

  • Serialization failures: If you try to serialize non-serializable state (functions, DOM nodes, circular references), resumption fails silently.
  • Task execution errors: Qwik's async task system can fail in ways that don't reach standard global error handlers.
  • Missing event listeners: If error handling code doesn't load when an interaction occurs, the user sees an unresponsive UI.
  • Server-side route errors: Qwik's integrated server rendering can fail before the client code even ships.

An effective error monitoring setup catches all of these, letting you understand what error tracking is and why it matters even for lean, performant apps.

Qwik's resumability means your JS payload stays small, but that also means fewer chances to bundle error-handling code. A hosted error-tracking service like LightTrace keeps your solution lightweight—no heavyweight SDKs pushing your bundle size up.

Setting Up LightTrace with the Sentry SDK

Qwik is compatible with any Sentry SDK—just point the dsn at LightTrace instead of Sentry.io. For browser and server monitoring, you'll need both @sentry/browser and @sentry/node.

First, install the SDKs:

npm install @sentry/browser @sentry/node

Then initialize Sentry for the browser in your Qwik app. Create a sentry.ts or sentry.config.ts file:

import * as Sentry from "@sentry/browser";

export const initSentry = () => {
  Sentry.init({
    dsn: "https://<your-key>@light-trace.robomiri.com/1",
    environment: import.meta.env.MODE,
    tracesSampleRate: 0.1, // capture 10% of transactions
    release: import.meta.env.VITE_APP_VERSION || "unknown",
    integrations: [
      new Sentry.Replay({
        maskAllText: true,
        blockAllMedia: true,
      }),
    ],
  });
};

Then call initSentry() early in your app's entry point—typically in src/entry.browser.tsx:

import { initSentry } from "./sentry.config";

initSentry();

export default App;

Qwik's resumability means your app won't hydrate until the user interacts. Initialize Sentry before the app mounts to catch any startup errors, but keep the SDK lean: disable features like session replay (LightTrace doesn't support it yet) to minimize the impact on your bundle.

Server-Side Error Capture with Middleware

Qwik's server architecture (via Qwik City) lets you wire up middleware to capture server-side errors before they reach the client. Create a middleware file at src/routes/plugin@errorhandler.ts:

import { type RequestHandler } from "@builder.io/qwik-city";
import * as Sentry from "@sentry/node";

Sentry.init({
  dsn: "https://<your-key>@light-trace.robomiri.com/1",
  environment: process.env.NODE_ENV || "development",
  tracesSampleRate: 0.1,
});

export const onRequest: RequestHandler = async (requestEvent) => {
  const { request, response, error } = requestEvent;

  // Capture any errors that occur during request handling
  if (error) {
    Sentry.captureException(error, {
      contexts: {
        route: {
          method: request.method,
          url: request.url,
        },
      },
    });
  }

  try {
    // Next middleware or route handler runs here
    await requestEvent.next?.();
  } catch (err) {
    Sentry.captureException(err, {
      level: "error",
      contexts: {
        route: {
          method: request.method,
          url: request.url,
        },
      },
    });
    throw err; // Re-throw so the error response is still sent
  }
};

This middleware catches route handler errors and database failures before they render, giving you full context in LightTrace: request method, URL, and the exact error stack.

Client-Side Error Capture and Task Monitoring

While the middleware catches server errors, you also need visibility into client-side task failures and event handler errors. Qwik's useTask$() hook can fail in ways that don't trigger the global error handler, so wrap critical tasks:

import { useTask$ } from "@builder.io/qwik";
import * as Sentry from "@sentry/browser";

export const MyComponent = component$(() => {
  useTask$(async () => {
    try {
      const data = await fetch("/api/data").then((r) => r.json());
      // Process data
    } catch (err) {
      Sentry.captureException(err, {
        tags: { component: "MyComponent", phase: "task" },
        contexts: {
          task: {
            name: "fetch-data",
          },
        },
      });
      // Optionally show a fallback UI or retry
    }
  });

  return <div>{/* ... */}</div>;
});

For global client errors (syntax errors, uncaught rejections), Sentry's browser SDK captures them automatically. But because Qwik defers JS loading, you must initialize early and monitor for both error and unhandledrejection events:

window.addEventListener("error", (event) => {
  Sentry.captureException(event.error);
});

window.addEventListener("unhandledrejection", (event) => {
  Sentry.captureException(event.reason);
});

Qwik usually handles this for you if you initialize the browser SDK, but explicit handlers ensure you don't miss task-related failures.

Distributed Tracing Across Server and Client

One of Qwik's strengths is its tight server-client integration. LightTrace supports distributed tracing, so you can track a single user interaction from the server request through to client-side task execution. Add trace context to your server-side errors:

const sentryTrace = request.headers.get("sentry-trace");
const baggage = request.headers.get("baggage");

Sentry.init({
  dsn: "https://<your-key>@light-trace.robomiri.com/1",
  tracesSampleRate: 0.1,
});

Sentry.startTransaction({
  name: `${request.method} ${new URL(request.url).pathname}`,
  op: "http.server",
  traceContext: sentryTrace ? Sentry.extractTraceparentData(sentryTrace) : undefined,
});

When the client makes a request to the server, Sentry's SDK automatically sends the sentry-trace header. Capturing it server-side lets you link client and server spans in LightTrace, making it easy to see the full request lifecycle.

Debugging Production Issues with LightTrace

Once errors arrive in LightTrace, you have several tools to diagnose and fix:

  • Fingerprinting: LightTrace groups errors by stack trace and context, so you see that a crash in MyComponent's task is one issue, not 50 separate ones.
  • Breadcrumbs: Every fetch, navigation, and custom event before the error is logged, so you know the user's path through your app.
  • Source maps: Upload your Qwik build's source maps to LightTrace so stack traces point to your original TypeScript, not minified output.
  • GitHub source links: Click from a stack frame directly to the exact line on GitHub where the error occurred.
  • Release health: Track crash-free sessions by release so you know which version introduced a regression.

For Qwik specifically, tag errors with the component and phase (task, render, event) so you can filter and prioritize. The example code above shows how to add tags; use them consistently to make your error dashboard searchable.

Never log or store user-sensitive data (passwords, API keys, PII) in error messages or breadcrumbs. LightTrace supports data scrubbing rules to mask patterns like credit-card numbers and email addresses. Configure these in your project settings to comply with privacy regulations.

Best Practices for Qwik Error Monitoring

  • Sample transactions thoughtfully: Qwik apps often handle thousands of lightweight interactions. A 10% sample rate is usually enough to catch errors without overwhelming your quota.
  • Keep the SDK small: Disable features you don't need (session replay, performance monitoring integrations) to stay within Qwik's bundle-size goals.
  • Use environment variables: Store your LightTrace DSN in .env.local and inject it at build time, not in committed code.
  • Test error capture locally: Throw a test error in development to confirm Sentry is initializing and reporting to LightTrace correctly.
  • Monitor your own alerts: Set up error-frequency alert rules in LightTrace so you're notified when a new issue emerges or error rates spike.

Error monitoring for Qwik works best when you treat it like any other performance concern: measure the overhead, configure it to fit your constraints, and keep it running continuously in production. The Sentry SDK + LightTrace approach scales from a single developer testing locally all the way to a production app serving millions.

Start tracking errors in minutes

Start monitoring errors in your Qwik app today—LightTrace includes 5,000 events per month free. Sign up in seconds, point your Sentry SDK at LightTrace, and get full visibility into both server and client errors without bloating your bundle.

LightTrace handles error deduplication, breadcrumbs, source maps, and GitHub source links so you can focus on building resilient Qwik applications. Your resumable, minimal-JS architecture deserves error tracking that respects those constraints.

Fix your next production error faster

Point any Sentry SDK at LightTrace — free up to 5,000 events/month.