diff --git a/.gitignore b/.gitignore index ea5e707..0f3420a 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,7 @@ data/ .vscode/ my_testing/ +autometrics-venv/ # Byte-compiled / optimized / DLL files __pycache__/ diff --git a/examples/fastapi-example.py b/examples/fastapi-example.py index 8c6e138..c3d4859 100644 --- a/examples/fastapi-example.py +++ b/examples/fastapi-example.py @@ -6,13 +6,12 @@ app = FastAPI() @app.get("/metrics") -async def metrics(): +def metrics(): return Response(generate_latest()) -@autometrics @app.get("/") -async def read_root(): - print("This is inside the read_root") +@autometrics +def read_root(): do_something() return {"Hello": "World"} @@ -20,8 +19,5 @@ async def read_root(): def do_something(): print("done") -print(read_root.__doc__) -print(do_something.__doc__) - -if __name__ == "__main__": +if __name__ == "__main__": uvicorn.run(app, host="localhost", port=8080) \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index c9ded23..378631b 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,7 +1,16 @@ -certifi==2022.12.7 -charset-normalizer==2.1.1 +anyio==3.6.2 +build==0.10.0 +click==8.1.3 +fastapi==0.95.0 +h11==0.14.0 idna==3.4 +packaging==23.0 prometheus-client==0.16.0 -requests==2.28.1 -urllib3==1.26.13 -python-dotenv==0.21.1 +pydantic==1.10.6 +pyproject_hooks==1.0.0 +python-dotenv==1.0.0 +sniffio==1.3.0 +starlette==0.26.1 +typing_extensions==4.5.0 +urllib3==1.26.15 +uvicorn==0.21.1 diff --git a/setup.cfg b/setup.cfg index 59ce26e..8835496 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,7 +1,5 @@ [metadata] -author = fiberplane -author_email = hello@fiberplane.com -description = Autometrics package for python + description = Autometrics package for python long_description = file: README.md long_description_content_type = text/markdown url = https://github.com/autometrics-dev/autometrics-py diff --git a/setup.py b/setup.py index a36d521..97613c4 100644 --- a/setup.py +++ b/setup.py @@ -6,7 +6,6 @@ packages=find_packages(), install_requires=[ 'prometheus_client', - 'prometheus_api_client', 'python-dotenv' ] ) \ No newline at end of file diff --git a/src/autometrics/autometrics.py b/src/autometrics/autometrics.py index 9e88250..28e2c9f 100644 --- a/src/autometrics/autometrics.py +++ b/src/autometrics/autometrics.py @@ -3,6 +3,7 @@ import inspect from .prometheus_url import Generator import os +from functools import wraps prom_counter = Counter('function_calls_count', 'query??', ['function', 'module', 'result']) prom_histogram = Histogram('function_calls_duration', 'query??', ['function', 'module']) @@ -17,6 +18,7 @@ def autometrics(func): else: classname = func.__qualname__.rsplit('.', 1)[0] module_name = f"{filename}.{classname}" + @wraps(func) def wrapper(*args, **kwargs): func_name = func.__name__ start_time = time.time()