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

@narrativetrace/hono

v0.2.0

Published

Hono middleware that opens a per-request trace and reports on completion, even when the handler throws

Readme

@narrativetrace/hono

Hono middleware (edge/serverless friendly) that opens a per-request NarrativeTrace context and fires a completion callback in a finally, so it runs even when the handler throws.

Install

pnpm add @narrativetrace/hono @narrativetrace/core @narrativetrace/observability hono

@narrativetrace/core, @narrativetrace/observability, and hono (>=4.0) are peer dependencies. You typically also want a context implementation such as AsyncNarrativeContext from @narrativetrace/core-node.

Usage

import { AsyncNarrativeContext, NarrativeTraceConfig } from "@narrativetrace/core-node";
import { narrativeTrace, getNarrativeContext } from "@narrativetrace/hono";
import { traceObject } from "@narrativetrace/proxy";
import { Hono } from "hono";

const ctx = new AsyncNarrativeContext(new NarrativeTraceConfig("detail"));
const app = new Hono();

app.use(
  "*",
  narrativeTrace(ctx, {
    // Skip health checks and static assets — no context or log scope is created.
    excludedPaths: ["/health"],
    // Fires in a finally with the response status code and request duration.
    onRequestComplete: (c, ctx, { statusCode, durationMs }) => {
      console.log(c.req.path, statusCode, durationMs, ctx.captureTrace());
    },
  }),
);

app.get("/hello/:name", (c) => {
  const svc = traceObject(new GreetingService(), getNarrativeContext(c) ?? ctx);
  return c.json({ message: svc.greet(c.req.param("name")) });
});

narrativeTrace also accepts extractRequest and extractUser overrides; a throwing extractor or callback never fails the request. Use getNarrativeContext(c) to reach the active context inside a handler.

clientIp

The default extractor never trusts the x-forwarded-for header — it is caller-controlled end to end, and Hono's base package has no runtime-agnostic notion of a trusted proxy hop count the way Express's req.ip does (via its trust proxy setting). clientIp is "unknown" unless you opt in.

If you have a getConnInfo for your deployment target (hono/deno, hono/bun, hono/cloudflare-workers, @hono/node-server/conninfo for Node, etc.) and it reports the real peer address for your setup, wire it in with withConnInfoClientIp:

import { getConnInfo } from "@hono/node-server/conninfo"; // pick the helper for your runtime
import { narrativeTrace, withConnInfoClientIp } from "@narrativetrace/hono";

app.use(narrativeTrace(ctx, { extractRequest: withConnInfoClientIp(getConnInfo) }));

If you're behind a reverse proxy you control and know the trusted hop count, resolve clientIp yourself in a custom extractRequest — this package deliberately ships no x-forwarded-for trust-boundary parser.

Learn more