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

hono-middleware-tracer

v1.1.3

Published

OpenTelemetry instrumentation package producing traces for hono middlewares

Downloads

27

Readme

hono-middleware-tracer

OpenTelemetry instrumentation that generates spans for every Hono middleware and handler.

npm OpenTelemetry Hono


Overview

hono-middleware-tracer wraps every middleware and handler in your Hono app with an OpenTelemetry span, giving you granular visibility into where time is spent across your request lifecycle.

[!IMPORTANT] This library requires @hono/otel. Without it, no spans will be produced — the library expects a parent trace that @hono/otel provides.


Generated traces

A span is created for every middleware or handler (supports the .get, .post, .patch, .put, .delete, .use, and onError). Given a server like this:

import { httpInstrumentationMiddleware } from "@hono/otel";
import { Hono } from "hono";

function sleep(ms: number) {
  return new Promise<void>((resolve) => setTimeout(resolve, ms));
}

const app = new Hono();
app.use(httpInstrumentationMiddleware());

app.use(async function someMiddlewarePassedToUse(_c, next) {
  await sleep(1000);
  const resp = await next();
  await sleep(2000);
  return resp;
});

app.get(
  "/foo",
  async function someMiddleware(_c, next) {
    await sleep(1000);
    const resp = await next();
    await sleep(2000);
    return resp;
  },
  // This will be traced as "anonymous"
  async (_c, next) => {
    await sleep(500);
    return next();
  },
  async function someHandler(c) {
    await sleep(1000);
    return c.json("bar", 200);
  },
);

The resulting trace looks like this (visualized with Grafana Tempo):

Screenshot of Grafana Tempo showcasing the generated spans

onError support

The Hono onError handler is also instrumented, with a fallback span name of errorHandler.

Span attributes

| Attribute | Description | |-----------|-------------| | hono.middleware.duration_millis.pre | Time in ms the handler/middleware spent before calling next | | hono.middleware.duration_millis.post | Time in ms spent after calling next. This is 0 for handlers that returned or threw without calling next |


Usage

Manual instrumentation

import { HonoMiddlewareTracer } from "hono-middleware-tracer";
import { NodeSDK } from "@opentelemetry/sdk-node";

const sdk = new NodeSDK({
  // ...
  instrumentations: [
    // ...
    new HonoMiddlewareTracer({ /* options */ }),
  ],
});

sdk.start();

No-code instrumentation

Recommended when using OTEL zero-code instrumentation. Preload the hono-middleware-tracer/register script with --require or --import:

node \
  --require @opentelemetry/auto-instrumentations-node/register \
  --require hono-middleware-tracer/register \
  ./dist/index.js

Works with tsx as well:

tsx \
  --require @opentelemetry/auto-instrumentations-node/register \
  --require hono-middleware-tracer/register \
  ./src/index.ts

Config

fallbackSpanName

Type: string | Default: "anonymous"

The span name used when a middleware function has no name (i.e. anonymous arrow functions). Named functions use their function name automatically.

new HonoMiddlewareTracer({
  fallbackSpanName: "unnamed",
})

Roadmap

  • [ ] Support @hono/zod-openapi
  • [ ] Support hono/factory