Skip to content

Commit

Permalink
Fix review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
あで committed Sep 27, 2023
1 parent fc9ec96 commit 962dab6
Show file tree
Hide file tree
Showing 15 changed files with 1,525 additions and 298 deletions.
40 changes: 21 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -240,31 +240,33 @@ exemplar collection by setting `AUTOMETRICS_EXEMPLARS=true`. You also need to en

## Exporting metrics

There are multiple ways to export metrics from your application, depending on your setup.
There are multiple ways to export metrics from your application, depending on your setup. You can see examples of how to do this in the [examples/export_metrics](https://github.com/autometrics-dev/autometrics-py/tree/main/examples/export_metrics) directory of this repository.

If you use the `prometheus` tracker, you have two options.

1. Create a route inside your app and respond with `generate_latest()`
```python
# This example uses FastAPI, but you can use any web framework
from fastapi import FastAPI, Response
from prometheus_client import generate_latest

# Set up a metrics endpoint for Prometheus to scrape
@app.get("/metrics")
def metrics():
return Response(generate_latest())
```

```python
# This example uses FastAPI, but you can use any web framework
from fastapi import FastAPI, Response
from prometheus_client import generate_latest

# Set up a metrics endpoint for Prometheus to scrape
@app.get("/metrics")
def metrics():
return Response(generate_latest())
```

2. Specify `prometheus-client` as the exporter type, and a separate server will be started to expose metrics from your app:
```python
exporter = {
"type": "prometheus-client",
"address": "localhost",
"port": 9464
}
init(tracker="prometheus", service_name="my-service", exporter=exporter)
```

```python
exporter = {
"type": "prometheus-client",
"address": "localhost",
"port": 9464
}
init(tracker="prometheus", service_name="my-service", exporter=exporter)
```

For the OpenTelemetry tracker, you have more options, including a custom metric reader. By default, when using this tracker, autometrics
will export metrics to the Prometheus registry via `prometheus-client`, from which you can export via one of the ways described above.
Expand Down
980 changes: 980 additions & 0 deletions cat

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
version: '3.9'
version: "3.9"

volumes:
app-logs:


services:
am:
image: autometrics/am:latest
extra_hosts:
- host.docker.internal:host-gateway
ports:
- "6789:6789"
- "9090:9090"
container_name: am
command: "start host.docker.internal:8080"
environment:
command: "start host.docker.internal:9464"
environment:
- LISTEN_ADDRESS=0.0.0.0:6789
restart: unless-stopped
volumes:
Expand All @@ -31,4 +31,4 @@ services:
- "55679:55679"
restart: unless-stopped
push-gateway:
image: ghcr.io/zapier/prom-aggregation-gateway:v0.7.0
image: ghcr.io/zapier/prom-aggregation-gateway:latest
27 changes: 27 additions & 0 deletions examples/export_metrics/otel-prometheus.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import time
from autometrics import autometrics, init

# Autometrics supports exporting metrics to Prometheus via the OpenTelemetry.
# 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. If you don't have a Prometheus server running, you can run Tilt or
# Docker Compose from the root of this repo to start one up.

init(
tracker="opentelemetry",
exporter={
"type": "otel-prometheus",
""
},
service_name="my-service",
)


@autometrics
def my_function():
pass


while True:
my_function()
time.sleep(1)
26 changes: 26 additions & 0 deletions examples/export_metrics/otlp.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import time
from autometrics import autometrics, init

# Autometrics supports exporting metrics to OTLP collectors via gRPC and HTTP transports.
# This example uses the gRPC transport, available settings are similar to the OpenTelemetry
# Python SDK. By default, the OTLP exporter will send metrics to localhost:4317.
# If you don't have an OTLP collector running, you can run Tilt or Docker Compose
# to start one up. See the README for more details.

init(
exporter={
"type": "otlp-proto-grpc",
"push_interval": 1000,
},
service_name="my-service",
)


@autometrics
def my_function():
pass


while True:
my_function()
time.sleep(1)
27 changes: 27 additions & 0 deletions examples/export_metrics/prometheus-client.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import time
from autometrics import autometrics, init

# 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. If you don't have a Prometheus server running, you can run Tilt or
# Docker Compose from the root of this repo to start one up.

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


@autometrics
def my_function():
pass


while True:
my_function()
time.sleep(1)
19 changes: 0 additions & 19 deletions examples/otlp/start.py

This file was deleted.

Loading

0 comments on commit 962dab6

Please sign in to comment.