mozilla-services / mozilla-services/markus

consider adding on_return and on_error transform functions to timer_decorator

Open
#120 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
70
Forks
9
PR merge metrics
No merged PRs in 30d

Description

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:

https://github.com/willkg/markus/blob/a3a5db6b9635fa04ceb66f4b2c11058b4e09ba17/src/markus/main.py#L515

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at the timer_decorator completion logic in src/markus/main.py around line 515, as linked in the issue. Review how returned values and errors are currently handled, then determine how the proposed on_return and on_error callbacks should receive and return tags, value, and result or exception. Done means both optional transforms have the stated defaults and are invoked after completion or failure.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
observability
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.