Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Assign lastEventId only if event was queued for submission #1565

Merged
merged 4 commits into from
Jun 28, 2021
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
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