Skip to content

Commit bcb313f

Browse files
authored
Merge pull request quarkusio#50054 from geoand/quarkusio#50040
Apply `server.port` tag to all the created Vert.x metrics
2 parents 96eff36 + 683ff2a commit bcb313f

File tree

1 file changed

+17
-7
lines changed

1 file changed

+17
-7
lines changed

extensions/micrometer/runtime/src/main/java/io/quarkus/micrometer/runtime/binder/vertx/VertxHttpServerMetrics.java

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import io.micrometer.core.instrument.LongTaskTimer;
1313
import io.micrometer.core.instrument.Meter.MeterProvider;
1414
import io.micrometer.core.instrument.MeterRegistry;
15+
import io.micrometer.core.instrument.Tag;
1516
import io.micrometer.core.instrument.Tags;
1617
import io.micrometer.core.instrument.Timer;
1718
import io.micrometer.core.instrument.binder.http.Outcome;
@@ -56,19 +57,18 @@ public class VertxHttpServerMetrics extends VertxTcpServerMetrics
5657
VertxHttpServerMetrics(MeterRegistry registry,
5758
HttpBinderConfiguration config,
5859
OpenTelemetryContextUnwrapper openTelemetryContextUnwrapper, HttpServerOptions httpServerOptions) {
59-
super(registry, "http.server", null);
60+
super(registry, "http.server", commonTags(httpServerOptions));
6061
this.config = config;
6162
this.openTelemetryContextUnwrapper = openTelemetryContextUnwrapper;
62-
6363
activeRequests = new LongAdder();
64+
65+
Tags commonTags = commonTags(httpServerOptions);
66+
6467
Gauge.Builder<LongAdder> activeRequestsBuilder = Gauge
6568
.builder(config.getHttpServerActiveRequestsName(), activeRequests, LongAdder::doubleValue)
6669
.tag("url.scheme", httpServerOptions.isSsl() ? "https" : "http");
67-
// we add a port tag (the one the application should actually bind to on the network host,
68-
// not the public one which we can't know easily) only if it's not random
69-
if (httpServerOptions.getPort() > 0) {
70-
activeRequestsBuilder
71-
.tag("server.port", "" + httpServerOptions.getPort());
70+
for (Tag commonTag : commonTags) {
71+
activeRequestsBuilder.tag(commonTag.getKey(), commonTag.getValue());
7272
}
7373
activeRequestsBuilder.register(registry);
7474

@@ -89,6 +89,16 @@ public class VertxHttpServerMetrics extends VertxTcpServerMetrics
8989
// not dev-mode changeable -----ˆ
9090
}
9191

92+
private static Tags commonTags(HttpServerOptions httpServerOptions) {
93+
Tags result = Tags.empty();
94+
// we add a port tag (the one the application should actually bind to on the network host,
95+
// not the public one which we can't know easily) only if it's not random
96+
if (httpServerOptions.getPort() > 0) {
97+
result = result.and("server.port", "" + httpServerOptions.getPort());
98+
}
99+
return result;
100+
}
101+
92102
private List<HttpServerMetricsTagsContributor> resolveHttpServerMetricsTagsContributors() {
93103
final List<HttpServerMetricsTagsContributor> httpServerMetricsTagsContributors;
94104
ArcContainer arcContainer = Arc.container();

0 commit comments

Comments
 (0)