You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A Python library that exports a decorator that makes it easy to understand the error rate, response time, and production usage of any function in your code. Jump straight from your IDE to live Prometheus charts for each HTTP/RPC handler, database method, or other piece of application logic.
**Autometrics is a library that exports a decorator that makes it easy to understand the error rate, response time, and production usage of any function in your code.** Jump straight from your IDE to live Prometheus charts for each HTTP/RPC handler, database method, or other piece of application logic.
6
9
7
10
Autometrics for Python provides:
8
11
@@ -22,6 +25,7 @@ See [Why Autometrics?](https://github.com/autometrics-dev#why-autometrics) for m
22
25
-[🚨 Define alerts](#alerts--slos) using SLO best practices directly in your source code
23
26
-[📊 Grafana dashboards](#dashboards) work out of the box to visualize the performance of instrumented functions & SLOs
24
27
-[⚙️ Configurable](#metrics-libraries) metric collection library (`opentelemetry`, `prometheus`, or `metrics`)
28
+
-[📍 Attach exemplars](https://github.com/autometrics-dev/autometrics-py/blob/main/examples/starlette-otel-exemplars.py) to connect metrics with traces
25
29
- ⚡ Minimal runtime overhead
26
30
27
31
## Using autometrics-py
@@ -130,6 +134,15 @@ The `version` is read from the `AUTOMETRICS_VERSION` environment variable, and t
130
134
131
135
This follows the method outlined in [Exposing the software version to Prometheus](https://www.robustperception.io/exposing-the-software-version-to-prometheus/).
132
136
137
+
## Exemplars
138
+
139
+
> **NOTE** - As of writing, aren't supported by the default tracker (`AUTOMETRICS_TRACKER=OPEN_TELEMETRY`).
140
+
> You can track the progress of this feature here: https://github.com/open-telemetry/opentelemetry-python/issues/2407
141
+
>
142
+
> Because this feature is currently experimental, you have to explicitly enable it by setting the environment variables `AUTOMETRICS_EXEMPLARS=true` and `AUTOMETRICS_TRACKER=prometheus`. Prometheus also doesn't support exemplars in default configuration, to enable them you need to launch Prometheus with the `--enable-feature=exemplar-storage` flag.
143
+
144
+
Exemplars are a way to attach additional information to a metric. If you have OpenTelemetry instrumentation set up, autometrics will try to attach the trace ID and span ID to the metrics. This allows you to jump from a metric to the trace that caused it.
145
+
133
146
## Development of the package
134
147
135
148
This package uses [poetry](https://python-poetry.org) as a package manager, with all dependencies separated into three groups:
Copy file name to clipboardExpand all lines: examples/README.md
+15
Original file line number
Diff line number
Diff line change
@@ -5,6 +5,7 @@ You should be able to run each example by:
5
5
- cloning this repository
6
6
- run `poetry install --with examples`
7
7
- and execute `poetry run python examples/<example>.py` from the root of the repo.
8
+
- for django and starlette examples, you can find the instructions in their respective READMEs
8
9
9
10
You can change the base url for Prometheus links via the `PROMETHEUS_URL` environment variable. So, if your local Prometheus were on a non-default port, like 9091, you would run:
10
11
@@ -57,3 +58,17 @@ Autometrics also tracks a label, `caller`, which is the name of the function tha
57
58
This is an example that shows you how to use autometrics to get metrics on http handlers with FastAPI. In this case, we're setting up the API ourselves, which means we need to expose a `/metrics` endpoint manually.
58
59
59
60
> Don't forget to configure Prometheus itself to scrape the metrics endpoint. Refer to the example `prometheus.yaml` file in the root of this project on how to set this up.
61
+
62
+
## `django-example`
63
+
64
+
This is a default Django project with autometrics configured. You can find examples of instrumenting function and class based views in `django_example/views`.
65
+
66
+
> Don't forget to configure Prometheus itself to scrape the metrics endpoint. Refer to the example `prometheus.yaml` file in the root of this project on how to set this up.
67
+
68
+
## `starlette-otel-exemplars.py`
69
+
70
+
This app shows how to use the OpenTelemetry integration to add exemplars to your metrics. In a distributed system, it allows you to track a request as it flows through your system by adding trace/span ids to it. We can catch these ids and expose them to Prometheus as exemplars. Do note that exemplars are an experimental feature and you need to enable it in Prometheus with a `--enable-feature=exemplar-storage` flag. Run the example with a command:
> Don't forget to configure Prometheus itself to scrape the metrics endpoint. Refer to the example `prometheus.yaml` file in the root of this project on how to set this up.
0 commit comments