Add a request tag for listen port

This commit is contained in:
ravi-signal
2026-02-05 17:18:09 -05:00
committed by GitHub
parent ea80077c25
commit 7e9da6d7ce
6 changed files with 47 additions and 20 deletions

View File

@@ -57,6 +57,9 @@ public class MetricsRequestEventListener implements RequestEventListener {
@VisibleForTesting
static final String AUTHENTICATED_TAG = "authenticated";
@VisibleForTesting
static final String LISTEN_PORT_TAG = "listenPort";
private final TrafficSource trafficSource;
private final MeterRegistry meterRegistry;
@@ -82,7 +85,7 @@ public class MetricsRequestEventListener implements RequestEventListener {
public void onEvent(final RequestEvent event) {
if (event.getType() == RequestEvent.Type.FINISHED) {
if (!event.getUriInfo().getMatchedTemplates().isEmpty()) {
final List<Tag> tags = new ArrayList<>(5);
final List<Tag> tags = new ArrayList<>();
tags.add(Tag.of(PATH_TAG, UriInfoUtil.getPathTemplate(event.getUriInfo())));
tags.add(Tag.of(METHOD_TAG, event.getContainerRequest().getMethod()));
tags.add(Tag.of(STATUS_CODE_TAG, String.valueOf(Optional
@@ -110,6 +113,11 @@ public class MetricsRequestEventListener implements RequestEventListener {
maybeClientVersionTag.ifPresent(tags::add);
Optional.ofNullable(event.getContainerRequest().getProperty(WebSocketResourceProvider.LISTEN_PORT_PROPERTY))
.filter(Integer.class::isInstance)
.map(Integer.class::cast)
.ifPresent(port -> tags.add(Tag.of(LISTEN_PORT_TAG, Integer.toString(port))));
meterRegistry.counter(REQUEST_COUNTER_NAME, tags).increment();
Optional.ofNullable(event.getContainerRequest().getProperty(WebSocketResourceProvider.REQUEST_LENGTH_PROPERTY))