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 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