Python
Quickstart

Getting started in Python

Here's how to get started with Python in a new or existing project.

Install the library

pip install autometrics

Import the library and use the decorator

from autometrics import autometrics
 
@autometrics
def create_user(name):
   # ...

Configure metrics exporting

You can configure autometrics to export using either Prometheus or OpenTelemetry libraries by calling the init function:

Autometrics supports exporting metrics to Prometheus via the Prometheus Python client. This example uses the Prometheus Python client, available settings are same as the Prometheus Python client. By default, the Prometheus exporter will expose metrics on port 9464.

from autometrics import autometrics, init
 
init(
    tracker="prometheus",
    exporter={
        "type": "prometheus",
        "port": 9464,
    },
    service_name="my-service",
)

Viewing your metrics

Using Autometrics Explorer

Autometrics Explorer is an open source accompanying utility to preview and validate your metrics locally. It will automatically run Prometheus under the hood for you and show you Autometrics-instrumented functions in a web UI.

See Local Development for more information.

shell
brew install autometrics-dev/tap/am
 
am start <YOUR_APP_METRICS_ENDPOINT>

View your metrics in your IDE or dashboard

Install the Autometrics VSCode extension (opens in a new tab) to get generated queries in your tooltips in your IDE.

You can now navigate your code in your IDE, hover over the instrumented functions and you will see links for generated queries for your metrics.

If you have Grafana you can also import the Autometrics dashboard (opens in a new tab) for an overview and detailed view of the function metrics.