Conversation
43ccb2b to
acf28e4
Compare
|
|
||
| // TODO: Write test | ||
| // for every class in bootstrap jar: | ||
| // assert class not present in agent jar |
There was a problem hiding this comment.
It might be easier to do a whitelist, maybe using something like https://google.github.io/guava/releases/17.0/api/docs/index.html?com/google/common/reflect/ClassPath.html to scan the classpath.
There was a problem hiding this comment.
Neat. I'll look into that.
| compile deps.opentracing | ||
| compile deps.slf4j | ||
| compile group: 'org.slf4j', name: 'slf4j-simple', version: '1.7.25' | ||
| // ^ Generally a bad idea for libraries, but we're shadowing. |
There was a problem hiding this comment.
You will need to apply the shadow rename rules here too.
There was a problem hiding this comment.
Never mind... I see it is handled by dd-java-agent instead.
There was a problem hiding this comment.
Yeah I wanted to keep the shadow rules in the same block so they're consistently applied.
|
|
||
| // 1. Skip classloaders which don't delegate to bootstrap | ||
|
|
||
| // 2. Skip incompatible versions of OpenTracing |
There was a problem hiding this comment.
These would be nice, but I'm curious how you plan to achieve them.
There was a problem hiding this comment.
When we transform classes we're given an instance of the classloader the class is about to load on. We can test that classloader to ensure its loading strategy and classpath are compatible with our instrumentation, and abort the instrumentation otherwise.
| @Slf4j | ||
| public class TracerInstaller { | ||
| /** Register a global tracer if no global tracer is already registered. */ | ||
| public static synchronized void installGlobalTracer() { |
There was a problem hiding this comment.
One idea that @adriancole suggested to me is instead of trying to register with GlobalTracer, just rewrite the get() method to just return our instance.
There was a problem hiding this comment.
What's the benefit of a bytecode rewrite instead of registering the global tracer?
There was a problem hiding this comment.
Primarily avoiding the volatile field lookup, but also preventing a possible exception if they are registering their own tracer.
|
|
||
| final ClassLoader agentClassLoader = TracingAgent.class.getClassLoader(); | ||
|
|
||
| inst.appendToSystemClassLoaderSearch(bootStrapJar); |
There was a problem hiding this comment.
Shouldn't this be appendToBootstrapClassLoaderSearch?
There was a problem hiding this comment.
It will be. At this stage I'm trying to get the gradle project and agent bootstrapping working. Next step is to start using the bootstrap and custom classloader.
| // in static initializers | ||
| DDJavaAgentInfo.VERSION.toString(); | ||
| DDTraceOTInfo.VERSION.toString(); | ||
| DDTraceApiInfo.VERSION.toString(); |
There was a problem hiding this comment.
It seems these were lost in the shuffle. Can you think of a better way to handle this? Do you think I'm being overly paranoid?
There was a problem hiding this comment.
They'll be back. I commented them out because the new dd-java-agent project has no dependencies and can't log. I'm going to move this over to the tooling project.
| "agent-bootstrap.jar.zip", | ||
| "agent-bootstrap.jar")); | ||
|
|
||
| final ClassLoader agentClassLoader = TracingAgent.class.getClassLoader(); |
There was a problem hiding this comment.
I assume the actual classloader will be used later?
|
I realize you asked me to focus on the gradle stuff... I think that is all good. Sorry if I added unnecessary comments to the other stuff. |
|
No problem, reviewing the other stuff is appreciated! |
a942380 to
fd022a1
Compare
There was a problem hiding this comment.
What was wrong with using TraceResolver?
There was a problem hiding this comment.
Opentracing is now on the bootstrap loader. When the TracerResolver calls the service loader it checks the classpath of the bootstrap loader. Our DDTracer is in the agent's classloader, so it doesn't see it.
c8ded5f to
faa2129
Compare
faa2129 to
f6dddc9
Compare
f6dddc9 to
55e5f57
Compare
|
Closing this out. Going to break this PR into several smaller ones. |
@tylerbenson If you have time, would you mind taking a look at the gradle project layout and config? Not urgent, and this isn't ready for a reveiw anyways.
Gradle Projects
dd-java-agent:agent-bootstrap: Runs on bootstrap loader. Contains api classes like opentracing, dd-trace-apidd-java-agent:agent-tooling: renaming of tooling. Contains dd-trace-ot and agent dependencies.dd-java-agent:instrumentation: A single project which depends onagent-toolingand all the instrumentation. Used to create a single shadowJar which contains both the core agent and the instrumentation.dd-java-agent: Bare-bones jar with no dependencies. Extracts the bootstrap and instrumentation jar, sets up the classpath and invokes agent and opentracing startup.