Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ public final class Experimental {
private static volatile BiConsumer<InstrumenterBuilder<?, ?>, AttributesExtractor<?, ?>>
operationListenerAttributesExtractorAdder;

private static volatile boolean dynamicAttachEnabled = false;

private Experimental() {}

public static void setRedactQueryParameters(
Expand Down Expand Up @@ -85,4 +87,12 @@ public static <REQUEST, RESPONSE> void internalAddOperationListenerAttributesExt
Experimental.operationListenerAttributesExtractorAdder =
(BiConsumer) operationListenerAttributesExtractorAdder;
}

public static void setDynamicAttachEnabled(boolean enabled) {
dynamicAttachEnabled = enabled;
}

public static boolean isDynamicAttachEnabled() {
return dynamicAttachEnabled;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
package io.opentelemetry.javaagent.bootstrap;

import io.opentelemetry.instrumentation.api.internal.ConfigPropertiesUtil;
import io.opentelemetry.instrumentation.api.internal.Experimental;
import java.io.File;
import java.lang.instrument.Instrumentation;
import java.lang.reflect.Constructor;
Expand Down Expand Up @@ -41,7 +42,7 @@ public static void initialize(
new PrivilegedAction<Void>() {
@Override
public Void run() {
setSystemProperties(agentArgs);
setSystemProperties(agentArgs, fromPremain);
return null;
}
});
Expand Down Expand Up @@ -215,7 +216,7 @@ private static AgentStarter createAgentStarter(
private AgentInitializer() {}

@SuppressWarnings("SystemOut")
static void setSystemProperties(@Nullable String agentArgs) {
static void setSystemProperties(@Nullable String agentArgs, boolean fromPremain) {
boolean debug = false;
if (agentArgs != null && !agentArgs.isEmpty()) {
for (String option : agentArgs.split(";")) {
Expand All @@ -236,5 +237,9 @@ static void setSystemProperties(@Nullable String agentArgs) {
}
}
}

if (!fromPremain || getBoolean("otel.javaagent.experimental.dynamic.attach", false)) {
Experimental.setDynamicAttachEnabled(true);
}
}
}
Loading