- OpenTelemetry auto-instrumentation for HTTP and system metrics (configured inside the application).
- Prometheus manual instrumentation to capture cat-specific business metrics.
The monitoring stack (Prometheus + Grafana) is already deployed in the
monitoring namespace for this lab. Use kubectl get po -n monitoring to confirm pods are running before continuing.default namespace
/metrics. This avoids needing a separate ServiceMonitor for the simple lab setup.
Accessing the Cat API UI
- The Cat API UI exposes endpoints to:
- View current cat mood metrics (JSON).
- Retrieve Prometheus metrics text at
/metrics. - Generate a random cat GIF and get JSON metadata.
- Make the cat “chase” a laser pointer (returns JSON metadata).
app/catapi.py (or catapi.py at the app root). The section titled “OpenTelemetry auto-instrumentation setup” is located around lines 24–89 in this repository. In that section you will typically see the following imports and initialization patterns:
- PrometheusMetricReader: exposes a Prometheus-compatible metrics endpoint so Prometheus can scrape metrics produced by OpenTelemetry.
- MeterProvider + set_meter_provider: configures the OpenTelemetry metrics SDK so code and instrumentations can create and record metrics.
- SystemMetricsInstrumentor: automatically collects system-level metrics (CPU, memory, etc.) without manual metric definitions.
- FastAPIInstrumentor: auto-instruments FastAPI to capture HTTP request metrics/traces (latency, status codes, etc.)
Typical initialization sequence in
catapi.py
- Create a
PrometheusMetricReaderand configure it with theMeterProvider. - Call
set_meter_providerto wire the SDK into the application. - Initialize
SystemMetricsInstrumentor()to gather system metrics. - Instrument the FastAPI app with
FastAPIInstrumentor()to capture HTTP metrics.
- In addition to auto-instrumentation, the application may include manual Prometheus metrics for domain-specific data (e.g., counters, histograms for cat actions). These are typically created using the Prometheus client library (e.g.,
prometheus_client) and exposed on/metrics, or via OpenTelemetry metrics translated for Prometheus viaPrometheusMetricReader.
- Open the application
/metricsendpoint (port 8000) using port-forwarding or from inside the cluster. - Confirm you see both Prometheus-style metrics and OpenTelemetry-provided metrics (system and HTTP metrics).
- In Grafana, open dashboards (if provided) or create panels that query Prometheus for the app metrics.
If the
/metrics endpoint is not reachable, verify: (1) the pod is Ready, (2) the service is created and targets the correct port, and (3) no network policies block access.- Prometheus: https://prometheus.io/
- OpenTelemetry: https://opentelemetry.io/
- FastAPI: https://fastapi.tiangolo.com/
- Grafana: https://grafana.com/
- Kubernetes docs: https://kubernetes.io/docs/
catapi.py, which two instrumentors are initialized to collect system and HTTP metrics?
Answer: SystemMetricsInstrumentor and FastAPIInstrumentor.