Search in sources :

Example 1 with Config

use of io.opentelemetry.instrumentation.api.config.Config in project opentelemetry-java-instrumentation by open-telemetry.

the class TestAgentListener method buildOtherConfiguredIgnores.

private static Trie<IgnoreAllow> buildOtherConfiguredIgnores() {
    Config config = Config.builder().build();
    IgnoredTypesBuilderImpl builder = new IgnoredTypesBuilderImpl();
    for (IgnoredTypesConfigurer configurer : SafeServiceLoader.loadOrdered(IgnoredTypesConfigurer.class)) {
        // skip built-in agent ignores
        if (configurer instanceof AdditionalLibraryIgnoredTypesConfigurer || configurer instanceof GlobalIgnoredTypesConfigurer) {
            continue;
        }
        configurer.configure(config, builder);
    }
    return builder.buildIgnoredTypesTrie();
}
Also used : IgnoredTypesConfigurer(io.opentelemetry.javaagent.extension.ignore.IgnoredTypesConfigurer) AdditionalLibraryIgnoredTypesConfigurer(io.opentelemetry.javaagent.tooling.ignore.AdditionalLibraryIgnoredTypesConfigurer) GlobalIgnoredTypesConfigurer(io.opentelemetry.javaagent.tooling.ignore.GlobalIgnoredTypesConfigurer) Config(io.opentelemetry.instrumentation.api.config.Config) IgnoredTypesBuilderImpl(io.opentelemetry.javaagent.tooling.ignore.IgnoredTypesBuilderImpl) GlobalIgnoredTypesConfigurer(io.opentelemetry.javaagent.tooling.ignore.GlobalIgnoredTypesConfigurer) AdditionalLibraryIgnoredTypesConfigurer(io.opentelemetry.javaagent.tooling.ignore.AdditionalLibraryIgnoredTypesConfigurer)

Example 2 with Config

use of io.opentelemetry.instrumentation.api.config.Config 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 3 with Config

use of io.opentelemetry.instrumentation.api.config.Config in project opentelemetry-java-instrumentation by open-telemetry.

the class AgentInstaller method installBytebuddyAgent.

/**
 * Install the core bytebuddy agent along with all implementations of {@link
 * InstrumentationModule}.
 *
 * @param inst Java Instrumentation used to install bytebuddy
 * @return the agent's class transformer
 */
public static ResettableClassFileTransformer installBytebuddyAgent(Instrumentation inst, Iterable<AgentListener> agentListeners) {
    WeakRefAsyncOperationEndStrategies.initialize();
    Config config = Config.get();
    setBootstrapPackages(config);
    // If noop OpenTelemetry is enabled, autoConfiguredSdk will be null and AgentListeners are not
    // called
    AutoConfiguredOpenTelemetrySdk autoConfiguredSdk = null;
    if (config.getBoolean(JAVAAGENT_NOOP_CONFIG, false)) {
        logger.info("Tracing and metrics are disabled because noop is enabled.");
        GlobalOpenTelemetry.set(NoopOpenTelemetry.getInstance());
    } else {
        autoConfiguredSdk = installOpenTelemetrySdk(config);
    }
    if (autoConfiguredSdk != null) {
        runBeforeAgentListeners(agentListeners, config, autoConfiguredSdk);
    }
    AgentBuilder agentBuilder = new AgentBuilder.Default().disableClassFormatChanges().with(AgentBuilder.RedefinitionStrategy.RETRANSFORMATION).with(new RedefinitionDiscoveryStrategy()).with(AgentBuilder.DescriptionStrategy.Default.POOL_ONLY).with(AgentTooling.poolStrategy()).with(new ClassLoadListener()).with(AgentTooling.locationStrategy(Utils.getBootstrapProxy()));
    if (JavaModule.isSupported()) {
        agentBuilder = agentBuilder.with(new ExposeAgentBootstrapListener(inst));
    }
    agentBuilder = configureIgnoredTypes(config, agentBuilder);
    if (logger.isDebugEnabled()) {
        agentBuilder = agentBuilder.with(AgentBuilder.RedefinitionStrategy.RETRANSFORMATION).with(new RedefinitionDiscoveryStrategy()).with(new RedefinitionLoggingListener()).with(new TransformLoggingListener());
    }
    int numberOfLoadedExtensions = 0;
    for (AgentExtension agentExtension : loadOrdered(AgentExtension.class)) {
        logger.debug("Loading extension {} [class {}]", agentExtension.extensionName(), agentExtension.getClass().getName());
        try {
            agentBuilder = agentExtension.extend(agentBuilder);
            numberOfLoadedExtensions++;
        } catch (Exception | LinkageError e) {
            logger.error("Unable to load extension {} [class {}]", agentExtension.extensionName(), agentExtension.getClass().getName(), e);
        }
    }
    logger.debug("Installed {} extension(s)", numberOfLoadedExtensions);
    ResettableClassFileTransformer resettableClassFileTransformer = agentBuilder.installOn(inst);
    ClassFileTransformerHolder.setClassFileTransformer(resettableClassFileTransformer);
    if (autoConfiguredSdk != null) {
        runAfterAgentListeners(agentListeners, config, autoConfiguredSdk);
    }
    return resettableClassFileTransformer;
}
Also used : Config(io.opentelemetry.instrumentation.api.config.Config) AutoConfiguredOpenTelemetrySdk(io.opentelemetry.sdk.autoconfigure.AutoConfiguredOpenTelemetrySdk) AgentBuilder(net.bytebuddy.agent.builder.AgentBuilder) ResettableClassFileTransformer(net.bytebuddy.agent.builder.ResettableClassFileTransformer)

Example 4 with Config

use of io.opentelemetry.instrumentation.api.config.Config in project splunk-otel-java by signalfx.

the class JfrSettingsOverridesTest method fallBackToDeprecatedConfig.

@Test
void fallBackToDeprecatedConfig() {
    Config config = mock(Config.class);
    when(config.getDuration(CONFIG_KEY_DEPRECATED_THREADDUMP_PERIOD, Duration.ZERO)).thenReturn(Duration.ofMillis(999));
    JfrSettingsOverrides overrides = new JfrSettingsOverrides(config);
    Map<String, String> jfrSettings = Map.of("jdk.ThreadDump#period", "12", "jdk.ThreadDump#enabled", "true");
    Map<String, String> result = overrides.apply(jfrSettings);
    assertNotSame(result, jfrSettings);
    assertEquals("999 ms", result.get("jdk.ThreadDump#period"));
}
Also used : Config(io.opentelemetry.instrumentation.api.config.Config) Test(org.junit.jupiter.api.Test)

Example 5 with Config

use of io.opentelemetry.instrumentation.api.config.Config in project splunk-otel-java by signalfx.

the class JfrSettingsOverridesTest method testOverrides.

@Test
void testOverrides() {
    Config config = mock(Config.class);
    when(config.getDuration(CONFIG_KEY_CALL_STACK_INTERVAL, Duration.ZERO)).thenReturn(Duration.ofMillis(163));
    when(config.getBoolean("splunk.profiler.tlab.enabled", false)).thenReturn(true);
    JfrSettingsOverrides overrides = new JfrSettingsOverrides(config);
    Map<String, String> jfrSettings = Map.of("jdk.ThreadDump#period", "12", "jdk.ThreadDump#enabled", "true", "jdk.ObjectAllocationInNewTLAB#enabled", "true", "jdk.ObjectAllocationOutsideTLAB#enabled", "true");
    Map<String, String> result = overrides.apply(jfrSettings);
    assertNotSame(result, jfrSettings);
    assertEquals("163 ms", result.get("jdk.ThreadDump#period"));
    assertEquals("true", result.get("jdk.ObjectAllocationInNewTLAB#enabled"));
    assertEquals("true", result.get("jdk.ObjectAllocationOutsideTLAB#enabled"));
}
Also used : Config(io.opentelemetry.instrumentation.api.config.Config) Test(org.junit.jupiter.api.Test)

Aggregations

Config (io.opentelemetry.instrumentation.api.config.Config)23 Test (org.junit.jupiter.api.Test)19 RecordedEvent (jdk.jfr.consumer.RecordedEvent)4 InvocationOnMock (org.mockito.invocation.InvocationOnMock)3 CONFIG_KEY_MEMORY_SAMPLER_INTERVAL (com.splunk.opentelemetry.profiler.Configuration.CONFIG_KEY_MEMORY_SAMPLER_INTERVAL)2 CONFIG_KEY_TLAB_ENABLED (com.splunk.opentelemetry.profiler.Configuration.CONFIG_KEY_TLAB_ENABLED)2 DEFAULT_MEMORY_ENABLED (com.splunk.opentelemetry.profiler.Configuration.DEFAULT_MEMORY_ENABLED)2 DEFAULT_MEMORY_SAMPLING_INTERVAL (com.splunk.opentelemetry.profiler.Configuration.DEFAULT_MEMORY_SAMPLING_INTERVAL)2 SOURCE_EVENT_NAME (com.splunk.opentelemetry.profiler.ProfilingSemanticAttributes.SOURCE_EVENT_NAME)2 SOURCE_TYPE (com.splunk.opentelemetry.profiler.ProfilingSemanticAttributes.SOURCE_TYPE)2 ALLOCATION_SIZE_KEY (com.splunk.opentelemetry.profiler.TLABProcessor.ALLOCATION_SIZE_KEY)2 SpanContextualizer (com.splunk.opentelemetry.profiler.context.SpanContextualizer)2 SpanLinkage (com.splunk.opentelemetry.profiler.context.SpanLinkage)2 EventPeriods (com.splunk.opentelemetry.profiler.events.EventPeriods)2 StackSerializer (com.splunk.opentelemetry.profiler.util.StackSerializer)2 AttributeKey (io.opentelemetry.api.common.AttributeKey)2 SpanContext (io.opentelemetry.api.trace.SpanContext)2 SpanId (io.opentelemetry.api.trace.SpanId)2 TraceFlags (io.opentelemetry.api.trace.TraceFlags)2 TraceId (io.opentelemetry.api.trace.TraceId)2