TimotheBarbe commented on code in PR #74848: URL: https://github.com/apache/airflow/pull/74848#discussion_r4311267036
########## shared/observability/src/airflow_shared/observability/metrics/datadog_logger.py: ########## @@ -39,6 +39,27 @@ log = logging.getLogger(__name__) +class _DogStatsdTimer(Timer): + """ + An implementation of stats.Timer() which sends its measured duration to DogStatsd. + + ``DogStatsd.timed()`` reports seconds unless the client sets ``use_ms``, and rounds to whole + milliseconds when it does, so the duration measured by ``Timer`` is sent instead. + """ + + def __init__(self, dogstatsd: DogStatsd, stat: str, tags: list[str], **kwargs) -> None: + super().__init__() + self.dogstatsd = dogstatsd + self.stat = stat + self.tags = tags + self.kwargs = kwargs + + def stop(self, send: bool = True) -> None: + super().stop(send) + if send and self.duration is not None: + self.dogstatsd.timing(metric=self.stat, value=self.duration, tags=self.tags, **self.kwargs) Review Comment: good catch ! -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
