Telemetry.IngestMetrics
Push metrics from running code into a metrics Source.
The source must take metrics: create it with platform: "prometheus";
any other source answers Forbidden (403), the same tag a wrong token
gets.
When to use it: for application metrics prefer Effect’s Metric
exported with Telemetry.Export. IngestMetrics is for metrics computed
outside Effect (a scraped value, a backfill with its own dt) or a host
where the export layer is not available.
Credential. The host receives the source’s own ingest token
(Redacted) and ingestingHost (BETTERSTACK_SOURCE_<SOURCE>_TOKEN /
…_INGESTING_HOST): it can only write into that source. No API token
reaches the host.
Cost. Metrics are billed by the number of distinct series: every new
combination of name and tags is a new one. Keep tags low-cardinality
(no request ids, no user ids).
Provide IngestMetricsHttp on the host’s implementation.
Pushing metrics from a Cloud.Service
Section titled “Pushing metrics from a Cloud.Service”A counter per request
export const AppMetrics = BetterStack.Telemetry.Source("AppMetrics", { platform: "prometheus" });
export default class Api extends BetterStack.Cloud.Service<Api>()( "Api", { server: Box, main: import.meta.url, port: 3000 }, Effect.gen(function* () { const metrics = yield* BetterStack.Telemetry.IngestMetrics(AppMetrics); return { fetch: Effect.gen(function* () { yield* metrics({ name: "orders_total", counter: { value: 1 }, tags: { region: "eu" } }); return HttpServerResponse.text("ok"); }).pipe(Effect.orDie), }; }).pipe(Effect.provide(BetterStack.Telemetry.IngestMetricsHttp)),) {}The same lines work on any Alchemy host (a Worker, a Lambda Function):
the binding writes its values through RuntimeContext, never through a
host-specific API.