Skip to content
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

Show correct runnable name in spring scheduling actuator #6140

Merged
merged 2 commits into from
Jun 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ public SpringSchedulingInstrumentationModule() {

@Override
public List<TypeInstrumentation> typeInstrumentations() {
return singletonList(new TaskInstrumentation());
return singletonList(new TaskSchedulerInstrumentation());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@

package io.opentelemetry.javaagent.instrumentation.spring.scheduling;

import static net.bytebuddy.matcher.ElementMatchers.isConstructor;
import static io.opentelemetry.javaagent.extension.matcher.AgentElementMatchers.implementsInterface;
import static net.bytebuddy.matcher.ElementMatchers.nameStartsWith;
import static net.bytebuddy.matcher.ElementMatchers.named;
import static net.bytebuddy.matcher.ElementMatchers.takesArgument;

Expand All @@ -15,25 +16,24 @@
import net.bytebuddy.description.type.TypeDescription;
import net.bytebuddy.matcher.ElementMatcher;

public class TaskInstrumentation implements TypeInstrumentation {
public class TaskSchedulerInstrumentation implements TypeInstrumentation {
@Override
public ElementMatcher<TypeDescription> typeMatcher() {
return named("org.springframework.scheduling.config.Task");
return implementsInterface(named("org.springframework.scheduling.TaskScheduler"));
}

@Override
public void transform(TypeTransformer transformer) {
transformer.applyAdviceToMethod(
isConstructor().and(takesArgument(0, Runnable.class)),
this.getClass().getName() + "$ConstructorAdvice");
nameStartsWith("schedule").and(takesArgument(0, Runnable.class)),
this.getClass().getName() + "$ScheduleMethodAdvice");
}

@SuppressWarnings("unused")
public static class ConstructorAdvice {
public static class ScheduleMethodAdvice {

@Advice.OnMethodEnter(suppress = Throwable.class)
public static void onConstruction(
@Advice.Argument(value = 0, readOnly = false) Runnable runnable) {
public static void onSchedule(@Advice.Argument(value = 0, readOnly = false) Runnable runnable) {
runnable = SpringSchedulingRunnableWrapper.wrapIfNeeded(runnable);
}
}
Expand Down