12
12
import io .micrometer .core .instrument .LongTaskTimer ;
13
13
import io .micrometer .core .instrument .Meter .MeterProvider ;
14
14
import io .micrometer .core .instrument .MeterRegistry ;
15
+ import io .micrometer .core .instrument .Tag ;
15
16
import io .micrometer .core .instrument .Tags ;
16
17
import io .micrometer .core .instrument .Timer ;
17
18
import io .micrometer .core .instrument .binder .http .Outcome ;
@@ -56,19 +57,18 @@ public class VertxHttpServerMetrics extends VertxTcpServerMetrics
56
57
VertxHttpServerMetrics (MeterRegistry registry ,
57
58
HttpBinderConfiguration config ,
58
59
OpenTelemetryContextUnwrapper openTelemetryContextUnwrapper , HttpServerOptions httpServerOptions ) {
59
- super (registry , "http.server" , null );
60
+ super (registry , "http.server" , commonTags ( httpServerOptions ) );
60
61
this .config = config ;
61
62
this .openTelemetryContextUnwrapper = openTelemetryContextUnwrapper ;
62
-
63
63
activeRequests = new LongAdder ();
64
+
65
+ Tags commonTags = commonTags (httpServerOptions );
66
+
64
67
Gauge .Builder <LongAdder > activeRequestsBuilder = Gauge
65
68
.builder (config .getHttpServerActiveRequestsName (), activeRequests , LongAdder ::doubleValue )
66
69
.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 ());
72
72
}
73
73
activeRequestsBuilder .register (registry );
74
74
@@ -89,6 +89,16 @@ public class VertxHttpServerMetrics extends VertxTcpServerMetrics
89
89
// not dev-mode changeable -----ˆ
90
90
}
91
91
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
+
92
102
private List <HttpServerMetricsTagsContributor > resolveHttpServerMetricsTagsContributors () {
93
103
final List <HttpServerMetricsTagsContributor > httpServerMetricsTagsContributors ;
94
104
ArcContainer arcContainer = Arc .container ();
0 commit comments