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

[improvement,feature] Support groovy code with the annotation API: #567

Merged
merged 2 commits into from
Apr 10, 2019

Conversation

fredgalvao
Copy link
Contributor

As per https://discuss.elastic.co/t/kibana-apm-not-showing-capturespan-and-capturetransaction/173026 and a few other tests I did myself in the last few weeks, apm-agent-java couldn't support code that went through groovyc with the annotation API (CaptureSpan, CaptureTransaction). I initially only saw that the annotations weren't making it to the final .class file, but couldn't investigate properly at the time.

It was only recently that I noticed that there was no RetentionPolicy for these two annotations, which was making the default RetentionPolicy#CLASS the chosen one, which can't really be seen during runtime by bytebuddy for things it doesn't fully understand. See this for more details on this, even though I can't really explain why bytebuddy would see it for java classes during runtime...

Changing the RetentionPolicy to RUNTIME enables everything I wanted and could test:

  • tested on both:
    • grails[2.2.4], groovy[2.0.8]
    • grails[3.3.1], groovy[2.4.11]
  • tested on both:
    • @CompileStatic
    • Normal(dynamic) compilation
  • tested on both:
    • Spring components/artifacts
    • Raw code

Tests were already failing on my machine on master, so I really don't know if I could ever break anything with this change, but I'm willing to bet it will be inoffensive.

groovyc can't see the same class headers javac can, so the annotations must survive the compilation process to be seen by bytebuddy
@ghost
Copy link

ghost commented Apr 8, 2019

Hi @fredgalvao, we have found your signature in our records, but it seems like you have signed with a different e-mail than the one used in your Git commit. Can you please add both of these e-mails into your Github profile (they can be hidden), so we can match your e-mails to your Github profile?

@fredgalvao
Copy link
Contributor Author

Sorry for the diff email thing. I've now fixed it.

@felixbarny
Copy link
Member

felixbarny commented Apr 9, 2019

Oh, boy, I can’t believe this oversight 🤦

Thanks a lot for investigating. I’m wondering how this has ever worked. While at it, could you also add the @Target(METHOD) annotation?

@codecov-io
Copy link

codecov-io commented Apr 9, 2019

Codecov Report

Merging #567 into master will decrease coverage by 0.04%.
The diff coverage is 66.66%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master     #567      +/-   ##
============================================
- Coverage     62.19%   62.15%   -0.05%     
+ Complexity     1264       68    -1196     
============================================
  Files           185      185              
  Lines          6994     7002       +8     
  Branches        810      811       +1     
============================================
+ Hits           4350     4352       +2     
- Misses         2370     2374       +4     
- Partials        274      276       +2
Impacted Files Coverage Δ Complexity Δ
...astic/apm/agent/configuration/ServiceNameUtil.java 77.27% <0%> (-3.68%) 0 <0> (-18)
...lastic/apm/agent/impl/transaction/Transaction.java 71.42% <0%> (-2.35%) 0 <0> (-21)
...ic/apm/agent/servlet/ServletTransactionHelper.java 76.22% <85.71%> (-0.76%) 0 <0> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 9860efd...bea9133. Read the comment docs.

@fredgalvao
Copy link
Contributor Author

My pleasure to help ;)

I’m wondering how this has ever worked.

#metoo

While at it, could you also add the @target(METHOD) annotation?

Done.

@eyalkoren eyalkoren self-requested a review April 10, 2019 05:27
@felixbarny felixbarny merged commit 218d925 into elastic:master Apr 10, 2019
@fredgalvao fredgalvao deleted the groovy-aop-annotations branch April 10, 2019 14:20
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.

4 participants