Skip to content

Commit a961ffa

Browse files
committed
fix: handle MetricIntakeType.DISTRIBUTION gracefully
fallback to GAUGE if DISTRIBUTION is not available in datadog-api-client version
1 parent 650d201 commit a961ffa

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

devops/datadog/models.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,21 @@ def to_series(self): # type: ignore[override]
4444
from datadog_api_client.v2.model.metric_point import MetricPoint
4545
from datadog_api_client.v2.model.metric_series import MetricSeries
4646

47-
intake_type = {
47+
# Map our MetricKind to Datadog's MetricIntakeType
48+
# Note: DISTRIBUTION may not be available in all datadog-api-client versions
49+
intake_type_map = {
4850
MetricKind.GAUGE: MetricIntakeType.GAUGE,
4951
MetricKind.COUNT: MetricIntakeType.COUNT,
50-
MetricKind.DISTRIBUTION: MetricIntakeType.DISTRIBUTION,
51-
}[self.kind]
52+
}
53+
# Fallback to GAUGE if DISTRIBUTION is not available
54+
if self.kind == MetricKind.DISTRIBUTION:
55+
if hasattr(MetricIntakeType, "DISTRIBUTION"):
56+
intake_type = MetricIntakeType.DISTRIBUTION
57+
else:
58+
# DISTRIBUTION not supported, use GAUGE as fallback
59+
intake_type = MetricIntakeType.GAUGE
60+
else:
61+
intake_type = intake_type_map[self.kind]
5262

5363
return MetricSeries(
5464
metric=self.name,

0 commit comments

Comments
 (0)