Skip to content

Commit 755d728

Browse files
authored
Fix missing transport attribute when flushing telemetry (#902)
* Fix transport attribute not being set * Update CHANGELOG.md * Set transport to udp for consistency
1 parent 3252664 commit 755d728

File tree

3 files changed

+22
-0
lines changed

3 files changed

+22
-0
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# Changelog
22

3+
## Unreleased
4+
* [Fixed] Fix missing transport attribute when flushing telemetry.
5+
36
## v0.52.0 / 2025-07-08
47

58
* [Added] Add Cardinality common field. See [#883](https://github.com/DataDog/datadogpy/pull/883)

datadog/dogstatsd/base.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -534,6 +534,7 @@ def socket(self, new_socket):
534534
except AttributeError: # _socket can't have a type if it doesn't have sockopts
535535
log.info("Unexpected socket provided with no support for getsockopt")
536536
self._socket_kind = None
537+
self._transport = "udp"
537538
# When the socket is None, we use the UDP optimal payload length
538539
self._max_payload_size = UDP_OPTIMAL_PAYLOAD_LENGTH
539540

tests/unit/dogstatsd/test_statsd.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2192,3 +2192,21 @@ def send(self, _):
21922192
statsd.increment("test", 1)
21932193

21942194
assert statsd.socket is not None
2195+
2196+
def test_transport_attribute_present_on_connection_error(self):
2197+
"""
2198+
Ensure `_transport` attribute is present for telemetry even if the socket is None.
2199+
"""
2200+
# This test will fail with an AttributeError before the fix.
2201+
# Use a non-resolvable host to trigger a connection error.
2202+
statsd = DogStatsd(
2203+
host='non.existent.host.datadog.internal',
2204+
telemetry_min_flush_interval=0 # Flush telemetry immediately
2205+
)
2206+
2207+
# This call will attempt to send a metric, fail to create a socket,
2208+
# and then attempt to send telemetry, which requires `_transport`.
2209+
statsd.gauge('test.metric', 1)
2210+
2211+
assert statsd.socket is None
2212+
assert statsd._transport is not None

0 commit comments

Comments
 (0)