Files
plugins/packages/metrics/src/prometheus.ts
T
chrnx de0081ddae
CI / dco (pull_request) Successful in 5s
CI / build (pull_request) Failing after 8s
CI / runtimes (bun) (pull_request) Failing after 6s
CI / runtimes (deno) (pull_request) Failing after 7s
CI / runtimes (edge) (pull_request) Failing after 6s
feat(metrics): publish the collector and a transformer to serve it
The transformer is exported instead of a route: the path, the auth and whether
the endpoint exists are the application's decisions, and a plugin that mounted
/metrics itself would be taking them.

No onShutdown — a bus subscription is an entry in a set and keeps nothing alive,
which is what rule 7 asks about. Closes green-tea#68.

Signed-off-by: Diego Resendez <diego.resendez@zero-oneit.com>
2026-09-18 13:27:08 -05:00

23 lines
790 B
TypeScript
Raw Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import type { TransformerFn } from '@green-tea/core';
/**
* Serves a rendered scrape as the Prometheus text exposition format.
*
* A `TransformerFn` rather than a route: the path, the auth and whether the endpoint exists at all
* are the application's decisions, and a plugin that mounted `/metrics` itself would be taking them.
* The version is part of the content type — Prometheus reads it, and omitting it makes a scrape fall
* back to a guess.
*
* @example
* ⁣@Get('/metrics')
* ⁣@Transformer(prometheus)
* scrape(@needs('metrics') collector: Metrics) {
* return collector.render();
* }
*/
export const prometheus: TransformerFn = (value) => ({
status: 200,
headers: { 'content-type': 'text/plain; version=0.0.4; charset=utf-8' },
body: String(value),
});