dd-trace-java
dd-trace-java copied to clipboard
[IAST] Call Site Instrumentation support
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:
-
A new instrumenter
datadog.trace.agent.tooling.bytebuddy.csi.CallSiteInstrumenterthat is able to register instances ofdatadog.trace.agent.tooling.csi.CallSiteAdviceto perform the instrumentation via ASM. -
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.CallSiteAdviceclasses. 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
}
}
- 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
INVOKEDYNAMICout 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 |