Skip to content

[workers-utils] Replace deprecated promjs with MetricsRegistry#12753

Open
petebacondarwin wants to merge 2 commits intomainfrom
pbacondarwin/replace-promjs-with-metrics-registry
Open

[workers-utils] Replace deprecated promjs with MetricsRegistry#12753
petebacondarwin wants to merge 2 commits intomainfrom
pbacondarwin/replace-promjs-with-metrics-registry

Conversation

@petebacondarwin
Copy link
Contributor

@petebacondarwin petebacondarwin commented Mar 4, 2026

Replace the deprecated and unmaintained promjs library with a lightweight MetricsRegistry class in @cloudflare/workers-utils/metrics.

promjs has been unmaintained for 3+ years, has a broken package.json (the main field points to a non-existent lib/ directory, requiring a vitest alias workaround), and is used in the most trivial way possible: just counters with no labels, always value 1, pushed per-request to a Prometheus gateway.

What changed:

  • Added MetricsRegistry class to @cloudflare/workers-utils/metrics that produces byte-identical Prometheus text exposition format for counter metrics (~80 lines including docs)
  • Added comprehensive test suite (35 tests) including cases ported from the original promjs test suite with attribution
  • Updated edge-preview-authenticated-proxy, playground-preview-worker, and format-errors to use the new MetricsRegistry
  • Removed promjs from all package.json files
  • Removed the vitest resolve alias workaround that was needed for promjs's broken package.json
  • Fixed format-errors tsconfig moduleResolution from "node" to "bundler" to support subpath exports

The metrics utility is exposed as a separate subpath export (@cloudflare/workers-utils/metrics) which produces a tiny 160-byte standalone module, ensuring compatibility with vitest-pool-workers/workerd's SSR module resolution.


  • Tests
    • Tests included/updated
    • Automated tests not possible - manual testing has been completed as follows:
    • Additional testing not necessary because:
  • Public documentation
    • Cloudflare docs PR(s):
    • Documentation not necessary because: internal refactoring, no user-facing changes

Open with Devin

@changeset-bot
Copy link

changeset-bot bot commented Mar 4, 2026

🦋 Changeset detected

Latest commit: 8429f12

The changes in this PR will be included in the next version bump.

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actions
Copy link
Contributor

github-actions bot commented Mar 4, 2026

✅ All changesets look good

@pkg-pr-new
Copy link

pkg-pr-new bot commented Mar 4, 2026

create-cloudflare

npm i https://pkg.pr.new/create-cloudflare@12753

@cloudflare/kv-asset-handler

npm i https://pkg.pr.new/@cloudflare/kv-asset-handler@12753

miniflare

npm i https://pkg.pr.new/miniflare@12753

@cloudflare/pages-shared

npm i https://pkg.pr.new/@cloudflare/pages-shared@12753

@cloudflare/unenv-preset

npm i https://pkg.pr.new/@cloudflare/unenv-preset@12753

@cloudflare/vite-plugin

npm i https://pkg.pr.new/@cloudflare/vite-plugin@12753

@cloudflare/vitest-pool-workers

npm i https://pkg.pr.new/@cloudflare/vitest-pool-workers@12753

@cloudflare/workers-editor-shared

npm i https://pkg.pr.new/@cloudflare/workers-editor-shared@12753

wrangler

npm i https://pkg.pr.new/wrangler@12753

commit: 5e79a55

@petebacondarwin petebacondarwin marked this pull request as ready for review March 4, 2026 13:49
@petebacondarwin petebacondarwin requested a review from a team as a code owner March 4, 2026 13:49
@workers-devprod
Copy link
Contributor

Codeowners approval required for this PR:

  • @cloudflare/wrangler
Show detailed file reviewers
  • packages/edge-preview-authenticated-proxy/package.json: [@cloudflare/wrangler]
  • packages/edge-preview-authenticated-proxy/src/index.ts: [@cloudflare/wrangler]
  • packages/edge-preview-authenticated-proxy/vitest.config.mts: [@cloudflare/wrangler]
  • packages/format-errors/package.json: [@cloudflare/wrangler]
  • packages/format-errors/src/index.ts: [@cloudflare/wrangler]
  • packages/format-errors/tsconfig.json: [@cloudflare/wrangler]
  • packages/playground-preview-worker/package.json: [@cloudflare/wrangler]
  • packages/playground-preview-worker/src/index.ts: [@cloudflare/wrangler]
  • packages/workers-utils/package.json: [@cloudflare/wrangler]
  • packages/workers-utils/src/index.ts: [@cloudflare/wrangler]
  • packages/workers-utils/src/metrics.ts: [@cloudflare/wrangler]
  • packages/workers-utils/tests/metrics.test.ts: [@cloudflare/wrangler]
  • packages/workers-utils/tsup.config.ts: [@cloudflare/wrangler]
  • pnpm-lock.yaml: [@cloudflare/wrangler]

Copy link
Contributor

@devin-ai-integration devin-ai-integration bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no potential bugs to report.

View in Devin Review to see 4 additional findings.

Open in Devin Review

Replace the deprecated and unmaintained promjs library (broken package.json,
no updates since 2022) with a lightweight MetricsRegistry class in
@cloudflare/workers-utils/metrics.

- Add MetricsRegistry class that produces byte-identical Prometheus text
  exposition format for counter metrics
- Add comprehensive test suite (35 tests) including cases ported from the
  original promjs test suite
- Update edge-preview-authenticated-proxy, playground-preview-worker, and
  format-errors to use the new MetricsRegistry
- Remove promjs from all package.json files
- Remove the vitest alias workaround for promjs broken package.json
- Fix format-errors tsconfig moduleResolution to support subpath exports
@petebacondarwin petebacondarwin force-pushed the pbacondarwin/replace-promjs-with-metrics-registry branch from 0c86431 to b88af36 Compare March 4, 2026 13:52
wsimon1982 pushed a commit to wsimon1982/workers-sdk that referenced this pull request Mar 4, 2026
…sue cloudflare#12753 to replace a deprecated library with a lightweight, maintained solution.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Untriaged

Development

Successfully merging this pull request may close these issues.

2 participants