Repository navigation
Expand file tree
/
Copy pathSentryScheduledCheckInPointcut.java
More file actions
66 lines (62 loc) · 2.67 KB
/
Copy pathSentryScheduledCheckInPointcut.java
File metadata and controls
66 lines (62 loc) · 2.67 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
58
59
60
61
62
63
64
65
66
package io.sentry.spring7.checkin;
import io.sentry.FilterString;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.util.ArrayList;
import java.util.List;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.springframework.aop.support.AopUtils;
import org.springframework.aop.support.StaticMethodMatcherPointcut;
import org.springframework.core.ReactiveAdapterRegistry;
import org.springframework.core.annotation.AnnotationUtils;
import org.springframework.util.ClassUtils;
/**
* Matches {@code @Scheduled} methods without {@link SentryCheckIn}, except excluded ones. Excludes
* match the task name ({@code ClassName.methodName}) exactly or as a regex.
*/
@ApiStatus.Internal
public final class SentryScheduledCheckInPointcut extends StaticMethodMatcherPointcut {
private final @NotNull List<FilterString> excludedScheduledTasks = new ArrayList<>();
public SentryScheduledCheckInPointcut(final @Nullable List<String> excludedScheduledTasks) {
if (excludedScheduledTasks != null) {
for (final @NotNull String task : excludedScheduledTasks) {
if (!task.trim().isEmpty()) {
this.excludedScheduledTasks.add(new FilterString(task.trim()));
}
}
}
}
@Override
public boolean matches(final @NotNull Method method, final @NotNull Class<?> targetClass) {
final @NotNull Class<?> userClass = ClassUtils.getUserClass(targetClass);
// CGLIB can't intercept these, and Spring calls private and static methods on the target
final int modifiers = method.getModifiers();
if (Modifier.isFinal(userClass.getModifiers())
|| Modifier.isFinal(modifiers)
|| Modifier.isPrivate(modifiers)
|| Modifier.isStatic(modifiers)) {
return false;
}
final @NotNull Method specificMethod = AopUtils.getMostSpecificMethod(method, userClass);
if (!SentryCheckInAdvice.isScheduled(specificMethod)
|| AnnotationUtils.findAnnotation(specificMethod, SentryCheckIn.class) != null) {
return false;
}
// Spring calls reactive and suspend methods once and subscribes to the result on each run
if (specificMethod.getParameterCount() > 0
|| ReactiveAdapterRegistry.getSharedInstance().getAdapter(specificMethod.getReturnType())
!= null) {
return false;
}
final @NotNull String taskName =
SentryCheckInAdvice.scheduledTaskName(userClass, specificMethod);
for (final @NotNull FilterString excluded : excludedScheduledTasks) {
if (excluded.getFilterString().equals(taskName) || excluded.matches(taskName)) {
return false;
}
}
return true;
}
}