use of io.opencensus.contrib.agent.instrumentation.Instrumenter in project instrumentation-java by census-instrumentation.
the class AgentMain method premain.
/**
* Initializes the OpenCensus Agent for Java.
*
* @param agentArgs agent options, passed as a single string by the JVM
* @param instrumentation the {@link Instrumentation} object provided by the JVM for instrumenting
* Java programming language code
* @throws Exception if initialization of the agent fails
* @see java.lang.instrument
* @since 0.6
*/
public static void premain(String agentArgs, Instrumentation instrumentation) throws Exception {
checkNotNull(instrumentation, "instrumentation");
logger.fine("Initializing.");
// The classes in bootstrap.jar, such as ContextManger and ContextStrategy, will be referenced
// from classes loaded by the bootstrap classloader. Thus, these classes have to be loaded by
// the bootstrap classloader, too.
instrumentation.appendToBootstrapClassLoaderSearch(new JarFile(Resources.getResourceAsTempFile("bootstrap.jar")));
checkLoadedByBootstrapClassloader(ContextTrampoline.class);
checkLoadedByBootstrapClassloader(ContextStrategy.class);
Settings settings = Settings.load();
AgentBuilder agentBuilder = new AgentBuilder.Default().disableClassFormatChanges().with(AgentBuilder.RedefinitionStrategy.RETRANSFORMATION).with(new AgentBuilderListener()).ignore(none());
for (Instrumenter instrumenter : ServiceLoader.load(Instrumenter.class)) {
agentBuilder = instrumenter.instrument(agentBuilder, settings);
}
agentBuilder.installOn(instrumentation);
logger.fine("Initialized.");
}
Aggregations