Skip to content

Commit c9509a5

Browse files
committed
Improve type safety in Micrometer HTTP server metrics
``` - Refactor context local data handling across Micrometer integration to improve type safety with generics. - Simplify and clean up code by removing unnecessary type casts in `ContextLocalTag`. ```
1 parent e3e3653 commit c9509a5

File tree

3 files changed

+3
-3
lines changed

3 files changed

+3
-3
lines changed

extensions/micrometer/runtime/src/main/java/io/quarkus/micrometer/runtime/HttpServerMetricsTagsContributor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,6 @@ interface Context {
3131
* work when {@link HttpServerMetricsTagsContributor#contribute(Context)} is called as the HTTP request has
3232
* already gone away.
3333
*/
34-
Object requestContextLocalData(Object key);
34+
<T> T requestContextLocalData(Object key);
3535
}
3636
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ public void disconnected(LongTaskTimer.Sample websocketMetric) {
271271
private record DefaultContext(HttpServerRequest request,
272272
HttpResponse response) implements HttpServerMetricsTagsContributor.Context {
273273
@Override
274-
public Object requestContextLocalData(Object key) {
274+
public <T> T requestContextLocalData(Object key) {
275275
return ((HttpServerRequestInternal) request).context().getLocal(key);
276276
}
277277
}

integration-tests/micrometer-prometheus/src/main/java/io/quarkus/ContextLocalTag.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ public class ContextLocalTag implements HttpServerMetricsTagsContributor {
1010

1111
@Override
1212
public Tags contribute(Context context) {
13-
String contextLocalData = (String) context.requestContextLocalData("context-local");
13+
String contextLocalData = context.requestContextLocalData("context-local");
1414
return Tags.of("dummy", contextLocalData != null ? contextLocalData : "value");
1515
}
1616
}

0 commit comments

Comments
 (0)