Skip to content

Commit 480c6c2

Browse files
authored
Merge pull request #19 from autometrics-dev/update_example_readme
Update examples
2 parents c364676 + 5e879bd commit 480c6c2

File tree

3 files changed

+30
-8
lines changed

3 files changed

+30
-8
lines changed

examples/README.md

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
# autometrics-py examples
22

3-
You should be able to run each example by executing `python examples/<example>.py` from the root of the repo.
3+
You should be able to run each example by:
4+
5+
- cloning this repository
6+
- run `poetry install --with examples`
7+
- and execute `poetry run python examples/<example>.py` from the root of the repo.
48

59
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:
610

examples/example.py

+24-6
Original file line numberDiff line numberDiff line change
@@ -69,13 +69,31 @@ def random_error():
6969
# Enter an infinite loop (with a 2 second sleep period), calling the "div_handled", "add", and "div_unhandled" methods,
7070
# in order to generate metrics.
7171
while True:
72-
ops.div_handled(2, 0)
72+
try:
73+
ops.div_handled(2, 0)
74+
except Exception:
75+
pass
76+
7377
ops.add(1, 2)
7478
ops.div_handled(2, 1)
75-
# Randomly call `div_unhandled` with a 50/50 chance of raising an error
76-
div_unhandled(2, random.randint(0, 1))
79+
80+
try:
81+
# Randomly call `div_unhandled` with a 50/50 chance of raising an error
82+
div_unhandled(2, random.randint(0, 1))
83+
except Exception:
84+
pass
85+
7786
ops.add(1, 2)
7887
time.sleep(2)
79-
# Call `div_unhandled` such that it raises an error
80-
div_unhandled(2, 0)
81-
random_error()
88+
89+
try:
90+
# Call `div_unhandled` such that it raises an error
91+
div_unhandled(2, 0)
92+
except Exception:
93+
pass
94+
95+
try:
96+
# Call random_error. It will randomly raise an error or return "ok"
97+
random_error()
98+
except Exception:
99+
pass

pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "autometrics"
3-
version = "0.3"
3+
version = "0.4"
44
description = "Easily add metrics to your system – and actually understand them using automatically customized Prometheus queries"
55
authors = ["Fiberplane <info@fiberplane.com>"]
66
license = "MIT OR Apache-2.0"

0 commit comments

Comments
 (0)