Skip to content

Commit c7a6cac

Browse files
jeanbisuttitraskgithub-actions[bot]
authored
Prevent runtime attach from application failure (#2765)
Co-authored-by: Trask Stalnaker <[email protected]> Co-authored-by: github-actions[bot] <github-action[bot]@users.noreply.github.com>
1 parent 5d5c9d4 commit c7a6cac

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

agent/runtime-attach/src/main/java/com/microsoft/applicationinsights/attach/ApplicationInsights.java

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import java.nio.charset.StandardCharsets;
1212
import java.util.Optional;
1313
import java.util.Properties;
14+
import java.util.logging.Level;
1415
import java.util.logging.Logger;
1516
import java.util.stream.Collectors;
1617

@@ -50,15 +51,19 @@ public static void attach() {
5051

5152
System.setProperty(RUNTIME_ATTACHED_ENABLED_PROPERTY, "true");
5253

53-
Optional<String> jsonConfig = findJsonConfig();
54-
if (jsonConfig.isPresent()) {
55-
System.setProperty(RUNTIME_ATTACHED_JSON_PROPERTY, jsonConfig.get());
56-
}
54+
try {
55+
Optional<String> jsonConfig = findJsonConfig();
56+
if (jsonConfig.isPresent()) {
57+
System.setProperty(RUNTIME_ATTACHED_JSON_PROPERTY, jsonConfig.get());
58+
}
5759

58-
String appInsightResourceName = findAppInsightResourceName();
59-
CoreRuntimeAttach runtimeAttach = new CoreRuntimeAttach(appInsightResourceName);
60+
String appInsightResourceName = findAppInsightResourceName();
61+
CoreRuntimeAttach runtimeAttach = new CoreRuntimeAttach(appInsightResourceName);
6062

61-
runtimeAttach.attachJavaagentToCurrentJVM();
63+
runtimeAttach.attachJavaagentToCurrentJVM();
64+
} catch (Throwable t) {
65+
logger.log(Level.WARNING, "Fail to runtime attach Application Insights", t);
66+
}
6267
}
6368

6469
private static Optional<String> findJsonConfig() {

0 commit comments

Comments
 (0)