diff --git a/instrumentation/jmx-metrics/javaagent/src/main/java/io/opentelemetry/instrumentation/javaagent/jmx/JmxMetricInsightInstaller.java b/instrumentation/jmx-metrics/javaagent/src/main/java/io/opentelemetry/instrumentation/javaagent/jmx/JmxMetricInsightInstaller.java index 2c2d989ba9f7..afc046b995dc 100644 --- a/instrumentation/jmx-metrics/javaagent/src/main/java/io/opentelemetry/instrumentation/javaagent/jmx/JmxMetricInsightInstaller.java +++ b/instrumentation/jmx-metrics/javaagent/src/main/java/io/opentelemetry/instrumentation/javaagent/jmx/JmxMetricInsightInstaller.java @@ -17,8 +17,7 @@ import io.opentelemetry.sdk.autoconfigure.AutoConfiguredOpenTelemetrySdk; import io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties; import java.io.InputStream; -import java.nio.file.Files; -import java.nio.file.Paths; +import java.net.URL; import java.time.Duration; import java.util.List; @@ -81,10 +80,15 @@ private static void buildFromDefaultRules( private static void buildFromUserRules( MetricConfiguration conf, ConfigProperties configProperties) { List configFiles = configProperties.getList("otel.jmx.config"); + String configFileUrlString; for (String configFile : configFiles) { - JmxMetricInsight.getLogger().log(FINE, "JMX config file name: {0}", configFile); + configFileUrlString = configFile; + if (configFile != null && !configFile.contains("://")) { + configFileUrlString = "file://" + configFile; + } + JmxMetricInsight.getLogger().log(FINE, "JMX config file name: {0}", configFileUrlString); RuleParser parserInstance = RuleParser.get(); - try (InputStream inputStream = Files.newInputStream(Paths.get(configFile))) { + try (InputStream inputStream = new URL(configFileUrlString).openStream()) { parserInstance.addMetricDefsTo(conf, inputStream, configFile); } catch (Exception e) { // yaml parsing errors are caught and logged inside of addMetricDefsTo