use of net.bytebuddy.agent.builder.AgentBuilder 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.");
}
use of net.bytebuddy.agent.builder.AgentBuilder in project instrumentation-java by census-instrumentation.
the class ThreadInstrumentationTest method instrument_enabled.
@Test
public void instrument_enabled() {
Settings settings = new Settings(ConfigFactory.parseString(FEATURE + ".enabled = true"));
AgentBuilder agentBuilder2 = instrumentation.instrument(agentBuilder, settings);
assertThat(agentBuilder2).isNotSameInstanceAs(agentBuilder);
}
use of net.bytebuddy.agent.builder.AgentBuilder in project instrumentation-java by census-instrumentation.
the class ExecutorInstrumentationTest method instrument_enabled.
@Test
public void instrument_enabled() {
Settings settings = new Settings(ConfigFactory.parseString(FEATURE + ".enabled = true"));
AgentBuilder agentBuilder2 = instrumentation.instrument(agentBuilder, settings);
assertThat(agentBuilder2).isNotSameInstanceAs(agentBuilder);
}
use of net.bytebuddy.agent.builder.AgentBuilder in project instrumentation-java by census-instrumentation.
the class UrlInstrumentationTest method instrument_disabled.
@Test
public void instrument_disabled() {
Settings settings = new Settings(ConfigFactory.parseString(FEATURE + ".enabled = false"));
AgentBuilder agentBuilder2 = instrumentation.instrument(agentBuilder, settings);
assertThat(agentBuilder2).isSameInstanceAs(agentBuilder);
}
use of net.bytebuddy.agent.builder.AgentBuilder in project Aeron by real-logic.
the class AgentBuilderListener method addClusterInstrumentation.
private static AgentBuilder addClusterInstrumentation(final AgentBuilder agentBuilder) {
AgentBuilder tempBuilder = agentBuilder;
tempBuilder = addEventInstrumentation(tempBuilder, CLUSTER_EVENT_CODES, ClusterEventCode.ELECTION_STATE_CHANGE, "Election", ClusterInterceptor.ElectionStateChange.class, "stateChange");
tempBuilder = addClusterConsensusModuleAgentInstrumentation(tempBuilder);
return tempBuilder;
}
Aggregations