Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Changelog

## Unreleased
* [Fixed] Fix missing transport attribute when flushing telemetry.

## v0.52.0 / 2025-07-08

* [Added] Add Cardinality common field. See [#883](https://github.com/DataDog/datadogpy/pull/883)
Expand Down
1 change: 1 addition & 0 deletions datadog/dogstatsd/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -534,6 +534,7 @@ def socket(self, new_socket):
except AttributeError: # _socket can't have a type if it doesn't have sockopts
log.info("Unexpected socket provided with no support for getsockopt")
self._socket_kind = None
self._transport = "udp"
# When the socket is None, we use the UDP optimal payload length
self._max_payload_size = UDP_OPTIMAL_PAYLOAD_LENGTH

Expand Down
18 changes: 18 additions & 0 deletions tests/unit/dogstatsd/test_statsd.py
Original file line number Diff line number Diff line change
Expand Up @@ -2192,3 +2192,21 @@ def send(self, _):
statsd.increment("test", 1)

assert statsd.socket is not None

def test_transport_attribute_present_on_connection_error(self):
"""
Ensure `_transport` attribute is present for telemetry even if the socket is None.
"""
# This test will fail with an AttributeError before the fix.
# Use a non-resolvable host to trigger a connection error.
statsd = DogStatsd(
host='non.existent.host.datadog.internal',
telemetry_min_flush_interval=0 # Flush telemetry immediately
)

# This call will attempt to send a metric, fail to create a socket,
# and then attempt to send telemetry, which requires `_transport`.
statsd.gauge('test.metric', 1)

assert statsd.socket is None
assert statsd._transport is not None
Loading