Skip to content

Commit

Permalink
Merge pull request #8 from autometrics-dev/fastapi
Browse files Browse the repository at this point in the history
Fastapi
  • Loading branch information
v-aparna authored Mar 23, 2023
2 parents a0c2f04 + 0b4e97f commit 8bb51d5
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 8 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
data/
.vscode/
my_testing/
autometrics-venv/

# Byte-compiled / optimized / DLL files
__pycache__/
Expand Down
23 changes: 23 additions & 0 deletions examples/fastapi-example.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
from fastapi import FastAPI, Response
import uvicorn
from autometrics.autometrics import autometrics
from prometheus_client import generate_latest

app = FastAPI()

@app.get("/metrics")
def metrics():
return Response(generate_latest())

@app.get("/")
@autometrics
def read_root():
do_something()
return {"Hello": "World"}

@autometrics
def do_something():
print("done")

if __name__ == "__main__":
uvicorn.run(app, host="localhost", port=8080)
38 changes: 34 additions & 4 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,37 @@
anyio==3.6.2
bleach==6.0.0
build==0.10.0
certifi==2022.12.7
charset-normalizer==2.1.1
charset-normalizer==3.1.0
click==8.1.3
docutils==0.19
fastapi==0.95.0
h11==0.14.0
idna==3.4
importlib-metadata==6.1.0
jaraco.classes==3.2.3
keyring==23.13.1
markdown-it-py==2.2.0
mdurl==0.1.2
more-itertools==9.1.0
packaging==23.0
pkginfo==1.9.6
prometheus-client==0.16.0
requests==2.28.1
urllib3==1.26.13
python-dotenv==0.21.1
pydantic==1.10.6
Pygments==2.14.0
pyproject_hooks==1.0.0
python-dotenv==1.0.0
readme-renderer==37.3
requests==2.28.2
requests-toolbelt==0.10.1
rfc3986==2.0.0
rich==13.3.2
six==1.16.0
sniffio==1.3.0
starlette==0.26.1
twine==4.0.2
typing_extensions==4.5.0
urllib3==1.26.15
uvicorn==0.21.1
webencodings==0.5.1
zipp==3.15.0
2 changes: 0 additions & 2 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
[metadata]
author = fiberplane
author_email = [email protected]
description = Autometrics package for python
long_description = file: README.md
long_description_content_type = text/markdown
Expand Down
3 changes: 1 addition & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@

setup(
name='autometrics',
version='0.1',
version='0.2',
packages=find_packages(),
install_requires=[
'prometheus_client',
'prometheus_api_client',
'python-dotenv'
]
)
2 changes: 2 additions & 0 deletions src/autometrics/autometrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'])
Expand All @@ -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()
Expand Down

0 comments on commit 8bb51d5

Please sign in to comment.