DataDog / datadogpy

The Datadog Python library
https://datadoghq.com/
Other
609 stars 303 forks source link

'DogStatsd' object has no attribute 'guage' #756

Closed brianomchugh closed 1 year ago

brianomchugh commented 1 year ago

Describe the bug Unable to push metrics to statsd from a thread. The documentation says that the DogStatsd instance should be thread-safe, but I always get:

'DogStatsd' object has no attribute 'guage'

To Reproduce Steps to reproduce the behavior:

from time import sleep
from threading import Thread
from datadog import DogStatsd

class push_metric(Thread):
  def __init__(self, metric_name, value):
    Thread.__init__(self)
    self.metric_name = metric_name
    self.value = value
    self.start()

  def run(self):
    try:
      statsd = DogStatsd(host="127.0.0.1", port=8125)
      statsd.guage(self.metric_name, self.value)
    except Exception as e:
      print(e)

def main():
  i = 0
  while(1):
    i += 1
    push_metric('testguage', i)
    sleep(5)

if __name__ == "__main__":
  main()

Expected behavior Guage metric gets pushed

Environment and Versions: Python 3.9.2 datadogpy 0.44.2

Additional context Same result using the global statsd instance (vs creating new instance every time as seen in the code)

sgnn7 commented 1 year ago

Hi Brian, I think you wanted to use statsd.gauge and not statsd.guage in your code so it's just a spelling error. I'll close the issue but feel free to reopen if this isn't the case.