Skip to content

Commit f99ce57

Browse files
authored
Merge branch 'main' into dependabot/github_actions/JamesIves/github-pages-deploy-action-4.6.1
2 parents 2a6326d + 25f1ca4 commit f99ce57

File tree

14 files changed

+207
-17
lines changed

14 files changed

+207
-17
lines changed

.github/workflows/agp-matrix.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ jobs:
5959

6060
# We tried to use the cache action to cache gradle stuff, but it made tests slower and timeout
6161
- name: Run instrumentation tests
62-
uses: reactivecircus/android-emulator-runner@6b0df4b0efb23bb0ec63d881db79aefbc976e4b2 # pin@v2
62+
uses: reactivecircus/android-emulator-runner@77986be26589807b8ebab3fde7bbf5c60dabec32 # pin@v2
6363
with:
6464
api-level: 30
6565
force-avd-creation: false

.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ jobs:
3535
run: make preMerge
3636

3737
- name: Upload coverage to Codecov
38-
uses: codecov/codecov-action@5ecb98a3c6b747ed38dc09f787459979aebb39be # pin@v4
38+
uses: codecov/codecov-action@e28ff129e5465c2c0dcc6f003fc735cb6ae0c673 # pin@v4
3939
with:
4040
name: sentry-java
4141
fail_ci_if_error: false

CHANGELOG.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
# Changelog
22

3-
## Unreleased
3+
## 7.11.0
4+
5+
### Features
6+
7+
- Report dropped spans ([#3528](https://github.com/getsentry/sentry-java/pull/3528))
48

59
### Fixes
610

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ android.useAndroidX=true
1010
android.defaults.buildfeatures.buildconfig=true
1111

1212
# Release information
13-
versionName=7.10.0
13+
versionName=7.11.0
1414

1515
# Override the SDK name on native crashes on Android
1616
sentryAndroidSdkName=sentry.native.android

sentry/api/sentry.api

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,7 @@ public final class io/sentry/DataCategory : java/lang/Enum {
229229
public static final field Profile Lio/sentry/DataCategory;
230230
public static final field Security Lio/sentry/DataCategory;
231231
public static final field Session Lio/sentry/DataCategory;
232+
public static final field Span Lio/sentry/DataCategory;
232233
public static final field Transaction Lio/sentry/DataCategory;
233234
public static final field Unknown Lio/sentry/DataCategory;
234235
public static final field UserReport Lio/sentry/DataCategory;
@@ -3142,6 +3143,7 @@ public final class io/sentry/clientreport/ClientReportRecorder : io/sentry/clien
31423143
public fun recordLostEnvelope (Lio/sentry/clientreport/DiscardReason;Lio/sentry/SentryEnvelope;)V
31433144
public fun recordLostEnvelopeItem (Lio/sentry/clientreport/DiscardReason;Lio/sentry/SentryEnvelopeItem;)V
31443145
public fun recordLostEvent (Lio/sentry/clientreport/DiscardReason;Lio/sentry/DataCategory;)V
3146+
public fun recordLostEvent (Lio/sentry/clientreport/DiscardReason;Lio/sentry/DataCategory;J)V
31453147
}
31463148

31473149
public final class io/sentry/clientreport/DiscardReason : java/lang/Enum {
@@ -3187,6 +3189,7 @@ public abstract interface class io/sentry/clientreport/IClientReportRecorder {
31873189
public abstract fun recordLostEnvelope (Lio/sentry/clientreport/DiscardReason;Lio/sentry/SentryEnvelope;)V
31883190
public abstract fun recordLostEnvelopeItem (Lio/sentry/clientreport/DiscardReason;Lio/sentry/SentryEnvelopeItem;)V
31893191
public abstract fun recordLostEvent (Lio/sentry/clientreport/DiscardReason;Lio/sentry/DataCategory;)V
3192+
public abstract fun recordLostEvent (Lio/sentry/clientreport/DiscardReason;Lio/sentry/DataCategory;J)V
31903193
}
31913194

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

32053209
public abstract interface class io/sentry/config/PropertiesProvider {

sentry/src/main/java/io/sentry/DataCategory.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ public enum DataCategory {
1414
Profile("profile"),
1515
MetricBucket("metric_bucket"),
1616
Transaction("transaction"),
17+
Span("span"),
1718
Security("security"),
1819
UserReport("user_report"),
1920
Unknown("unknown");

sentry/src/main/java/io/sentry/Hub.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -686,10 +686,22 @@ public void flush(long timeoutMillis) {
686686
options
687687
.getClientReportRecorder()
688688
.recordLostEvent(DiscardReason.BACKPRESSURE, DataCategory.Transaction);
689+
options
690+
.getClientReportRecorder()
691+
.recordLostEvent(
692+
DiscardReason.BACKPRESSURE,
693+
DataCategory.Span,
694+
transaction.getSpans().size() + 1);
689695
} else {
690696
options
691697
.getClientReportRecorder()
692698
.recordLostEvent(DiscardReason.SAMPLE_RATE, DataCategory.Transaction);
699+
options
700+
.getClientReportRecorder()
701+
.recordLostEvent(
702+
DiscardReason.SAMPLE_RATE,
703+
DataCategory.Span,
704+
transaction.getSpans().size() + 1);
693705
}
694706
} else {
695707
StackItem item = null;

sentry/src/main/java/io/sentry/SentryClient.java

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,7 @@ private SentryTransaction processTransaction(
412412
final @NotNull Hint hint,
413413
final @NotNull List<EventProcessor> eventProcessors) {
414414
for (final EventProcessor processor : eventProcessors) {
415+
final int spanCountBeforeProcessor = transaction.getSpans().size();
415416
try {
416417
transaction = processor.process(transaction, hint);
417418
} catch (Throwable e) {
@@ -423,6 +424,7 @@ private SentryTransaction processTransaction(
423424
"An exception occurred while processing transaction by processor: %s",
424425
processor.getClass().getName());
425426
}
427+
final int spanCountAfterProcessor = transaction == null ? 0 : transaction.getSpans().size();
426428

427429
if (transaction == null) {
428430
options
@@ -434,7 +436,25 @@ private SentryTransaction processTransaction(
434436
options
435437
.getClientReportRecorder()
436438
.recordLostEvent(DiscardReason.EVENT_PROCESSOR, DataCategory.Transaction);
439+
// If we drop a transaction, we are also dropping all its spans (+1 for the root span)
440+
options
441+
.getClientReportRecorder()
442+
.recordLostEvent(
443+
DiscardReason.EVENT_PROCESSOR, DataCategory.Span, spanCountBeforeProcessor + 1);
437444
break;
445+
} else if (spanCountAfterProcessor < spanCountBeforeProcessor) {
446+
// If the callback removed some spans, we report it
447+
final int droppedSpanCount = spanCountBeforeProcessor - spanCountAfterProcessor;
448+
options
449+
.getLogger()
450+
.log(
451+
SentryLevel.DEBUG,
452+
"%d spans were dropped by a processor: %s",
453+
droppedSpanCount,
454+
processor.getClass().getName());
455+
options
456+
.getClientReportRecorder()
457+
.recordLostEvent(DiscardReason.EVENT_PROCESSOR, DataCategory.Span, droppedSpanCount);
438458
}
439459
}
440460
return transaction;
@@ -666,7 +686,9 @@ public void captureSession(final @NotNull Session session, final @Nullable Hint
666686
return SentryId.EMPTY_ID;
667687
}
668688

689+
final int spanCountBeforeCallback = transaction.getSpans().size();
669690
transaction = executeBeforeSendTransaction(transaction, hint);
691+
final int spanCountAfterCallback = transaction == null ? 0 : transaction.getSpans().size();
670692

671693
if (transaction == null) {
672694
options
@@ -675,7 +697,24 @@ public void captureSession(final @NotNull Session session, final @Nullable Hint
675697
options
676698
.getClientReportRecorder()
677699
.recordLostEvent(DiscardReason.BEFORE_SEND, DataCategory.Transaction);
700+
// If we drop a transaction, we are also dropping all its spans (+1 for the root span)
701+
options
702+
.getClientReportRecorder()
703+
.recordLostEvent(
704+
DiscardReason.BEFORE_SEND, DataCategory.Span, spanCountBeforeCallback + 1);
678705
return SentryId.EMPTY_ID;
706+
} else if (spanCountAfterCallback < spanCountBeforeCallback) {
707+
// If the callback removed some spans, we report it
708+
final int droppedSpanCount = spanCountBeforeCallback - spanCountAfterCallback;
709+
options
710+
.getLogger()
711+
.log(
712+
SentryLevel.DEBUG,
713+
"%d spans were dropped by beforeSendTransaction.",
714+
droppedSpanCount);
715+
options
716+
.getClientReportRecorder()
717+
.recordLostEvent(DiscardReason.BEFORE_SEND, DataCategory.Span, droppedSpanCount);
679718
}
680719

681720
try {

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

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
import io.sentry.SentryItemType;
88
import io.sentry.SentryLevel;
99
import io.sentry.SentryOptions;
10+
import io.sentry.protocol.SentrySpan;
11+
import io.sentry.protocol.SentryTransaction;
1012
import java.util.ArrayList;
1113
import java.util.Date;
1214
import java.util.List;
@@ -84,8 +86,19 @@ public void recordLostEnvelopeItem(
8486
.log(SentryLevel.ERROR, "Unable to restore counts from previous client report.");
8587
}
8688
} else {
87-
recordLostEventInternal(
88-
reason.getReason(), categoryFromItemType(itemType).getCategory(), 1L);
89+
final @NotNull DataCategory itemCategory = categoryFromItemType(itemType);
90+
if (itemCategory.equals(DataCategory.Transaction)) {
91+
final @Nullable SentryTransaction transaction =
92+
envelopeItem.getTransaction(options.getSerializer());
93+
if (transaction != null) {
94+
final @NotNull List<SentrySpan> spans = transaction.getSpans();
95+
// When a transaction is dropped, we also record its spans as dropped plus one,
96+
// since Relay extracts an additional span from the transaction.
97+
recordLostEventInternal(
98+
reason.getReason(), DataCategory.Span.getCategory(), spans.size() + 1L);
99+
}
100+
}
101+
recordLostEventInternal(reason.getReason(), itemCategory.getCategory(), 1L);
89102
}
90103
} catch (Throwable e) {
91104
options.getLogger().log(SentryLevel.ERROR, e, "Unable to record lost envelope item.");
@@ -94,8 +107,14 @@ public void recordLostEnvelopeItem(
94107

95108
@Override
96109
public void recordLostEvent(@NotNull DiscardReason reason, @NotNull DataCategory category) {
110+
recordLostEvent(reason, category, 1);
111+
}
112+
113+
@Override
114+
public void recordLostEvent(
115+
@NotNull DiscardReason reason, @NotNull DataCategory category, long count) {
97116
try {
98-
recordLostEventInternal(reason.getReason(), category.getCategory(), 1L);
117+
recordLostEventInternal(reason.getReason(), category.getCategory(), count);
99118
} catch (Throwable e) {
100119
options.getLogger().log(SentryLevel.ERROR, e, "Unable to record lost event.");
101120
}

sentry/src/main/java/io/sentry/clientreport/IClientReportRecorder.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ void recordLostEnvelopeItem(
1616

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

19+
void recordLostEvent(@NotNull DiscardReason reason, @NotNull DataCategory category, long count);
20+
1921
@NotNull
2022
SentryEnvelope attachReportToEnvelope(@NotNull SentryEnvelope envelope);
2123
}

0 commit comments

Comments
 (0)