Skip to content

Fix API annotations discardable instrumentation#2682

Merged
eyalkoren merged 6 commits intoelastic:mainfrom
eyalkoren:CaptureSpan-annotation-instr-fix
Jun 29, 2022
Merged

Fix API annotations discardable instrumentation#2682
eyalkoren merged 6 commits intoelastic:mainfrom
eyalkoren:CaptureSpan-annotation-instr-fix

Conversation

@eyalkoren
Copy link
Contributor

@eyalkoren eyalkoren commented Jun 23, 2022

What does this PR do?

Fixes an issue that was introduced through #2632 by the addition of the discardable attributes to the @CaptureSpan and @Traced annotations.

The application error looks as follows:

Caused by: java.lang.VerifyError: Bad type on operand stack
Exception Details:
...  
Reason:
    Type null (current frame, stack[5]) is not assignable to integer

The annotations instrumentation is tolerant to addition of annotation attributes, assigning such with null. The issue in this case is that the new attributes are of boolean type, which is not assignable from null.

Checklist

  • This is a bugfix
    • I have updated the unit tests and Javadoc
    • I have updated the API documentation
    • I have updated CHANGELOG.asciidoc
    • I have fixated the relevant integration tests on public API version 1.30.0 and verified that they fail without this fix
@eyalkoren eyalkoren added the bug Bugs label Jun 23, 2022
@eyalkoren eyalkoren self-assigned this Jun 23, 2022
@ghost
Copy link

ghost commented Jun 23, 2022

💚 Build Succeeded

the below badges are clickable and redirect to their specific view in the CI or DOCS
Pipeline View Test View Changes Artifacts preview preview

Expand to view the summary

Build stats

  • Start Time: 2022-06-29T09:16:40.019+0000

  • Duration: 54 min 47 sec

Test stats 🧪

Test Results
Failed 0
Passed 3052
Skipped 36
Total 3088

💚 Flaky test report

Tests succeeded.

🤖 GitHub comments

To re-run your PR in the CI, just comment with:

  • /test : Re-trigger the build.

  • run benchmark tests : Run the benchmark tests.

  • run jdk compatibility tests : Run the JDK Compatibility tests.

  • run integration tests : Run the Agent Integration tests.

  • run end-to-end tests : Run the APM-ITs.

  • run windows tests : Build & tests on windows.

  • run elasticsearch-ci/docs : Re-trigger the docs validation. (use unformatted text in the comment!)

* </p>
*/
boolean discardable() default true;
String discardable() default "true";
Copy link
Member

Choose a reason for hiding this comment

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

This would be a breaking change.
Maybe there's a way to use a non-constant stack manipulation here:

return Target.ForStackManipulation.of(getAnnotationValue(instrumentedMethod, annotation.load()));

And use the wrapper type Boolean as a method argument here:

@AnnotationValueOffsetMappingFactory.AnnotationValueExtractor(annotationClassName = "co.elastic.apm.api.Traced", method = "discardable") boolean discardable) {

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This would be a breaking change.

It was added in 1.32.0 for a specific user request, I think we can get away with that. Otherwise, it is currently a breaking change...

Maybe there's a way to use a non-constant stack manipulation

Hmm, interesting. I am not familiar with that enough. Are you proposing to work this area so that the advice is supplied with a different default, other than null? I'll look into it. The problem is that I cannot use a generic default to any boolean attribute, because the default in this case needs to be true, so I will have to do something specific for this attribute

Copy link
Contributor Author

@eyalkoren eyalkoren Jun 23, 2022

Choose a reason for hiding this comment

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

@felixbarny it worked! Thanks a lot ❤️

And use the wrapper type Boolean as a method argument here

This causes a VerifyError, probably because of what Byte Buddy makes of it at runtime, that mismatches the co.elastic.apm.api.Traced#discardable() signature. However, using the primitive boolean here works.

@eyalkoren eyalkoren added await-release Mark issues that depend on next release, or PRs that are planned to be included and removed await-release Mark issues that depend on next release, or PRs that are planned to be included labels Jun 27, 2022
@eyalkoren eyalkoren enabled auto-merge (squash) June 28, 2022 08:24
@eyalkoren eyalkoren force-pushed the CaptureSpan-annotation-instr-fix branch from e36102f to 89dc581 Compare June 28, 2022 09:03
@eyalkoren eyalkoren disabled auto-merge June 28, 2022 09:24
@eyalkoren eyalkoren merged commit 0363849 into elastic:main Jun 29, 2022
@eyalkoren eyalkoren deleted the CaptureSpan-annotation-instr-fix branch June 29, 2022 12:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

2 participants