Skip to content

Commit 05d0fd0

Browse files
authored
Don't allow agent to attach multiple times (#174)
Signed-off-by: Pavol Loffay <[email protected]>
1 parent cfddd6a commit 05d0fd0

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

javaagent/src/main/java/org/hypertrace/agent/instrument/HypertraceAgent.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ public class HypertraceAgent {
3939
private static final String OTEL_DEFAULT_LOG_LEVEL =
4040
"io.opentelemetry.javaagent.slf4j.simpleLogger.defaultLogLevel";
4141

42+
private static HypertraceAgent instance;
43+
4244
public static void premain(String agentArgs, Instrumentation inst) {
4345
agentmain(agentArgs, inst);
4446
}
@@ -49,6 +51,14 @@ public static void agentmain(String agentArgs, Instrumentation inst) {
4951
System.setProperty(argEntry.getKey(), argEntry.getValue());
5052
}
5153

54+
// TODO consider removing
55+
// https://github.com/open-telemetry/opentelemetry-java-instrumentation/pull/1898
56+
if (instance != null) {
57+
System.out.println("Agent is already running. Will not attempt to attach");
58+
return;
59+
}
60+
61+
instance = new HypertraceAgent();
5262
setDefaultConfig();
5363
OpenTelemetryAgent.premain(agentArgs, inst);
5464
}

0 commit comments

Comments
 (0)