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

Provide elapsed time when using 'timed' context manager #135

Closed
tuukkamustonen opened this issue May 26, 2016 · 2 comments
Closed

Provide elapsed time when using 'timed' context manager #135

tuukkamustonen opened this issue May 26, 2016 · 2 comments
Assignees

Comments

@tuukkamustonen
Copy link

tuukkamustonen commented May 26, 2016

Consider:

with statsd.timed('mymetric') as t:
    ...
t.ms  # get elapsed time

This is possible with statsd python package, but unfortunately not with datadog package (elapsed time is not stored in _TimedContextManagerDecorator. If I made a PR, would be willing to merge something like this:

    class _TimedContextManagerDecorator(object):

        def __init__(self, statsd, metric=None, tags=None, sample_rate=1, use_ms=None):
            ...
            self.elapsed = None

        def __enter__(self):
            ...
            return self

        def _send(self, start):
            self.elapsed = time() - start
            ...

And yeah, I could call time() - t.start myself, but it wouldn't match the sent value as time() could be different already...

@tuukkamustonen tuukkamustonen changed the title Provide elapsed time when using context manager Provide elapsed time when using 'timed' context manager May 26, 2016
@yannmh yannmh self-assigned this May 26, 2016
@yannmh
Copy link
Member

yannmh commented May 26, 2016

Nice idea @tuukkamustonen 💡 , I was not actually aware that such a method exists in the statsd Python package.
We'll be happy to review your PR if you decide to make one :)

@tuukkamustonen
Copy link
Author

Fixed in #154.

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