Skip to content

Commit bd55a7b

Browse files
authored
With runtime attachment, applicationinsights.log file is now located in user dir because the agent jar is located in a temp folder that is dropped when the JVM shuts down (#2345)
1 parent 5e4986b commit bd55a7b

File tree

1 file changed

+11
-2
lines changed
  • agent/agent-tooling/src/main/java/com/microsoft/applicationinsights/agent/internal/configuration

1 file changed

+11
-2
lines changed

agent/agent-tooling/src/main/java/com/microsoft/applicationinsights/agent/internal/configuration/Configuration.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import com.microsoft.applicationinsights.agent.internal.common.FriendlyException;
3333
import io.opentelemetry.api.common.AttributeKey;
3434
import io.opentelemetry.sdk.logs.data.Severity;
35+
import java.io.File;
3536
import java.util.ArrayList;
3637
import java.util.HashMap;
3738
import java.util.HashSet;
@@ -521,8 +522,12 @@ public static class DestinationFile {
521522

522523
private static String getDefaultPath() {
523524
if (!DiagnosticsHelper.isRpIntegration()) {
524-
// this will be relative to the directory where agent jar is located
525-
return DEFAULT_NAME;
525+
if (isRuntimeAttached()) { // With runtime attachment, the agent jar is located in a temp
526+
// folder that is dropped when the JVM shuts down
527+
String userDir = System.getProperty("user.dir");
528+
return userDir + File.separator + DEFAULT_NAME;
529+
}
530+
return DEFAULT_NAME; // this will be relative to the directory where agent jar is located
526531
}
527532
if (DiagnosticsHelper.useAppSvcRpIntegrationLogging()) {
528533
return StatusFile.getLogDir() + "/" + DEFAULT_NAME;
@@ -536,6 +541,10 @@ private static String getDefaultPath() {
536541
}
537542
}
538543

544+
private static boolean isRuntimeAttached() {
545+
return Boolean.getBoolean("applicationinsights.internal.runtime.attached");
546+
}
547+
539548
public static class SamplingOverride {
540549
// TODO (trask) consider making this required when moving out of preview
541550
@Nullable public SpanKind spanKind;

0 commit comments

Comments
 (0)