npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@oluso/nextjs

v1.1.1

Published

Oluso error monitoring for Next.js applications: instrumentation hooks, route/middleware wrappers, and React bindings for the App Router and Pages Router

Readme

@oluso/nextjs

AI-powered error monitoring for Next.js applications: server-side capture for the App Router, Pages Router, and Middleware, plus React bindings for Client Components. Works unchanged on both the Node.js and Edge runtimes.

Installation

npm install @oluso/nextjs

Requires Next.js >=13.4.0 and React >=18.2.0.

Recommended setup: instrumentation.ts

Next.js's instrumentation.ts is the one place guaranteed to run exactly once per server instance, and its onRequestError hook is called for errors from Server Components, Route Handlers, Server Actions, and Middleware — whether or not you've wrapped them individually. This is the fastest path to full coverage:

// instrumentation.ts
import { Oluso, registerOlusoProcessHandlers, createOnRequestError } from '@oluso/nextjs';

export const oluso = new Oluso({
  apiKey: process.env.OLUSO_API_KEY!,
  environment: process.env.NODE_ENV,
});

export async function register() {
  registerOlusoProcessHandlers(oluso); // uncaughtException / unhandledRejection, Node runtime only
}

export const onRequestError = createOnRequestError(oluso);

That's the whole server-side integration for a basic setup. The with* wrappers below are opt-in, for routes where you also want request-scoped breadcrumbs recorded during the handler, not just the failure itself.

App Router route handlers

// app/api/widgets/route.ts
import { withOluso } from '@oluso/nextjs';
import { oluso } from '../../../instrumentation';

export const GET = withOluso(oluso, async (req) => {
  oluso.addBreadcrumb({ message: 'fetching widgets', category: 'db' });
  const widgets = await db.widgets.findMany();
  return Response.json(widgets);
});

Wrap each exported method (GET, POST, ...) separately. Thrown errors and 5xx responses are reported with the request's method, URL, and sanitized headers attached; the request body is never read here (it's a stream your handler needs to consume itself).

Pages Router API routes

// pages/api/widgets.ts
import { withOlusoApiRoute } from '@oluso/nextjs';
import { oluso } from '../../instrumentation';

export default withOlusoApiRoute(oluso, async (req, res) => {
  const widgets = await db.widgets.findMany();
  res.json(widgets);
});

Middleware

// middleware.ts
import { withOlusoMiddleware } from '@oluso/nextjs';
import { oluso } from './instrumentation';

export const middleware = withOlusoMiddleware(oluso, async (req) => {
  ...
});

Middleware always runs on the Edge runtime — this wrapper (and the rest of the server client) has no dependency on Node's http/os modules, so it works there unchanged.

Client Components

Import from the /client subpath, which carries its own 'use client' directive — importing these from the main entry point would pull server-only code into the client bundle.

// app/layout.tsx
import { OlusoProvider } from '@oluso/nextjs/client';

export default function RootLayout({ children }: { children: React.ReactNode }) {
  return (
    <html>
      <body>
        <OlusoProvider options={{ apiKey: process.env.NEXT_PUBLIC_OLUSO_API_KEY! }}>
          {children}
        </OlusoProvider>
      </body>
    </html>
  );
}
// app/dashboard/error.tsx
'use client';
import { useOlusoErrorEffect } from '@oluso/nextjs/client';

export default function Error({ error, reset }: { error: Error & { digest?: string }; reset: () => void }) {
  useOlusoErrorEffect(error); // reports once per distinct error, including error.digest
  return (
    <div>
      Something went wrong.
      <button onClick={reset}>Try again</button>
    </div>
  );
}

useOlusoErrorEffect needs an <OlusoProvider> above it in the tree, which rules out global-error.tsx specifically — it replaces the root layout the provider would normally live in. For that file, construct an OlusoClient directly instead:

// app/global-error.tsx
'use client';
import { OlusoClient } from '@oluso/nextjs/client';
import { useEffect } from 'react';

const client = new OlusoClient({ apiKey: process.env.NEXT_PUBLIC_OLUSO_API_KEY! });

export default function GlobalError({ error }: { error: Error & { digest?: string } }) {
  useEffect(() => {
    client.captureException(error);
  }, [error]);

  return (
    <html>
      <body>Something went seriously wrong.</body>
    </html>
  );
}

useOluso() and ErrorBoundary are also re-exported from @oluso/nextjs/client for manual reporting and non-route error boundaries, same as @oluso/react.

Breadcrumbs & User Context (server-side)

oluso.addBreadcrumb/setUserContext/setCustomContext are scoped to the current request when called inside a with* wrapper (via AsyncLocalStorage), so concurrent requests on a self-hosted, long-running Next.js server don't bleed context into each other:

export const POST = withOluso(oluso, async (req) => {
  const user = await getUser(req);
  oluso.setUserContext({ id: user.id });
  oluso.addBreadcrumb({ message: 'checkout started', category: 'action' });

  try {
    await doCheckout();
  } catch (err) {
    oluso.captureException(err, { step: 'checkout' });
    return Response.json({ error: 'checkout failed' }, { status: 500 });
  }

  return Response.json({ ok: true });
});

Advanced Configuration

new Oluso({
  apiKey: 'your-api-key',
  endpoint: 'https://api.oluso.dev/api/v1/error/report', // override for self-hosting
  environment: 'staging',
  defaultSeverity: 'medium',
  maxBreadcrumbs: 50,
  maxErrorsPerMinute: 100,
  sensitiveKeys: ['ssn', 'internal_id'],
  shouldReport: (err) => !err.message.includes('expected'),
});

Process monitors

The same Oluso instance exposes heartbeat(url, options), assertOutcome(options), and workflow(reference, runId?) in route handlers, server actions, instrumentation, and background workers. See the complete monitor guide.

License

MIT