Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 377d98a

Browse filesBrowse files
Fix log count in client reports (#4869)
* Fix log count in client reports * add assertion to test * Format code * changelog --------- Co-authored-by: Sentry Github Bot <bot+github-bot@sentry.io>
1 parent 372184d commit 377d98a
Copy full SHA for 377d98a

3 files changed

+46-2Lines changed: 46 additions & 2 deletions

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎CHANGELOG.md‎

Copy file name to clipboardExpand all lines: CHANGELOG.md
+1Lines changed: 1 addition & 0 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
- [Config] Trim whitespace on properties path ([#4880](https://github.com/getsentry/sentry-java/pull/4880))
1010
- Only set `DefaultReplayBreadcrumbConverter` if replay is available ([#4888](https://github.com/getsentry/sentry-java/pull/4888))
1111
- Session Replay: Cache connection status instead of using blocking calls ([#4891](https://github.com/getsentry/sentry-java/pull/4891))
12+
- Fix log count in client reports ([#4869](https://github.com/getsentry/sentry-java/pull/4869))
1213

1314
### Improvements
1415

Collapse file

‎sentry/src/main/java/io/sentry/clientreport/ClientReportRecorder.java‎

Copy file name to clipboardExpand all lines: sentry/src/main/java/io/sentry/clientreport/ClientReportRecorder.java
+13-2Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import io.sentry.SentryEnvelopeItem;
77
import io.sentry.SentryItemType;
88
import io.sentry.SentryLevel;
9+
import io.sentry.SentryLogEvents;
910
import io.sentry.SentryOptions;
1011
import io.sentry.protocol.SentrySpan;
1112
import io.sentry.protocol.SentryTransaction;
@@ -98,9 +99,19 @@ public void recordLostEnvelopeItem(
9899
reason.getReason(), DataCategory.Span.getCategory(), spans.size() + 1L);
99100
executeOnDiscard(reason, DataCategory.Span, spans.size() + 1L);
100101
}
102+
recordLostEventInternal(reason.getReason(), itemCategory.getCategory(), 1L);
103+
executeOnDiscard(reason, itemCategory, 1L);
104+
} else if (itemCategory.equals(DataCategory.LogItem)) {
105+
final @Nullable SentryLogEvents logs = envelopeItem.getLogs(options.getSerializer());
106+
if (logs != null) {
107+
final long count = logs.getItems().size();
108+
recordLostEventInternal(reason.getReason(), itemCategory.getCategory(), count);
109+
executeOnDiscard(reason, itemCategory, count);
110+
}
111+
} else {
112+
recordLostEventInternal(reason.getReason(), itemCategory.getCategory(), 1L);
113+
executeOnDiscard(reason, itemCategory, 1L);
101114
}
102-
recordLostEventInternal(reason.getReason(), itemCategory.getCategory(), 1L);
103-
executeOnDiscard(reason, itemCategory, 1L);
104115
}
105116
} catch (Throwable e) {
106117
options.getLogger().log(SentryLevel.ERROR, e, "Unable to record lost envelope item.");
Collapse file

‎sentry/src/test/java/io/sentry/clientreport/ClientReportTest.kt‎

Copy file name to clipboardExpand all lines: sentry/src/test/java/io/sentry/clientreport/ClientReportTest.kt
+32Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ import io.sentry.SentryEnvelope
1616
import io.sentry.SentryEnvelopeHeader
1717
import io.sentry.SentryEnvelopeItem
1818
import io.sentry.SentryEvent
19+
import io.sentry.SentryLogEvent
20+
import io.sentry.SentryLogEvents
21+
import io.sentry.SentryLogLevel
22+
import io.sentry.SentryLongDate
1923
import io.sentry.SentryOptions
2024
import io.sentry.SentryReplayEvent
2125
import io.sentry.SentryTracer
@@ -347,6 +351,34 @@ class ClientReportTest {
347351
verify(onDiscardMock, times(1)).execute(DiscardReason.BEFORE_SEND, DataCategory.Profile, 1)
348352
}
349353

354+
@Test
355+
fun `recording lost client report counts log entries`() {
356+
val onDiscardMock = mock<SentryOptions.OnDiscardCallback>()
357+
givenClientReportRecorder { options -> options.onDiscard = onDiscardMock }
358+
359+
val envelope =
360+
testHelper.newEnvelope(
361+
SentryEnvelopeItem.fromLogs(
362+
opts.serializer,
363+
SentryLogEvents(
364+
listOf(
365+
SentryLogEvent(SentryId(), SentryLongDate(1), "log message 1", SentryLogLevel.ERROR),
366+
SentryLogEvent(SentryId(), SentryLongDate(2), "log message 2", SentryLogLevel.WARN),
367+
)
368+
),
369+
)
370+
)
371+
372+
clientReportRecorder.recordLostEnvelopeItem(DiscardReason.NETWORK_ERROR, envelope.items.first())
373+
374+
verify(onDiscardMock, times(1)).execute(DiscardReason.NETWORK_ERROR, DataCategory.LogItem, 2)
375+
376+
val clientReport = clientReportRecorder.resetCountsAndGenerateClientReport()
377+
val logItem =
378+
clientReport!!.discardedEvents!!.first { it.category == DataCategory.LogItem.category }
379+
assertEquals(2, logItem.quantity)
380+
}
381+
350382
private fun givenClientReportRecorder(
351383
callback: Sentry.OptionsConfiguration<SentryOptions>? = null
352384
) {

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.