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

@shipfox/node-opentelemetry

v0.4.1

Published

Opinionated OpenTelemetry setup for Node services with:

Readme

Shipfox OpenTelemetry

Opinionated OpenTelemetry setup for Node services with:

  • One-call initialization (traces + instance Prometheus metrics)
  • A separate provider for service-level Prometheus metrics
  • Sensible defaults and environment-based config

It should be used with other packages from Shipfox.

What it does

  • startInstanceInstrumentation(options): Boots a NodeSDK with auto-instrumentations, Fastify instrumentation, Prometheus metrics reader, and optional OTLP trace exporter.
  • getFastifyInstrumentation(): Access the Fastify instrumentation instance created during startup.
  • startServiceMetrics(options?): Creates a standalone MeterProvider for custom service metrics with its own Prometheus reader.
  • getServiceMetricsProvider(): Returns the service metrics provider (creates one if missing).
  • instanceMetrics: Re-export of @opentelemetry/api metrics for convenience.
  • shutdownInstrumentation(): Gracefully shuts down instance and service metrics.

Environment variables (via @shipfox/config):

  • OTEL_SERVICE_NAME (optional if you pass serviceName in code)
  • TRACES_COLLECTOR_URL (optional; if set, enables OTLP trace export over HTTP)

Exported ports and endpoints (defaults):

  • Instance metrics: :9464/metrics
  • Service metrics: :9474/metrics

Installation

pnpm add @shipfox/node-opentelemetry
# or
yarn add @shipfox/node-opentelemetry
# or
npm install @shipfox/node-opentelemetry

Quick start

import {
  startInstanceInstrumentation,
  shutdownInstrumentation,
  instanceMetrics,
} from "@shipfox/node-opentelemetry";

// Start as early as possible in your process
startInstanceInstrumentation({
  serviceName: "billing-api", // falls back to OTEL_SERVICE_NAME if omitted
  exporter: {
    instance: { port: 9464, endpoint: "/metrics" },
    service: { port: 9474, endpoint: "/metrics" },
  },
});

// Optionally expose a health handler and ensure graceful shutdown
process.on("SIGTERM", async () => {
  await shutdownInstrumentation();
  process.exit(0);
});

// You can still access the global API directly when creating metrics on the instance provider
const meter = instanceMetrics.getMeter("billing-api");
const requestCounter = meter.createCounter("http_requests_total");

function onRequestHandled() {
  requestCounter.add(1, { route: "/invoices", method: "GET" });
}

Service-level custom metrics

Use a dedicated provider (separate port) for application-specific metrics:

import { getServiceMetricsProvider } from "@shipfox/node-opentelemetry";

const provider = getServiceMetricsProvider();
const meter = provider.getMeter("billing-service");

const queueDepth = meter.createObservableGauge("queue_depth");
meter.addBatchObservableCallback((observableResult) => {
  observableResult.observe(queueDepth, 42, { queue: "invoices" });
});

Traces (OTLP over HTTP)

If TRACES_COLLECTOR_URL is set (e.g., to an OTLP endpoint like http://otel-collector:4318/v1/traces), the instance instrumentation will export traces via the OTLP HTTP exporter. Leave it unset to disable trace exporting.

Configuration via environment

export OTEL_SERVICE_NAME="billing-api"
# Enable OTLP HTTP traces export (optional)
export TRACES_COLLECTOR_URL="http://otel-collector:4318/v1/traces"
# Prometheus endpoints can be adjusted in code via start options