Skip to content

Commit d45c721

Browse files
authored
Hubs/Scopes Merge 31 - Fix EventProcessor ordering on Scopes (#3360)
* replace hub with scopes * Add Scopes * Introduce `IScopes` interface. * Replace `IHub` with `IScopes` in core * Replace `IHub` with `IScopes` in android core * Replace `IHub` with `IScopes` in android integrations * Replace `IHub` with `IScopes` in apollo integrations * Replace `IHub` with `IScopes` in okhttp integration * Replace `IHub` with `IScopes` in graphql integration * Replace `IHub` with `IScopes` in logging integrations * Replace `IHub` with `IScopes` in more integrations * Replace `IHub` with `IScopes` in OTel integration * Replace `IHub` with `IScopes` in Spring 5 / Spring Boot 2 integrations * Replace `IHub` with `IScopes` in Spring 6 / Spring Boot 3 integrations * Replace `IHub` with `IScopes` in samples * gitscopes -> github * Replace ThreadLocal with ScopesStorage * Move client and throwable to span map to scope * Add global scope * use global scope in Scopes * Implement pushScope popScope and withScope for Scopes * Add pushIsolationScope; add fork methods to ISCope * Use separate scopes for current, isolation and global scope; rename mainScopes to rootScopes * Allow controlling which scope configureScope uses * Combine scopes * Use new API for CRONS integrations * Add lifecycle helper * Change spring integrations to use new API * Use new API in servlet integrations * Use new API for kotlin coroutines and wrapers for Supplier/Callable * Discussion TODOs * Fix breadcrumb ordering * Mark TODOS with [HSM] * Add getGlobalScope and forkedRootScopes to IScopes * Fix EventProcessor ordering on scopes
1 parent e296fb6 commit d45c721

32 files changed

+278
-8
lines changed

sentry-android-core/api/sentry-android-core.api

+3
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ public final class io/sentry/android/core/AnrIntegrationFactory {
9797

9898
public final class io/sentry/android/core/AnrV2EventProcessor : io/sentry/BackfillingEventProcessor {
9999
public fun <init> (Landroid/content/Context;Lio/sentry/android/core/SentryAndroidOptions;Lio/sentry/android/core/BuildInfoProvider;)V
100+
public fun getOrder ()Ljava/lang/Long;
100101
public fun process (Lio/sentry/SentryEvent;Lio/sentry/Hint;)Lio/sentry/SentryEvent;
101102
public fun process (Lio/sentry/protocol/SentryTransaction;Lio/sentry/Hint;)Lio/sentry/protocol/SentryTransaction;
102103
}
@@ -236,6 +237,7 @@ public final class io/sentry/android/core/PhoneStateBreadcrumbsIntegration : io/
236237

237238
public final class io/sentry/android/core/ScreenshotEventProcessor : io/sentry/EventProcessor {
238239
public fun <init> (Lio/sentry/android/core/SentryAndroidOptions;Lio/sentry/android/core/BuildInfoProvider;)V
240+
public fun getOrder ()Ljava/lang/Long;
239241
public fun process (Lio/sentry/SentryEvent;Lio/sentry/Hint;)Lio/sentry/SentryEvent;
240242
public fun process (Lio/sentry/protocol/SentryTransaction;Lio/sentry/Hint;)Lio/sentry/protocol/SentryTransaction;
241243
}
@@ -386,6 +388,7 @@ public final class io/sentry/android/core/UserInteractionIntegration : android/a
386388

387389
public final class io/sentry/android/core/ViewHierarchyEventProcessor : io/sentry/EventProcessor {
388390
public fun <init> (Lio/sentry/android/core/SentryAndroidOptions;)V
391+
public fun getOrder ()Ljava/lang/Long;
389392
public fun process (Lio/sentry/SentryEvent;Lio/sentry/Hint;)Lio/sentry/SentryEvent;
390393
public fun process (Lio/sentry/protocol/SentryTransaction;Lio/sentry/Hint;)Lio/sentry/protocol/SentryTransaction;
391394
public static fun snapshotViewHierarchy (Landroid/app/Activity;Lio/sentry/ILogger;)Lio/sentry/protocol/ViewHierarchy;

sentry-android-core/src/main/java/io/sentry/android/core/AnrV2EventProcessor.java

+5
Original file line numberDiff line numberDiff line change
@@ -429,6 +429,11 @@ private void setOptionsTags(final @NotNull SentryBaseEvent event) {
429429
}
430430
// endregion
431431

432+
@Override
433+
public @Nullable Long getOrder() {
434+
return 12000L;
435+
}
436+
432437
// region static values
433438
private void setStaticValues(final @NotNull SentryEvent event) {
434439
mergeUser(event);

sentry-android-core/src/main/java/io/sentry/android/core/DefaultAndroidEventProcessor.java

+5
Original file line numberDiff line numberDiff line change
@@ -303,4 +303,9 @@ private void setSideLoadedInfo(final @NotNull SentryBaseEvent event) {
303303

304304
return transaction;
305305
}
306+
307+
@Override
308+
public @Nullable Long getOrder() {
309+
return 8000L;
310+
}
306311
}

sentry-android-core/src/main/java/io/sentry/android/core/PerformanceAndroidEventProcessor.java

+5
Original file line numberDiff line numberDiff line change
@@ -254,4 +254,9 @@ private static SentrySpan timeSpanToSentrySpan(
254254
null,
255255
defaultSpanData);
256256
}
257+
258+
@Override
259+
public @Nullable Long getOrder() {
260+
return 9000L;
261+
}
257262
}

sentry-android-core/src/main/java/io/sentry/android/core/ScreenshotEventProcessor.java

+5
Original file line numberDiff line numberDiff line change
@@ -98,4 +98,9 @@ public ScreenshotEventProcessor(
9898
hint.set(ANDROID_ACTIVITY, activity);
9999
return event;
100100
}
101+
102+
@Override
103+
public @Nullable Long getOrder() {
104+
return 10000L;
105+
}
101106
}

sentry-android-core/src/main/java/io/sentry/android/core/ViewHierarchyEventProcessor.java

+5
Original file line numberDiff line numberDiff line change
@@ -284,4 +284,9 @@ private static ViewHierarchyNode viewToNode(@NotNull final View view) {
284284

285285
return node;
286286
}
287+
288+
@Override
289+
public @Nullable Long getOrder() {
290+
return 11000L;
291+
}
287292
}

sentry-opentelemetry/sentry-opentelemetry-core/api/sentry-opentelemetry-core.api

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
public final class io/sentry/opentelemetry/OpenTelemetryLinkErrorEventProcessor : io/sentry/EventProcessor {
22
public fun <init> ()V
3+
public fun getOrder ()Ljava/lang/Long;
34
public fun process (Lio/sentry/SentryEvent;Lio/sentry/Hint;)Lio/sentry/SentryEvent;
45
}
56

sentry-opentelemetry/sentry-opentelemetry-core/src/main/java/io/sentry/opentelemetry/OpenTelemetryLinkErrorEventProcessor.java

+5
Original file line numberDiff line numberDiff line change
@@ -99,4 +99,9 @@ public OpenTelemetryLinkErrorEventProcessor() {
9999

100100
return event;
101101
}
102+
103+
@Override
104+
public @Nullable Long getOrder() {
105+
return 6000L;
106+
}
102107
}

sentry-servlet-jakarta/src/main/java/io/sentry/servlet/jakarta/SentryRequestHttpServletRequestProcessor.java

+5
Original file line numberDiff line numberDiff line change
@@ -56,4 +56,9 @@ public SentryRequestHttpServletRequestProcessor(@NotNull HttpServletRequest http
5656
private static @Nullable String toString(final @Nullable Enumeration<String> enumeration) {
5757
return enumeration != null ? String.join(",", Collections.list(enumeration)) : null;
5858
}
59+
60+
@Override
61+
public @Nullable Long getOrder() {
62+
return 4000L;
63+
}
5964
}

sentry-servlet/src/main/java/io/sentry/servlet/SentryRequestHttpServletRequestProcessor.java

+5
Original file line numberDiff line numberDiff line change
@@ -56,4 +56,9 @@ public SentryRequestHttpServletRequestProcessor(@NotNull HttpServletRequest http
5656
private static @Nullable String toString(final @Nullable Enumeration<String> enumeration) {
5757
return enumeration != null ? String.join(",", Collections.list(enumeration)) : null;
5858
}
59+
60+
@Override
61+
public @Nullable Long getOrder() {
62+
return 4000L;
63+
}
5964
}

sentry-spring-jakarta/api/sentry-spring-jakarta.api

+2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ public final class io/sentry/spring/jakarta/BuildConfig {
55

66
public final class io/sentry/spring/jakarta/ContextTagsEventProcessor : io/sentry/EventProcessor {
77
public fun <init> (Lio/sentry/SentryOptions;)V
8+
public fun getOrder ()Ljava/lang/Long;
89
public fun process (Lio/sentry/SentryEvent;Lio/sentry/Hint;)Lio/sentry/SentryEvent;
910
}
1011

@@ -43,6 +44,7 @@ public class io/sentry/spring/jakarta/SentryInitBeanPostProcessor : org/springfr
4344

4445
public class io/sentry/spring/jakarta/SentryRequestHttpServletRequestProcessor : io/sentry/EventProcessor {
4546
public fun <init> (Lio/sentry/spring/jakarta/tracing/TransactionNameProvider;Ljakarta/servlet/http/HttpServletRequest;)V
47+
public fun getOrder ()Ljava/lang/Long;
4648
public fun process (Lio/sentry/SentryEvent;Lio/sentry/Hint;)Lio/sentry/SentryEvent;
4749
}
4850

sentry-spring-jakarta/src/main/java/io/sentry/spring/jakarta/ContextTagsEventProcessor.java

+5
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,9 @@ public ContextTagsEventProcessor(final @NotNull SentryOptions options) {
3838
}
3939
return event;
4040
}
41+
42+
@Override
43+
public @Nullable Long getOrder() {
44+
return 14000L;
45+
}
4146
}

sentry-spring-jakarta/src/main/java/io/sentry/spring/jakarta/SentryRequestHttpServletRequestProcessor.java

+6
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import io.sentry.util.Objects;
99
import jakarta.servlet.http.HttpServletRequest;
1010
import org.jetbrains.annotations.NotNull;
11+
import org.jetbrains.annotations.Nullable;
1112

1213
/** Attaches transaction name from the HTTP request to {@link SentryEvent}. */
1314
@Open
@@ -30,4 +31,9 @@ public SentryRequestHttpServletRequestProcessor(
3031
}
3132
return event;
3233
}
34+
35+
@Override
36+
public @Nullable Long getOrder() {
37+
return 5000L;
38+
}
3339
}

sentry-spring-jakarta/src/main/java/io/sentry/spring/jakarta/SentrySpringFilter.java

+6
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import jakarta.servlet.http.HttpServletResponse;
2525
import java.io.IOException;
2626
import org.jetbrains.annotations.NotNull;
27+
import org.jetbrains.annotations.Nullable;
2728
import org.springframework.http.MediaType;
2829
import org.springframework.util.MimeType;
2930
import org.springframework.web.filter.OncePerRequestFilter;
@@ -157,5 +158,10 @@ public RequestBodyExtractingEventProcessor(
157158
}
158159
return event;
159160
}
161+
162+
@Override
163+
public @Nullable Long getOrder() {
164+
return 3000L;
165+
}
160166
}
161167
}

sentry-spring/api/sentry-spring.api

+2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ public final class io/sentry/spring/BuildConfig {
55

66
public final class io/sentry/spring/ContextTagsEventProcessor : io/sentry/EventProcessor {
77
public fun <init> (Lio/sentry/SentryOptions;)V
8+
public fun getOrder ()Ljava/lang/Long;
89
public fun process (Lio/sentry/SentryEvent;Lio/sentry/Hint;)Lio/sentry/SentryEvent;
910
}
1011

@@ -43,6 +44,7 @@ public class io/sentry/spring/SentryInitBeanPostProcessor : org/springframework/
4344

4445
public class io/sentry/spring/SentryRequestHttpServletRequestProcessor : io/sentry/EventProcessor {
4546
public fun <init> (Lio/sentry/spring/tracing/TransactionNameProvider;Ljavax/servlet/http/HttpServletRequest;)V
47+
public fun getOrder ()Ljava/lang/Long;
4648
public fun process (Lio/sentry/SentryEvent;Lio/sentry/Hint;)Lio/sentry/SentryEvent;
4749
}
4850

sentry-spring/src/main/java/io/sentry/spring/ContextTagsEventProcessor.java

+5
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,9 @@ public ContextTagsEventProcessor(final @NotNull SentryOptions options) {
3838
}
3939
return event;
4040
}
41+
42+
@Override
43+
public @Nullable Long getOrder() {
44+
return 14000L;
45+
}
4146
}

sentry-spring/src/main/java/io/sentry/spring/SentryRequestHttpServletRequestProcessor.java

+6
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import io.sentry.util.Objects;
99
import javax.servlet.http.HttpServletRequest;
1010
import org.jetbrains.annotations.NotNull;
11+
import org.jetbrains.annotations.Nullable;
1112

1213
/** Attaches transaction name from the HTTP request to {@link SentryEvent}. */
1314
@Open
@@ -30,4 +31,9 @@ public SentryRequestHttpServletRequestProcessor(
3031
}
3132
return event;
3233
}
34+
35+
@Override
36+
public @Nullable Long getOrder() {
37+
return 5000L;
38+
}
3339
}

sentry-spring/src/main/java/io/sentry/spring/SentrySpringFilter.java

+6
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import javax.servlet.http.HttpServletRequest;
2525
import javax.servlet.http.HttpServletResponse;
2626
import org.jetbrains.annotations.NotNull;
27+
import org.jetbrains.annotations.Nullable;
2728
import org.springframework.http.MediaType;
2829
import org.springframework.util.MimeType;
2930
import org.springframework.web.filter.OncePerRequestFilter;
@@ -157,5 +158,10 @@ public RequestBodyExtractingEventProcessor(
157158
}
158159
return event;
159160
}
161+
162+
@Override
163+
public @Nullable Long getOrder() {
164+
return 3000L;
165+
}
160166
}
161167
}

sentry/api/sentry.api

+22
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,7 @@ public final class io/sentry/CombinedScopeView : io/sentry/IScope {
255255
public fun getLastEventId ()Lio/sentry/protocol/SentryId;
256256
public fun getLevel ()Lio/sentry/SentryLevel;
257257
public fun getOptions ()Lio/sentry/SentryOptions;
258+
public fun getOrderedEventProcessors ()Ljava/util/List;
258259
public fun getPropagationContext ()Lio/sentry/PropagationContext;
259260
public fun getRequest ()Lio/sentry/protocol/Request;
260261
public fun getScreen ()Ljava/lang/String;
@@ -342,6 +343,7 @@ public final class io/sentry/DateUtils {
342343

343344
public final class io/sentry/DeduplicateMultithreadedEventProcessor : io/sentry/EventProcessor {
344345
public fun <init> (Lio/sentry/SentryOptions;)V
346+
public fun getOrder ()Ljava/lang/Long;
345347
public fun process (Lio/sentry/SentryEvent;Lio/sentry/Hint;)Lio/sentry/SentryEvent;
346348
}
347349

@@ -377,6 +379,7 @@ public final class io/sentry/DsnUtil {
377379

378380
public final class io/sentry/DuplicateEventDetectionEventProcessor : io/sentry/EventProcessor {
379381
public fun <init> (Lio/sentry/SentryOptions;)V
382+
public fun getOrder ()Ljava/lang/Long;
380383
public fun process (Lio/sentry/SentryEvent;Lio/sentry/Hint;)Lio/sentry/SentryEvent;
381384
}
382385

@@ -392,6 +395,7 @@ public final class io/sentry/EnvelopeSender : io/sentry/IEnvelopeSender {
392395
}
393396

394397
public abstract interface class io/sentry/EventProcessor {
398+
public fun getOrder ()Ljava/lang/Long;
395399
public fun process (Lio/sentry/SentryEvent;Lio/sentry/Hint;)Lio/sentry/SentryEvent;
396400
public fun process (Lio/sentry/protocol/SentryTransaction;Lio/sentry/Hint;)Lio/sentry/protocol/SentryTransaction;
397401
}
@@ -788,6 +792,7 @@ public abstract interface class io/sentry/IScope {
788792
public abstract fun getLastEventId ()Lio/sentry/protocol/SentryId;
789793
public abstract fun getLevel ()Lio/sentry/SentryLevel;
790794
public abstract fun getOptions ()Lio/sentry/SentryOptions;
795+
public abstract fun getOrderedEventProcessors ()Ljava/util/List;
791796
public abstract fun getPropagationContext ()Lio/sentry/PropagationContext;
792797
public abstract fun getRequest ()Lio/sentry/protocol/Request;
793798
public abstract fun getScreen ()Ljava/lang/String;
@@ -1161,6 +1166,7 @@ public abstract interface class io/sentry/JsonUnknown {
11611166
public final class io/sentry/MainEventProcessor : io/sentry/EventProcessor, java/io/Closeable {
11621167
public fun <init> (Lio/sentry/SentryOptions;)V
11631168
public fun close ()V
1169+
public fun getOrder ()Ljava/lang/Long;
11641170
public fun process (Lio/sentry/SentryEvent;Lio/sentry/Hint;)Lio/sentry/SentryEvent;
11651171
public fun process (Lio/sentry/protocol/SentryTransaction;Lio/sentry/Hint;)Lio/sentry/protocol/SentryTransaction;
11661172
}
@@ -1448,6 +1454,7 @@ public final class io/sentry/NoOpScope : io/sentry/IScope {
14481454
public fun getLastEventId ()Lio/sentry/protocol/SentryId;
14491455
public fun getLevel ()Lio/sentry/SentryLevel;
14501456
public fun getOptions ()Lio/sentry/SentryOptions;
1457+
public fun getOrderedEventProcessors ()Ljava/util/List;
14511458
public fun getPropagationContext ()Lio/sentry/PropagationContext;
14521459
public fun getRequest ()Lio/sentry/protocol/Request;
14531460
public fun getScreen ()Ljava/lang/String;
@@ -1891,6 +1898,7 @@ public final class io/sentry/Scope : io/sentry/IScope {
18911898
public fun getLastEventId ()Lio/sentry/protocol/SentryId;
18921899
public fun getLevel ()Lio/sentry/SentryLevel;
18931900
public fun getOptions ()Lio/sentry/SentryOptions;
1901+
public fun getOrderedEventProcessors ()Ljava/util/List;
18941902
public fun getPropagationContext ()Lio/sentry/PropagationContext;
18951903
public fun getRequest ()Lio/sentry/protocol/Request;
18961904
public fun getScreen ()Ljava/lang/String;
@@ -1961,6 +1969,7 @@ public abstract class io/sentry/ScopeObserverAdapter : io/sentry/IScopeObserver
19611969
}
19621970

19631971
public final class io/sentry/ScopeType : java/lang/Enum {
1972+
public static final field COMBINED Lio/sentry/ScopeType;
19641973
public static final field CURRENT Lio/sentry/ScopeType;
19651974
public static final field GLOBAL Lio/sentry/ScopeType;
19661975
public static final field ISOLATION Lio/sentry/ScopeType;
@@ -3808,6 +3817,14 @@ public final class io/sentry/internal/debugmeta/ResourcesDebugMetaLoader : io/se
38083817
public fun loadDebugMeta ()Ljava/util/List;
38093818
}
38103819

3820+
public final class io/sentry/internal/eventprocessor/EventProcessorAndOrder : java/lang/Comparable {
3821+
public fun <init> (Lio/sentry/EventProcessor;Ljava/lang/Long;)V
3822+
public fun compareTo (Lio/sentry/internal/eventprocessor/EventProcessorAndOrder;)I
3823+
public synthetic fun compareTo (Ljava/lang/Object;)I
3824+
public fun getEventProcessor ()Lio/sentry/EventProcessor;
3825+
public fun getOrder ()Ljava/lang/Long;
3826+
}
3827+
38113828
public abstract interface class io/sentry/internal/gestures/GestureTargetLocator {
38123829
public abstract fun locate (Ljava/lang/Object;FFLio/sentry/internal/gestures/UiElement$Type;)Lio/sentry/internal/gestures/UiElement;
38133830
}
@@ -5384,6 +5401,11 @@ public final class io/sentry/util/DebugMetaPropertiesApplier {
53845401
public static fun getProguardUuid (Ljava/util/Properties;)Ljava/lang/String;
53855402
}
53865403

5404+
public final class io/sentry/util/EventProcessorUtils {
5405+
public fun <init> ()V
5406+
public static fun unwrap (Ljava/util/List;)Ljava/util/List;
5407+
}
5408+
53875409
public final class io/sentry/util/ExceptionUtils {
53885410
public fun <init> ()V
53895411
public static fun findRootCause (Ljava/lang/Throwable;)Ljava/lang/Throwable;

sentry/src/main/java/io/sentry/CombinedScopeView.java

+13-6
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
package io.sentry;
22

3+
import io.sentry.internal.eventprocessor.EventProcessorAndOrder;
34
import io.sentry.protocol.Contexts;
45
import io.sentry.protocol.Request;
56
import io.sentry.protocol.SentryId;
67
import io.sentry.protocol.User;
8+
import io.sentry.util.EventProcessorUtils;
79
import java.util.ArrayList;
810
import java.util.Collection;
911
import java.util.Collections;
@@ -341,15 +343,20 @@ public void clearAttachments() {
341343
}
342344

343345
@Override
344-
public @NotNull List<EventProcessor> getEventProcessors() {
345-
// TODO [HSM] mechanism for ordering event processors
346-
final @NotNull List<EventProcessor> allEventProcessors = new CopyOnWriteArrayList<>();
347-
allEventProcessors.addAll(globalScope.getEventProcessors());
348-
allEventProcessors.addAll(isolationScope.getEventProcessors());
349-
allEventProcessors.addAll(scope.getEventProcessors());
346+
public @NotNull List<EventProcessorAndOrder> getOrderedEventProcessors() {
347+
final @NotNull List<EventProcessorAndOrder> allEventProcessors = new CopyOnWriteArrayList<>();
348+
allEventProcessors.addAll(globalScope.getOrderedEventProcessors());
349+
allEventProcessors.addAll(isolationScope.getOrderedEventProcessors());
350+
allEventProcessors.addAll(scope.getOrderedEventProcessors());
351+
Collections.sort(allEventProcessors);
350352
return allEventProcessors;
351353
}
352354

355+
@Override
356+
public @NotNull List<EventProcessor> getEventProcessors() {
357+
return EventProcessorUtils.unwrap(getOrderedEventProcessors());
358+
}
359+
353360
@Override
354361
public void addEventProcessor(@NotNull EventProcessor eventProcessor) {
355362
getDefaultWriteScope().addEventProcessor(eventProcessor);

sentry/src/main/java/io/sentry/DeduplicateMultithreadedEventProcessor.java

+5
Original file line numberDiff line numberDiff line change
@@ -62,4 +62,9 @@ public DeduplicateMultithreadedEventProcessor(final @NotNull SentryOptions optio
6262
processedEvents.put(type, currentEventTid);
6363
return event;
6464
}
65+
66+
@Override
67+
public @Nullable Long getOrder() {
68+
return 7000L;
69+
}
6570
}

sentry/src/main/java/io/sentry/DuplicateEventDetectionEventProcessor.java

+5
Original file line numberDiff line numberDiff line change
@@ -62,4 +62,9 @@ private static <T> boolean containsAnyKey(
6262
}
6363
return causes;
6464
}
65+
66+
@Override
67+
public @Nullable Long getOrder() {
68+
return 1000L;
69+
}
6570
}

0 commit comments

Comments
 (0)