diff --git a/components/mediation/data-publishers/org.wso2.micro.integrator.observability/src/main/java/org/wso2/micro/integrator/observability/metric/handler/MetricHandler.java b/components/mediation/data-publishers/org.wso2.micro.integrator.observability/src/main/java/org/wso2/micro/integrator/observability/metric/handler/MetricHandler.java index 9c3ae218df..540d80081f 100644 --- a/components/mediation/data-publishers/org.wso2.micro.integrator.observability/src/main/java/org/wso2/micro/integrator/observability/metric/handler/MetricHandler.java +++ b/components/mediation/data-publishers/org.wso2.micro.integrator.observability/src/main/java/org/wso2/micro/integrator/observability/metric/handler/MetricHandler.java @@ -318,11 +318,10 @@ private String getApiName(String contextPath, MessageContext synCtx) { if (RESTUtils.matchApiPath(contextPath, apiContextPath)) { apiName = api.getName(); synCtx.setProperty(RESTConstants.PROCESSED_API, api); - // if we match to a versioned API, search should stop. - // else check other API's to see if there is a match - if (StringUtils.isNotEmpty(api.getVersion())) { - break; - } + // Since the APIs are already sorted in descending order, we should stop at the first match with the context path. + // Continuing the loop could result in matching a path that only shares the same starting string. + // Ex: /test/ API context path will match with /test/1.0.0 + break; } } return apiName;