From 08c997459244e3cc734b82ee0c7dfbc0db421455 Mon Sep 17 00:00:00 2001 From: Maciej Walkowiak Date: Fri, 25 Jun 2021 17:10:43 +0200 Subject: [PATCH 1/4] Assign lastEventId only if event has been sent successfully Fixes #1414 --- CHANGELOG.md | 1 + sentry/api/sentry.api | 1 + sentry/src/main/java/io/sentry/Hub.java | 2 +- sentry/src/test/java/io/sentry/HubTest.kt | 13 +++++++++++++ 4 files changed, 16 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0e673e2497..4b489d3dcc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) +* Feat: Assign lastEventId only if event has been sent successfully () ## 5.1.0-beta.1 diff --git a/sentry/api/sentry.api b/sentry/api/sentry.api index 1e25bf9548..1bb674dc44 100644 --- a/sentry/api/sentry.api +++ b/sentry/api/sentry.api @@ -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; diff --git a/sentry/src/main/java/io/sentry/Hub.java b/sentry/src/main/java/io/sentry/Hub.java index 9daf50a9d4..490da48cbc 100644 --- a/sentry/src/main/java/io/sentry/Hub.java +++ b/sentry/src/main/java/io/sentry/Hub.java @@ -87,6 +87,7 @@ 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() @@ -94,7 +95,6 @@ public boolean isEnabled() { SentryLevel.ERROR, "Error while capturing event with id: " + event.getEventId(), e); } } - this.lastEventId = sentryId; return sentryId; } diff --git a/sentry/src/test/java/io/sentry/HubTest.kt b/sentry/src/test/java/io/sentry/HubTest.kt index 2195afc283..a1aea67909 100644 --- a/sentry/src/test/java/io/sentry/HubTest.kt +++ b/sentry/src/test/java/io/sentry/HubTest.kt @@ -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() From 503d965c9f36cee9e217ea6f6d39d7f67832ff2e Mon Sep 17 00:00:00 2001 From: Maciej Walkowiak Date: Fri, 25 Jun 2021 17:15:55 +0200 Subject: [PATCH 2/4] Changelog. --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4b489d3dcc..dabae92dbb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,7 +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) -* Feat: Assign lastEventId only if event has been sent successfully () +* Feat: Assign lastEventId only if event has been sent successfully (#1565) ## 5.1.0-beta.1 From e52cb68687b652f4e1bf0c55caf71ff1151d9f2d Mon Sep 17 00:00:00 2001 From: Maciej Walkowiak Date: Fri, 25 Jun 2021 19:29:00 +0200 Subject: [PATCH 3/4] Update CHANGELOG.md Co-authored-by: Bruno Garcia --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index dabae92dbb..591884beaa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,7 +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) -* Feat: Assign lastEventId only if event has been sent successfully (#1565) +* Feat: Assign lastEventId only if event was queued for submission (#1565) ## 5.1.0-beta.1 From 3be1351245d0d7a34f01c8705fcd3bc33cfea391 Mon Sep 17 00:00:00 2001 From: Manoel Aranda Neto <5731772+marandaneto@users.noreply.github.com> Date: Mon, 28 Jun 2021 09:12:57 +0200 Subject: [PATCH 4/4] Update CHANGELOG.md --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 591884beaa..7ff85b3e40 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,7 +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) -* Feat: Assign lastEventId only if event was queued for submission (#1565) +* Fix: Assign lastEventId only if event was queued for submission (#1565) ## 5.1.0-beta.1