dd-trace-java | Datadog APM client for Java | Monitoring library
kandi X-RAY | dd-trace-java Summary
kandi X-RAY | dd-trace-java Summary
Datadog APM client for Java
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
- Returns the JdkTypeIDs for the given type ID .
- Write long .
- Checks to see if this matches the target type .
- Parse the header value .
- Matches a string against a pattern .
- Creates an instance of GraphStageLogic .
- Enrich an attack .
- Asserts instrumentation with instrumentation .
- Returns the Transformer .
- Installs the agent .
dd-trace-java Key Features
dd-trace-java Examples and Code Snippets
Community Discussions
Trending Discussions on dd-trace-java
QUESTION
I have a springboot application which I'm trying to instrument using bytebuddy. I'm running into classpath issues which I'm not able to understand.
Firstly, the following is other literature on this:
https://github.com/raphw/byte-buddy/issues/473
https://github.com/raphw/byte-buddy/issues/87
Unable to instrument apache httpclient using javaagent for spring boot uber jar application
https://github.com/raphw/byte-buddy/issues/109
https://github.com/raphw/byte-buddy/issues/473
https://github.com/raphw/byte-buddy/issues/489
https://github.com/spring-projects/spring-boot/issues/4868
https://github.com/alibaba/transmittable-thread-local/issues/161
Problem is that Spring-boot bundles the application into one uber-jar, which contains other jars inside it
A thing to note here is, that if I run the application using IntelliJ, it doesn't use the uber-jar and runs via main class with a bunch of jars as classpath arguments.
Due to this difference, When running via uber-jar(java -jar target/demo-0.0.1-SNAPSHOT.jar
), some classes are not available at the time the Agent runs. The classes are loadable at the time of application main, as spring-boot uses its own classloader, which is created at some time b/w agent and application main methods.
I'll describe the behaviour at various points of time below:
At time of PreMain of AgentThread.currentThread().getContextClassLoader() = Launcher$AppClassLoader
Agent.class.classLoader = Launcher$AppClassLoader
Class.forName("org.springframework.web.servlet.HandlerAdapter") => ClassNotFoundException
Class.forName("javax.servlet.http.HttpServletRequest") => ClassNotFoundException
Both spring and javax classes are not loaded as they are not directly in the classpath as per the App Classloader. It's part of an inner jar, something like app.jar!/BOOT-INF/lib/some.jar
App Classloader won't be able to load this.
Thread.currentThread().getContextClassLoader() =
org.springframework.boot.loader.LaunchedURLClassLoader
DemoApplication.class.classloader = same as above
Class.forName("org.springframework.web.servlet.HandlerAdapter") => loads successfully
- Same for javax class, loads successfully.
After loading, Class.forName("javax.servlet.http.HttpServletRequest").classLoader
is also the same LaunchedURLClassLoader
.
builder.visit
call (when bytebuddy is modifying the class definitions)
Code:
I have two classes, SpringBootInterceptor
(which contains the intercept method) and SpringBootInterceptorOne
(which contains the entry and exit method)
ANSWER
Answered 2020-Feb-17 at 21:43The problem is that the advice class will be loaded on the system class loader as a part of the agent whereas the actual application code is loaded on a sub-class loader that is not visible to the system class loader. This situation does not change if you load your agent on the boot loader either. Therefore, the agent cannot load the HttpServletRequest
class which is part of the uber-jar.
This is a typical problem with agents and Byte Buddy has a standard way to circumvent it by using a Transformer.ForAdvice
instance instead of using the Advice
class directly. Byte Buddy then creates a virtual class loader hierarchy that considers classes represented by both class loaders.
Update: The problem is that you are calling down to your interceptor that is defined in the system class loader where the class in question is not available. The annotated code will be inlined but the invoked method will not. If you copy-pasted the code into the annotated method, the behavior is as you'd expect it. Byte Buddy uses the annotated code as template and reuses a lot of information emitted by javac to guarantee a speedy conversion. Therefore, the library cannot simply copy the method and should rather feed the entire method body to javac.
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install dd-trace-java
You can use dd-trace-java like any standard Java library. Please include the the jar files in your classpath. You can also use any IDE and you can run and debug the dd-trace-java component as you would do with any other Java program. Best practice is to use a build tool that supports dependency management such as Maven or Gradle. For Maven installation, please refer maven.apache.org. For Gradle installation, please refer gradle.org .
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page