dd-trace-java icon indicating copy to clipboard operation
dd-trace-java copied to clipboard

[IAST] Call Site Instrumentation support

Open manuel-alvarez-alvarez opened this issue 3 years ago • 0 comments

What Does This Do

This PR contains the basics to do Call Site Instrumentation in the tracer. In order to try to ease the pain of reviewing the PR, the code is separated in three commits:

  1. A new instrumenter datadog.trace.agent.tooling.bytebuddy.csi.CallSiteInstrumenter that is able to register instances of datadog.trace.agent.tooling.csi.CallSiteAdvice to perform the instrumentation via ASM.

  2. A new gradle plugin call-site-instrumentation that reads classes in a format close to ByteBuddy with AspectJ notation to automatically build datadog.trace.agent.tooling.csi.CallSiteAdvice classes. The next piece of code is an example of a class defining advices:

@CallSite
public class SampleCallSite {

  @CallSite.Before(
      "java.security.MessageDigest java.security.MessageDigest.getInstance(java.lang.String)")
  public static void beforeMessageDigestGetInstance(@Advice.Argument(0) final String algorithm) {
    // do something with the algorithm
  }
}
  1. A sample project csi-mock-to-remove that showcases the use of the plugin and the call site instrumentation API. This module should be removed before the final merge.

Motivation

Instrumentations related to IAST often affect core parts of the JDK (String, StringBuilder...) where using callee instrumentation (by default in ByteBuddy) is not good enough for performance. Call site instrumentation focuses on the calls to the instrumented methods enabling the use of inclusion/exclusion lists to fine tune where to instrument.

Additional Notes

  • The vast majority of the code corresponds to a gradle plugin to generate the advices, it can be separated into a different project if compilation and testing of such plugin makes working with the tracer cumbersome.
  • This PR leaves INVOKEDYNAMIC out of the picture for now, it will be taken care of in future PRs

Performance remarks

Preliminary startup performance results from the benchmark with petclinic:

No library Datadog Datadog + CSI
INFO:oejs.Server:main: Started @4870ms INFO:oejs.Server:main: Started @8283ms INFO:oejs.Server:main: Started @8691ms

manuel-alvarez-alvarez avatar Aug 09 '22 15:08 manuel-alvarez-alvarez