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

@dstny/scp-metrics

v0.1.0

Published

Standalone OpenTelemetry Metrics SDK

Readme

@dstny/scp-metrics

Standalone wrapper around the OpenTelemetry Metrics SDK for OTLP/HTTP export to Alloy → Prometheus.

Adds one thing the raw OTel JS API doesn't give you: a compile-time label schema per metric, so every call site for a given metric name is forced to pass the exact same label shape.

Usage

import { ScpMetrics } from '@dstny/scp-metrics'

const scpMetrics = new ScpMetrics()

await scpMetrics.init({
  url: 'https://alloy.example.com/v1/metrics',
  token: accessToken,
  resourceAttributes: { 'service.name': 'ScpSdk', 'service.version': '1.2.3' },
  // Delays the very first export by rand(0, 5s) so a mass reconnect (deploy, outage
  // recovery) doesn't make every client hit the collector at once. Defaults to true.
  initialJitter: true,
})

// Labels type is declared once and enforced at every call site.
const requestCount = scpMetrics.defineCounter<{ method: string }>('http_requests_total')
requestCount.add(1, { method: 'GET' })
// requestCount.add(1)                          // compile error: missing labels
// requestCount.add(1, { method: 'GET', x: 1 }) // compile error: excess label key

const requestDuration = scpMetrics.defineHistogram<{ status: 'success' | 'failure' }>(
  'http_request_duration_ms'
)
requestDuration.record(842, { status: 'success' })

On token refresh or logout, call scpMetrics.setToken(newToken) / scpMetrics.shutdown() - both rebind that instance's MeterProvider live, no page reload needed.

Design notes

  • No shared/global state: each new ScpMetrics() instance owns its own MeterProvider and instrument handles, so independent instances never contend for the same pipeline. This is deliberate rather than an oversight - @opentelemetry/api's own global meter-provider registry only supports one registered provider per process, so this package bypasses it entirely and holds a local MeterProvider reference per instance instead. In practice this means different consumers (or the same consumer reporting to different destinations) can each construct their own instance and init() it with its own url/token, and they will never observe or interfere with each other's metrics.
  • initialJitter (default on) delays the very first export by rand(0, 5s) so a mass reconnect (deploy, outage recovery) doesn't make every client hit the collector at once.
  • Export is purely interval-driven: a PeriodicExportingMetricReader samples current instrument state on a fixed ~5s clock, independent of whether anything changed. Required for Prometheus rate()/staleness semantics, and keeps request volume bounded by the clock tick rather than by how many/how often instruments are updated.
  • Keep label attributes low-cardinality - see the linked Prometheus naming docs. A runtime check in registry.ts warns (never throws) if the same metric name is later recorded with a different label key set, since that's a real Prometheus problem TS generics alone can't catch across separately-compiled call sites. This check is process-wide (not per-instance): it's a cheap dev-time safety net for divergent defineX<...>() declarations, not part of the actual metrics export path, so it doesn't reintroduce cross-instance coupling.