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

Fix regression in spring-scheduling span name #5436

Merged
merged 1 commit into from
Feb 24, 2022
Merged

Fix regression in spring-scheduling span name #5436

merged 1 commit into from
Feb 24, 2022

Conversation

trask
Copy link
Member

@trask trask commented Feb 24, 2022

This fixes (and adds test for) a small (unreleased) regression introduced in #5342.

@trask trask requested a review from a team February 24, 2022 01:32
@@ -14,7 +14,7 @@
public Class<?> codeClass(Runnable runnable) {
if (runnable instanceof ScheduledMethodRunnable) {
ScheduledMethodRunnable scheduledMethodRunnable = (ScheduledMethodRunnable) runnable;
return scheduledMethodRunnable.getTarget().getClass();
return scheduledMethodRunnable.getMethod().getDeclaringClass();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suspect that it might be better to attempt to unwrap the target object.

// unwrap spring aop proxy
// based on org.springframework.test.util.AopTestUtils#getTargetObject
@SuppressWarnings("unchecked")
public static <T> T unwrapProxy(T candidate) {
try {
if (AopUtils.isAopProxy(candidate) && candidate instanceof Advised) {
Object target = ((Advised) candidate).getTargetSource().getTarget();
if (target != null) {
return (T) target;
}
}
return candidate;
} catch (Throwable ignore) {
return candidate;
}
}

Unfortunately this is a common issue with getting class from object, there is no easy way to tell whether we got a proxy and how to unwrap it.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I gave this a try, but the unwrapped class in the test I added was still EnhancedClassTaskConfig$$EnhancerByCGLIB$$b6a5b321@4ac197a7

@trask trask merged commit 02a4fd4 into open-telemetry:main Feb 24, 2022
@trask trask deleted the spring-scheduling-span-name-regression branch February 24, 2022 20:27
RashmiRam pushed a commit to RashmiRam/opentelemetry-auto-instr-java that referenced this pull request May 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants