Skip to content

Commit 5479c22

Browse files
committed
Log info message about change in semantics when host is not set
1 parent ca24fa7 commit 5479c22

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

exporters/prometheus/src/main/java/io/opentelemetry/exporter/prometheus/PrometheusHttpServerBuilder.java

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import java.util.concurrent.ExecutorService;
1919
import java.util.concurrent.Executors;
2020
import java.util.function.Predicate;
21+
import java.util.logging.Logger;
2122
import javax.annotation.Nullable;
2223

2324
/** A builder for {@link PrometheusHttpServer}. */
@@ -26,8 +27,12 @@ public final class PrometheusHttpServerBuilder {
2627
static final int DEFAULT_PORT = 9464;
2728
private static final String DEFAULT_HOST = "localhost";
2829
private static final MemoryMode DEFAULT_MEMORY_MODE = MemoryMode.REUSABLE_DATA;
30+
private static final Logger LOGGER =
31+
Logger.getLogger(PrometheusHttpServerBuilder.class.getName());
2932

30-
private String host = DEFAULT_HOST;
33+
// Temporarily nullable to detect when it's not set and log warning about 0.0.0.0 -> localhost
34+
// change
35+
@Nullable private String host;
3136
private int port = DEFAULT_PORT;
3237
private PrometheusRegistry prometheusRegistry = new PrometheusRegistry();
3338
private PrometheusMetricReaderBuilder metricReaderBuilder = PrometheusMetricReader.builder();
@@ -178,9 +183,17 @@ public PrometheusHttpServer build() {
178183
"MemoryMode REUSEABLE_DATA cannot be used with custom executor, "
179184
+ "since data may be corrupted if reading metrics concurrently");
180185
}
186+
String resolvedHost = host;
187+
if (resolvedHost == null) {
188+
// TODO (jack-berg): Remove log after 1.64.0 release
189+
LOGGER.info(
190+
"PrometheusHttpServer host not set, defaulting to localhost. Previously defaulted to 0.0.0.0. "
191+
+ "If you depend on the old behavior, set host to 0.0.0.0 explicitly.");
192+
resolvedHost = DEFAULT_HOST;
193+
}
181194
return new PrometheusHttpServer(
182195
new PrometheusHttpServerBuilder(this), // copy to prevent modification
183-
host,
196+
resolvedHost,
184197
port,
185198
executor,
186199
prometheusRegistry,

0 commit comments

Comments
 (0)