Skip to content

Commit

Permalink
Assign lastEventId only if event was queued for submission (#1565)
Browse files Browse the repository at this point in the history
  • Loading branch information
maciejwalkowiak authored Jun 28, 2021
1 parent ceccb11 commit e7fb5c3
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
* Fix: Clock drift issue when calling DateUtils#getDateTimeWithMillisPrecision (#1557)
* Feat: Set mechanism type in SentryExceptionResolver (#1556)
* Ref: Prefer snake case for HTTP integration data keys (#1559)
* Fix: Assign lastEventId only if event was queued for submission (#1565)

## 5.1.0-beta.1

Expand Down
1 change: 1 addition & 0 deletions sentry/api/sentry.api
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,7 @@ public final class io/sentry/Scope {
public fun addBreadcrumb (Lio/sentry/Breadcrumb;Ljava/lang/Object;)V
public fun addEventProcessor (Lio/sentry/EventProcessor;)V
public fun clear ()V
public fun clearAttachments ()V
public fun clearBreadcrumbs ()V
public fun clearTransaction ()V
public fun getContexts ()Lio/sentry/protocol/Contexts;
Expand Down
2 changes: 1 addition & 1 deletion sentry/src/main/java/io/sentry/Hub.java
Original file line number Diff line number Diff line change
Expand Up @@ -87,14 +87,14 @@ public boolean isEnabled() {
assignTraceContext(event);
final StackItem item = stack.peek();
sentryId = item.getClient().captureEvent(event, item.getScope(), hint);
this.lastEventId = sentryId;
} catch (Exception e) {
options
.getLogger()
.log(
SentryLevel.ERROR, "Error while capturing event with id: " + event.getEventId(), e);
}
}
this.lastEventId = sentryId;
return sentryId;
}

Expand Down
13 changes: 13 additions & 0 deletions sentry/src/test/java/io/sentry/HubTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,19 @@ class HubTest {
verify(mockClient).captureEvent(eq(event), any(), eq(hint))
}

@Test
fun `when captureEvent is called on disabled hub, lastEventId does not get overwritten`() {
val (sut, mockClient) = getEnabledHub()
whenever(mockClient.captureEvent(any(), any(), anyOrNull())).thenReturn(SentryId(UUID.randomUUID()))
val event = SentryEvent()
val hint = { }
sut.captureEvent(event, hint)
val lastEventId = sut.lastEventId
sut.close()
sut.captureEvent(event, hint)
assertEquals(lastEventId, sut.lastEventId)
}

@Test
fun `when captureEvent is called and session tracking is disabled, it should not capture a session`() {
val (sut, mockClient) = getEnabledHub()
Expand Down

0 comments on commit e7fb5c3

Please sign in to comment.