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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## Unreleased

### Features

- Add `trace_metric_byte` data category and record byte-level client reports when trace metrics are discarded ([#5626](https://github.com/getsentry/sentry-java/pull/5626))

### Fixes

- 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))
Expand Down
1 change: 1 addition & 0 deletions sentry/api/sentry.api
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,7 @@ public final class io/sentry/DataCategory : java/lang/Enum {
public static final field Session Lio/sentry/DataCategory;
public static final field Span Lio/sentry/DataCategory;
public static final field TraceMetric Lio/sentry/DataCategory;
public static final field TraceMetricByte Lio/sentry/DataCategory;
public static final field Transaction Lio/sentry/DataCategory;
public static final field Unknown Lio/sentry/DataCategory;
public static final field UserReport Lio/sentry/DataCategory;
Expand Down
1 change: 1 addition & 0 deletions sentry/src/main/java/io/sentry/DataCategory.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public enum DataCategory {
LogItem("log_item"),
LogByte("log_byte"),
TraceMetric("trace_metric"),
TraceMetricByte("trace_metric_byte"),
Monitor("monitor"),
Profile("profile"),
ProfileChunkUi("profile_chunk_ui"),
Expand Down
8 changes: 8 additions & 0 deletions sentry/src/main/java/io/sentry/SentryClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -1336,6 +1336,7 @@ public void captureMetric(
}

if (metricsEvent != null) {
final @NotNull SentryMetricsEvent tmpMetricsEvent = metricsEvent;
metricsEvent = executeBeforeSendMetric(metricsEvent, hint);

if (metricsEvent == null) {
Expand All @@ -1345,6 +1346,13 @@ public void captureMetric(
options
.getClientReportRecorder()
.recordLostEvent(DiscardReason.BEFORE_SEND, DataCategory.TraceMetric);
final long metricsEventNumberOfBytes =
JsonSerializationUtils.byteSizeOf(
options.getSerializer(), options.getLogger(), tmpMetricsEvent);
options
.getClientReportRecorder()
.recordLostEvent(
DiscardReason.BEFORE_SEND, DataCategory.TraceMetricByte, metricsEventNumberOfBytes);
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,9 @@ public void recordLostEnvelopeItem(
final @NotNull List<SentryMetricsEvent> items = metrics.getItems();
final long count = items.size();
recordLostEventInternal(reason.getReason(), itemCategory.getCategory(), count);
final long metricBytes = envelopeItem.getData().length;
recordLostEventInternal(
reason.getReason(), DataCategory.TraceMetricByte.getCategory(), metricBytes);
executeOnDiscard(reason, itemCategory, count);
} else {
options
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import io.sentry.clientreport.DiscardReason;
import io.sentry.transport.ReusableCountLatch;
import io.sentry.util.AutoClosableReentrantLock;
import io.sentry.util.JsonSerializationUtils;
import java.util.ArrayList;
import java.util.List;
import java.util.Queue;
Expand Down Expand Up @@ -58,6 +59,12 @@ public void add(final @NotNull SentryMetricsEvent metricsEvent) {
options
.getClientReportRecorder()
.recordLostEvent(DiscardReason.QUEUE_OVERFLOW, DataCategory.TraceMetric);
final long lostBytes =
JsonSerializationUtils.byteSizeOf(
options.getSerializer(), options.getLogger(), metricsEvent);
options
.getClientReportRecorder()
.recordLostEvent(DiscardReason.QUEUE_OVERFLOW, DataCategory.TraceMetricByte, lostBytes);
return;
}
pendingCount.increment();
Expand Down
10 changes: 8 additions & 2 deletions sentry/src/test/java/io/sentry/SentryClientTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,10 @@ class SentryClientTest {

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

Expand All @@ -408,7 +411,10 @@ class SentryClientTest {

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,9 @@ class ClientReportTest {
val metricItem =
clientReport!!.discardedEvents!!.first { it.category == DataCategory.TraceMetric.category }
assertEquals(3, metricItem.quantity)
val metricByteItem =
clientReport.discardedEvents!!.first { it.category == DataCategory.TraceMetricByte.category }
assertEquals(envelope.items.first().data.size.toLong(), metricByteItem.quantity)
}

private fun givenClientReportRecorder(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import io.sentry.clientreport.DiscardedEvent
import io.sentry.protocol.SentryId
import io.sentry.test.DeferredExecutorService
import io.sentry.test.injectForField
import io.sentry.util.JsonSerializationUtils
import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertFalse
Expand Down Expand Up @@ -80,9 +81,16 @@ class MetricsBatchProcessorTest {
processor.add(droppedMetricsEvent)

// verify that a client report was recorded for the dropped metrics item
val droppedBytes =
JsonSerializationUtils.byteSizeOf(options.serializer, options.logger, droppedMetricsEvent)
val expectedEvents =
mutableListOf(
DiscardedEvent(DiscardReason.QUEUE_OVERFLOW.reason, DataCategory.TraceMetric.category, 1)
DiscardedEvent(DiscardReason.QUEUE_OVERFLOW.reason, DataCategory.TraceMetric.category, 1),
DiscardedEvent(
DiscardReason.QUEUE_OVERFLOW.reason,
DataCategory.TraceMetricByte.category,
droppedBytes,
),
)

ClientReportTestHelper.assertClientReport(options.clientReportRecorder, expectedEvents)
Expand Down
Loading