Skip to content

PrometheusHttpServer.toBuilder() drops the configured default handler #8618

Description

@thswlsqls

Describe the bug

PrometheusHttpServer.toBuilder() returns a builder that has lost the HttpHandler set via PrometheusHttpServerBuilder.setDefaultHandler(). A server rebuilt from that builder no longer serves metrics on /.

Steps to reproduce

HttpHandler handler = exchange -> { /* serve metrics on "/" */ };
PrometheusHttpServer server = PrometheusHttpServer.builder().setDefaultHandler(handler).build();

// handler is gone here
PrometheusHttpServer rebuilt = server.toBuilder().setPort(0).build();

What did you expect to see?

The rebuilt server keeps the configured default handler. PrometheusHttpServer.toBuilder() documents "Returns a new PrometheusHttpServerBuilder with the same configuration as this instance."

What did you see instead?

defaultHandler is null on the returned builder. The package-private copy constructor PrometheusHttpServerBuilder(PrometheusHttpServerBuilder) (exporters/prometheus/src/main/java/io/opentelemetry/exporter/prometheus/PrometheusHttpServerBuilder.java line 48-57) copies 8 of the builder's 9 fields and omits defaultHandler. The sibling authenticator field is @Nullable, setter-only and passed to HTTPServer.builder() the same way, and it is copied.

The field was added in #6476 without a matching copy-constructor line; memoryMode had the same omission and was fixed later in #6799.

What version and what artifacts are you using?

Artifacts: opentelemetry-exporter-prometheus
Version: main @ 63ebd94
How did you reference these artifacts? implementation("io.opentelemetry:opentelemetry-exporter-prometheus")

Environment

Compiler: Temurin 21
OS: N/A

Additional context

N/A

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions