cyberdelia / metrology

A library to easily measure what's going on in your python.
https://metrology.readthedocs.org
MIT License
309 stars 25 forks source link

backwards compatible tag support for graphite, librato, logger and statsd (kinda) #42

Closed ghost closed 4 years ago

ghost commented 4 years ago

Why

What

This patch brings tag support to metrology. Each metric can have multiple tags associated with it and metrics with the same name but different tags are distinct from one another.

All public method signatures are backwards compatible. This is achieved by reusing the name parameter in that it can now be a string as previously or a dict containing the name and tags. I've implemented an alternate version where tags are an optional parameter but didn't like the overall look of this (https://github.com/sv-fko/metrology/tree/tag_support)

This is what it looks like in code:

c = self.registry.counter({
   "name": "orders_processed",
   "product": "widgets",
   "payment_method": "credit_card" 
 })

Reporter implementations can optin to the tag support by consuming the with_tags property of the registry while old reporters can still just use the iterator on the registry itself which just returns name and value like previously.

Drive-by changes

Open issues

Please let me know what you think. If you would be willing to merge this, I'd update the docs.

cyberdelia commented 4 years ago

That’s a very nice addition, I’ll need some time to review it. If anyone else want to review it they are welcome to as well.

ghost commented 4 years ago

Thank you for your consideration. I've updated the README to complete the patch for review.