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

@last9/otel-cron

v0.1.0

Published

OTel FaaS-compliant instrumentation for cron job observability

Readme

@last9/otel-cron

Cron jobs have an observability problem. They miss their window, throw unhandled exceptions, or silently stop running — and you find out from users, not alerts. This library fixes that.

Wrap your job function with withCronJob and get OTel FaaS-compliant spans and metrics. No changes to your job logic required.

import { withCronJob } from '@last9/otel-cron';

await withCronJob(
  { name: 'send-digest', cron: '0 8 * * *' },
  async () => {
    await sendDigestEmails();
  }
);

Uses the global OTel API — configure your providers as you normally would and withCronJob picks them up.

Installation

npm install @last9/otel-cron @opentelemetry/sdk-node @opentelemetry/exporter-trace-otlp-http @opentelemetry/exporter-metrics-otlp-http

Peer dependency: @opentelemetry/api ^1.9.0.

Configuration

Set these environment variables before starting your process. Never hardcode them — use .env files locally and your secrets manager in production.

# Where to send telemetry
OTEL_EXPORTER_OTLP_ENDPOINT=https://your-collector:4318

# Auth header — keep this out of source control
OTEL_EXPORTER_OTLP_HEADERS="Authorization=Bearer your-token-here"

# Identifies your service in traces and metrics
OTEL_SERVICE_NAME=my-app

Bootstrap the SDK once at process startup, before any withCronJob calls:

// instrumentation.ts
import { NodeSDK } from '@opentelemetry/sdk-node';
import { OTLPTraceExporter } from '@opentelemetry/exporter-trace-otlp-http';
import { OTLPMetricExporter } from '@opentelemetry/exporter-metrics-otlp-http';
import { PeriodicExportingMetricReader } from '@opentelemetry/sdk-metrics';

const sdk = new NodeSDK({
  traceExporter: new OTLPTraceExporter(),      // reads OTEL_EXPORTER_OTLP_ENDPOINT + HEADERS
  metricReader: new PeriodicExportingMetricReader({
    exporter: new OTLPMetricExporter(),         // same env vars
    exportIntervalMillis: 60_000,
  }),
});

sdk.start();

Run it with --require so it loads before your application code:

node --require ./instrumentation.js your-cron-runner.js

Or with tsx / ts-node:

node --require tsx/cjs --require ./instrumentation.ts your-cron-runner.ts

The OTLP exporters read OTEL_EXPORTER_OTLP_ENDPOINT and OTEL_EXPORTER_OTLP_HEADERS automatically — no URL or auth token in code.

Missed-run alerting

The faas.last_success_time gauge records a Unix timestamp after every successful run. Wire it to a dead-man alert:

time() - faas_last_success_time{faas_name="send-digest"} > 90000

That fires if the daily digest hasn't succeeded in 25 hours — no scheduler integration, no sidecar, no external ping service.

Timeouts

await withCronJob(
  { name: 'generate-report', cron: '0 6 * * *', timeout: 30_000 },
  async () => {
    await generateReport();
  }
);

Exceeding the timeout throws FaaSTimeoutError and increments faas.timeouts rather than faas.errors. Timeouts are a distinct failure mode worth tracking separately. The underlying function keeps running after the error is thrown; use an AbortController if you need hard cancellation.

Signals

| Signal | Type | Description | |--------|------|-------------| | faas.invocations | Counter | Every invocation | | faas.errors | Counter | Non-timeout failures | | faas.timeouts | Counter | Timeout breaches | | faas.invoke_duration | Histogram (seconds) | Wall-clock duration | | faas.last_success_time | ObservableGauge (Unix s) | Timestamp of last success | | Span | SERVER · faas.trigger=timer | FaaS semantic convention |

Options

| Option | Type | Required | Description | |--------|------|----------|-------------| | name | string | Yes | Job identifier. Becomes faas.name on every signal. | | cron | string | Yes | Cron expression, emitted as faas.cron on the span. | | timeout | number | No | Deadline in milliseconds. |

Notes

State is keyed on globalThis under Symbol.for('@last9/otel-cron/state'). Two copies of this package in the same process share state — the right behavior in monorepos. Run npm dedupe if you see duplicate metric registrations.

OTel API v1 only (^1.9.0). v2 compatibility requires a new major.