Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Quickstart: First pass #46

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 81 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,87 @@ See [Why Autometrics?](https://github.com/autometrics-dev#why-autometrics) for m
- [⚙️ Configurable](#metrics-libraries) metric collection library (`opentelemetry`, `prometheus`, or `metrics`)
- ⚡ Minimal runtime overhead

1. Add `autometrics` to your project:

```sh
pip3 install autometrics
```

2. Instrument your functions with the [`@autometrics`](https://pypi.org/project/autometrics/) decorator

<details>

<summary> Tip: Adding autometrics to all <code>pub</code> functions (not necessarily recommended 😅)
</summary>
<br />

You can use a search and replace to add autometrics to all public functions. Yes, this is a bit nuts.

Use a regular expression search to replace:

```
((?:async)? def .*)
```

With:

```
@autometrics
$1
```

And then check which files you need to add `from autometrics import autometrics` at the top of.

</details>

3. Export the metrics for Prometheus

<details>

<summary>
For projects not currently using Prometheus metrics
</summary>

<br />

Autometrics includes optional functions to help collect and prepare metrics to be collected by Prometheus.

Create a route on your API (probably mounted under `/metrics`) that returns the following:

```py
from autometrics import autometrics
from fastapi import FastAPI, Response
from prometheus_client import start_http_server

app = FastAPI()

@app.get("/metrics")
def metrics():
return Response(generate_latest())

```

</details>

<details>

<summary>
For projects already using custom Prometheus metrics
</summary>

<br />

Configure `autometrics` to use the same underlying metrics library you use with the appropriate feature flag (see [below](#metrics-libraries)).

The `autometrics` metrics will be produced alongside yours.

You do not need to use the Prometheus exporter functions this library provides (you can leave out the `prometheus-exporter` feature flag) and you do not need a separate endpoint for autometrics' metrics.

</details>

4. [Configure Prometheus](https://github.com/autometrics-dev#5-configuring-prometheus) to scrape your metrics endpoint
5. (Optional) If you have Grafana, import the [Autometrics dashboards](https://github.com/autometrics-dev/autometrics-shared#dashboards) for an overview and detailed view of the function metrics

## Using autometrics-py

- Set up a [Prometheus instance](https://prometheus.io/download/)
Expand Down