wolph / python-statsd

Python Client for the Etsy NodeJS Statsd Server
http://readthedocs.org/docs/python-statsd/en/latest/
BSD 3-Clause "New" or "Revised" License
110 stars 39 forks source link

Fixed a bug where ``self.logger`` wouldn't be available in manual use. #6

Closed toastdriven closed 12 years ago

toastdriven commented 12 years ago

In trying to manually use the following code:

timer = statsd.Timer(slug, connection=conn)
timer.send('total', seconds_taken)

...it would blow up with the exception AttributeError: 'Timer' object has no attribute 'logger'. This commit fixes that.

wolph commented 12 years ago

That code actually works just fine for me without your patch.

Not that using super is bad or anything, but they should behave identically in this case. Can you explain how/why this diff would solve your issue?

toastdriven commented 12 years ago

Irritatingly, I'm having trouble reproducing it when using alone. However, in building https://github.com/frankwiles/django-app-metrics/pull/12/files, it errors using the old-style initialization but using super works fine. Can reproduce it there every time. :( If you see anything I did in using python-statsd that's obviously wrong, I'd welcome the thoughts.

wolph commented 12 years ago

I don't see anything obviously wrong there, but I would strongly recommend not using Celery for logging to statsd. Since statsd will log using UDP it won't ever block* your requests so the overhead is a lot lower than sending a task to Celery.

One possible cause of your issues, a stray pyc file. If the statsd object is somehow something different... although that's a long shot imho.

I will merge in your changes regardless since they won't hurt anyone, but personally I'd like to find out what's going wrong :)

toastdriven commented 12 years ago

Unfortunately, @fwiles ran the setup on his machine & had the same failure, so I'm not sure it's .pyc-related. And agreed on the UDP bit, but the idea is that the backends are pluggable & keeping the code similar makes it easier.

Long story short, I lost four hours of my life trying to decipher what the difference between your version & mine really was & came up empty handed. Sorry for the pain, but thanks for the merge.

wolph commented 12 years ago

Very weird bug... I'm also very curious as to what is going wrong there. It might even be some weird relative vs. absolute import thing... getting the wrong object might cause this.

Since there's also a statsd.py in the other project. But... if it works than I'll just leave it alone :) I'll bump the version too.