Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ private void sendErrorResponseWithStackTrace(Exception requestHandlerException)
httpExchange.getResponseHeaders().set("Content-Type", "text/plain; charset=utf-8");
httpExchange.sendResponseHeaders(500, stackTrace.length);
httpExchange.getResponseBody().write(stackTrace);
} catch (Exception errorWriterException) {
} catch (IOException errorWriterException) {
// We want to avoid logging so that we don't mess with application logs when the HTTPServer
// is used in a Java agent.
// However, if we can't even send an error response to the client there's nothing we can do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ static Resource getResourceField(AutoConfiguredOpenTelemetrySdk sdk) {
Method method = AutoConfiguredOpenTelemetrySdk.class.getDeclaredMethod("getResource");
method.setAccessible(true);
return (Resource) method.invoke(sdk);
} catch (Exception e) {
} catch (ReflectiveOperationException e) {
throw new RuntimeException(e);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package io.prometheus.metrics.exporter.opentelemetry;

import io.opentelemetry.sdk.common.InstrumentationScopeInfo;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

class PrometheusInstrumentationScope {
Expand All @@ -21,8 +23,15 @@ static InstrumentationScopeInfo loadInstrumentationScopeInfo(
String path, String nameKey, String versionKey) {
try {
Properties properties = new Properties();
properties.load(
PrometheusInstrumentationScope.class.getClassLoader().getResourceAsStream(path));
InputStream stream =
PrometheusInstrumentationScope.class.getClassLoader().getResourceAsStream(path);
if (stream == null) {
throw new IllegalStateException(
"Prometheus metrics library initialization error: Failed to read "
+ path
+ " from classpath.");
}
properties.load(stream);
String instrumentationScopeName = properties.getProperty(nameKey);
if (instrumentationScopeName == null) {
throw new IllegalStateException(
Expand All @@ -44,7 +53,7 @@ static InstrumentationScopeInfo loadInstrumentationScopeInfo(
return InstrumentationScopeInfo.builder(instrumentationScopeName)
.setVersion(instrumentationScopeVersion)
.build();
} catch (Exception e) {
} catch (IOException e) {
throw new IllegalStateException(
"Prometheus metrics library initialization error: Failed to read "
+ path
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ void loadInstrumentationScopeInfo() {
() ->
PrometheusInstrumentationScope.loadInstrumentationScopeInfo(
"instrumentationScope.properties", "name", "version"))
.havingRootCause()
.withMessage(
"Prometheus metrics library initialization error: name not found in"
+ " instrumentationScope.properties in classpath.");
Expand All @@ -32,7 +31,6 @@ void loadInstrumentationScopeInfo() {
() ->
PrometheusInstrumentationScope.loadInstrumentationScopeInfo(
"instrumentationScope.properties", "instrumentationScope.name", "version"))
.havingRootCause()
.withMessage(
"Prometheus metrics library initialization error: version not found in"
+ " instrumentationScope.properties in classpath.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ public MetricSnapshots collect() {
.labels(labels)
.value(stats.evictionWeight())
.build());
} catch (Exception e) {
} catch (UnsupportedOperationException e) {
// EvictionWeight metric is unavailable, newer version of Caffeine is needed.
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ protected <K, V> void collectMetricKind(
if (snapshot != null) {
builder.metricSnapshot(snapshot);
}
} catch (Exception e) {
} catch (RuntimeException e) {
if (!invalidMetricHandler.suppressException(metricName, e)) {
throw e;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,8 @@ private String vmNativeMemorySummaryInBytesOrEmpty() {
} else {
return summary;
}
} catch (Exception ex) {
// ignore errors
} catch (RuntimeException ex) {
// ignore errors (native memory tracking not enabled or other runtime failures)
isEnabled.set(false);
return "";
}
Expand Down
Loading