Skip to content

Commit

Permalink
Merge branch 'main' into dependabot/github_actions/JamesIves/github-p…
Browse files Browse the repository at this point in the history
…ages-deploy-action-4.6.1
  • Loading branch information
stefanosiano authored Jul 4, 2024
2 parents 2a6326d + 25f1ca4 commit f99ce57
Show file tree
Hide file tree
Showing 14 changed files with 207 additions and 17 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/agp-matrix.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ jobs:

# We tried to use the cache action to cache gradle stuff, but it made tests slower and timeout
- name: Run instrumentation tests
uses: reactivecircus/android-emulator-runner@6b0df4b0efb23bb0ec63d881db79aefbc976e4b2 # pin@v2
uses: reactivecircus/android-emulator-runner@77986be26589807b8ebab3fde7bbf5c60dabec32 # pin@v2
with:
api-level: 30
force-avd-creation: false
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ jobs:
run: make preMerge

- name: Upload coverage to Codecov
uses: codecov/codecov-action@5ecb98a3c6b747ed38dc09f787459979aebb39be # pin@v4
uses: codecov/codecov-action@e28ff129e5465c2c0dcc6f003fc735cb6ae0c673 # pin@v4
with:
name: sentry-java
fail_ci_if_error: false
Expand Down
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# Changelog

## Unreleased
## 7.11.0

### Features

- Report dropped spans ([#3528](https://github.com/getsentry/sentry-java/pull/3528))

### Fixes

Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ android.useAndroidX=true
android.defaults.buildfeatures.buildconfig=true

# Release information
versionName=7.10.0
versionName=7.11.0

# Override the SDK name on native crashes on Android
sentryAndroidSdkName=sentry.native.android
Expand Down
4 changes: 4 additions & 0 deletions sentry/api/sentry.api
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@ public final class io/sentry/DataCategory : java/lang/Enum {
public static final field Profile Lio/sentry/DataCategory;
public static final field Security Lio/sentry/DataCategory;
public static final field Session Lio/sentry/DataCategory;
public static final field Span 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 Expand Up @@ -3142,6 +3143,7 @@ public final class io/sentry/clientreport/ClientReportRecorder : io/sentry/clien
public fun recordLostEnvelope (Lio/sentry/clientreport/DiscardReason;Lio/sentry/SentryEnvelope;)V
public fun recordLostEnvelopeItem (Lio/sentry/clientreport/DiscardReason;Lio/sentry/SentryEnvelopeItem;)V
public fun recordLostEvent (Lio/sentry/clientreport/DiscardReason;Lio/sentry/DataCategory;)V
public fun recordLostEvent (Lio/sentry/clientreport/DiscardReason;Lio/sentry/DataCategory;J)V
}

public final class io/sentry/clientreport/DiscardReason : java/lang/Enum {
Expand Down Expand Up @@ -3187,6 +3189,7 @@ public abstract interface class io/sentry/clientreport/IClientReportRecorder {
public abstract fun recordLostEnvelope (Lio/sentry/clientreport/DiscardReason;Lio/sentry/SentryEnvelope;)V
public abstract fun recordLostEnvelopeItem (Lio/sentry/clientreport/DiscardReason;Lio/sentry/SentryEnvelopeItem;)V
public abstract fun recordLostEvent (Lio/sentry/clientreport/DiscardReason;Lio/sentry/DataCategory;)V
public abstract fun recordLostEvent (Lio/sentry/clientreport/DiscardReason;Lio/sentry/DataCategory;J)V
}

public abstract interface class io/sentry/clientreport/IClientReportStorage {
Expand All @@ -3200,6 +3203,7 @@ public final class io/sentry/clientreport/NoOpClientReportRecorder : io/sentry/c
public fun recordLostEnvelope (Lio/sentry/clientreport/DiscardReason;Lio/sentry/SentryEnvelope;)V
public fun recordLostEnvelopeItem (Lio/sentry/clientreport/DiscardReason;Lio/sentry/SentryEnvelopeItem;)V
public fun recordLostEvent (Lio/sentry/clientreport/DiscardReason;Lio/sentry/DataCategory;)V
public fun recordLostEvent (Lio/sentry/clientreport/DiscardReason;Lio/sentry/DataCategory;J)V
}

public abstract interface class io/sentry/config/PropertiesProvider {
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 @@ -14,6 +14,7 @@ public enum DataCategory {
Profile("profile"),
MetricBucket("metric_bucket"),
Transaction("transaction"),
Span("span"),
Security("security"),
UserReport("user_report"),
Unknown("unknown");
Expand Down
12 changes: 12 additions & 0 deletions sentry/src/main/java/io/sentry/Hub.java
Original file line number Diff line number Diff line change
Expand Up @@ -686,10 +686,22 @@ public void flush(long timeoutMillis) {
options
.getClientReportRecorder()
.recordLostEvent(DiscardReason.BACKPRESSURE, DataCategory.Transaction);
options
.getClientReportRecorder()
.recordLostEvent(
DiscardReason.BACKPRESSURE,
DataCategory.Span,
transaction.getSpans().size() + 1);
} else {
options
.getClientReportRecorder()
.recordLostEvent(DiscardReason.SAMPLE_RATE, DataCategory.Transaction);
options
.getClientReportRecorder()
.recordLostEvent(
DiscardReason.SAMPLE_RATE,
DataCategory.Span,
transaction.getSpans().size() + 1);
}
} else {
StackItem item = null;
Expand Down
39 changes: 39 additions & 0 deletions sentry/src/main/java/io/sentry/SentryClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,7 @@ private SentryTransaction processTransaction(
final @NotNull Hint hint,
final @NotNull List<EventProcessor> eventProcessors) {
for (final EventProcessor processor : eventProcessors) {
final int spanCountBeforeProcessor = transaction.getSpans().size();
try {
transaction = processor.process(transaction, hint);
} catch (Throwable e) {
Expand All @@ -423,6 +424,7 @@ private SentryTransaction processTransaction(
"An exception occurred while processing transaction by processor: %s",
processor.getClass().getName());
}
final int spanCountAfterProcessor = transaction == null ? 0 : transaction.getSpans().size();

if (transaction == null) {
options
Expand All @@ -434,7 +436,25 @@ private SentryTransaction processTransaction(
options
.getClientReportRecorder()
.recordLostEvent(DiscardReason.EVENT_PROCESSOR, DataCategory.Transaction);
// If we drop a transaction, we are also dropping all its spans (+1 for the root span)
options
.getClientReportRecorder()
.recordLostEvent(
DiscardReason.EVENT_PROCESSOR, DataCategory.Span, spanCountBeforeProcessor + 1);
break;
} else if (spanCountAfterProcessor < spanCountBeforeProcessor) {
// If the callback removed some spans, we report it
final int droppedSpanCount = spanCountBeforeProcessor - spanCountAfterProcessor;
options
.getLogger()
.log(
SentryLevel.DEBUG,
"%d spans were dropped by a processor: %s",
droppedSpanCount,
processor.getClass().getName());
options
.getClientReportRecorder()
.recordLostEvent(DiscardReason.EVENT_PROCESSOR, DataCategory.Span, droppedSpanCount);
}
}
return transaction;
Expand Down Expand Up @@ -666,7 +686,9 @@ public void captureSession(final @NotNull Session session, final @Nullable Hint
return SentryId.EMPTY_ID;
}

final int spanCountBeforeCallback = transaction.getSpans().size();
transaction = executeBeforeSendTransaction(transaction, hint);
final int spanCountAfterCallback = transaction == null ? 0 : transaction.getSpans().size();

if (transaction == null) {
options
Expand All @@ -675,7 +697,24 @@ public void captureSession(final @NotNull Session session, final @Nullable Hint
options
.getClientReportRecorder()
.recordLostEvent(DiscardReason.BEFORE_SEND, DataCategory.Transaction);
// If we drop a transaction, we are also dropping all its spans (+1 for the root span)
options
.getClientReportRecorder()
.recordLostEvent(
DiscardReason.BEFORE_SEND, DataCategory.Span, spanCountBeforeCallback + 1);
return SentryId.EMPTY_ID;
} else if (spanCountAfterCallback < spanCountBeforeCallback) {
// If the callback removed some spans, we report it
final int droppedSpanCount = spanCountBeforeCallback - spanCountAfterCallback;
options
.getLogger()
.log(
SentryLevel.DEBUG,
"%d spans were dropped by beforeSendTransaction.",
droppedSpanCount);
options
.getClientReportRecorder()
.recordLostEvent(DiscardReason.BEFORE_SEND, DataCategory.Span, droppedSpanCount);
}

try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import io.sentry.SentryItemType;
import io.sentry.SentryLevel;
import io.sentry.SentryOptions;
import io.sentry.protocol.SentrySpan;
import io.sentry.protocol.SentryTransaction;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
Expand Down Expand Up @@ -84,8 +86,19 @@ public void recordLostEnvelopeItem(
.log(SentryLevel.ERROR, "Unable to restore counts from previous client report.");
}
} else {
recordLostEventInternal(
reason.getReason(), categoryFromItemType(itemType).getCategory(), 1L);
final @NotNull DataCategory itemCategory = categoryFromItemType(itemType);
if (itemCategory.equals(DataCategory.Transaction)) {
final @Nullable SentryTransaction transaction =
envelopeItem.getTransaction(options.getSerializer());
if (transaction != null) {
final @NotNull List<SentrySpan> spans = transaction.getSpans();
// When a transaction is dropped, we also record its spans as dropped plus one,
// since Relay extracts an additional span from the transaction.
recordLostEventInternal(
reason.getReason(), DataCategory.Span.getCategory(), spans.size() + 1L);
}
}
recordLostEventInternal(reason.getReason(), itemCategory.getCategory(), 1L);
}
} catch (Throwable e) {
options.getLogger().log(SentryLevel.ERROR, e, "Unable to record lost envelope item.");
Expand All @@ -94,8 +107,14 @@ public void recordLostEnvelopeItem(

@Override
public void recordLostEvent(@NotNull DiscardReason reason, @NotNull DataCategory category) {
recordLostEvent(reason, category, 1);
}

@Override
public void recordLostEvent(
@NotNull DiscardReason reason, @NotNull DataCategory category, long count) {
try {
recordLostEventInternal(reason.getReason(), category.getCategory(), 1L);
recordLostEventInternal(reason.getReason(), category.getCategory(), count);
} catch (Throwable e) {
options.getLogger().log(SentryLevel.ERROR, e, "Unable to record lost event.");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ void recordLostEnvelopeItem(

void recordLostEvent(@NotNull DiscardReason reason, @NotNull DataCategory category);

void recordLostEvent(@NotNull DiscardReason reason, @NotNull DataCategory category, long count);

@NotNull
SentryEnvelope attachReportToEnvelope(@NotNull SentryEnvelope envelope);
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ public void recordLostEvent(@NotNull DiscardReason reason, @NotNull DataCategory
// do nothing
}

@Override
public void recordLostEvent(
@NotNull DiscardReason reason, @NotNull DataCategory category, long count) {
// do nothing
}

@Override
public @NotNull SentryEnvelope attachReportToEnvelope(@NotNull SentryEnvelope envelope) {
return envelope;
Expand Down
14 changes: 12 additions & 2 deletions sentry/src/test/java/io/sentry/HubTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -1450,11 +1450,16 @@ class HubTest {
sut.bindClient(mockClient)

val sentryTracer = SentryTracer(TransactionContext("name", "op", TracesSamplingDecision(false)), sut)
// Unsampled spans are not added to the transaction, so they are not recorded
sentryTracer.startChild("dropped span", "span 1").finish()
sentryTracer.finish()

assertClientReport(
options.clientReportRecorder,
listOf(DiscardedEvent(DiscardReason.SAMPLE_RATE.reason, DataCategory.Transaction.category, 1))
listOf(
DiscardedEvent(DiscardReason.SAMPLE_RATE.reason, DataCategory.Transaction.category, 1),
DiscardedEvent(DiscardReason.SAMPLE_RATE.reason, DataCategory.Span.category, 1)
)
)
}

Expand All @@ -1472,11 +1477,16 @@ class HubTest {
whenever(mockBackpressureMonitor.downsampleFactor).thenReturn(1)

val sentryTracer = SentryTracer(TransactionContext("name", "op", TracesSamplingDecision(false)), sut)
// Unsampled spans are not added to the transaction, so they are not recorded
sentryTracer.startChild("dropped span", "span 1").finish()
sentryTracer.finish()

assertClientReport(
options.clientReportRecorder,
listOf(DiscardedEvent(DiscardReason.BACKPRESSURE.reason, DataCategory.Transaction.category, 1))
listOf(
DiscardedEvent(DiscardReason.BACKPRESSURE.reason, DataCategory.Transaction.category, 1),
DiscardedEvent(DiscardReason.BACKPRESSURE.reason, DataCategory.Span.category, 1)
)
)
}
//endregion
Expand Down
Loading

0 comments on commit f99ce57

Please sign in to comment.