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

cloudflare-worker-metrics

v1.4.0

Published

Lightweight metrics collection for Cloudflare Workers

Readme

cloudflare-worker-metrics

Lightweight metrics collection for Cloudflare Workers.

Metrics are aggregated during invocation and then finally flushed via logs. The cloudflare-worker-metrics-exporter then reads those logs and emits them to an OTEL endpoint.

Usage

import { metrics } from 'cloudflare-worker-metrics';

export default {
  async fetch(request, env, ctx) {
    metrics.count('http_requests', 1, { method: request.method });
    metrics.gauge('connections_active', getActiveCount());
    metrics.histogram('response_duration', elapsed, { endpoint: '/api' });

    const response = await handleRequest(request);
    metrics.flush();
    return response;
  },
};

Type-safe usage

Define a registry of metric names and their tag shapes, then create a typed metrics instance:

import { createMetrics } from 'cloudflare-worker-metrics';

type MyMetrics = {
  http_request_count: { method: string; route: string }
  http_response_duration_ms: { method: string; route: string; status: number }
  db_query_duration_ms: { operation: string; table: string }
}

const metrics = createMetrics<MyMetrics>({
  globalTags: { build_version: '1.0.0' },
});

metrics.count('http_request_count', 1, { method: 'GET', route: '/api/health' });
metrics.histogram('http_response_duration_ms', 42, { method: 'GET', route: '/api/health', status: 200 });
metrics.flush();

createMetrics<T>(options?)

Create a typed metrics instance. T maps metric names to their expected tag shapes. Only registered names are accepted and tags are type-checked per metric.

Options:

  • globalTags — tags automatically merged into every emission (metric-specific tags take precedence).

API

metrics.count(name, value?, tags?)

Increment a counter. Values with the same name+tags are summed.

metrics.gauge(name, value, tags?)

Set a gauge. Last write wins for the same name+tags.

metrics.histogram(name, value, tags?)

Record a histogram observation. Each call emits a raw histogram entry.

metrics.flush()

Flush all metrics to console.log as cwm- prefixed JSON. Auto-splits at 250 KiB.