Skip to content

Commit f8be45b

Browse files
committed
Fix constant_tags accumulation in ThreadStatsWriter.flush to prevent metric loss
1 parent 2b85536 commit f8be45b

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

datadog_lambda/thread_stats_writer.py

+7-1
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,11 @@ def flush(self, tags=None):
2727
Modified based on `datadog.threadstats.base.ThreadStats.flush()`,
2828
to gain better control over exception handling.
2929
"""
30+
original_constant_tags = self.thread_stats.constant_tags.copy()
3031
if tags:
31-
self.thread_stats.constant_tags = self.thread_stats.constant_tags + tags
32+
# Temporarily add tags for this flush
33+
self.thread_stats.constant_tags = original_constant_tags + tags
34+
3235
_, dists = self.thread_stats._get_aggregate_metrics_and_dists(float("inf"))
3336
count_dists = len(dists)
3437
if not count_dists:
@@ -62,6 +65,9 @@ def flush(self, tags=None):
6265
logger.debug(
6366
"Flush #%s failed", self.thread_stats.flush_count, exc_info=True
6467
)
68+
finally:
69+
# Reset constant_tags to its original state
70+
self.thread_stats.constant_tags = original_constant_tags
6571

6672
def stop(self):
6773
self.thread_stats.stop()

0 commit comments

Comments
 (0)