Skip to content
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 @@ -8,6 +8,7 @@

### Fixes

- Record byte-level client reports when event processors discard logs or trace metrics ([#5718](https://github.com/getsentry/sentry-java/pull/5718))
- Name the device-info caching thread `SentryDeviceInfoCache` so all threads spawned by the SDK are identifiable ([#5684](https://github.com/getsentry/sentry-java/pull/5684))

## 8.47.0
Expand Down
18 changes: 18 additions & 0 deletions sentry/src/main/java/io/sentry/SentryClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -511,6 +511,7 @@ private SentryEvent processEvent(
private SentryLogEvent processLogEvent(
@NotNull SentryLogEvent event, final @NotNull List<EventProcessor> eventProcessors) {
for (final EventProcessor processor : eventProcessors) {
final @NotNull SentryLogEvent eventBeforeProcessor = event;
try {
event = processor.process(event);
} catch (Throwable e) {
Expand All @@ -533,6 +534,13 @@ private SentryLogEvent processLogEvent(
options
.getClientReportRecorder()
.recordLostEvent(DiscardReason.EVENT_PROCESSOR, DataCategory.LogItem);
final long logEventNumberOfBytes =
JsonSerializationUtils.byteSizeOf(
options.getSerializer(), options.getLogger(), eventBeforeProcessor);
options
.getClientReportRecorder()
.recordLostEvent(
DiscardReason.EVENT_PROCESSOR, DataCategory.LogByte, logEventNumberOfBytes);
break;
}
}
Expand All @@ -545,6 +553,7 @@ private SentryMetricsEvent processMetricsEvent(
final @NotNull List<EventProcessor> eventProcessors,
final @NotNull Hint hint) {
for (final EventProcessor processor : eventProcessors) {
final @NotNull SentryMetricsEvent eventBeforeProcessor = event;
try {
event = processor.process(event, hint);
} catch (Throwable e) {
Expand All @@ -567,6 +576,15 @@ private SentryMetricsEvent processMetricsEvent(
options
.getClientReportRecorder()
.recordLostEvent(DiscardReason.EVENT_PROCESSOR, DataCategory.TraceMetric);
final long metricsEventNumberOfBytes =
JsonSerializationUtils.byteSizeOf(
options.getSerializer(), options.getLogger(), eventBeforeProcessor);
options
.getClientReportRecorder()
.recordLostEvent(
DiscardReason.EVENT_PROCESSOR,
DataCategory.TraceMetricByte,
metricsEventNumberOfBytes);
break;
}
}
Expand Down
67 changes: 67 additions & 0 deletions sentry/src/test/java/io/sentry/SentryClientTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import io.sentry.test.injectForField
import io.sentry.transport.ITransport
import io.sentry.transport.ITransportGate
import io.sentry.util.HintUtils
import io.sentry.util.JsonSerializationUtils
import java.io.ByteArrayInputStream
import java.io.ByteArrayOutputStream
import java.io.File
Expand Down Expand Up @@ -341,6 +342,39 @@ class SentryClientTest {
)
}

@Test
fun `when log is dropped by event processor, log byte discard is recorded`() {
val scope = createScope()
val logEvent = SentryLogEvent(SentryId(), SentryNanotimeDate(), "message", SentryLogLevel.WARN)
val logEventNumberOfBytes =
JsonSerializationUtils.byteSizeOf(
fixture.sentryOptions.serializer,
fixture.sentryOptions.logger,
logEvent,
)
scope.addEventProcessor(
object : EventProcessor {
override fun process(event: SentryLogEvent): SentryLogEvent? = null
}
)

val sut = fixture.getSut()
sut.captureLog(logEvent, scope)

verify(fixture.loggerBatchProcessor, never()).add(any())
assertClientReport(
fixture.sentryOptions.clientReportRecorder,
listOf(
DiscardedEvent(DiscardReason.EVENT_PROCESSOR.reason, DataCategory.LogItem.category, 1),
DiscardedEvent(
DiscardReason.EVENT_PROCESSOR.reason,
DataCategory.LogByte.category,
logEventNumberOfBytes,
),
),
)
}

@Test
fun `when beforeSendLog is returns new instance, new instance is sent`() {
val scope = createScope()
Expand Down Expand Up @@ -418,6 +452,39 @@ class SentryClientTest {
)
}

@Test
fun `when metric is dropped by event processor, metric byte discard is recorded`() {
val scope = createScope()
val metricsEvent = SentryMetricsEvent(SentryId(), SentryNanotimeDate(), "name", "gauge", 123.0)
val metricsEventNumberOfBytes =
JsonSerializationUtils.byteSizeOf(
fixture.sentryOptions.serializer,
fixture.sentryOptions.logger,
metricsEvent,
)
scope.addEventProcessor(
object : EventProcessor {
override fun process(event: SentryMetricsEvent, hint: Hint): SentryMetricsEvent? = null
}
)

val sut = fixture.getSut()
sut.captureMetric(metricsEvent, scope, null)

verify(fixture.metricsBatchProcessor, never()).add(any())
assertClientReport(
fixture.sentryOptions.clientReportRecorder,
listOf(
DiscardedEvent(DiscardReason.EVENT_PROCESSOR.reason, DataCategory.TraceMetric.category, 1),
DiscardedEvent(
DiscardReason.EVENT_PROCESSOR.reason,
DataCategory.TraceMetricByte.category,
metricsEventNumberOfBytes,
),
),
)
}

@Test
fun `when beforeSendMetric is returns new instance, new instance is sent`() {
val scope = createScope()
Expand Down
Loading