Skip to content

Commit

Permalink
Provide backwards compatible telemetry counters (#801)
Browse files Browse the repository at this point in the history
* AMLII-1297 provide backwards compatible telemetry counters

Fixes #795

* Add test case for the public telemetry api
  • Loading branch information
vickenty authored Nov 24, 2023
1 parent 4cd7ba3 commit 5455e9c
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
10 changes: 9 additions & 1 deletion datadog/dogstatsd/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -929,11 +929,19 @@ def _reset_telemetry(self):
self.bytes_dropped_queue = 0
self.bytes_dropped_writer = 0
self.packets_sent = 0
self.packets_dropped = 0
self.packets_dropped_queue = 0
self.packets_dropped_writer = 0
self._last_flush_time = time.time()

# Aliases for backwards compatibility.
@property
def packets_dropped(self):
return self.packets_dropped_queue + self.packets_dropped_writer

@property
def bytes_dropped(self):
return self.bytes_dropped_queue + self.bytes_dropped_writer

def _flush_telemetry(self):
telemetry_tags = ",".join(self._add_constant_tags(self._client_tags))

Expand Down
15 changes: 15 additions & 0 deletions tests/unit/dogstatsd/test_statsd.py
Original file line number Diff line number Diff line change
Expand Up @@ -1928,3 +1928,18 @@ def test_set_socket_timeout(self):
statsd.set_socket_timeout(1)
self.assertEqual(statsd.socket.timeout, 1)
self.assertEqual(statsd.socket_timeout, 1)

def test_telemetry_api(self):
statsd = DogStatsd(disable_background_sender=False)

self.assertEqual(statsd.metrics_count, 0)
self.assertEqual(statsd.events_count, 0)
self.assertEqual(statsd.service_checks_count, 0)
self.assertEqual(statsd.bytes_sent, 0)
self.assertEqual(statsd.bytes_dropped, 0)
self.assertEqual(statsd.bytes_dropped_queue, 0)
self.assertEqual(statsd.bytes_dropped_writer, 0)
self.assertEqual(statsd.packets_sent, 0)
self.assertEqual(statsd.packets_dropped, 0)
self.assertEqual(statsd.packets_dropped_queue, 0)
self.assertEqual(statsd.packets_dropped_writer, 0)

0 comments on commit 5455e9c

Please sign in to comment.