Skip to content

Fix using WithSpan annotation in java6 class - #2699

Merged
trask merged 2 commits into
open-telemetry:mainfrom
laurit:withspan-java6
Apr 2, 2021
Merged

Fix using WithSpan annotation in java6 class#2699
trask merged 2 commits into
open-telemetry:mainfrom
laurit:withspan-java6

Conversation

@laurit

@laurit laurit commented Apr 2, 2021

Copy link
Copy Markdown
Contributor

No description provided.

@ghost ghost left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

LGTM. We could probably make the java6 test more readable by moving it to a separate test module with maxJavaVersionForTests set to 6.

@mateuszrzeszutek

mateuszrzeszutek commented Apr 2, 2021

Copy link
Copy Markdown
Member

We could probably make the java6 test more readable by moving it to a separate test module with maxJavaVersionForTests set to 6.

Unfortunately I don't think this'd work: tests Java process runs with our javaagent, which does not support Java <8.

Comment on lines +386 to +410
setup:
/*
class GeneratedJava6TestClass implements Runnable {
@WithSpan
public void run() {
TraceUtils.runUnderTrace("intercept", {})
}
}
*/
Class<?> generatedClass = new ByteBuddy(ClassFileVersion.JAVA_V6)
.subclass(Object)
.name("GeneratedJava6TestClass")
.implement(Runnable)
.defineMethod("run", void.class, Modifier.PUBLIC).intercept(MethodDelegation.to(new Object() {
@RuntimeType
void intercept(@This Object o) {
TraceUtils.runUnderTrace("intercept", {})
}
}))
.visit(new MemberAttributeExtension.ForMethod()
.annotateMethod(AnnotationDescription.Builder.ofType(WithSpan).build())
.on(ElementMatchers.named("run")))
.make()
.load(getClass().getClassLoader())
.getLoaded()

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nice, I would have found a (random old) library that was compiled to Java 6 and tested instrumentation of that library, but this is better 👍

@trask
trask merged commit 87950d1 into open-telemetry:main Apr 2, 2021
@laurit
laurit deleted the withspan-java6 branch August 24, 2021 07:48
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.

3 participants