Repository navigation
feat(spring): Add an option to monitor all @Scheduled methods in Spring Boot 4 #6277
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
62 commits
Select commit
Hold shift + click to select a range
ea62aa1
ref(core): Add MonitorConfigUtils to convert schedules to monitor con…
wedamija 28761ae
fix(core): Only send monitor configs Sentry reads the same way
wedamija bd47026
ref(core): Add MonitorConfigUtils.fromSpringScheduled
wedamija fca4216
fix(core): Return no config for stepped single value ranges
wedamija 780c605
fix(core): Read Spring crons per parser and skip fixed delays
wedamija 5d745c7
feat(spring): Send monitor config from @Scheduled with @SentryCheckIn
wedamija bcd5682
feat(spring): Send @Scheduled monitor config by default
wedamija 6f5ad4e
ref(spring): Shorten upsertMonitorConfig Javadoc
wedamija d758789
fix(core): Keep Sunday-only day of week ranges
wedamija d903a79
fix(spring): Only catch runtime exceptions when deriving monitor config
wedamija 5db58a4
ref(spring): Shorten upsertMonitorConfig Javadoc
wedamija 1ca0891
feat(spring-jakarta): Monitor all @Scheduled methods with sentry.moni…
wedamija 358f88a
changelog
wedamija e20963e
feat(spring): Monitor all @Scheduled methods in Spring Boot 2
wedamija 7b150ae
docs(changelog): Link Spring Boot 2 PR
wedamija fcd00c7
feat(spring): Monitor all @Scheduled methods in Spring Boot 4
wedamija b90f364
docs(changelog): Link Spring Boot 4 PR
wedamija 552de8f
fix(spring-jakarta): Skip reactive @Scheduled methods when monitoring…
wedamija 270d4bf
Merge branch 'danf/spring-monitor-scheduled-tasks' into danf/spring-m…
wedamija 6261137
fix(spring): Skip reactive @Scheduled methods when monitoring all tasks
wedamija e922106
Merge branch 'danf/spring-monitor-scheduled-tasks-boot2' into danf/sp…
wedamija aa3995d
fix(spring-7): Skip reactive @Scheduled methods when monitoring all t…
wedamija 26054cd
fix(spring): Skip jobs with unsupported schedules when monitoring all…
wedamija 38bce82
Merge remote-tracking branch 'origin/danf/spring-monitor-scheduled-ta…
wedamija 7baac07
fix(spring): Skip jobs with unsupported schedules when monitoring all…
wedamija 647f38c
Merge branch 'danf-skip-tmp-6276' into danf-skip-tmp-6277
wedamija 99505ac
fix(spring): Skip jobs with unsupported schedules when monitoring all…
wedamija 408c89a
Merge remote-tracking branch 'origin/main' into danf/monitor-config-u…
wedamija 4c08ff0
Merge branch 'danf/monitor-config-utils' into danf/spring-checkin-sch…
wedamija b63d62e
Merge branch 'danf/spring-checkin-scheduled-config' into danf/spring-…
wedamija 40a2789
Merge branch 'danf/spring-monitor-scheduled-tasks' into danf/spring-m…
wedamija d242a14
Merge branch 'danf/spring-monitor-scheduled-tasks-boot2' into danf/sp…
wedamija 1e7aa24
ref(spring): Use pattern-matching instanceof for the @Scheduled time …
wedamija e22b15e
Merge branch 'danf/spring-checkin-scheduled-config' into danf/spring-…
wedamija bf12297
Merge branch 'danf/spring-monitor-scheduled-tasks' into danf/spring-m…
wedamija dc71f65
Merge branch 'danf/spring-monitor-scheduled-tasks-boot2' into danf/sp…
wedamija 5b38d5e
fix(spring): Satisfy NullAway in the Spring 7 scheduled check-in advice
wedamija 0b9b852
fix(core): Use a 2 minute check-in margin for crons with fixed seconds
wedamija ae5ae63
Merge branch 'danf/monitor-config-utils' into danf/spring-checkin-sch…
wedamija 129cb73
fix(spring): Default upsertMonitorConfig to false and read @Scheduled…
wedamija 7683e57
Merge branch 'danf/spring-checkin-scheduled-config' into danf/spring-…
wedamija a496af8
fix(spring): Find @Scheduled tasks to monitor the way Spring does
wedamija e67963b
Merge branch 'danf/spring-monitor-scheduled-tasks' into danf/spring-m…
wedamija 2f0e285
fix(spring): Find @Scheduled tasks to monitor the way Spring does
wedamija b6d56b2
Merge branch 'danf/spring-monitor-scheduled-tasks-boot2' into danf/sp…
wedamija f734070
fix(spring): Find @Scheduled tasks to monitor the way Spring does
wedamija 2789b4c
Merge remote-tracking branch 'origin/main' into danf/spring-monitor-s…
wedamija d9ba607
feat(spring): Warn when two @Scheduled methods share a monitor slug
wedamija 0b6e26c
Merge branch 'danf/spring-monitor-scheduled-tasks' into danf/spring-m…
wedamija f96738e
feat(spring): Warn when two @Scheduled methods share a monitor slug
wedamija 4ea5c65
Merge branch 'danf/spring-monitor-scheduled-tasks-boot2' into danf/sp…
wedamija cc9e28a
feat(spring): Warn when two @Scheduled methods share a monitor slug
wedamija 09e7160
ref(spring): Reuse the target class for the slug collision check
wedamija 70c3f22
Merge branch 'danf/spring-monitor-scheduled-tasks' into danf/spring-m…
wedamija 233f5b0
ref(spring): Reuse the target class for the slug collision check
wedamija 480ea17
Merge branch 'danf/spring-monitor-scheduled-tasks-boot2' into danf/sp…
wedamija 2a61e06
fix(spring): Skip private and static @Scheduled methods when monitori…
wedamija cd0a3ae
Merge branch 'danf/spring-monitor-scheduled-tasks' into danf/spring-m…
wedamija 8ae1938
fix(spring): Skip private and static @Scheduled methods when monitori…
wedamija 386f0d4
Merge branch 'danf/spring-monitor-scheduled-tasks-boot2' into danf/sp…
wedamija 4484aa3
fix(spring): Skip private and static @Scheduled methods when monitori…
wedamija 910cfbf
Merge commit 'refs/s2/main' into danf/spring-monitor-scheduled-tasks-…
wedamija File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
sentry-spring-7/src/main/java/io/sentry/spring7/checkin/SentryScheduledCheckInPointcut.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,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; | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.