Skip to content

Commit d701281

Browse files
committed
don't send None to statsd daemon as metric value
1 parent 166051f commit d701281

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

datadog/dogstatsd/base.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,9 @@ def decrement(self, metric, value=1, tags=None, sample_rate=1):
129129
>>> statsd.decrement('files.remaining')
130130
>>> statsd.decrement('active.connections', 2)
131131
"""
132+
if value is None:
133+
return
134+
132135
self._report(metric, 'c', -value, tags, sample_rate)
133136

134137
def histogram(self, metric, value, tags=None, sample_rate=1):
@@ -222,6 +225,9 @@ def set(self, metric, value, tags=None, sample_rate=1):
222225
self._report(metric, 's', value, tags, sample_rate)
223226

224227
def _report(self, metric, metric_type, value, tags, sample_rate):
228+
if value is None:
229+
return
230+
225231
if sample_rate != 1 and random() > sample_rate:
226232
return
227233

tests/unit/dogstatsd/test_statsd.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,27 @@ def test_tags_from_environment_and_constant(self):
421421
statsd.gauge('gt', 123.4)
422422
t.assert_equal('gt:123.4|g|#country:canada,red,country:china,age:45,blue', statsd.socket.recv())
423423

424+
def test_gauge_doesnt_send_None(self):
425+
self.statsd.gauge('metric', None)
426+
assert self.recv() is None
427+
428+
def test_increment_doesnt_send_None(self):
429+
self.statsd.increment('metric', None)
430+
assert self.recv() is None
431+
432+
def test_decrement_doesnt_send_None(self):
433+
self.statsd.decrement('metric', None)
434+
assert self.recv() is None
435+
436+
def test_timing_doesnt_send_None(self):
437+
self.statsd.timing('metric', None)
438+
assert self.recv() is None
439+
440+
def test_histogram_doesnt_send_None(self):
441+
self.statsd.histogram('metric', None)
442+
assert self.recv() is None
443+
444+
424445
if __name__ == '__main__':
425446
statsd = statsd
426447
while True:

0 commit comments

Comments
 (0)