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

@prifina-dev/next-telemetry

v1.0.17

Published

Lightweight telemetry library for Next.js App Router applications.

Readme

next-telemetry

Lightweight telemetry library for Next.js App Router applications.

Installation

Copy this library to your Next.js project or use as a local package.

Quick Start

1. Environment Variables

Add to .env.local:

NEXT_PUBLIC_TELEMETRY_ENABLED=true
NEXT_PUBLIC_TELEMETRY_API_URL=http://localhost:4000
NEXT_PUBLIC_TELEMETRY_APP_NAME=my-app
NEXT_PUBLIC_TELEMETRY_ENV=dev

2. Browser Setup

In your Next.js app, update app/layout.js to initialize telemetry:

import { TelemetryProvider } from "./telemetry-provider";

export default function RootLayout({ children }) {
  return (
    <html>
      <body>
        <TelemetryProvider>{children}</TelemetryProvider>
      </body>
    </html>
  );
}

Create app/telemetry-provider.js in your app:

"use client";
import { initBrowserTelemetry, TelemetryErrorBoundary } from "next-telemetry/client";
import { useEffect } from "react";

export function TelemetryProvider({ children }) {
  useEffect(() => {
    initBrowserTelemetry();
  }, []);
  
  return <TelemetryErrorBoundary>{children}</TelemetryErrorBoundary>;
}

3. API Route Handler (app/api/*/route.js)

Wrap API route handlers to capture server-side errors:

import { withTelemetryRoute } from "next-telemetry/server";

export const GET = withTelemetryRoute(async (req) => {
  // Your API logic here
  return Response.json({ data: "success" });
});

export const POST = withTelemetryRoute(async (req) => {
  const body = await req.json();
  // Your logic
  return Response.json({ success: true });
});

4. Client-Side Error Capture

Browser errors are automatically captured by initBrowserTelemetry() and TelemetryErrorBoundary.

For manual capture (e.g., in your authFetch() wrapper):

import { captureException } from "next-telemetry";

export async function authFetch(url, options) {
  try {
    const response = await fetch(url, {
      ...options,
      headers: { ...options?.headers, Authorization: `Bearer ${token}` }
    });
    
    if (!response.ok) {
      const error = new Error(`HTTP ${response.status}`);
      captureException(error, {
        extra: { url, status: response.status, method: options?.method }
      });
      throw error;
    }
    
    return response;
  } catch (error) {
    captureException(error, { extra: { url } });
    throw error;
  }
}

API Reference

Client Functions

  • initBrowserTelemetry(opts) - Initialize browser error capture (call once on mount)
  • TelemetryErrorBoundary - React Error Boundary component
  • captureException(error, context) - Manual error capture (use in try/catch blocks)

Server Functions

  • withTelemetryRoute(handler, opts) - Wrap API route handlers
  • captureException(error, context) - Manual error capture

Configuration

Environment variables (use NEXT_PUBLIC_ prefix for browser access):

  • TELEMETRY_ENABLED - Enable/disable telemetry
  • TELEMETRY_API_URL - Telemetry API endpoint
  • TELEMETRY_APP_NAME - Application name
  • TELEMETRY_ENV - Environment (dev/staging/prod)
  • TELEMETRY_RELEASE - Release version (optional)
  • TELEMETRY_APP_DIRS - Comma-separated app directories (default: app,src,lib,components)
  • TELEMETRY_IGNORE_PATTERNS - Comma-separated ignore patterns (default: node_modules,next/dist,react-dom,internal)

Copy Rule File to Your App

Copy TELEMETRY_RULES.md to your Next.js app's .amazonq/rules/ directory:

cp TELEMETRY_RULES.md /path/to/your-nextjs-app/.amazonq/rules/telemetry.md

This helps Amazon Q understand how to use the telemetry library in your project.