Repository navigation
Expand file tree
/
Copy pathSentryScheduleHook.java
More file actions
57 lines (50 loc) · 2.07 KB
/
Copy pathSentryScheduleHook.java
File metadata and controls
57 lines (50 loc) · 2.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package io.sentry.spring.webflux;
import io.sentry.IScopes;
import io.sentry.ISentryLifecycleToken;
import io.sentry.Sentry;
import java.util.function.Function;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;
/**
* Hook meant to used with {@link reactor.core.scheduler.Schedulers#onScheduleHook(String,
* Function)} to configure Reactor to copy correct scopes into the operating thread.
*/
@ApiStatus.Experimental
public final class SentryScheduleHook implements Function<Runnable, Runnable> {
/**
* Runnable class names that should be excluded from scope forking. These are typically internal
* scheduler loops that reschedule themselves indefinitely, which would cause memory issues due to
* scope parent chain buildup.
*
* @see <a href="https://github.com/getsentry/sentry-java/issues/5051">GitHub Issue #5051</a>
* @see <a href="https://github.com/getsentry/sentry-java/issues/6248">GitHub Issue #6248</a>
*/
private static final String[] EXCLUDED_RUNNABLE_PREFIXES = {
"reactor.kafka.receiver.internals.ConsumerEventLoop",
"reactor.netty.internal.shaded.reactor.pool.SimpleDequePool$$Lambda",
"reactor.netty.http.client.Http2Pool$$Lambda",
"reactor.netty.resources.PooledConnectionProvider$$Lambda"
};
// The standalone reactor.pool.SimpleDequePool is intentionally not excluded because it also
// schedules acquisition-delivery tasks that require scope propagation.
static boolean isExcluded(final @NotNull String runnableClassName) {
for (final String excludedPrefix : EXCLUDED_RUNNABLE_PREFIXES) {
if (runnableClassName.startsWith(excludedPrefix)) {
return true;
}
}
return false;
}
@Override
public Runnable apply(final @NotNull Runnable runnable) {
if (isExcluded(runnable.getClass().getName())) {
return runnable;
}
final IScopes newScopes = Sentry.getCurrentScopes().forkedCurrentScope("spring.scheduleHook");
return () -> {
try (final @NotNull ISentryLifecycleToken ignored = newScopes.makeCurrent()) {
runnable.run();
}
};
}
}