elastic / apm-agent-java

Home Page:https://www.elastic.co/guide/en/apm/agent/java/current/index.html

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Instrumentation annotations inheritance is flawed

JonasKunz opened this issue · comments

A user in the discussion forums reported broken behaviour for the @CaptureSpan inheritance feature, causing the instrumentation to break with NPEs.

This comes from the fact that for instrumenting methods, we check the entire superclass and interface hierarchy to see if the method overrides any method annotated with @CaptureSpan. When searching for the annotation values, we fail to do the same:

  • We currently only check super-classes and ignore interfaces when searching
  • We stop searching the parents when a parent does not override the method we are searching for: e.g. given the following class hierarchy, the instrumentation on C will break:
class A { @CaptureSpan void foo(){} }
class B extends A { }
class C extends B { void foo(){} }

We should fix the annotation scanning algorithm:

  • Do a breath-first search on the superclasses AND interfaces of the instrumented method
  • Only stop, when we found a method with the annotation we were searching for