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

Context managed statsd.timed #25

Closed
LeoCavaille opened this issue Apr 3, 2015 · 2 comments · Fixed by #65
Closed

Context managed statsd.timed #25

LeoCavaille opened this issue Apr 3, 2015 · 2 comments · Fixed by #65

Comments

@LeoCavaille
Copy link
Member

Right now you can use statsd.timed, that would be cool when you want to measure the runtime of some random code to be able to do:

with statsd.timed('execution_time'):
    [some code...]
clokep added a commit to percipient/datadogpy that referenced this issue Jun 30, 2015
This enables a context manager in statsd so you can easily time
a set of code without saving the start time, etc. manually:

```python
with statsd.timed_context('user.query.time', sample_rate=0.5):
    # Do what you need to ...
    pass

start = time.time()
try:
    get_user(user_id)
finally:
    statsd.timing('user.query.time', time.time() - start)
```

Two tests are also added for this code.

Fixes DataDog#25
clokep added a commit to percipient/datadogpy that referenced this issue Jun 30, 2015
This enables a context manager in statsd so you can easily time
a set of code without saving the start time, etc. manually:

```python
    with statsd.timed_context('user.query.time', sample_rate=0.5):
        # Do what you need to ...
        pass

    # Is equivalent to ...
    start = time.time()
    try:
        get_user(user_id)
    finally:
        statsd.timing('user.query.time', time.time() - start)
```

Two tests are also added for this code.

Fixes DataDog#25
@LeoCavaille
Copy link
Member Author

:yay: thanks!!

@clokep
Copy link
Contributor

clokep commented Jul 1, 2015

You're welcome! :)

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

Successfully merging a pull request may close this issue.

2 participants