Skip to main content
In this lesson we’ll extend instrumentation concepts with hands-on practice using both manual Prometheus instrumentation and OpenTelemetry auto-instrumentation. The sample application is a small FastAPI “Cat API” that demonstrates:
  • OpenTelemetry auto-instrumentation for HTTP and system metrics (configured inside the application).
  • Prometheus manual instrumentation to capture cat-specific business metrics.
Welcome banner (environment):
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.
Verification: check the monitoring pods
Example output:
Deploy the Cat API into the default namespace
Wait for the Cat API pod to become Ready:
Example pod lifecycle:
Deployment manifest (app/k8s/deployment.yaml)
The deployment includes Prometheus scrape annotations so the cluster Prometheus can automatically discover and scrape the application on port 8000 at /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).
Example JSON returned for “collective cat mood”:
Example JSON returned when generating a random GIF:
OpenTelemetry auto-instrumentation setup Open the application file at 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:
What each piece does
  • 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.)
Summary table: OpenTelemetry components used Typical initialization sequence in catapi.py
  1. Create a PrometheusMetricReader and configure it with the MeterProvider.
  2. Call set_meter_provider to wire the SDK into the application.
  3. Initialize SystemMetricsInstrumentor() to gather system metrics.
  4. Instrument the FastAPI app with FastAPIInstrumentor() to capture HTTP metrics.
This order ensures system and HTTP metrics are registered with the same MeterProvider and that the Prometheus-compatible reader exposes them at the app’s metrics endpoint for scraping. Manual Prometheus instrumentation (business 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 via PrometheusMetricReader.
How to validate metrics are scrapped
  1. Open the application /metrics endpoint (port 8000) using port-forwarding or from inside the cluster.
  2. Confirm you see both Prometheus-style metrics and OpenTelemetry-provided metrics (system and HTTP metrics).
  3. In Grafana, open dashboards (if provided) or create panels that query Prometheus for the app metrics.
Example: port-forward to test locally
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.
References and links Question: In the OpenTelemetry auto-instrumentation section of catapi.py, which two instrumentors are initialized to collect system and HTTP metrics? Answer: SystemMetricsInstrumentor and FastAPIInstrumentor.

Watch Video