From 6b80866a492539dab3f8088677e1c3f2f6b2bae1 Mon Sep 17 00:00:00 2001 From: decobot Date: Mon, 6 Apr 2026 16:06:46 -0300 Subject: [PATCH 1/2] feat(o11y): add outgoing_fetch counter and duration histogram metrics --- observability/otel/metrics.ts | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/observability/otel/metrics.ts b/observability/otel/metrics.ts index b5ea77d7d..20404e778 100644 --- a/observability/otel/metrics.ts +++ b/observability/otel/metrics.ts @@ -63,3 +63,29 @@ if (OTEL_IS_ENABLED) { } export const meter: IMeter = meterProvider.getMeter("deco"); + +// Outgoing fetch metrics — always on, low cardinality (host, not path). +import { ValueType } from "../../deps.ts"; +import { onFetch, parseUrlParts } from "../../utils/patched_fetch.ts"; + +const fetchCount = meter.createCounter("outgoing_fetch", { + unit: "1", + valueType: ValueType.INT, +}); + +const fetchDuration = meter.createHistogram("outgoing_fetch_duration", { + unit: "ms", + valueType: ValueType.DOUBLE, +}); + +onFetch((event) => { + const { host } = parseUrlParts(event.url); + const attrs = { + app: event.app ?? "unknown", + host: host ?? "unknown", + method: event.method, + status: event.status, + }; + fetchCount.add(1, attrs); + fetchDuration.record(event.durationMs, attrs); +}); From 994e7dc721d602853c7bf86d989db61ac8c0a8e3 Mon Sep 17 00:00:00 2001 From: decobot Date: Mon, 6 Apr 2026 16:11:11 -0300 Subject: [PATCH 2/2] fix: disable outgoing fetch metrics by default, enable with OTEL_METRICS_OUTGOING_FETCH=true --- observability/otel/metrics.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/observability/otel/metrics.ts b/observability/otel/metrics.ts index 20404e778..1b0fb6163 100644 --- a/observability/otel/metrics.ts +++ b/observability/otel/metrics.ts @@ -64,10 +64,12 @@ if (OTEL_IS_ENABLED) { export const meter: IMeter = meterProvider.getMeter("deco"); -// Outgoing fetch metrics — always on, low cardinality (host, not path). +// Outgoing fetch metrics — disabled by default. Enable with OTEL_METRICS_OUTGOING_FETCH=true. import { ValueType } from "../../deps.ts"; import { onFetch, parseUrlParts } from "../../utils/patched_fetch.ts"; +if (Deno.env.get("OTEL_METRICS_OUTGOING_FETCH") === "true") { + const fetchCount = meter.createCounter("outgoing_fetch", { unit: "1", valueType: ValueType.INT, @@ -89,3 +91,5 @@ onFetch((event) => { fetchCount.add(1, attrs); fetchDuration.record(event.durationMs, attrs); }); + +} // OTEL_METRICS_OUTGOING_FETCH