Skip to content

Fix observability: route metrics through Cloud Monitoring#56

Merged
shlbatra merged 3 commits into
mainfrom
fix/observability-cloud-monitoring
Jul 1, 2026
Merged

Fix observability: route metrics through Cloud Monitoring#56
shlbatra merged 3 commits into
mainfrom
fix/observability-cloud-monitoring

Conversation

@shlbatra

@shlbatra shlbatra commented Jul 1, 2026

Copy link
Copy Markdown
Owner

Summary

The FastAPI server on Cloud Run was pushing OTLP metrics to otel-collector:4317 — a Docker-internal hostname unreachable from Cloud Run. Metrics were silently dropped. This PR unifies all production metrics through a single path: Cloud Monitoring → stackdriver-exporter → Prometheus → Grafana.

Changes

  • FastAPI server — environment-aware exporter: CloudMonitoringMetricsExporter in production (Cloud Run), OTLPMetricExporter when OTEL_EXPORTER_OTLP_ENDPOINT is set (local dev)
  • Dockerfile.fastapi — removed hardcoded OTEL_EXPORTER_OTLP_ENDPOINT=http://otel-collector:4317 so production defaults to Cloud Monitoring
  • requirements.fastapi.txt (both copies) — added opentelemetry-exporter-gcp-monitoring
  • docker-compose.observability.yml — switched stackdriver-exporter from env vars to CLI flags (--monitoring.metrics-prefixes), added GCP ADC credential mount, moved OTel Collector behind profiles: ["local-dev"], added custom.googleapis.com/dataflow and workload.googleapis.com metric prefixes
  • observability_plan.md — updated architecture diagrams, collection patterns table, metric name mapping, implementation phases, and docker-compose snippets
  • README.md — updated observability section with Cloud Monitoring architecture, new start commands, and production metric names

Architecture (before → after)

BEFORE (broken):
  Cloud Run FastAPI → OTLP → otel-collector:4317 → ✖ unreachable

AFTER (unified):
  Cloud Run FastAPI ──→ Cloud Monitoring ──→ stackdriver-exporter ──→ Prometheus ──→ Grafana
  Dataflow Beam     ──→ Cloud Monitoring ──↗
  GCP platform      ──→ Cloud Monitoring ──↗

Verified locally

  • stackdriver-exporter UP, scraping 212 GCP metrics including:
    • 33 Beam custom metrics (parse_success, fetch_latency, prediction_latency, etc.)
    • 61 Dataflow system metrics
    • 61 Cloud Run metrics
    • 53 Pub/Sub metrics

Test plan

  • stackdriver-exporter starts and Prometheus scrapes it successfully
  • Beam custom metrics (custom.googleapis.com/dataflow) appear in Prometheus
  • Cloud Run / Dataflow / Pub/Sub platform metrics appear in Prometheus
  • Deploy updated FastAPI Docker image to Cloud Run — verify Using Cloud Monitoring exporter in startup logs
  • Verify workload_googleapis_com:fastapi_predictions_total appears after sending predictions
  • Update Grafana dashboard queries from fastapi_fastapi_* to production metric names

🤖 Generated with Claude Code

shlbatra and others added 3 commits July 1, 2026 14:28
FastAPI on Cloud Run was pushing OTLP to otel-collector:4317 — a Docker
hostname unreachable from Cloud Run. Switch to environment-aware exporter:
CloudMonitoringMetricsExporter for production, OTLPMetricExporter for
local dev only. Add missing stackdriver-exporter prefixes for Beam custom
metrics and FastAPI workload metrics.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@shlbatra shlbatra merged commit a155db1 into main Jul 1, 2026
1 check passed
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.

1 participant