Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support finding applicationinsights.json in current dir when using runtime attach #3990

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
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
Prev Previous commit
Next Next commit
up
  • Loading branch information
trask committed Dec 20, 2024
commit 765ccd10f457c2b224c8825a57b0c530c0ed243f
Original file line number Diff line number Diff line change
@@ -4,6 +4,7 @@
package com.microsoft.applicationinsights.attach;

import io.opentelemetry.contrib.attach.core.CoreRuntimeAttach;
import javax.annotation.Nullable;
import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
@@ -81,23 +82,23 @@ private static Optional<String> findJsonConfigFromClasspath() {
return Optional.empty();
}

String json = findJson(configContentAsInputStream);
String json = read(configContentAsInputStream);
return Optional.of(json);
}

private static Optional<String> findJsonConfigFromFileSystem() {

InputStream configContentAsInputStream = findDefaultFileInCurrentDirAsStream();
InputStream configContentAsInputStream = findJsonConfigFromFileSystemAsStream();

if (configContentAsInputStream == null) {
return Optional.empty();
}

String json = findJson(configContentAsInputStream);
String json = read(configContentAsInputStream);
return Optional.of(json);
}

private static String findJson(InputStream configContentAsInputStream) {
private static String read(InputStream configContentAsInputStream) {
try (InputStreamReader inputStreamReader =
new InputStreamReader(configContentAsInputStream, StandardCharsets.UTF_8);
BufferedReader bufferedReader = new BufferedReader(inputStreamReader)) {
@@ -108,6 +109,7 @@ private static String findJson(InputStream configContentAsInputStream) {
}
}

@Nullable
private static InputStream findResourceAsStream(String fileName) {
InputStream configContentAsInputStream =
ApplicationInsights.class.getResourceAsStream("/" + fileName);
@@ -117,7 +119,8 @@ private static InputStream findResourceAsStream(String fileName) {
return configContentAsInputStream;
}

private static InputStream findDefaultFileInCurrentDirAsStream() {
@Nullable
private static InputStream findJsonConfigFromFileSystemAsStream() {
File defaultFile = new File("config/applicationinsights.json");
if (!defaultFile.exists()) {
defaultFile = new File("applicationinsights.json");
Loading