How to use this client across some application in Pythonic way? #724
-
Hi all, Sorry if this questions is too broad or inappropriate. Basically I'm wondering how should I use this client in my project. Let's say I have 30 methods or/and functions throughout my project that I would love to track execution time etc. I would probably define something like this: # metrics.py module
MODEL_PREDICTION_PROCESSING_TIME = Summary('model_prediction_processing_time', 'Time spent while running prediction')
# Other 30ish lines each defining some metric like the above one And would use it as a decorator on my method for example like this: # Some other module for example: model.py
from metrics import MODEL_PREDICTION_PROCESSING_TIME
class SomeModel:
@MODEL_PREDICTION_PROCESSING_TIME.time()
def _predict(self, features: List) -> tuple:
pass Now, is this good approach for the python client? Should I define maybe these global variables in the module that uses them or? Thank you upfront |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 5 replies
-
Typically I will try to define a metric in the same file as where it is used, but I have certainly come across some cases where that has not made sense. Sometimes that means I change around where the timing is done, e.g. I will time |
Beta Was this translation helpful? Give feedback.
Typically I will try to define a metric in the same file as where it is used, but I have certainly come across some cases where that has not made sense. Sometimes that means I change around where the timing is done, e.g. I will time
predict
from where it is being called instead of having to remember to time it for each implementation. What you describe will work fine though, keeping the definition and usage close is just something I find easier to reason about/maintain.