Skip to content

Commit

Permalink
Merge f9127c1 into dd03aa1
Browse files Browse the repository at this point in the history
  • Loading branch information
adinauer committed Mar 10, 2023
2 parents dd03aa1 + f9127c1 commit 95f1d9a
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 34 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
### Fixes

- Deprecate reportFullDisplayed in favor of reportFullyDisplayed ([#2585](https://github.com/getsentry/sentry-java/pull/2585))
- No longer send event / transaction to Sentry if `beforeSend` / `beforeSendTransaction` throws ([#2591](https://github.com/getsentry/sentry-java/pull/2591))
- Add version to sentryClientName used in auth header ([#2596](https://github.com/getsentry/sentry-java/pull/2596))

## 6.15.0
Expand Down
22 changes: 4 additions & 18 deletions sentry/src/main/java/io/sentry/SentryClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -705,15 +705,8 @@ private void sortBreadcrumbsByDate(
"The BeforeSend callback threw an exception. It will be added as breadcrumb and continue.",
e);

final Breadcrumb breadcrumb = new Breadcrumb();
breadcrumb.setMessage("BeforeSend callback failed.");
breadcrumb.setCategory("SentryClient");
breadcrumb.setLevel(SentryLevel.ERROR);
if (e.getMessage() != null) {
breadcrumb.setData("sentry:message", e.getMessage());
}

event.addBreadcrumb(breadcrumb);
// drop event in case of an error in beforeSend due to PII concerns
event = null;
}
}
return event;
Expand All @@ -734,15 +727,8 @@ private void sortBreadcrumbsByDate(
"The BeforeSendTransaction callback threw an exception. It will be added as breadcrumb and continue.",
e);

final Breadcrumb breadcrumb = new Breadcrumb();
breadcrumb.setMessage("BeforeSendTransaction callback failed.");
breadcrumb.setCategory("SentryClient");
breadcrumb.setLevel(SentryLevel.ERROR);
if (e.getMessage() != null) {
breadcrumb.setData("sentry:message", e.getMessage());
}

transaction.addBreadcrumb(breadcrumb);
// drop transaction in case of an error in beforeSend due to PII concerns
transaction = null;
}
}
return transaction;
Expand Down
32 changes: 16 additions & 16 deletions sentry/src/test/java/io/sentry/SentryClientTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -194,21 +194,21 @@ class SentryClientTest {
}

@Test
fun `when beforeSend throws an exception, breadcrumb is added and event is sent`() {
fun `when beforeSend throws an exception, event is dropped`() {
val exception = Exception("test")

exception.stackTrace.toString()
fixture.sentryOptions.setBeforeSend { _, _ -> throw exception }
val sut = fixture.getSut()
val actual = SentryEvent()
sut.captureEvent(actual)
val id = sut.captureEvent(actual)

assertNotNull(actual.breadcrumbs) {
assertEquals("test", it.first().data["sentry:message"])
assertEquals("SentryClient", it.first().category)
assertEquals(SentryLevel.ERROR, it.first().level)
assertEquals("BeforeSend callback failed.", it.first().message)
}
assertEquals(SentryId.EMPTY_ID, id)

assertClientReport(
fixture.sentryOptions.clientReportRecorder,
listOf(DiscardedEvent(DiscardReason.BEFORE_SEND.reason, DataCategory.Error.category, 1))
)
}

@Test
Expand Down Expand Up @@ -808,21 +808,21 @@ class SentryClientTest {
}

@Test
fun `when beforeSendTransaction throws an exception, breadcrumb is added and event is sent`() {
fun `when beforeSendTransaction throws an exception, transaction is dropped`() {
val exception = Exception("test")

exception.stackTrace.toString()
fixture.sentryOptions.setBeforeSendTransaction { _, _ -> throw exception }

val transaction = SentryTransaction(fixture.sentryTracer)
fixture.getSut().captureTransaction(transaction, fixture.sentryTracer.traceContext())
val id = fixture.getSut().captureTransaction(transaction, fixture.sentryTracer.traceContext())

assertNotNull(transaction.breadcrumbs) {
assertEquals("test", it.first().data["sentry:message"])
assertEquals("SentryClient", it.first().category)
assertEquals(SentryLevel.ERROR, it.first().level)
assertEquals("BeforeSendTransaction callback failed.", it.first().message)
}
assertEquals(SentryId.EMPTY_ID, id)

assertClientReport(
fixture.sentryOptions.clientReportRecorder,
listOf(DiscardedEvent(DiscardReason.BEFORE_SEND.reason, DataCategory.Transaction.category, 1))
)
}

@Test
Expand Down

0 comments on commit 95f1d9a

Please sign in to comment.