Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

consider adding on_return and on_error transform functions to timer_decorator #120

Open
willkg opened this issue Sep 15, 2023 · 2 comments

Comments

@willkg
Copy link
Owner

willkg commented Sep 15, 2023

I often want to decorate functions with timer_decorator, but want to provide different tags depending on the returned result or error.

What if we added on_return and on_error transform functions with defaults:

def on_return(tags, value, ret):
    return tags, value, ret
def on_error(tags, value, exc):
    return tags, value, exc

These would get called here after the function has completed:

return fun(*args, **kwargs)

@willkg
Copy link
Owner Author

willkg commented Sep 15, 2023

@jwhitlock Have you ever needed something like this?

@jwhitlock
Copy link
Contributor

No, I haven't needed something like that, and I usually don't reach for timer_decorator

I've been using codetiming recently like this:

with Timer(logger=None) as something_timer:
    ret = do_something()
log_data = {
   something_s = round(something_timer.last, 3)
}
log.info("Ran something", extra=log_data)
markus.timing('ran.something', something_timer.last)

I can't really recommend my method or codetiming (main benefit - someone else maintains it). But usually, when I time something, I want to log it, not just send metrics.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants