Skip to content

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

Merged
petebacondarwin merged 6 commits intomainfrom
pbacondarwin/replace-promjs-with-metrics-registry
Mar 22, 2026
Merged

[workers-utils] Replace deprecated promjs with MetricsRegistry#12753
petebacondarwin merged 6 commits intomainfrom
pbacondarwin/replace-promjs-with-metrics-registry

Conversation

@petebacondarwin
Copy link
Copy Markdown
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
Copy Markdown

changeset-bot bot commented Mar 4, 2026

🦋 Changeset detected

Latest commit: 11a97bd

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
Copy Markdown
Contributor

github-actions bot commented Mar 4, 2026

✅ All changesets look good

@pkg-pr-new
Copy link
Copy Markdown

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: 11a97bd

@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
Copy Markdown
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
Copy Markdown
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

@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.
@petebacondarwin
Copy link
Copy Markdown
Contributor Author

Blocked on #12791

@petebacondarwin petebacondarwin added blocked Blocked on other work and removed blocked Blocked on other work labels Mar 6, 2026
@petebacondarwin petebacondarwin force-pushed the pbacondarwin/replace-promjs-with-metrics-registry branch 2 times, most recently from 5ebbdc4 to 07f0772 Compare March 11, 2026 09:53
@workers-devprod
Copy link
Copy Markdown
Contributor

workers-devprod commented Mar 11, 2026

Codeowners approval required for this PR:

  • ✅ @cloudflare/wrangler
Show detailed file reviewers

Copy link
Copy Markdown
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 found 2 new potential issues.

⚠️ 2 issues in files not directly in the diff

⚠️ Incomplete migration: format-errors test file still mocks removed promjs dependency (packages/format-errors/src/__tests__/index.test.ts:5-12)

The PR removed promjs from packages/format-errors/package.json and migrated the source code (packages/format-errors/src/index.ts:1) to use @cloudflare/workers-utils/metrics, but the test file was not updated. It still contains vi.mock("promjs", ...) which mocks a module that no longer exists in the dependency tree. While this dead mock doesn't cause an immediate test failure (since the tested functions don't exercise the default export's metrics path), it's an incomplete mechanical transformation — the analogous cleanup was correctly done for edge-preview-authenticated-proxy (its vitest config was updated) but missed here.


⚠️ Incomplete migration: format-errors vitest.config.mts still has promjs alias pointing to non-existent path (packages/format-errors/vitest.config.mts:11-18)

The PR removed promjs from packages/format-errors/package.json but did not update packages/format-errors/vitest.config.mts, which still contains a resolve alias mapping promjs to node_modules/promjs/index.js (line 16). Since promjs is no longer installed, this path doesn't exist. The analogous cleanup was correctly performed for packages/edge-preview-authenticated-proxy/vitest.config.mts (which had the same alias removed in this PR), but was missed for format-errors. While this dead alias doesn't currently cause a test failure (nothing imports promjs anymore), it's stale configuration that should be cleaned up as part of this migration.

View 7 additional findings in Devin Review.

Open in Devin Review

@petebacondarwin petebacondarwin force-pushed the pbacondarwin/replace-promjs-with-metrics-registry branch from 07f0772 to 68e5f27 Compare March 11, 2026 14:09
Copy link
Copy Markdown
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 found 2 new potential issues.

⚠️ 2 issues in files not directly in the diff

⚠️ Incomplete migration: format-errors test file still mocks removed promjs dependency (packages/format-errors/src/__tests__/index.test.ts:5-12)

The PR removed promjs from packages/format-errors/package.json and migrated the source code (packages/format-errors/src/index.ts:1) to use @cloudflare/workers-utils/metrics, but the test file was not updated. It still contains vi.mock("promjs", ...) which mocks a module that no longer exists in the dependency tree. While this dead mock doesn't cause an immediate test failure (since the tested functions don't exercise the default export's metrics path), it's an incomplete mechanical transformation — the analogous cleanup was correctly done for edge-preview-authenticated-proxy (its vitest config was updated) but missed here.


⚠️ Incomplete migration: format-errors vitest.config.mts still has promjs alias pointing to non-existent path (packages/format-errors/vitest.config.mts:11-18)

The PR removed promjs from packages/format-errors/package.json but did not update packages/format-errors/vitest.config.mts, which still contains a resolve alias mapping promjs to node_modules/promjs/index.js (line 16). Since promjs is no longer installed, this path doesn't exist. The analogous cleanup was correctly performed for packages/edge-preview-authenticated-proxy/vitest.config.mts (which had the same alias removed in this PR), but was missed for format-errors. While this dead alias doesn't currently cause a test failure (nothing imports promjs anymore), it's stale configuration that should be cleaned up as part of this migration.

View 7 additional findings in Devin Review.

Open in Devin Review

@github-project-automation github-project-automation bot moved this from Untriaged to Approved in workers-sdk Mar 11, 2026
devin-ai-integration[bot]

This comment was marked as resolved.

Copy link
Copy Markdown
Member

@dario-piotrowicz dario-piotrowicz left a comment

Choose a reason for hiding this comment

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

Looks good to me, however I'd suggest not to use generic names as /metrics and MetricsRegistry but instead have names that clearly convey that these are Prometheus specific. Such as /prometheus-metrics and PrometheusMetricsRegistry for example

Comment thread packages/workers-utils/tests/prometheus-metrics.test.ts
Comment thread packages/workers-utils/tests/prometheus-metrics.test.ts
@petebacondarwin petebacondarwin force-pushed the pbacondarwin/replace-promjs-with-metrics-registry branch 2 times, most recently from de29014 to e6ad9d4 Compare March 13, 2026 18:13
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 e6ad9d4 to 11a97bd Compare March 21, 2026 16:10
@workers-devprod
Copy link
Copy Markdown
Contributor

Codeowners approval required for this PR:

  • ✅ @cloudflare/wrangler
Show detailed file reviewers

@petebacondarwin petebacondarwin merged commit ea8b1a4 into main Mar 22, 2026
47 of 48 checks passed
@petebacondarwin petebacondarwin deleted the pbacondarwin/replace-promjs-with-metrics-registry branch March 22, 2026 14:50
@github-project-automation github-project-automation bot moved this from Approved to Done in workers-sdk Mar 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

4 participants