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

@bonniernews/exp-metrics

v4.0.0

Published

Simple bootstrapping of basic prometheus metrics for your express based application.

Readme

exp-metrics

Run tests

Simple wrapper of OpenTelemetry metrics with the same API as prom-client, to make the transition from prom-client easy, and also add functionality that OpenTelemetry lacks.

Types of metrics and API

  • Counter
    • inc([labels,] [value])
  • Gauge
    • set([labels,] value)
    • inc([labels,] [value])
    • dec([labels,] [value])
  • Summary (histogram in OpenTelemetry terms)
    • observe([labels,] value) or observe(value[, labels])

Creating a metric with a name that already exists returns the existing metric, so metrics.counter({ name: "x" }) is safe to call per request.

A gauge keeps one value per label set, i.e. gauge.set({ queue: "a" }, 1) and gauge.set({ queue: "b" }, 2) are reported as two series.

Installing

npm install @bonniernews/exp-metrics

Usage

const expMetrics = require("@bonniernews/exp-metrics");

metrics = expMetrics("my-service-name", {
  // optional overrides, see more below
});

const myCounter = metrics.counter({
  name: "my_counter",
  help: "My counter",
})

myCounter.inc(2);
myCounter.inc({ foo: "bar" }, 3);

See more in the prom-client documentation.

TypeScript types are included.

Options

  • enabled (default true): false keeps the same API but exports nothing and never calls Google Cloud, e.g. for tests and local development
  • buckets: explicit histogram buckets for every summary, see Histogram buckets

Any other key is set as an OpenTelemetry resource attribute, overriding the defaults (gcp.project_id, service.name, service.namespace, service.instance.id). See the OpenTelemetry documentation.

Histogram buckets

Summaries are exported as exponential histograms by default. They have fine resolution per series, but every series picks its own bucket layout, so percentiles aggregated across series (e.g. p95 over all instances) in Cloud Monitoring can be very coarse.

Explicit buckets give every series the same layout, so they aggregate exactly, with a precision of the bucket width:

// one summary
metrics.summary({ name: "my_summary", buckets: [ 10, 50, 100, 250, 500, 1000 ] });

// every summary, including http_response_time_milliseconds
// true = OpenTelemetry defaults [ 0, 5, 10, 25, 50, 75, 100, 250, 500, 750, 1000, 2500, 5000, 7500, 10000 ]
expMetrics("my-service-name", { buckets: true });
expMetrics("my-service-name", { buckets: [ 10, 50, 100, 250, 500, 1000 ] });

Summaries with their own buckets are exported with the instrumentation scope exp-metrics-buckets instead of exp-metrics.

Shutdown

Metrics are exported every 60 seconds. Flush the remaining metrics before the process exits:

process.on("SIGTERM", async () => {
  await metrics.shutdown();
  process.exit(0);
});

Google Cloud

Metrics are exported every 60 seconds over OTLP to the Google Cloud Telemetry API, authenticated with Application Default Credentials. The project is resolved from the credentials (or GOOGLE_CLOUD_PROJECT), and can be overridden with "gcp.project_id" in the config.

Requirements:

  • The Telemetry API is enabled: gcloud services enable telemetry.googleapis.com
  • The service account has the roles/telemetry.writer role

Metrics show up in Cloud Monitoring as prometheus.googleapis.com/<name>/<counter|gauge|histogram> on the prometheus_target resource, e.g. prometheus.googleapis.com/http_responses_total/counter.