File tree Expand file tree Collapse file tree 3 files changed +22
-0
lines changed
Expand file tree Collapse file tree 3 files changed +22
-0
lines changed Original file line number Diff line number Diff line change 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 )
Original file line number Diff line number Diff 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
Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments