diff --git a/lxd/request/request.go b/lxd/request/request.go index d44e7817fdf4..e06c35f8d28f 100644 --- a/lxd/request/request.go +++ b/lxd/request/request.go @@ -78,7 +78,10 @@ func CountStartedRequest(r *http.Request) { // The callback function is used to mark the request as completed for the API metrics. func MetricsCallback(request *http.Request, result metrics.RequestResult) { callback, err := GetCtxValue[func(metrics.RequestResult)](request.Context(), MetricsCallbackFunc) - if err != nil && (strings.HasPrefix(request.URL.Path, "/1.0") || request.URL.Path == "/") { + + // Verify the auth method in the request context to determine if the request comes from the /dev/lxd socket. + authMethod, _ := GetCtxValue[string](request.Context(), CtxProtocol) + if err != nil && strings.HasPrefix(request.URL.Path, "/1.0") && authMethod != api.AuthenticationMethodDevLxd { // Log a warning if endpoint is part of the main API, and therefore should be counted fot the API metrics. logger.Warn("Request will not be counted for the API metrics", logger.Ctx{"url": request.URL.Path, "method": request.Method, "remote": request.RemoteAddr}) } else if err == nil && callback != nil {