From 225fbe1b7f4d096d310999dafb75dd1a0dffb684 Mon Sep 17 00:00:00 2001 From: Markus Hintersteiner Date: Mon, 17 Jun 2024 23:01:18 +0200 Subject: [PATCH 1/2] Fix schedule flag reset --- .../src/main/java/io/sentry/MetricsAggregator.java | 2 ++ .../test/java/io/sentry/MetricsAggregatorTest.kt | 13 +++++++++++++ 2 files changed, 15 insertions(+) diff --git a/sentry/src/main/java/io/sentry/MetricsAggregator.java b/sentry/src/main/java/io/sentry/MetricsAggregator.java index 71e5a40f3f..ebc634700b 100644 --- a/sentry/src/main/java/io/sentry/MetricsAggregator.java +++ b/sentry/src/main/java/io/sentry/MetricsAggregator.java @@ -239,6 +239,8 @@ public void flush(boolean force) { force = true; } + flushScheduled = false; + final @NotNull Set flushableBuckets = getFlushableBuckets(force); if (flushableBuckets.isEmpty()) { logger.log(SentryLevel.DEBUG, "Metrics: nothing to flush"); diff --git a/sentry/src/test/java/io/sentry/MetricsAggregatorTest.kt b/sentry/src/test/java/io/sentry/MetricsAggregatorTest.kt index 1b2b2f36e1..01948114de 100644 --- a/sentry/src/test/java/io/sentry/MetricsAggregatorTest.kt +++ b/sentry/src/test/java/io/sentry/MetricsAggregatorTest.kt @@ -312,6 +312,19 @@ class MetricsAggregatorTest { // there is no other metric to capture, so flush is not scheduled again assertFalse(fixture.executorService.hasScheduledRunnables()) + + // once another metric is emitted + aggregator.increment( + "name1", + 1.0, + MeasurementUnit.Custom("unit0"), + mapOf("key0" to "value0"), + 20_001, + null + ) + + // then flush should be scheduled again + assertTrue(fixture.executorService.hasScheduledRunnables()) } @Test From 544692e725873e5960a66249f06bb21bc95d48cc Mon Sep 17 00:00:00 2001 From: Markus Hintersteiner Date: Mon, 17 Jun 2024 23:11:56 +0200 Subject: [PATCH 2/2] Update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 49b1043474..338c998881 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ ### Fixes - Remove profiling timeout logic and disable profiling on API 21 ([#3478](https://github.com/getsentry/sentry-java/pull/3478)) +- Properly reset metric flush flag on metric emission ([#3493](https://github.com/getsentry/sentry-java/pull/3493)) ## 7.10.0