Search in sources :

Example 1 with AgentBuilder

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.");
}
Also used : AgentBuilder(net.bytebuddy.agent.builder.AgentBuilder) Instrumenter(io.opencensus.contrib.agent.instrumentation.Instrumenter) JarFile(java.util.jar.JarFile)

Example 2 with AgentBuilder

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);
}
Also used : AgentBuilder(net.bytebuddy.agent.builder.AgentBuilder) Settings(io.opencensus.contrib.agent.Settings) Test(org.junit.Test)

Example 3 with 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);
}
Also used : AgentBuilder(net.bytebuddy.agent.builder.AgentBuilder) Settings(io.opencensus.contrib.agent.Settings) Test(org.junit.Test)

Example 4 with 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);
}
Also used : AgentBuilder(net.bytebuddy.agent.builder.AgentBuilder) Settings(io.opencensus.contrib.agent.Settings) Test(org.junit.Test)

Example 5 with 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;
}
Also used : AgentBuilder(net.bytebuddy.agent.builder.AgentBuilder)

Aggregations

AgentBuilder (net.bytebuddy.agent.builder.AgentBuilder)17 Settings (io.opencensus.contrib.agent.Settings)6 Test (org.junit.Test)6 Instrumenter (io.opencensus.contrib.agent.instrumentation.Instrumenter)1 JarFile (java.util.jar.JarFile)1 ByteBuddy (net.bytebuddy.ByteBuddy)1 AgentRunner (org.agrona.concurrent.AgentRunner)1 SleepingMillisIdleStrategy (org.agrona.concurrent.SleepingMillisIdleStrategy)1