Search in sources :

Example 1 with AgentListener

use of io.opentelemetry.javaagent.extension.AgentListener in project opentelemetry-java-instrumentation by open-telemetry.

the class AgentInstaller method installBytebuddyAgent.

public static void installBytebuddyAgent(Instrumentation inst) {
    logVersionInfo();
    Config config = Config.get();
    if (config.getBoolean(JAVAAGENT_ENABLED_CONFIG, true)) {
        setupUnsafe(inst);
        List<AgentListener> agentListeners = loadOrdered(AgentListener.class);
        installBytebuddyAgent(inst, agentListeners);
    } else {
        logger.debug("Tracing is disabled, not installing instrumentations.");
    }
}
Also used : Config(io.opentelemetry.instrumentation.api.config.Config) AgentListener(io.opentelemetry.javaagent.extension.AgentListener)

Example 2 with AgentListener

use of io.opentelemetry.javaagent.extension.AgentListener in project opentelemetry-java-instrumentation by open-telemetry.

the class AgentInstaller method runAfterAgentListeners.

private static void runAfterAgentListeners(Iterable<AgentListener> agentListeners, Config config, AutoConfiguredOpenTelemetrySdk autoConfiguredSdk) {
    // java.util.logging.LogManager maintains a final static LogManager, which is created during
    // class initialization. Some AgentListener implementations may use JRE bootstrap classes
    // which touch this class (e.g. JFR classes or some MBeans).
    // It is worth noting that starting from Java 9 (JEP 264) Java platform classes no longer use
    // JUL directly, but instead they use a new System.Logger interface, so the LogManager issue
    // applies mainly to Java 8.
    // This means applications which require a custom LogManager may not have a chance to set the
    // global LogManager if one of those AgentListeners runs first: it will incorrectly
    // set the global LogManager to the default JVM one in cases where the instrumented application
    // sets the LogManager system property or when the custom LogManager class is not on the system
    // classpath.
    // Our solution is to delay the initialization of AgentListeners when we detect a custom
    // log manager being used.
    // Once we see the LogManager class loading, it's safe to run AgentListener#afterAgent() because
    // the application is already setting the global LogManager and AgentListener won't be able
    // to touch it due to classloader locking.
    boolean shouldForceSynchronousAgentListenersCalls = Config.get().getBoolean(FORCE_SYNCHRONOUS_AGENT_LISTENERS_CONFIG, false);
    if (!shouldForceSynchronousAgentListenersCalls && isJavaBefore9() && isAppUsingCustomLogManager()) {
        logger.debug("Custom JUL LogManager detected: delaying AgentListener#afterAgent() calls");
        registerClassLoadCallback("java.util.logging.LogManager", new DelayedAfterAgentCallback(config, agentListeners, autoConfiguredSdk));
    } else {
        for (AgentListener agentListener : agentListeners) {
            agentListener.afterAgent(config, autoConfiguredSdk);
        }
    }
}
Also used : AgentListener(io.opentelemetry.javaagent.extension.AgentListener)

Aggregations

AgentListener (io.opentelemetry.javaagent.extension.AgentListener)2 Config (io.opentelemetry.instrumentation.api.config.Config)1