Building a Prometheus exporter for the demo app surfaced that a request that fails emits three lifecycle events, and nothing in the types, the docs or the changelog says which of them is the one to count. The obvious first implementation double-counts every failure.
What happens
For one POST /api/orders that fails validation, a subscriber sees:
Event
Where
status
durationMs
request:start
src/http/core.ts:246
—
—
request:failed
src/pipeline.ts:144
absent
absent
request:end
src/http/core.ts:259
422
present
request:end fires in observedDispatchafterdispatch returns, so it fires for every dispatched request — handled, thrown, and unmatched alike — and it is the only one of the three carrying the real status.
A consumer that reasonably reads request:end as "the request succeeded" and request:failed as "the request failed" counts that one request twice, the second time under whatever status it invents for an event that has none. In my case:
http_requests_total{route="/api/orders",method="POST",status="422"} 1
http_requests_total{route="/api/orders",method="POST",status="500"} 1 # same request
The same happens with route:unmatched (src/http/core.ts:297), which fires in addition to the request:end that follows it — two events, one 404.
Why it matters
This is the stream's primary use. logRequests is a subscriber like any other and gets it right, because it subscribes to request:end for the outcome and request:failed only for the message (src/logger.ts:115). But that division is knowledge living in one implementation, not in the contract, and the contract is what an exporter is written against.
The doc comment on EventPayload explains that fields past name are optional because "boot and mesh events have no request to name". It never says that three of these events describe the same request — which is the fact a consumer needs before it writes a single line.
Scope
Ordered by how much they cost:
Document the overlap — that request:end is terminal and universal, that request:failed is "handler code threw" and is additional, and that route:unmatched is likewise additional. A sentence next to LifecycleEvent would have prevented this.
Consider a status on request:failed. It is already known at the point it renders. Without it the event cannot be counted on its own — it must be joined to the request:end that follows, through requestId, for something the emitter already had.
Nothing needs to change in the emission itself. Three events for one request is defensible — they answer different questions. Only silence about it is the defect.
Related
Found while writing metrics.plugin.ts for the green-desk demo (Node/Deno/Bun). The corrected version counts request:end only, and uses request:failed for a separate http_request_errors_total — "handler code threw", which a status alone cannot express, since a rendered 422 is also a throw.
Building a Prometheus exporter for the demo app surfaced that a request that fails emits **three** lifecycle events, and nothing in the types, the docs or the changelog says which of them is the one to count. The obvious first implementation double-counts every failure.
## What happens
For one `POST /api/orders` that fails validation, a subscriber sees:
| Event | Where | `status` | `durationMs` |
|---|---|---|---|
| `request:start` | `src/http/core.ts:246` | — | — |
| `request:failed` | `src/pipeline.ts:144` | **absent** | absent |
| `request:end` | `src/http/core.ts:259` | `422` | present |
`request:end` fires in `observedDispatch` *after* `dispatch` returns, so it fires for every dispatched request — handled, thrown, and unmatched alike — and it is the only one of the three carrying the real status.
A consumer that reasonably reads `request:end` as "the request succeeded" and `request:failed` as "the request failed" counts that one request twice, the second time under whatever status it invents for an event that has none. In my case:
```
http_requests_total{route="/api/orders",method="POST",status="422"} 1
http_requests_total{route="/api/orders",method="POST",status="500"} 1 # same request
```
The same happens with `route:unmatched` (`src/http/core.ts:297`), which fires *in addition to* the `request:end` that follows it — two events, one 404.
## Why it matters
This is the stream's primary use. `logRequests` is a subscriber like any other and gets it right, because it subscribes to `request:end` for the outcome and `request:failed` only for the message (`src/logger.ts:115`). But that division is knowledge living in one implementation, not in the contract, and the contract is what an exporter is written against.
The doc comment on `EventPayload` explains that fields past `name` are optional because "boot and mesh events have no request to name". It never says that three of these events describe **the same request** — which is the fact a consumer needs before it writes a single line.
## Scope
Ordered by how much they cost:
1. **Document the overlap** — that `request:end` is terminal and universal, that `request:failed` is "handler code threw" and is *additional*, and that `route:unmatched` is likewise additional. A sentence next to `LifecycleEvent` would have prevented this.
2. **Consider a `status` on `request:failed`.** It is already known at the point it renders. Without it the event cannot be counted on its own — it must be joined to the `request:end` that follows, through `requestId`, for something the emitter already had.
3. Nothing needs to change in the emission itself. Three events for one request is defensible — they answer different questions. Only silence about it is the defect.
## Related
Found while writing `metrics.plugin.ts` for the `green-desk` demo (Node/Deno/Bun). The corrected version counts `request:end` only, and uses `request:failed` for a separate `http_request_errors_total` — "handler code threw", which a status alone cannot express, since a rendered 422 is also a throw.
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
Building a Prometheus exporter for the demo app surfaced that a request that fails emits three lifecycle events, and nothing in the types, the docs or the changelog says which of them is the one to count. The obvious first implementation double-counts every failure.
What happens
For one
POST /api/ordersthat fails validation, a subscriber sees:statusdurationMsrequest:startsrc/http/core.ts:246request:failedsrc/pipeline.ts:144request:endsrc/http/core.ts:259422request:endfires inobservedDispatchafterdispatchreturns, so it fires for every dispatched request — handled, thrown, and unmatched alike — and it is the only one of the three carrying the real status.A consumer that reasonably reads
request:endas "the request succeeded" andrequest:failedas "the request failed" counts that one request twice, the second time under whatever status it invents for an event that has none. In my case:The same happens with
route:unmatched(src/http/core.ts:297), which fires in addition to therequest:endthat follows it — two events, one 404.Why it matters
This is the stream's primary use.
logRequestsis a subscriber like any other and gets it right, because it subscribes torequest:endfor the outcome andrequest:failedonly for the message (src/logger.ts:115). But that division is knowledge living in one implementation, not in the contract, and the contract is what an exporter is written against.The doc comment on
EventPayloadexplains that fields pastnameare optional because "boot and mesh events have no request to name". It never says that three of these events describe the same request — which is the fact a consumer needs before it writes a single line.Scope
Ordered by how much they cost:
request:endis terminal and universal, thatrequest:failedis "handler code threw" and is additional, and thatroute:unmatchedis likewise additional. A sentence next toLifecycleEventwould have prevented this.statusonrequest:failed. It is already known at the point it renders. Without it the event cannot be counted on its own — it must be joined to therequest:endthat follows, throughrequestId, for something the emitter already had.Related
Found while writing
metrics.plugin.tsfor thegreen-deskdemo (Node/Deno/Bun). The corrected version countsrequest:endonly, and usesrequest:failedfor a separatehttp_request_errors_total— "handler code threw", which a status alone cannot express, since a rendered 422 is also a throw.