Skip to content

Commit

Permalink
Skip loading agent if traceable agent has been loaded (#180)
Browse files Browse the repository at this point in the history
Signed-off-by: Pavol Loffay <p.loffay@gmail.com>
  • Loading branch information
pavolloffay authored Dec 17, 2020
1 parent d5e5699 commit 17e1dcb
Showing 1 changed file with 14 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ public static void premain(String agentArgs, Instrumentation inst) {
}

public static void agentmain(String agentArgs, Instrumentation inst) {
if (isTraceableAgentLoaded()) {
System.out.println("Traceable agent is already running. Will not attempt to attach");
return;
}

Map<String, String> parsedArgs = parseAgentArgs(agentArgs);
for (Map.Entry<String, String> argEntry : parsedArgs.entrySet()) {
System.setProperty(argEntry.getKey(), argEntry.getValue());
Expand Down Expand Up @@ -103,4 +108,13 @@ private static Map<String, String> parseAgentArgs(String agentArgs) {
}
return argsMap;
}

private static boolean isTraceableAgentLoaded() {
try {
Class.forName("ai.traceable.agent.bootstrap.AgentContext", true, null);
return true;
} catch (Throwable e) {
return false;
}
}
}

0 comments on commit 17e1dcb

Please sign in to comment.