Skip to content

Commit 8bb51d5

Browse files
authored
Merge pull request #8 from autometrics-dev/fastapi
Fastapi
2 parents a0c2f04 + 0b4e97f commit 8bb51d5

File tree

6 files changed

+61
-8
lines changed

6 files changed

+61
-8
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
data/
33
.vscode/
44
my_testing/
5+
autometrics-venv/
56

67
# Byte-compiled / optimized / DLL files
78
__pycache__/

examples/fastapi-example.py

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
from fastapi import FastAPI, Response
2+
import uvicorn
3+
from autometrics.autometrics import autometrics
4+
from prometheus_client import generate_latest
5+
6+
app = FastAPI()
7+
8+
@app.get("/metrics")
9+
def metrics():
10+
return Response(generate_latest())
11+
12+
@app.get("/")
13+
@autometrics
14+
def read_root():
15+
do_something()
16+
return {"Hello": "World"}
17+
18+
@autometrics
19+
def do_something():
20+
print("done")
21+
22+
if __name__ == "__main__":
23+
uvicorn.run(app, host="localhost", port=8080)

requirements.txt

+34-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,37 @@
1+
anyio==3.6.2
2+
bleach==6.0.0
3+
build==0.10.0
14
certifi==2022.12.7
2-
charset-normalizer==2.1.1
5+
charset-normalizer==3.1.0
6+
click==8.1.3
7+
docutils==0.19
8+
fastapi==0.95.0
9+
h11==0.14.0
310
idna==3.4
11+
importlib-metadata==6.1.0
12+
jaraco.classes==3.2.3
13+
keyring==23.13.1
14+
markdown-it-py==2.2.0
15+
mdurl==0.1.2
16+
more-itertools==9.1.0
17+
packaging==23.0
18+
pkginfo==1.9.6
419
prometheus-client==0.16.0
5-
requests==2.28.1
6-
urllib3==1.26.13
7-
python-dotenv==0.21.1
20+
pydantic==1.10.6
21+
Pygments==2.14.0
22+
pyproject_hooks==1.0.0
23+
python-dotenv==1.0.0
24+
readme-renderer==37.3
25+
requests==2.28.2
26+
requests-toolbelt==0.10.1
27+
rfc3986==2.0.0
28+
rich==13.3.2
29+
six==1.16.0
30+
sniffio==1.3.0
31+
starlette==0.26.1
32+
twine==4.0.2
33+
typing_extensions==4.5.0
34+
urllib3==1.26.15
35+
uvicorn==0.21.1
36+
webencodings==0.5.1
37+
zipp==3.15.0

setup.cfg

-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
[metadata]
2-
author = fiberplane
3-
author_email = hello@fiberplane.com
42
description = Autometrics package for python
53
long_description = file: README.md
64
long_description_content_type = text/markdown

setup.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,10 @@
22

33
setup(
44
name='autometrics',
5-
version='0.1',
5+
version='0.2',
66
packages=find_packages(),
77
install_requires=[
88
'prometheus_client',
9-
'prometheus_api_client',
109
'python-dotenv'
1110
]
1211
)

src/autometrics/autometrics.py

+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import inspect
44
from .prometheus_url import Generator
55
import os
6+
from functools import wraps
67

78
prom_counter = Counter('function_calls_count', 'query??', ['function', 'module', 'result'])
89
prom_histogram = Histogram('function_calls_duration', 'query??', ['function', 'module'])
@@ -17,6 +18,7 @@ def autometrics(func):
1718
else:
1819
classname = func.__qualname__.rsplit('.', 1)[0]
1920
module_name = f"{filename}.{classname}"
21+
@wraps(func)
2022
def wrapper(*args, **kwargs):
2123
func_name = func.__name__
2224
start_time = time.time()

0 commit comments

Comments
 (0)