> ## Documentation Index
> Fetch the complete documentation index at: https://notes.kodekloud.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Auto Instrumentation Overview

> Overview of using OpenTelemetry auto-instrumentation to quickly collect standard observability metrics from frameworks and runtimes, complemented by manual instrumentation for business metrics.

Manual instrumentation requires adding metric calls inside your application code and updating them as the code evolves. That gives precise control, but it demands developer time, coordination across teams, and ongoing maintenance.

When you need the standard "golden-signal" metrics quickly across many services, manually instrumenting every service may be impractical. Auto-instrumentation provides a lower-effort, faster path to basic observability by hooking into frameworks and runtimes to emit common metrics without changing business logic.

One widely adopted standard for auto-instrumentation is OpenTelemetry (OTel). OpenTelemetry is a CNCF project that provides libraries for major languages and frameworks — Python, Java, Node.js, .NET, Go and frameworks such as FastAPI, Flask, Django, Spring Boot, and Express.

Here's the general workflow.

![An OpenTelemetry infographic showing the OpenTelemetry logo in the center and lists supported languages (Python, Java, Node.js, .NET, Go) on the left and frameworks (FastAPI, Flask, Django, Spring Boot, Express) on the right.](https://mintcdn.com/kodekloud-c4ac6d9a/qM9vA-hQoWNCxcKa/images/Grafana-Prometheus-for-Metrics-Driven-Observability/Metric-Instrumentation/Auto-Instrumentation-Overview/opentelemetry-infographic-languages-frameworks.jpg?fit=max\&auto=format\&n=qM9vA-hQoWNCxcKa\&q=85\&s=cc7af9fab4e10969de26129514d0503e)

How auto-instrumentation typically works

1. Choose and initialize an exporter.\
   OpenTelemetry uses an internal metric model; an exporter converts that model into your backend’s format. A common choice for Prometheus users is the Prometheus exporter, which exposes an HTTP endpoint that Prometheus can scrape.

2. Wire the exporter into the OTel metric pipeline.\
   This configures the MeterProvider (or equivalent) so captured metrics flow to your exporter and metric backend.

3. Enable framework instrumentation.\
   Install and activate the instrumentation package for your framework (for example, FastAPIInstrumentor). The instrumenter intercepts framework-level operations (HTTP requests, DB calls, etc.) and emits standard metrics automatically.

Minimal Python + FastAPI example (Prometheus exporter)

```python theme={null}
# app_instrumentation.py
from fastapi import FastAPI

# Prometheus exporter and metric reader
from opentelemetry.exporter.prometheus import PrometheusMetricReader
from opentelemetry.sdk.metrics import MeterProvider
from opentelemetry import metrics

prometheus_reader = PrometheusMetricReader()
meter_provider = MeterProvider(metric_readers=[prometheus_reader])
metrics.set_meter_provider(meter_provider)

# Framework instrumentation
from opentelemetry.instrumentation.fastapi import FastAPIInstrumentor

app = FastAPI()
FastAPIInstrumentor.instrument_app(app)

# Your normal FastAPI routes follow...
@app.get("/hello")
async def hello():
    return {"msg": "hello"}
```

What the instrumenter does for each request

* Records request start time on entry.
* On completion, records response status and computes duration.
* Emits counters and histograms with labels such as `path`, `method`, and `status_code` so you can slice-and-dice traffic, errors, and latency.

Why this helps

* Your application code remains unchanged: instrumentation runs at the framework level.
* You quickly collect the classic observability signals across many services without touching business logic.
* Once the OTel stack is in place, adding traces or correlated logs is straightforward.

Which telemetry does auto-instrumentation provide?
Auto-instrumentation maps well to the four golden signals:

| Golden Signal | Typical auto-instrumented metrics | Examples |
| - | - | - |
| Traffic | HTTP request counts and throughput by endpoint and method | Request counters labeled with `path`/`method` |
| Errors | Response error counts by status code | Counters for `4xx`, `5xx` responses |
| Latency | Request duration histograms to compute percentiles | Histograms enabling P50/P95/P99 calculations |
| Saturation | Runtime and host-level metrics (CPU, memory, I/O) | Runtime exporters, node-exporter, kube-state-metrics |

![A presentation slide titled "Auto-Instrumentation – What Do You Get?" showing the four golden signals of observability (Traffic, Errors, Latency, Saturation) with associated metrics. Examples listed include HTTP request counts, 4xx/5xx errors and response codes, P50/P95/P99 percentiles and request duration histograms, plus disk I/O, memory and CPU.](https://mintcdn.com/kodekloud-c4ac6d9a/qM9vA-hQoWNCxcKa/images/Grafana-Prometheus-for-Metrics-Driven-Observability/Metric-Instrumentation/Auto-Instrumentation-Overview/auto-instrumentation-golden-signals-observability-metrics.jpg?fit=max\&auto=format\&n=qM9vA-hQoWNCxcKa\&q=85\&s=c72f853639985bd51471514d6c5f939c)

Best practices and trade-offs

* Use auto-instrumentation for framework and infrastructure signals (HTTP, DB clients, runtimes).
* Use manual instrumentation for domain-specific metrics (orders placed, conversion rate, payment status).
* Combine both approaches: auto-instrumentation provides the baseline golden signals while manual instrumentation captures business semantics.

OpenTelemetry covers metrics, traces, and logs. This guide focuses on metrics, but the same OTel libraries make it simple to add distributed tracing and correlated logging later — adopt OTel now to ease future expansions into tracing and log correlation.

![A slide titled "A Note on OpenTelemetry" showing three stylized columns labeled "Metrics" (purple), "Logs" (orange), and "Traces" (green). The columns represent the core observability signals.](https://mintcdn.com/kodekloud-c4ac6d9a/qM9vA-hQoWNCxcKa/images/Grafana-Prometheus-for-Metrics-Driven-Observability/Metric-Instrumentation/Auto-Instrumentation-Overview/opentelemetry-metrics-logs-traces.jpg?fit=max\&auto=format\&n=qM9vA-hQoWNCxcKa\&q=85\&s=9d953ac21a3c1f384630691b5cae91ba)

Important limitation
Auto-instrumentation cannot infer your business logic or domain concepts. It will not count orders placed by product category or track feature-specific usage unless you add explicit instrumentation inside your application.

Auto-instrumentation does not replace domain-specific metrics. For metrics tied to business behavior (for example, `orders_created` or `payment_attempts`), add manual instrumentation in your code alongside auto-instrumentation.

When to choose auto-instrumentation

| Situation | Recommendation |
| -: | - |
| You need baseline observability across many existing services quickly | Use auto-instrumentation to collect golden signals with minimal code changes |
| You require business/domain metrics | Add manual instrumentation for those specific counters/histograms |
| You want a future-proof telemetry platform | Adopt OpenTelemetry to unify metrics, traces, and logs |

Next steps / resources

* Try the hands-on lab that demonstrates Python + FastAPI + OpenTelemetry for auto-instrumentation and shows how to add manual metrics where needed.
* OTel docs: [https://opentelemetry.io/](https://opentelemetry.io/)
* Prometheus docs: [https://prometheus.io/docs/](https://prometheus.io/docs/)

A hands-on lab demonstrates using Python, FastAPI, and OpenTelemetry together to auto-instrument an application and add manual metrics where needed.

> [card] [Watch Video](https://learn.kodekloud.com/user/courses/grafana-prometheus-for-metrics-driven-observability/module/f101faec-1de6-4831-b109-d9edcafb246c/lesson/32866336-a20e-4ce7-803c-cbda49e3478a)

> [card] [Practice Lab](https://learn.kodekloud.com/user/courses/grafana-prometheus-for-metrics-driven-observability/module/f101faec-1de6-4831-b109-d9edcafb246c/lesson/2fb46f0c-7304-42cb-ad78-61f6aa8bb431)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.