Skip to content

feat(o11y): outgoing fetch metrics (counter + histogram)#1155

Open
nicacioliveira wants to merge 2 commits into
mainfrom
feat/outgoing-fetch-metrics
Open

feat(o11y): outgoing fetch metrics (counter + histogram)#1155
nicacioliveira wants to merge 2 commits into
mainfrom
feat/outgoing-fetch-metrics

Conversation

@nicacioliveira

@nicacioliveira nicacioliveira commented Apr 6, 2026

Copy link
Copy Markdown
Contributor

What

Adds always-on metrics for outgoing HTTP fetches:

  • outgoing_fetch counter — total calls by app, host, method, status
  • outgoing_fetch_duration histogram (ms) — latency by app, host, method, status

Uses host only (not path) to keep cardinality low.

Queries

# Calls/s to VTEX
rate(outgoing_fetch_total{host=~".*vtex.*"}[5m])

# P95 latency by host
histogram_quantile(0.95, rate(outgoing_fetch_duration_bucket[5m]))

# Compare sites with/without Redis
rate(outgoing_fetch_total{app="vtex"}[5m]) by (service)

Always on, no env var needed. Log-based outgoing fetch remains off by default (OTEL_LOG_OUTGOING_FETCH=true).


Summary by cubic

Adds metrics for outgoing HTTP fetches to track request volume and latency with low-cardinality labels. Disabled by default; enable with OTEL_METRICS_OUTGOING_FETCH=true.

  • New Features
    • outgoing_fetch counter: counts requests by app, host, method, status.
    • outgoing_fetch_duration histogram (ms): records latency with the same labels.
    • Uses host only (no path) to keep cardinality low.
    • Log-based outgoing fetch remains off unless OTEL_LOG_OUTGOING_FETCH=true.

Written for commit 994e7dc. Summary will update on new commits.

Summary by CodeRabbit

  • New Features
    • Added optional outgoing network-request telemetry (configurable via environment) that captures request counts and response-duration histograms.
    • Collected attributes include destination host, application identifier, HTTP method, and response status (defaults to "unknown" when absent), enabling richer visibility into external request performance.

@github-actions

github-actions Bot commented Apr 6, 2026

Copy link
Copy Markdown
Contributor

Tagging Options

Should a new tag be published when this PR is merged?

  • 👍 for Patch 1.191.3 update
  • 🎉 for Minor 1.192.0 update
  • 🚀 for Major 2.0.0 update

@coderabbitai

coderabbitai Bot commented Apr 6, 2026

Copy link
Copy Markdown

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: c1818c5c-5501-4696-9dc6-a4b982f634ef

📥 Commits

Reviewing files that changed from the base of the PR and between 6b80866 and 994e7dc.

📒 Files selected for processing (1)
  • observability/otel/metrics.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • observability/otel/metrics.ts

📝 Walkthrough

Walkthrough

Optional OpenTelemetry metrics added to record outgoing fetches: an outgoing_fetch counter and outgoing_fetch_duration histogram. An onFetch callback extracts app/host/method/status attributes and records count and duration (ms) for each fetch when OTEL_METRICS_OUTGOING_FETCH === "true".

Changes

Cohort / File(s) Summary
Fetch Telemetry Metrics
observability/otel/metrics.ts
Adds optional outgoing-fetch telemetry gated by OTEL_METRICS_OUTGOING_FETCH === "true". Registers onFetch callback that parses destination host from event.url, builds attributes { app, host, method, status } (defaults to "unknown"), increments outgoing_fetch counter and records event.durationMs to outgoing_fetch_duration histogram (unit "ms").

Sequence Diagram(s)

sequenceDiagram
    participant Fetch as "Outgoing Fetch"
    participant Handler as "onFetch Handler"
    participant Metrics as "OTel Metrics SDK"
    participant Exporter as "OTel Exporter"

    Fetch->>Handler: emit fetch event (url, method, status, durationMs)
    Handler->>Handler: parse host, normalize attributes (app, host, method, status)
    Handler->>Metrics: increment outgoing_fetch counter (attributes)
    Handler->>Metrics: record outgoing_fetch_duration histogram (durationMs, attributes)
    Metrics->>Exporter: export metrics batch
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Suggested reviewers

  • igoramf

Poem

🐰 I hopped through code on nimble feet,

Counting fetches, timing each beat.
Hosts and methods I softly note,
So telemetry sings from every moat. 🥕

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'feat(o11y): outgoing fetch metrics (counter + histogram)' directly and clearly describes the main change: adding observability metrics for outgoing fetches with specific metric types.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/outgoing-fetch-metrics

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 1 file

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 issue found across 1 file (changes from recent commits).

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="observability/otel/metrics.ts">

<violation number="1" location="observability/otel/metrics.ts:71">
P1: Outgoing fetch metrics are now gated by `OTEL_METRICS_OUTGOING_FETCH`, which disables the feature by default instead of keeping it always-on.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

import { ValueType } from "../../deps.ts";
import { onFetch, parseUrlParts } from "../../utils/patched_fetch.ts";

if (Deno.env.get("OTEL_METRICS_OUTGOING_FETCH") === "true") {

@cubic-dev-ai cubic-dev-ai Bot Apr 6, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1: Outgoing fetch metrics are now gated by OTEL_METRICS_OUTGOING_FETCH, which disables the feature by default instead of keeping it always-on.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At observability/otel/metrics.ts, line 71:

<comment>Outgoing fetch metrics are now gated by `OTEL_METRICS_OUTGOING_FETCH`, which disables the feature by default instead of keeping it always-on.</comment>

<file context>
@@ -64,10 +64,12 @@ if (OTEL_IS_ENABLED) {
 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", {
</file context>
Fix with Cubic

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants