Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@

- Reduce unboxing in `DateUtils.nanosToDate` ([#5523](https://github.com/getsentry/sentry-java/pull/5523))

### Fixes

- Fix performance collector scheduling many tasks in a row ([#5524](https://github.com/getsentry/sentry-java/pull/5524))

## 8.43.2

### Improvements
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ public final class DefaultCompositePerformanceCollector implements CompositePerf

private final @NotNull SentryOptions options;
private final @NotNull AtomicBoolean isStarted = new AtomicBoolean(false);
private long lastCollectionTimestamp = 0;

public DefaultCompositePerformanceCollector(final @NotNull SentryOptions options) {
this.options = Objects.requireNonNull(options, "The options object is required.");
Expand Down Expand Up @@ -112,16 +111,8 @@ public void run() {
new TimerTask() {
@Override
public void run() {
long now = System.currentTimeMillis();
Comment thread
runningcode marked this conversation as resolved.
// The timer is scheduled to run every 100ms on average. In case it takes longer,
// subsequent tasks are executed more quickly. If two tasks are scheduled to run in
// less than 10ms, the measurement that we collect is not meaningful, so we skip it
if (now - lastCollectionTimestamp <= 10) {
return;
}
timedOutTransactions.clear();

lastCollectionTimestamp = now;
final @NotNull PerformanceCollectionData tempData =
new PerformanceCollectionData(options.getDateProvider().now().nanoTimestamp());

Expand All @@ -147,7 +138,7 @@ public void run() {
}
}
};
timer.scheduleAtFixedRate(
timer.schedule(
timerTask,
TRANSACTION_COLLECTION_INTERVAL_MILLIS,
TRANSACTION_COLLECTION_INTERVAL_MILLIS);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ class DefaultCompositePerformanceCollectorTest {
val collector = fixture.getSut(null, null)
assertTrue(fixture.options.performanceCollectors.isEmpty())
collector.start(fixture.transaction1)
verify(fixture.mockTimer, never())!!.scheduleAtFixedRate(any(), any<Long>(), any())
verify(fixture.mockTimer, never())!!.schedule(any(), any<Long>(), any())
}

@Test
Expand All @@ -104,22 +104,22 @@ class DefaultCompositePerformanceCollectorTest {
fun `when start, timer is scheduled every 100 milliseconds`() {
val collector = fixture.getSut()
collector.start(fixture.transaction1)
verify(fixture.mockTimer)!!.scheduleAtFixedRate(any(), any<Long>(), eq(100))
verify(fixture.mockTimer)!!.schedule(any(), any<Long>(), eq(100))
}

@Test
fun `when start with a string, timer is scheduled every 100 milliseconds`() {
val collector = fixture.getSut()
collector.start(fixture.id1)
verify(fixture.mockTimer)!!.scheduleAtFixedRate(any(), any<Long>(), eq(100))
verify(fixture.mockTimer)!!.schedule(any(), any<Long>(), eq(100))
}

@Test
fun `when stop, timer is stopped`() {
val collector = fixture.getSut()
collector.start(fixture.transaction1)
collector.stop(fixture.transaction1)
verify(fixture.mockTimer)!!.scheduleAtFixedRate(any(), any<Long>(), eq(100))
verify(fixture.mockTimer)!!.schedule(any(), any<Long>(), eq(100))
verify(fixture.mockTimer)!!.cancel()
}

Expand All @@ -128,15 +128,15 @@ class DefaultCompositePerformanceCollectorTest {
val collector = fixture.getSut()
collector.start(fixture.id1)
collector.stop(fixture.id1)
verify(fixture.mockTimer)!!.scheduleAtFixedRate(any(), any<Long>(), eq(100))
verify(fixture.mockTimer)!!.schedule(any(), any<Long>(), eq(100))
verify(fixture.mockTimer)!!.cancel()
}

@Test
fun `stopping a not collected transaction return null`() {
val collector = fixture.getSut()
val data = collector.stop(fixture.transaction1)
verify(fixture.mockTimer, never())!!.scheduleAtFixedRate(any(), any<Long>(), eq(100))
verify(fixture.mockTimer, never())!!.schedule(any(), any<Long>(), eq(100))
verify(fixture.mockTimer, never())!!.cancel()
assertNull(data)
}
Expand All @@ -145,7 +145,7 @@ class DefaultCompositePerformanceCollectorTest {
fun `stopping a not collected id return null`() {
val collector = fixture.getSut()
val data = collector.stop(fixture.id1)
verify(fixture.mockTimer, never())!!.scheduleAtFixedRate(any(), any<Long>(), eq(100))
verify(fixture.mockTimer, never())!!.schedule(any(), any<Long>(), eq(100))
verify(fixture.mockTimer, never())!!.cancel()
assertNull(data)
}
Expand Down Expand Up @@ -316,7 +316,7 @@ class DefaultCompositePerformanceCollectorTest {
collector.close()

// Timer was canceled
verify(fixture.mockTimer)!!.scheduleAtFixedRate(any(), any<Long>(), eq(100))
verify(fixture.mockTimer)!!.schedule(any(), any<Long>(), eq(100))
verify(fixture.mockTimer)!!.cancel()

// Data was cleared
Expand Down
Loading