Skip to content

Commit

Permalink
improvement based on review
Browse files Browse the repository at this point in the history
  • Loading branch information
zeitlinger committed Feb 20, 2024
1 parent 4766bb5 commit 145660f
Showing 1 changed file with 7 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
package io.opentelemetry.instrumentation.spring.resources;

import static java.util.logging.Level.FINE;
import static java.util.logging.Level.WARNING;

import io.opentelemetry.api.common.AttributeKey;
import io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties;
Expand Down Expand Up @@ -60,20 +61,17 @@ public Resource createResource(ConfigProperties config) {

protected Optional<Properties> getPropertiesFromBuildInfo() {
try (InputStream in = system.openClasspathResource("META-INF", "build-info.properties")) {
return in != null ? getPropertiesFromStream(in) : Optional.empty();
return in != null ? Optional.of(getPropertiesFromStream(in)) : Optional.empty();
} catch (Exception e) {
logger.log(WARNING, "Failed to read build-info.properties", e);
return Optional.empty();
}
}

private static Optional<Properties> getPropertiesFromStream(InputStream in) {
private static Properties getPropertiesFromStream(InputStream in) throws IOException {
Properties properties = new Properties();
try {
// Note: load() uses ISO 8859-1 encoding, same as spring uses by default for property files
properties.load(in);
return Optional.of(properties);
} catch (IOException e) {
return Optional.empty();
}
// Note: load() uses ISO 8859-1 encoding, same as spring uses by default for property files
properties.load(in);
return properties;
}
}

0 comments on commit 145660f

Please sign in to comment.