Nothing consumes the lifecycle stream but the logger — every user writes the same collector #68

Closed
opened 2026-08-20 17:53:20 +00:00 by chrnx · 1 comment
Owner

The lifecycle stream landed in 26.8.0-beta.1 and is genuinely enough to build on. But there is nothing to build with, so every user who wants metrics writes the same collector, and each one gets to make the same mistakes independently.

What exists today

createApp({ logRequests: true }) writes lines. That is the only consumer core ships. For anything a dashboard reads, a user subscribes to app.bus and writes it themselves.

That was a deliberate call and it should stand — core keeps one runtime dependency, and a metrics registry is not it. The changelog says so:

No metrics registry and no OpenTelemetry exporter in core — those live outside it.

"Outside it" is currently nowhere.

What writing one actually costs

I wrote a Prometheus exporter for the green-desk demo: ~80 lines, zero dependencies, bus.on plus a provider node registered through scope.add. The stream carried everything it needed. Three things went wrong on the first pass, and none of them are exotic:

  1. Counted request:end and request:failed and route:unmatched → every failed request counted twice, the second time under an invented 500. (#64)
  2. Emitted the duration summary once per status → duplicate time series in one scrape, which Prometheus rejects outright.
  3. Had to decide what to label an unmatched route with, given that the event carries only the concrete path. (#65)

Every user writing this hits all three. Two of them are silent — the metrics simply lie.

Scope

A separate package, e.g. @green-tea/metrics, so core's dependency count does not move:

  • a Prometheus collector over request:end / request:failed, with a route handler for the scrape;
  • histogram buckets rather than the sum/count summary a hand-rolled version stops at;
  • an OTLP exporter as a second entry point — traceparent is already carried verbatim through the payload, so the hook exists and nothing in core has to change to support it;
  • stream:open / stream:close and boot:provider:* too, which a hand-rolled collector never bothers with and which are exactly what says whether SSE clients are piling up.

The demo's version is a working reference for the first item, mistakes and all: yt-demos/green-tea/src/observability/metrics.plugin.ts, with check-metrics.mjs asserting the counting.

Related

Depends on nothing; #64 and #65 would make the collector simpler and are worth doing first either way.

The lifecycle stream landed in `26.8.0-beta.1` and is genuinely enough to build on. But there is nothing to build *with*, so every user who wants metrics writes the same collector, and each one gets to make the same mistakes independently. ## What exists today `createApp({ logRequests: true })` writes lines. That is the only consumer core ships. For anything a dashboard reads, a user subscribes to `app.bus` and writes it themselves. That was a deliberate call and it should stand — core keeps one runtime dependency, and a metrics registry is not it. The changelog says so: > No metrics registry and no OpenTelemetry exporter in core — those live outside it. **"Outside it" is currently nowhere.** ## What writing one actually costs I wrote a Prometheus exporter for the `green-desk` demo: ~80 lines, zero dependencies, `bus.on` plus a provider node registered through `scope.add`. The stream carried everything it needed. Three things went wrong on the first pass, and none of them are exotic: 1. Counted `request:end` *and* `request:failed` *and* `route:unmatched` → every failed request counted twice, the second time under an invented `500`. (#64) 2. Emitted the duration summary once per status → duplicate time series in one scrape, which Prometheus rejects outright. 3. Had to decide what to label an unmatched route with, given that the event carries only the concrete path. (#65) Every user writing this hits all three. Two of them are silent — the metrics simply lie. ## Scope A separate package, e.g. `@green-tea/metrics`, so core's dependency count does not move: - a Prometheus collector over `request:end` / `request:failed`, with a route handler for the scrape; - histogram buckets rather than the sum/count summary a hand-rolled version stops at; - an OTLP exporter as a second entry point — `traceparent` is already carried verbatim through the payload, so the hook exists and nothing in core has to change to support it; - `stream:open` / `stream:close` and `boot:provider:*` too, which a hand-rolled collector never bothers with and which are exactly what says whether SSE clients are piling up. The demo's version is a working reference for the first item, mistakes and all: `yt-demos/green-tea/src/observability/metrics.plugin.ts`, with `check-metrics.mjs` asserting the counting. ## Related Depends on nothing; #64 and #65 would make the collector simpler and are worth doing first either way.
Author
Owner

Closed by @green-tea/metrics, in the new Green-Tea/plugins repo (plugins#2, merged to develop). "Outside it" is no longer nowhere, and core's dependency count did not move.

What shipped is the first scope bullet: a Prometheus collector over request:end / request:failed, plus a prometheus transformer rather than a route — the path, the auth and whether the endpoint exists at all stay the application's decisions.

The three first-pass mistakes this issue documented are what the package is built around, and each has a test:

  1. Double counting. request:end is the request counter and nothing else is — it is terminal and universal, and request:failed fires in addition to it for the same request. request:failed increments a separate error counter. (#64)
  2. Duplicate time series. Duration accumulates per route + method only; status is a label on the request counter alone, so one scrape carries one duration series per route.
  3. Unbounded labels. Labels come from route, never name — route is bounded by the route table, name is built from the path that arrived and is bounded by nothing. An event carrying no route gets <unknown>, deliberately distinct from core's <unmatched>, which asserts a different fact. (#65)

Three scope bullets did not ship, and are not covered anywhere yet:

  • Histogram buckets. The collector still emits a summary with _sum / _count — precisely what this issue said to replace. Quantiles cannot be aggregated across instances, so this matters as soon as there is more than one.
  • The OTLP exporter as a second entry point.
  • stream:open / stream:close and boot:provider:*. Only the two request events are consumed, so nothing yet reports whether SSE clients are piling up.

Closing this one because its premise — that the ecosystem has no consumer of the lifecycle stream — no longer holds. The three above want their own issue against the plugin rather than keeping this one open.

Closed by `@green-tea/metrics`, in the new `Green-Tea/plugins` repo (plugins#2, merged to develop). "Outside it" is no longer nowhere, and core's dependency count did not move. What shipped is the first scope bullet: a Prometheus collector over `request:end` / `request:failed`, plus a `prometheus` transformer rather than a route — the path, the auth and whether the endpoint exists at all stay the application's decisions. The three first-pass mistakes this issue documented are what the package is built around, and each has a test: 1. **Double counting.** `request:end` is the request counter and nothing else is — it is terminal and universal, and `request:failed` fires *in addition* to it for the same request. `request:failed` increments a separate error counter. (#64) 2. **Duplicate time series.** Duration accumulates per `route` + `method` only; status is a label on the request counter alone, so one scrape carries one duration series per route. 3. **Unbounded labels.** Labels come from `route`, never `name` — `route` is bounded by the route table, `name` is built from the path that arrived and is bounded by nothing. An event carrying no route gets `<unknown>`, deliberately distinct from core's `<unmatched>`, which asserts a different fact. (#65) **Three scope bullets did not ship, and are not covered anywhere yet:** - **Histogram buckets.** The collector still emits a `summary` with `_sum` / `_count` — precisely what this issue said to replace. Quantiles cannot be aggregated across instances, so this matters as soon as there is more than one. - **The OTLP exporter** as a second entry point. - **`stream:open` / `stream:close` and `boot:provider:*`.** Only the two request events are consumed, so nothing yet reports whether SSE clients are piling up. Closing this one because its premise — that the ecosystem has no consumer of the lifecycle stream — no longer holds. The three above want their own issue against the plugin rather than keeping this one open.
chrnx closed this issue 2026-09-19 17:07:26 +00:00
Sign in to join this conversation.