diff --git a/assets/templates/middleware/metrics b/assets/templates/middleware/metrics
index 9e1406280e5f19c4535e0ca6ca9d77d4f2206ef6..9dd4047d8908de2d094acc3bc4170bfd5552ec13 100644
--- a/assets/templates/middleware/metrics
+++ b/assets/templates/middleware/metrics
@@ -26,14 +26,14 @@ func {{ $funcName }} (requestMetrics *metrics.RequestMetrics) Middleware {
 {{ range $method := .Interface.Methods }}
     // {{ $method.Name }} implements {{ $.Interface.Type }}
     func (m {{ $decorator }}) {{ $method.Declaration }} {
-        m.requestMetrics.Total.WithLabelValues("{{ $method.Name }}").Inc()
         timer := prometheus.NewTimer(m.requestMetrics.DurationSeconds.WithLabelValues("{{ $method.Name }}"))
-        defer func() {
-            timer.ObserveDuration()
-            if err != nil {
-                m.requestMetrics.FailedTotal.WithLabelValues("{{ $method.Name }}").Inc()
-            }
-        }()
-        {{ $method.Pass "m.next." }}
+        defer timer.ObserveDuration()
+        m.requestMetrics.Total.WithLabelValues("{{ $method.Name }}").Inc()
+        {{ $method.ResultsNames }} = m.next.{{ $method.Call }}
+        if err != nil {
+            m.requestMetrics.FailedTotal.WithLabelValues("{{ $method.Name }}").Inc()
+            return
+        }
+        return
     }
 {{ end }}
\ No newline at end of file
diff --git a/images/middleware/metrics_middleware.go b/images/middleware/metrics_middleware.go
index 2ed5e6adfd8ca9b21f21ed59156eb6f7094f3f06..f583718d99a1f2bad613f279c447307c6b715c78 100644
--- a/images/middleware/metrics_middleware.go
+++ b/images/middleware/metrics_middleware.go
@@ -33,13 +33,13 @@ func MetricsMiddleware(requestMetrics *metrics.RequestMetrics) Middleware {
 
 // Get implements images.Images
 func (m metricsMiddleware) Get(ctx context.Context, source *files.File, opts *images.GetOptions) (result *files.File, err error) {
-	m.requestMetrics.Total.WithLabelValues("Get").Inc()
 	timer := prometheus.NewTimer(m.requestMetrics.DurationSeconds.WithLabelValues("Get"))
-	defer func() {
-		timer.ObserveDuration()
-		if err != nil {
-			m.requestMetrics.FailedTotal.WithLabelValues("Get").Inc()
-		}
-	}()
-	return m.next.Get(ctx, source, opts)
+	defer timer.ObserveDuration()
+	m.requestMetrics.Total.WithLabelValues("Get").Inc()
+	result, err = m.next.Get(ctx, source, opts)
+	if err != nil {
+		m.requestMetrics.FailedTotal.WithLabelValues("Get").Inc()
+		return
+	}
+	return
 }
diff --git a/pkg/collaborators/middleware/metrics_middleware.go b/pkg/collaborators/middleware/metrics_middleware.go
index 00eb495f75ee72a9ed62be211495ba68a68b64a8..0e4dcc986e394f6ea1f12d49b7fbfd7303987f01 100644
--- a/pkg/collaborators/middleware/metrics_middleware.go
+++ b/pkg/collaborators/middleware/metrics_middleware.go
@@ -32,65 +32,65 @@ func MetricsMiddleware(requestMetrics *metrics.RequestMetrics) Middleware {
 
 // Get implements collaborators.Collaborators
 func (m metricsMiddleware) Get(ctx context.Context, spaceId string, subject string) (role string, err error) {
-	m.requestMetrics.Total.WithLabelValues("Get").Inc()
 	timer := prometheus.NewTimer(m.requestMetrics.DurationSeconds.WithLabelValues("Get"))
-	defer func() {
-		timer.ObserveDuration()
-		if err != nil {
-			m.requestMetrics.FailedTotal.WithLabelValues("Get").Inc()
-		}
-	}()
-	return m.next.Get(ctx, spaceId, subject)
+	defer timer.ObserveDuration()
+	m.requestMetrics.Total.WithLabelValues("Get").Inc()
+	role, err = m.next.Get(ctx, spaceId, subject)
+	if err != nil {
+		m.requestMetrics.FailedTotal.WithLabelValues("Get").Inc()
+		return
+	}
+	return
 }
 
 // ListCollaborators implements collaborators.Collaborators
 func (m metricsMiddleware) ListCollaborators(ctx context.Context, spaceId string) (collaborators []*collaborators.Collaborator, err error) {
-	m.requestMetrics.Total.WithLabelValues("ListCollaborators").Inc()
 	timer := prometheus.NewTimer(m.requestMetrics.DurationSeconds.WithLabelValues("ListCollaborators"))
-	defer func() {
-		timer.ObserveDuration()
-		if err != nil {
-			m.requestMetrics.FailedTotal.WithLabelValues("ListCollaborators").Inc()
-		}
-	}()
-	return m.next.ListCollaborators(ctx, spaceId)
+	defer timer.ObserveDuration()
+	m.requestMetrics.Total.WithLabelValues("ListCollaborators").Inc()
+	collaborators, err = m.next.ListCollaborators(ctx, spaceId)
+	if err != nil {
+		m.requestMetrics.FailedTotal.WithLabelValues("ListCollaborators").Inc()
+		return
+	}
+	return
 }
 
 // ListSpaces implements collaborators.Collaborators
 func (m metricsMiddleware) ListSpaces(ctx context.Context, subject string) (spaces []*collaborators.Collaborator, err error) {
-	m.requestMetrics.Total.WithLabelValues("ListSpaces").Inc()
 	timer := prometheus.NewTimer(m.requestMetrics.DurationSeconds.WithLabelValues("ListSpaces"))
-	defer func() {
-		timer.ObserveDuration()
-		if err != nil {
-			m.requestMetrics.FailedTotal.WithLabelValues("ListSpaces").Inc()
-		}
-	}()
-	return m.next.ListSpaces(ctx, subject)
+	defer timer.ObserveDuration()
+	m.requestMetrics.Total.WithLabelValues("ListSpaces").Inc()
+	spaces, err = m.next.ListSpaces(ctx, subject)
+	if err != nil {
+		m.requestMetrics.FailedTotal.WithLabelValues("ListSpaces").Inc()
+		return
+	}
+	return
 }
 
 // Remove implements collaborators.Collaborators
 func (m metricsMiddleware) Remove(ctx context.Context, spaceId string, subject string) (err error) {
-	m.requestMetrics.Total.WithLabelValues("Remove").Inc()
 	timer := prometheus.NewTimer(m.requestMetrics.DurationSeconds.WithLabelValues("Remove"))
-	defer func() {
-		timer.ObserveDuration()
-		if err != nil {
-			m.requestMetrics.FailedTotal.WithLabelValues("Remove").Inc()
-		}
-	}()
-	return m.next.Remove(ctx, spaceId, subject)
+	defer timer.ObserveDuration()
+	m.requestMetrics.Total.WithLabelValues("Remove").Inc()
+	err = m.next.Remove(ctx, spaceId, subject)
+	if err != nil {
+		m.requestMetrics.FailedTotal.WithLabelValues("Remove").Inc()
+		return
+	}
+	return
 }
 
 // Set implements collaborators.Collaborators
 func (m metricsMiddleware) Set(ctx context.Context, spaceId string, subject string, role string) (err error) {
-	m.requestMetrics.Total.WithLabelValues("Set").Inc()
 	timer := prometheus.NewTimer(m.requestMetrics.DurationSeconds.WithLabelValues("Set"))
-	defer func() {
-		timer.ObserveDuration()
-		if err != nil {
-			m.requestMetrics.FailedTotal.WithLabelValues("Set").Inc()
-		}
-	}()
-	return m.next.Set(ctx, spaceId, subject, role)
+	defer timer.ObserveDuration()
+	m.requestMetrics.Total.WithLabelValues("Set").Inc()
+	err = m.next.Set(ctx, spaceId, subject, role)
+	if err != nil {
+		m.requestMetrics.FailedTotal.WithLabelValues("Set").Inc()
+		return
+	}
+	return
 }
diff --git a/pkg/collections/middleware/metrics_middleware.go b/pkg/collections/middleware/metrics_middleware.go
index b98b626656d8edbf2770f5f0ac609c300a9c6628..012e11270f8a9ceb9ae11b762c1e2bb7b781d310 100644
--- a/pkg/collections/middleware/metrics_middleware.go
+++ b/pkg/collections/middleware/metrics_middleware.go
@@ -33,91 +33,91 @@ func MetricsMiddleware(requestMetrics *metrics.RequestMetrics) Middleware {
 
 // Create implements collections.Collections
 func (m metricsMiddleware) Create(ctx context.Context, collection *collections.Collection) (created *collections.Collection, err error) {
-	m.requestMetrics.Total.WithLabelValues("Create").Inc()
 	timer := prometheus.NewTimer(m.requestMetrics.DurationSeconds.WithLabelValues("Create"))
-	defer func() {
-		timer.ObserveDuration()
-		if err != nil {
-			m.requestMetrics.FailedTotal.WithLabelValues("Create").Inc()
-		}
-	}()
-	return m.next.Create(ctx, collection)
+	defer timer.ObserveDuration()
+	m.requestMetrics.Total.WithLabelValues("Create").Inc()
+	created, err = m.next.Create(ctx, collection)
+	if err != nil {
+		m.requestMetrics.FailedTotal.WithLabelValues("Create").Inc()
+		return
+	}
+	return
 }
 
 // Delete implements collections.Collections
 func (m metricsMiddleware) Delete(ctx context.Context, spaceId string, envId string, collectionId string) (err error) {
-	m.requestMetrics.Total.WithLabelValues("Delete").Inc()
 	timer := prometheus.NewTimer(m.requestMetrics.DurationSeconds.WithLabelValues("Delete"))
-	defer func() {
-		timer.ObserveDuration()
-		if err != nil {
-			m.requestMetrics.FailedTotal.WithLabelValues("Delete").Inc()
-		}
-	}()
-	return m.next.Delete(ctx, spaceId, envId, collectionId)
+	defer timer.ObserveDuration()
+	m.requestMetrics.Total.WithLabelValues("Delete").Inc()
+	err = m.next.Delete(ctx, spaceId, envId, collectionId)
+	if err != nil {
+		m.requestMetrics.FailedTotal.WithLabelValues("Delete").Inc()
+		return
+	}
+	return
 }
 
 // Get implements collections.Collections
 func (m metricsMiddleware) Get(ctx context.Context, spaceId string, envId string, collectionId string, options ...*collections.GetOptions) (collection *collections.Collection, err error) {
-	m.requestMetrics.Total.WithLabelValues("Get").Inc()
 	timer := prometheus.NewTimer(m.requestMetrics.DurationSeconds.WithLabelValues("Get"))
-	defer func() {
-		timer.ObserveDuration()
-		if err != nil {
-			m.requestMetrics.FailedTotal.WithLabelValues("Get").Inc()
-		}
-	}()
-	return m.next.Get(ctx, spaceId, envId, collectionId, options...)
+	defer timer.ObserveDuration()
+	m.requestMetrics.Total.WithLabelValues("Get").Inc()
+	collection, err = m.next.Get(ctx, spaceId, envId, collectionId, options...)
+	if err != nil {
+		m.requestMetrics.FailedTotal.WithLabelValues("Get").Inc()
+		return
+	}
+	return
 }
 
 // List implements collections.Collections
 func (m metricsMiddleware) List(ctx context.Context, spaceId string, envId string, filter *collections.Filter) (collections []*collections.Collection, err error) {
-	m.requestMetrics.Total.WithLabelValues("List").Inc()
 	timer := prometheus.NewTimer(m.requestMetrics.DurationSeconds.WithLabelValues("List"))
-	defer func() {
-		timer.ObserveDuration()
-		if err != nil {
-			m.requestMetrics.FailedTotal.WithLabelValues("List").Inc()
-		}
-	}()
-	return m.next.List(ctx, spaceId, envId, filter)
+	defer timer.ObserveDuration()
+	m.requestMetrics.Total.WithLabelValues("List").Inc()
+	collections, err = m.next.List(ctx, spaceId, envId, filter)
+	if err != nil {
+		m.requestMetrics.FailedTotal.WithLabelValues("List").Inc()
+		return
+	}
+	return
 }
 
 // SetSchema implements collections.Collections
 func (m metricsMiddleware) SetSchema(ctx context.Context, spaceId string, envId string, collectionId string, schema *schema.Schema) (err error) {
-	m.requestMetrics.Total.WithLabelValues("SetSchema").Inc()
 	timer := prometheus.NewTimer(m.requestMetrics.DurationSeconds.WithLabelValues("SetSchema"))
-	defer func() {
-		timer.ObserveDuration()
-		if err != nil {
-			m.requestMetrics.FailedTotal.WithLabelValues("SetSchema").Inc()
-		}
-	}()
-	return m.next.SetSchema(ctx, spaceId, envId, collectionId, schema)
+	defer timer.ObserveDuration()
+	m.requestMetrics.Total.WithLabelValues("SetSchema").Inc()
+	err = m.next.SetSchema(ctx, spaceId, envId, collectionId, schema)
+	if err != nil {
+		m.requestMetrics.FailedTotal.WithLabelValues("SetSchema").Inc()
+		return
+	}
+	return
 }
 
 // SetState implements collections.Collections
 func (m metricsMiddleware) SetState(ctx context.Context, spaceId string, envId string, collectionId string, state *collections.StateInfo) (err error) {
-	m.requestMetrics.Total.WithLabelValues("SetState").Inc()
 	timer := prometheus.NewTimer(m.requestMetrics.DurationSeconds.WithLabelValues("SetState"))
-	defer func() {
-		timer.ObserveDuration()
-		if err != nil {
-			m.requestMetrics.FailedTotal.WithLabelValues("SetState").Inc()
-		}
-	}()
-	return m.next.SetState(ctx, spaceId, envId, collectionId, state)
+	defer timer.ObserveDuration()
+	m.requestMetrics.Total.WithLabelValues("SetState").Inc()
+	err = m.next.SetState(ctx, spaceId, envId, collectionId, state)
+	if err != nil {
+		m.requestMetrics.FailedTotal.WithLabelValues("SetState").Inc()
+		return
+	}
+	return
 }
 
 // Update implements collections.Collections
 func (m metricsMiddleware) Update(ctx context.Context, coll *collections.Collection) (err error) {
-	m.requestMetrics.Total.WithLabelValues("Update").Inc()
 	timer := prometheus.NewTimer(m.requestMetrics.DurationSeconds.WithLabelValues("Update"))
-	defer func() {
-		timer.ObserveDuration()
-		if err != nil {
-			m.requestMetrics.FailedTotal.WithLabelValues("Update").Inc()
-		}
-	}()
-	return m.next.Update(ctx, coll)
+	defer timer.ObserveDuration()
+	m.requestMetrics.Total.WithLabelValues("Update").Inc()
+	err = m.next.Update(ctx, coll)
+	if err != nil {
+		m.requestMetrics.FailedTotal.WithLabelValues("Update").Inc()
+		return
+	}
+	return
 }
diff --git a/pkg/environments/middleware/metrics_middleware.go b/pkg/environments/middleware/metrics_middleware.go
index da593edcc68108d074463e4490a7ca028bd248f1..3f4723b64bad3b651b7940cda9f6ee77ae74939e 100644
--- a/pkg/environments/middleware/metrics_middleware.go
+++ b/pkg/environments/middleware/metrics_middleware.go
@@ -32,104 +32,104 @@ func MetricsMiddleware(requestMetrics *metrics.RequestMetrics) Middleware {
 
 // Create implements environments.Environments
 func (m metricsMiddleware) Create(ctx context.Context, env *environments.Environment) (created *environments.Environment, err error) {
-	m.requestMetrics.Total.WithLabelValues("Create").Inc()
 	timer := prometheus.NewTimer(m.requestMetrics.DurationSeconds.WithLabelValues("Create"))
-	defer func() {
-		timer.ObserveDuration()
-		if err != nil {
-			m.requestMetrics.FailedTotal.WithLabelValues("Create").Inc()
-		}
-	}()
-	return m.next.Create(ctx, env)
+	defer timer.ObserveDuration()
+	m.requestMetrics.Total.WithLabelValues("Create").Inc()
+	created, err = m.next.Create(ctx, env)
+	if err != nil {
+		m.requestMetrics.FailedTotal.WithLabelValues("Create").Inc()
+		return
+	}
+	return
 }
 
 // Delete implements environments.Environments
 func (m metricsMiddleware) Delete(ctx context.Context, spaceId string, envId string) (err error) {
-	m.requestMetrics.Total.WithLabelValues("Delete").Inc()
 	timer := prometheus.NewTimer(m.requestMetrics.DurationSeconds.WithLabelValues("Delete"))
-	defer func() {
-		timer.ObserveDuration()
-		if err != nil {
-			m.requestMetrics.FailedTotal.WithLabelValues("Delete").Inc()
-		}
-	}()
-	return m.next.Delete(ctx, spaceId, envId)
+	defer timer.ObserveDuration()
+	m.requestMetrics.Total.WithLabelValues("Delete").Inc()
+	err = m.next.Delete(ctx, spaceId, envId)
+	if err != nil {
+		m.requestMetrics.FailedTotal.WithLabelValues("Delete").Inc()
+		return
+	}
+	return
 }
 
 // Get implements environments.Environments
 func (m metricsMiddleware) Get(ctx context.Context, spaceId string, envId string) (env *environments.Environment, err error) {
-	m.requestMetrics.Total.WithLabelValues("Get").Inc()
 	timer := prometheus.NewTimer(m.requestMetrics.DurationSeconds.WithLabelValues("Get"))
-	defer func() {
-		timer.ObserveDuration()
-		if err != nil {
-			m.requestMetrics.FailedTotal.WithLabelValues("Get").Inc()
-		}
-	}()
-	return m.next.Get(ctx, spaceId, envId)
+	defer timer.ObserveDuration()
+	m.requestMetrics.Total.WithLabelValues("Get").Inc()
+	env, err = m.next.Get(ctx, spaceId, envId)
+	if err != nil {
+		m.requestMetrics.FailedTotal.WithLabelValues("Get").Inc()
+		return
+	}
+	return
 }
 
 // List implements environments.Environments
 func (m metricsMiddleware) List(ctx context.Context, spaceId string) (envs []*environments.Environment, err error) {
-	m.requestMetrics.Total.WithLabelValues("List").Inc()
 	timer := prometheus.NewTimer(m.requestMetrics.DurationSeconds.WithLabelValues("List"))
-	defer func() {
-		timer.ObserveDuration()
-		if err != nil {
-			m.requestMetrics.FailedTotal.WithLabelValues("List").Inc()
-		}
-	}()
-	return m.next.List(ctx, spaceId)
+	defer timer.ObserveDuration()
+	m.requestMetrics.Total.WithLabelValues("List").Inc()
+	envs, err = m.next.List(ctx, spaceId)
+	if err != nil {
+		m.requestMetrics.FailedTotal.WithLabelValues("List").Inc()
+		return
+	}
+	return
 }
 
 // Migrate implements environments.Environments
 func (m metricsMiddleware) Migrate(ctx context.Context, spaceId string, envId string, options ...*environments.MigrateOptions) (err error) {
-	m.requestMetrics.Total.WithLabelValues("Migrate").Inc()
 	timer := prometheus.NewTimer(m.requestMetrics.DurationSeconds.WithLabelValues("Migrate"))
-	defer func() {
-		timer.ObserveDuration()
-		if err != nil {
-			m.requestMetrics.FailedTotal.WithLabelValues("Migrate").Inc()
-		}
-	}()
-	return m.next.Migrate(ctx, spaceId, envId, options...)
+	defer timer.ObserveDuration()
+	m.requestMetrics.Total.WithLabelValues("Migrate").Inc()
+	err = m.next.Migrate(ctx, spaceId, envId, options...)
+	if err != nil {
+		m.requestMetrics.FailedTotal.WithLabelValues("Migrate").Inc()
+		return
+	}
+	return
 }
 
 // RemoveAlias implements environments.Environments
 func (m metricsMiddleware) RemoveAlias(ctx context.Context, spaceId string, envId string, alias string) (err error) {
-	m.requestMetrics.Total.WithLabelValues("RemoveAlias").Inc()
 	timer := prometheus.NewTimer(m.requestMetrics.DurationSeconds.WithLabelValues("RemoveAlias"))
-	defer func() {
-		timer.ObserveDuration()
-		if err != nil {
-			m.requestMetrics.FailedTotal.WithLabelValues("RemoveAlias").Inc()
-		}
-	}()
-	return m.next.RemoveAlias(ctx, spaceId, envId, alias)
+	defer timer.ObserveDuration()
+	m.requestMetrics.Total.WithLabelValues("RemoveAlias").Inc()
+	err = m.next.RemoveAlias(ctx, spaceId, envId, alias)
+	if err != nil {
+		m.requestMetrics.FailedTotal.WithLabelValues("RemoveAlias").Inc()
+		return
+	}
+	return
 }
 
 // SetAlias implements environments.Environments
 func (m metricsMiddleware) SetAlias(ctx context.Context, spaceId string, envId string, alias string) (err error) {
-	m.requestMetrics.Total.WithLabelValues("SetAlias").Inc()
 	timer := prometheus.NewTimer(m.requestMetrics.DurationSeconds.WithLabelValues("SetAlias"))
-	defer func() {
-		timer.ObserveDuration()
-		if err != nil {
-			m.requestMetrics.FailedTotal.WithLabelValues("SetAlias").Inc()
-		}
-	}()
-	return m.next.SetAlias(ctx, spaceId, envId, alias)
+	defer timer.ObserveDuration()
+	m.requestMetrics.Total.WithLabelValues("SetAlias").Inc()
+	err = m.next.SetAlias(ctx, spaceId, envId, alias)
+	if err != nil {
+		m.requestMetrics.FailedTotal.WithLabelValues("SetAlias").Inc()
+		return
+	}
+	return
 }
 
 // Update implements environments.Environments
 func (m metricsMiddleware) Update(ctx context.Context, env *environments.Environment) (err error) {
-	m.requestMetrics.Total.WithLabelValues("Update").Inc()
 	timer := prometheus.NewTimer(m.requestMetrics.DurationSeconds.WithLabelValues("Update"))
-	defer func() {
-		timer.ObserveDuration()
-		if err != nil {
-			m.requestMetrics.FailedTotal.WithLabelValues("Update").Inc()
-		}
-	}()
-	return m.next.Update(ctx, env)
+	defer timer.ObserveDuration()
+	m.requestMetrics.Total.WithLabelValues("Update").Inc()
+	err = m.next.Update(ctx, env)
+	if err != nil {
+		m.requestMetrics.FailedTotal.WithLabelValues("Update").Inc()
+		return
+	}
+	return
 }
diff --git a/pkg/invitations/middleware/metrics_middleware.go b/pkg/invitations/middleware/metrics_middleware.go
index 8ce2d3b7a747825f0007339155f0b9a5053640a5..ac82571ec0416446956e6e684b1d92f0e5db507a 100644
--- a/pkg/invitations/middleware/metrics_middleware.go
+++ b/pkg/invitations/middleware/metrics_middleware.go
@@ -33,65 +33,65 @@ func MetricsMiddleware(requestMetrics *metrics.RequestMetrics) Middleware {
 
 // Accept implements invitations.Invitations
 func (m metricsMiddleware) Accept(ctx context.Context, invitationId string, userId string) (err error) {
-	m.requestMetrics.Total.WithLabelValues("Accept").Inc()
 	timer := prometheus.NewTimer(m.requestMetrics.DurationSeconds.WithLabelValues("Accept"))
-	defer func() {
-		timer.ObserveDuration()
-		if err != nil {
-			m.requestMetrics.FailedTotal.WithLabelValues("Accept").Inc()
-		}
-	}()
-	return m.next.Accept(ctx, invitationId, userId)
+	defer timer.ObserveDuration()
+	m.requestMetrics.Total.WithLabelValues("Accept").Inc()
+	err = m.next.Accept(ctx, invitationId, userId)
+	if err != nil {
+		m.requestMetrics.FailedTotal.WithLabelValues("Accept").Inc()
+		return
+	}
+	return
 }
 
 // Create implements invitations.Invitations
 func (m metricsMiddleware) Create(ctx context.Context, invitation *invitations.Invitation) (created *invitations.Invitation, err error) {
-	m.requestMetrics.Total.WithLabelValues("Create").Inc()
 	timer := prometheus.NewTimer(m.requestMetrics.DurationSeconds.WithLabelValues("Create"))
-	defer func() {
-		timer.ObserveDuration()
-		if err != nil {
-			m.requestMetrics.FailedTotal.WithLabelValues("Create").Inc()
-		}
-	}()
-	return m.next.Create(ctx, invitation)
+	defer timer.ObserveDuration()
+	m.requestMetrics.Total.WithLabelValues("Create").Inc()
+	created, err = m.next.Create(ctx, invitation)
+	if err != nil {
+		m.requestMetrics.FailedTotal.WithLabelValues("Create").Inc()
+		return
+	}
+	return
 }
 
 // Delete implements invitations.Invitations
 func (m metricsMiddleware) Delete(ctx context.Context, invitationId string) (err error) {
-	m.requestMetrics.Total.WithLabelValues("Delete").Inc()
 	timer := prometheus.NewTimer(m.requestMetrics.DurationSeconds.WithLabelValues("Delete"))
-	defer func() {
-		timer.ObserveDuration()
-		if err != nil {
-			m.requestMetrics.FailedTotal.WithLabelValues("Delete").Inc()
-		}
-	}()
-	return m.next.Delete(ctx, invitationId)
+	defer timer.ObserveDuration()
+	m.requestMetrics.Total.WithLabelValues("Delete").Inc()
+	err = m.next.Delete(ctx, invitationId)
+	if err != nil {
+		m.requestMetrics.FailedTotal.WithLabelValues("Delete").Inc()
+		return
+	}
+	return
 }
 
 // Find implements invitations.Invitations
 func (m metricsMiddleware) Find(ctx context.Context, filter *invitations.Filter, opts *options.FindOptions) (invitations []*invitations.Invitation, total int, err error) {
-	m.requestMetrics.Total.WithLabelValues("Find").Inc()
 	timer := prometheus.NewTimer(m.requestMetrics.DurationSeconds.WithLabelValues("Find"))
-	defer func() {
-		timer.ObserveDuration()
-		if err != nil {
-			m.requestMetrics.FailedTotal.WithLabelValues("Find").Inc()
-		}
-	}()
-	return m.next.Find(ctx, filter, opts)
+	defer timer.ObserveDuration()
+	m.requestMetrics.Total.WithLabelValues("Find").Inc()
+	invitations, total, err = m.next.Find(ctx, filter, opts)
+	if err != nil {
+		m.requestMetrics.FailedTotal.WithLabelValues("Find").Inc()
+		return
+	}
+	return
 }
 
 // Get implements invitations.Invitations
 func (m metricsMiddleware) Get(ctx context.Context, invitationId string) (invitation *invitations.Invitation, err error) {
-	m.requestMetrics.Total.WithLabelValues("Get").Inc()
 	timer := prometheus.NewTimer(m.requestMetrics.DurationSeconds.WithLabelValues("Get"))
-	defer func() {
-		timer.ObserveDuration()
-		if err != nil {
-			m.requestMetrics.FailedTotal.WithLabelValues("Get").Inc()
-		}
-	}()
-	return m.next.Get(ctx, invitationId)
+	defer timer.ObserveDuration()
+	m.requestMetrics.Total.WithLabelValues("Get").Inc()
+	invitation, err = m.next.Get(ctx, invitationId)
+	if err != nil {
+		m.requestMetrics.FailedTotal.WithLabelValues("Get").Inc()
+		return
+	}
+	return
 }
diff --git a/pkg/items/middleware/metrics_middleware.go b/pkg/items/middleware/metrics_middleware.go
index 72fb917b0ab4afc128c65adfc3a2891de685f1ad..a9f7b8f9099750db9dca96a06442f594cd3e0681 100644
--- a/pkg/items/middleware/metrics_middleware.go
+++ b/pkg/items/middleware/metrics_middleware.go
@@ -33,234 +33,234 @@ func MetricsMiddleware(requestMetrics *metrics.RequestMetrics) Middleware {
 
 // Aggregate implements items.Items
 func (m metricsMiddleware) Aggregate(ctx context.Context, spaceId string, envId string, collectionId string, filter *items.Filter, options ...*items.AggregateOptions) (result map[string]interface{}, err error) {
-	m.requestMetrics.Total.WithLabelValues("Aggregate").Inc()
 	timer := prometheus.NewTimer(m.requestMetrics.DurationSeconds.WithLabelValues("Aggregate"))
-	defer func() {
-		timer.ObserveDuration()
-		if err != nil {
-			m.requestMetrics.FailedTotal.WithLabelValues("Aggregate").Inc()
-		}
-	}()
-	return m.next.Aggregate(ctx, spaceId, envId, collectionId, filter, options...)
+	defer timer.ObserveDuration()
+	m.requestMetrics.Total.WithLabelValues("Aggregate").Inc()
+	result, err = m.next.Aggregate(ctx, spaceId, envId, collectionId, filter, options...)
+	if err != nil {
+		m.requestMetrics.FailedTotal.WithLabelValues("Aggregate").Inc()
+		return
+	}
+	return
 }
 
 // AggregatePublished implements items.Items
 func (m metricsMiddleware) AggregatePublished(ctx context.Context, spaceId string, envId string, collectionId string, filter *items.Filter, options ...*items.AggregatePublishedOptions) (result map[string]interface{}, err error) {
-	m.requestMetrics.Total.WithLabelValues("AggregatePublished").Inc()
 	timer := prometheus.NewTimer(m.requestMetrics.DurationSeconds.WithLabelValues("AggregatePublished"))
-	defer func() {
-		timer.ObserveDuration()
-		if err != nil {
-			m.requestMetrics.FailedTotal.WithLabelValues("AggregatePublished").Inc()
-		}
-	}()
-	return m.next.AggregatePublished(ctx, spaceId, envId, collectionId, filter, options...)
+	defer timer.ObserveDuration()
+	m.requestMetrics.Total.WithLabelValues("AggregatePublished").Inc()
+	result, err = m.next.AggregatePublished(ctx, spaceId, envId, collectionId, filter, options...)
+	if err != nil {
+		m.requestMetrics.FailedTotal.WithLabelValues("AggregatePublished").Inc()
+		return
+	}
+	return
 }
 
 // Archive implements items.Items
 func (m metricsMiddleware) Archive(ctx context.Context, item *items.Item, options ...*items.ArchiveOptions) (err error) {
-	m.requestMetrics.Total.WithLabelValues("Archive").Inc()
 	timer := prometheus.NewTimer(m.requestMetrics.DurationSeconds.WithLabelValues("Archive"))
-	defer func() {
-		timer.ObserveDuration()
-		if err != nil {
-			m.requestMetrics.FailedTotal.WithLabelValues("Archive").Inc()
-		}
-	}()
-	return m.next.Archive(ctx, item, options...)
+	defer timer.ObserveDuration()
+	m.requestMetrics.Total.WithLabelValues("Archive").Inc()
+	err = m.next.Archive(ctx, item, options...)
+	if err != nil {
+		m.requestMetrics.FailedTotal.WithLabelValues("Archive").Inc()
+		return
+	}
+	return
 }
 
 // Create implements items.Items
 func (m metricsMiddleware) Create(ctx context.Context, item *items.Item, opts ...*items.CreateOptions) (created *items.Item, err error) {
-	m.requestMetrics.Total.WithLabelValues("Create").Inc()
 	timer := prometheus.NewTimer(m.requestMetrics.DurationSeconds.WithLabelValues("Create"))
-	defer func() {
-		timer.ObserveDuration()
-		if err != nil {
-			m.requestMetrics.FailedTotal.WithLabelValues("Create").Inc()
-		}
-	}()
-	return m.next.Create(ctx, item, opts...)
+	defer timer.ObserveDuration()
+	m.requestMetrics.Total.WithLabelValues("Create").Inc()
+	created, err = m.next.Create(ctx, item, opts...)
+	if err != nil {
+		m.requestMetrics.FailedTotal.WithLabelValues("Create").Inc()
+		return
+	}
+	return
 }
 
 // Delete implements items.Items
 func (m metricsMiddleware) Delete(ctx context.Context, item *items.Item, options ...*items.DeleteOptions) (err error) {
-	m.requestMetrics.Total.WithLabelValues("Delete").Inc()
 	timer := prometheus.NewTimer(m.requestMetrics.DurationSeconds.WithLabelValues("Delete"))
-	defer func() {
-		timer.ObserveDuration()
-		if err != nil {
-			m.requestMetrics.FailedTotal.WithLabelValues("Delete").Inc()
-		}
-	}()
-	return m.next.Delete(ctx, item, options...)
+	defer timer.ObserveDuration()
+	m.requestMetrics.Total.WithLabelValues("Delete").Inc()
+	err = m.next.Delete(ctx, item, options...)
+	if err != nil {
+		m.requestMetrics.FailedTotal.WithLabelValues("Delete").Inc()
+		return
+	}
+	return
 }
 
 // Find implements items.Items
 func (m metricsMiddleware) Find(ctx context.Context, spaceId string, envId string, collectionId string, filter *items.Filter, options ...*items.FindOptions) (items []*items.Item, total int, err error) {
-	m.requestMetrics.Total.WithLabelValues("Find").Inc()
 	timer := prometheus.NewTimer(m.requestMetrics.DurationSeconds.WithLabelValues("Find"))
-	defer func() {
-		timer.ObserveDuration()
-		if err != nil {
-			m.requestMetrics.FailedTotal.WithLabelValues("Find").Inc()
-		}
-	}()
-	return m.next.Find(ctx, spaceId, envId, collectionId, filter, options...)
+	defer timer.ObserveDuration()
+	m.requestMetrics.Total.WithLabelValues("Find").Inc()
+	items, total, err = m.next.Find(ctx, spaceId, envId, collectionId, filter, options...)
+	if err != nil {
+		m.requestMetrics.FailedTotal.WithLabelValues("Find").Inc()
+		return
+	}
+	return
 }
 
 // FindArchived implements items.Items
 func (m metricsMiddleware) FindArchived(ctx context.Context, spaceId string, envId string, collectionId string, filter *items.Filter, options ...*items.FindArchivedOptions) (items []*items.Item, total int, err error) {
-	m.requestMetrics.Total.WithLabelValues("FindArchived").Inc()
 	timer := prometheus.NewTimer(m.requestMetrics.DurationSeconds.WithLabelValues("FindArchived"))
-	defer func() {
-		timer.ObserveDuration()
-		if err != nil {
-			m.requestMetrics.FailedTotal.WithLabelValues("FindArchived").Inc()
-		}
-	}()
-	return m.next.FindArchived(ctx, spaceId, envId, collectionId, filter, options...)
+	defer timer.ObserveDuration()
+	m.requestMetrics.Total.WithLabelValues("FindArchived").Inc()
+	items, total, err = m.next.FindArchived(ctx, spaceId, envId, collectionId, filter, options...)
+	if err != nil {
+		m.requestMetrics.FailedTotal.WithLabelValues("FindArchived").Inc()
+		return
+	}
+	return
 }
 
 // FindPublished implements items.Items
 func (m metricsMiddleware) FindPublished(ctx context.Context, spaceId string, envId string, collectionId string, filter *items.Filter, options ...*items.FindPublishedOptions) (items []*items.Item, total int, err error) {
-	m.requestMetrics.Total.WithLabelValues("FindPublished").Inc()
 	timer := prometheus.NewTimer(m.requestMetrics.DurationSeconds.WithLabelValues("FindPublished"))
-	defer func() {
-		timer.ObserveDuration()
-		if err != nil {
-			m.requestMetrics.FailedTotal.WithLabelValues("FindPublished").Inc()
-		}
-	}()
-	return m.next.FindPublished(ctx, spaceId, envId, collectionId, filter, options...)
+	defer timer.ObserveDuration()
+	m.requestMetrics.Total.WithLabelValues("FindPublished").Inc()
+	items, total, err = m.next.FindPublished(ctx, spaceId, envId, collectionId, filter, options...)
+	if err != nil {
+		m.requestMetrics.FailedTotal.WithLabelValues("FindPublished").Inc()
+		return
+	}
+	return
 }
 
 // Get implements items.Items
 func (m metricsMiddleware) Get(ctx context.Context, spaceId string, envId string, collectionId string, itemId string, options ...*items.GetOptions) (item *items.Item, err error) {
-	m.requestMetrics.Total.WithLabelValues("Get").Inc()
 	timer := prometheus.NewTimer(m.requestMetrics.DurationSeconds.WithLabelValues("Get"))
-	defer func() {
-		timer.ObserveDuration()
-		if err != nil {
-			m.requestMetrics.FailedTotal.WithLabelValues("Get").Inc()
-		}
-	}()
-	return m.next.Get(ctx, spaceId, envId, collectionId, itemId, options...)
+	defer timer.ObserveDuration()
+	m.requestMetrics.Total.WithLabelValues("Get").Inc()
+	item, err = m.next.Get(ctx, spaceId, envId, collectionId, itemId, options...)
+	if err != nil {
+		m.requestMetrics.FailedTotal.WithLabelValues("Get").Inc()
+		return
+	}
+	return
 }
 
 // GetPublished implements items.Items
 func (m metricsMiddleware) GetPublished(ctx context.Context, spaceId string, envId string, collectionId string, itemId string, options ...*items.GetPublishedOptions) (item *items.Item, err error) {
-	m.requestMetrics.Total.WithLabelValues("GetPublished").Inc()
 	timer := prometheus.NewTimer(m.requestMetrics.DurationSeconds.WithLabelValues("GetPublished"))
-	defer func() {
-		timer.ObserveDuration()
-		if err != nil {
-			m.requestMetrics.FailedTotal.WithLabelValues("GetPublished").Inc()
-		}
-	}()
-	return m.next.GetPublished(ctx, spaceId, envId, collectionId, itemId, options...)
+	defer timer.ObserveDuration()
+	m.requestMetrics.Total.WithLabelValues("GetPublished").Inc()
+	item, err = m.next.GetPublished(ctx, spaceId, envId, collectionId, itemId, options...)
+	if err != nil {
+		m.requestMetrics.FailedTotal.WithLabelValues("GetPublished").Inc()
+		return
+	}
+	return
 }
 
 // GetRevision implements items.Items
 func (m metricsMiddleware) GetRevision(ctx context.Context, spaceId string, envId string, collectionId string, itemId string, revisionId string, options ...*items.GetRevisionOptions) (item *items.Item, err error) {
-	m.requestMetrics.Total.WithLabelValues("GetRevision").Inc()
 	timer := prometheus.NewTimer(m.requestMetrics.DurationSeconds.WithLabelValues("GetRevision"))
-	defer func() {
-		timer.ObserveDuration()
-		if err != nil {
-			m.requestMetrics.FailedTotal.WithLabelValues("GetRevision").Inc()
-		}
-	}()
-	return m.next.GetRevision(ctx, spaceId, envId, collectionId, itemId, revisionId, options...)
+	defer timer.ObserveDuration()
+	m.requestMetrics.Total.WithLabelValues("GetRevision").Inc()
+	item, err = m.next.GetRevision(ctx, spaceId, envId, collectionId, itemId, revisionId, options...)
+	if err != nil {
+		m.requestMetrics.FailedTotal.WithLabelValues("GetRevision").Inc()
+		return
+	}
+	return
 }
 
 // Introspect implements items.Items
 func (m metricsMiddleware) Introspect(ctx context.Context, item *items.Item, opts ...*items.IntrospectOptions) (itm *items.Item, sch *schema.Schema, err error) {
-	m.requestMetrics.Total.WithLabelValues("Introspect").Inc()
 	timer := prometheus.NewTimer(m.requestMetrics.DurationSeconds.WithLabelValues("Introspect"))
-	defer func() {
-		timer.ObserveDuration()
-		if err != nil {
-			m.requestMetrics.FailedTotal.WithLabelValues("Introspect").Inc()
-		}
-	}()
-	return m.next.Introspect(ctx, item, opts...)
+	defer timer.ObserveDuration()
+	m.requestMetrics.Total.WithLabelValues("Introspect").Inc()
+	itm, sch, err = m.next.Introspect(ctx, item, opts...)
+	if err != nil {
+		m.requestMetrics.FailedTotal.WithLabelValues("Introspect").Inc()
+		return
+	}
+	return
 }
 
 // ListRevisions implements items.Items
 func (m metricsMiddleware) ListRevisions(ctx context.Context, spaceId string, envId string, collectionId string, itemId string, options ...*items.ListRevisionsOptions) (items []*items.Item, err error) {
-	m.requestMetrics.Total.WithLabelValues("ListRevisions").Inc()
 	timer := prometheus.NewTimer(m.requestMetrics.DurationSeconds.WithLabelValues("ListRevisions"))
-	defer func() {
-		timer.ObserveDuration()
-		if err != nil {
-			m.requestMetrics.FailedTotal.WithLabelValues("ListRevisions").Inc()
-		}
-	}()
-	return m.next.ListRevisions(ctx, spaceId, envId, collectionId, itemId, options...)
+	defer timer.ObserveDuration()
+	m.requestMetrics.Total.WithLabelValues("ListRevisions").Inc()
+	items, err = m.next.ListRevisions(ctx, spaceId, envId, collectionId, itemId, options...)
+	if err != nil {
+		m.requestMetrics.FailedTotal.WithLabelValues("ListRevisions").Inc()
+		return
+	}
+	return
 }
 
 // Publish implements items.Items
 func (m metricsMiddleware) Publish(ctx context.Context, item *items.Item, options ...*items.PublishOptions) (err error) {
-	m.requestMetrics.Total.WithLabelValues("Publish").Inc()
 	timer := prometheus.NewTimer(m.requestMetrics.DurationSeconds.WithLabelValues("Publish"))
-	defer func() {
-		timer.ObserveDuration()
-		if err != nil {
-			m.requestMetrics.FailedTotal.WithLabelValues("Publish").Inc()
-		}
-	}()
-	return m.next.Publish(ctx, item, options...)
+	defer timer.ObserveDuration()
+	m.requestMetrics.Total.WithLabelValues("Publish").Inc()
+	err = m.next.Publish(ctx, item, options...)
+	if err != nil {
+		m.requestMetrics.FailedTotal.WithLabelValues("Publish").Inc()
+		return
+	}
+	return
 }
 
 // Unarchive implements items.Items
 func (m metricsMiddleware) Unarchive(ctx context.Context, item *items.Item, options ...*items.UnarchiveOptions) (err error) {
-	m.requestMetrics.Total.WithLabelValues("Unarchive").Inc()
 	timer := prometheus.NewTimer(m.requestMetrics.DurationSeconds.WithLabelValues("Unarchive"))
-	defer func() {
-		timer.ObserveDuration()
-		if err != nil {
-			m.requestMetrics.FailedTotal.WithLabelValues("Unarchive").Inc()
-		}
-	}()
-	return m.next.Unarchive(ctx, item, options...)
+	defer timer.ObserveDuration()
+	m.requestMetrics.Total.WithLabelValues("Unarchive").Inc()
+	err = m.next.Unarchive(ctx, item, options...)
+	if err != nil {
+		m.requestMetrics.FailedTotal.WithLabelValues("Unarchive").Inc()
+		return
+	}
+	return
 }
 
 // Undelete implements items.Items
 func (m metricsMiddleware) Undelete(ctx context.Context, item *items.Item, options ...*items.UndeleteOptions) (err error) {
-	m.requestMetrics.Total.WithLabelValues("Undelete").Inc()
 	timer := prometheus.NewTimer(m.requestMetrics.DurationSeconds.WithLabelValues("Undelete"))
-	defer func() {
-		timer.ObserveDuration()
-		if err != nil {
-			m.requestMetrics.FailedTotal.WithLabelValues("Undelete").Inc()
-		}
-	}()
-	return m.next.Undelete(ctx, item, options...)
+	defer timer.ObserveDuration()
+	m.requestMetrics.Total.WithLabelValues("Undelete").Inc()
+	err = m.next.Undelete(ctx, item, options...)
+	if err != nil {
+		m.requestMetrics.FailedTotal.WithLabelValues("Undelete").Inc()
+		return
+	}
+	return
 }
 
 // Unpublish implements items.Items
 func (m metricsMiddleware) Unpublish(ctx context.Context, item *items.Item, options ...*items.UnpublishOptions) (err error) {
-	m.requestMetrics.Total.WithLabelValues("Unpublish").Inc()
 	timer := prometheus.NewTimer(m.requestMetrics.DurationSeconds.WithLabelValues("Unpublish"))
-	defer func() {
-		timer.ObserveDuration()
-		if err != nil {
-			m.requestMetrics.FailedTotal.WithLabelValues("Unpublish").Inc()
-		}
-	}()
-	return m.next.Unpublish(ctx, item, options...)
+	defer timer.ObserveDuration()
+	m.requestMetrics.Total.WithLabelValues("Unpublish").Inc()
+	err = m.next.Unpublish(ctx, item, options...)
+	if err != nil {
+		m.requestMetrics.FailedTotal.WithLabelValues("Unpublish").Inc()
+		return
+	}
+	return
 }
 
 // Update implements items.Items
 func (m metricsMiddleware) Update(ctx context.Context, item *items.Item, options ...*items.UpdateOptions) (err error) {
-	m.requestMetrics.Total.WithLabelValues("Update").Inc()
 	timer := prometheus.NewTimer(m.requestMetrics.DurationSeconds.WithLabelValues("Update"))
-	defer func() {
-		timer.ObserveDuration()
-		if err != nil {
-			m.requestMetrics.FailedTotal.WithLabelValues("Update").Inc()
-		}
-	}()
-	return m.next.Update(ctx, item, options...)
+	defer timer.ObserveDuration()
+	m.requestMetrics.Total.WithLabelValues("Update").Inc()
+	err = m.next.Update(ctx, item, options...)
+	if err != nil {
+		m.requestMetrics.FailedTotal.WithLabelValues("Update").Inc()
+		return
+	}
+	return
 }
diff --git a/pkg/locales/middleware/metrics_middleware.go b/pkg/locales/middleware/metrics_middleware.go
index cdd45c9766221f49cea1d4960aecde4dc7dfedd3..a8296a4c728ab629f1fde80b293cd1edfc1990e9 100644
--- a/pkg/locales/middleware/metrics_middleware.go
+++ b/pkg/locales/middleware/metrics_middleware.go
@@ -32,39 +32,39 @@ func MetricsMiddleware(requestMetrics *metrics.RequestMetrics) Middleware {
 
 // Create implements locales.Locales
 func (m metricsMiddleware) Create(ctx context.Context, locale *locales.Locale) (created *locales.Locale, err error) {
-	m.requestMetrics.Total.WithLabelValues("Create").Inc()
 	timer := prometheus.NewTimer(m.requestMetrics.DurationSeconds.WithLabelValues("Create"))
-	defer func() {
-		timer.ObserveDuration()
-		if err != nil {
-			m.requestMetrics.FailedTotal.WithLabelValues("Create").Inc()
-		}
-	}()
-	return m.next.Create(ctx, locale)
+	defer timer.ObserveDuration()
+	m.requestMetrics.Total.WithLabelValues("Create").Inc()
+	created, err = m.next.Create(ctx, locale)
+	if err != nil {
+		m.requestMetrics.FailedTotal.WithLabelValues("Create").Inc()
+		return
+	}
+	return
 }
 
 // Delete implements locales.Locales
 func (m metricsMiddleware) Delete(ctx context.Context, spaceId string, localeId string) (err error) {
-	m.requestMetrics.Total.WithLabelValues("Delete").Inc()
 	timer := prometheus.NewTimer(m.requestMetrics.DurationSeconds.WithLabelValues("Delete"))
-	defer func() {
-		timer.ObserveDuration()
-		if err != nil {
-			m.requestMetrics.FailedTotal.WithLabelValues("Delete").Inc()
-		}
-	}()
-	return m.next.Delete(ctx, spaceId, localeId)
+	defer timer.ObserveDuration()
+	m.requestMetrics.Total.WithLabelValues("Delete").Inc()
+	err = m.next.Delete(ctx, spaceId, localeId)
+	if err != nil {
+		m.requestMetrics.FailedTotal.WithLabelValues("Delete").Inc()
+		return
+	}
+	return
 }
 
 // List implements locales.Locales
 func (m metricsMiddleware) List(ctx context.Context, spaceId string) (locales []*locales.Locale, err error) {
-	m.requestMetrics.Total.WithLabelValues("List").Inc()
 	timer := prometheus.NewTimer(m.requestMetrics.DurationSeconds.WithLabelValues("List"))
-	defer func() {
-		timer.ObserveDuration()
-		if err != nil {
-			m.requestMetrics.FailedTotal.WithLabelValues("List").Inc()
-		}
-	}()
-	return m.next.List(ctx, spaceId)
+	defer timer.ObserveDuration()
+	m.requestMetrics.Total.WithLabelValues("List").Inc()
+	locales, err = m.next.List(ctx, spaceId)
+	if err != nil {
+		m.requestMetrics.FailedTotal.WithLabelValues("List").Inc()
+		return
+	}
+	return
 }
diff --git a/pkg/members/middleware/metrics_middleware.go b/pkg/members/middleware/metrics_middleware.go
index 27b28e642e3ce48aa1247edcb3c2053fddd9424a..8e947287343e7801d486edfd8cacff182fc158cd 100644
--- a/pkg/members/middleware/metrics_middleware.go
+++ b/pkg/members/middleware/metrics_middleware.go
@@ -32,78 +32,78 @@ func MetricsMiddleware(requestMetrics *metrics.RequestMetrics) Middleware {
 
 // Get implements members.Members
 func (m metricsMiddleware) Get(ctx context.Context, orgId string, userId string) (role members.Role, err error) {
-	m.requestMetrics.Total.WithLabelValues("Get").Inc()
 	timer := prometheus.NewTimer(m.requestMetrics.DurationSeconds.WithLabelValues("Get"))
-	defer func() {
-		timer.ObserveDuration()
-		if err != nil {
-			m.requestMetrics.FailedTotal.WithLabelValues("Get").Inc()
-		}
-	}()
-	return m.next.Get(ctx, orgId, userId)
+	defer timer.ObserveDuration()
+	m.requestMetrics.Total.WithLabelValues("Get").Inc()
+	role, err = m.next.Get(ctx, orgId, userId)
+	if err != nil {
+		m.requestMetrics.FailedTotal.WithLabelValues("Get").Inc()
+		return
+	}
+	return
 }
 
 // ListMembers implements members.Members
 func (m metricsMiddleware) ListMembers(ctx context.Context, orgId string) (members []*members.Member, err error) {
-	m.requestMetrics.Total.WithLabelValues("ListMembers").Inc()
 	timer := prometheus.NewTimer(m.requestMetrics.DurationSeconds.WithLabelValues("ListMembers"))
-	defer func() {
-		timer.ObserveDuration()
-		if err != nil {
-			m.requestMetrics.FailedTotal.WithLabelValues("ListMembers").Inc()
-		}
-	}()
-	return m.next.ListMembers(ctx, orgId)
+	defer timer.ObserveDuration()
+	m.requestMetrics.Total.WithLabelValues("ListMembers").Inc()
+	members, err = m.next.ListMembers(ctx, orgId)
+	if err != nil {
+		m.requestMetrics.FailedTotal.WithLabelValues("ListMembers").Inc()
+		return
+	}
+	return
 }
 
 // ListOrganizations implements members.Members
 func (m metricsMiddleware) ListOrganizations(ctx context.Context, userId string) (organizations []*members.Member, err error) {
-	m.requestMetrics.Total.WithLabelValues("ListOrganizations").Inc()
 	timer := prometheus.NewTimer(m.requestMetrics.DurationSeconds.WithLabelValues("ListOrganizations"))
-	defer func() {
-		timer.ObserveDuration()
-		if err != nil {
-			m.requestMetrics.FailedTotal.WithLabelValues("ListOrganizations").Inc()
-		}
-	}()
-	return m.next.ListOrganizations(ctx, userId)
+	defer timer.ObserveDuration()
+	m.requestMetrics.Total.WithLabelValues("ListOrganizations").Inc()
+	organizations, err = m.next.ListOrganizations(ctx, userId)
+	if err != nil {
+		m.requestMetrics.FailedTotal.WithLabelValues("ListOrganizations").Inc()
+		return
+	}
+	return
 }
 
 // Remove implements members.Members
 func (m metricsMiddleware) Remove(ctx context.Context, orgId string, userId string) (err error) {
-	m.requestMetrics.Total.WithLabelValues("Remove").Inc()
 	timer := prometheus.NewTimer(m.requestMetrics.DurationSeconds.WithLabelValues("Remove"))
-	defer func() {
-		timer.ObserveDuration()
-		if err != nil {
-			m.requestMetrics.FailedTotal.WithLabelValues("Remove").Inc()
-		}
-	}()
-	return m.next.Remove(ctx, orgId, userId)
+	defer timer.ObserveDuration()
+	m.requestMetrics.Total.WithLabelValues("Remove").Inc()
+	err = m.next.Remove(ctx, orgId, userId)
+	if err != nil {
+		m.requestMetrics.FailedTotal.WithLabelValues("Remove").Inc()
+		return
+	}
+	return
 }
 
 // RemoveAll implements members.Members
 func (m metricsMiddleware) RemoveAll(ctx context.Context, orgId string) (err error) {
-	m.requestMetrics.Total.WithLabelValues("RemoveAll").Inc()
 	timer := prometheus.NewTimer(m.requestMetrics.DurationSeconds.WithLabelValues("RemoveAll"))
-	defer func() {
-		timer.ObserveDuration()
-		if err != nil {
-			m.requestMetrics.FailedTotal.WithLabelValues("RemoveAll").Inc()
-		}
-	}()
-	return m.next.RemoveAll(ctx, orgId)
+	defer timer.ObserveDuration()
+	m.requestMetrics.Total.WithLabelValues("RemoveAll").Inc()
+	err = m.next.RemoveAll(ctx, orgId)
+	if err != nil {
+		m.requestMetrics.FailedTotal.WithLabelValues("RemoveAll").Inc()
+		return
+	}
+	return
 }
 
 // Set implements members.Members
 func (m metricsMiddleware) Set(ctx context.Context, orgId string, userId string, role members.Role) (err error) {
-	m.requestMetrics.Total.WithLabelValues("Set").Inc()
 	timer := prometheus.NewTimer(m.requestMetrics.DurationSeconds.WithLabelValues("Set"))
-	defer func() {
-		timer.ObserveDuration()
-		if err != nil {
-			m.requestMetrics.FailedTotal.WithLabelValues("Set").Inc()
-		}
-	}()
-	return m.next.Set(ctx, orgId, userId, role)
+	defer timer.ObserveDuration()
+	m.requestMetrics.Total.WithLabelValues("Set").Inc()
+	err = m.next.Set(ctx, orgId, userId, role)
+	if err != nil {
+		m.requestMetrics.FailedTotal.WithLabelValues("Set").Inc()
+		return
+	}
+	return
 }
diff --git a/pkg/organizations/middleware/metrics_middleware.go b/pkg/organizations/middleware/metrics_middleware.go
index c7cbccc6aec1ae13dd0804d92cfabf1341cb6f9c..dc1110733b630a3383c6c1dd49493ff237daec00 100644
--- a/pkg/organizations/middleware/metrics_middleware.go
+++ b/pkg/organizations/middleware/metrics_middleware.go
@@ -33,65 +33,65 @@ func MetricsMiddleware(requestMetrics *metrics.RequestMetrics) Middleware {
 
 // Create implements organizations.Organizations
 func (m metricsMiddleware) Create(ctx context.Context, org *organizations.Organization) (created *organizations.Organization, err error) {
-	m.requestMetrics.Total.WithLabelValues("Create").Inc()
 	timer := prometheus.NewTimer(m.requestMetrics.DurationSeconds.WithLabelValues("Create"))
-	defer func() {
-		timer.ObserveDuration()
-		if err != nil {
-			m.requestMetrics.FailedTotal.WithLabelValues("Create").Inc()
-		}
-	}()
-	return m.next.Create(ctx, org)
+	defer timer.ObserveDuration()
+	m.requestMetrics.Total.WithLabelValues("Create").Inc()
+	created, err = m.next.Create(ctx, org)
+	if err != nil {
+		m.requestMetrics.FailedTotal.WithLabelValues("Create").Inc()
+		return
+	}
+	return
 }
 
 // Delete implements organizations.Organizations
 func (m metricsMiddleware) Delete(ctx context.Context, orgId string) (err error) {
-	m.requestMetrics.Total.WithLabelValues("Delete").Inc()
 	timer := prometheus.NewTimer(m.requestMetrics.DurationSeconds.WithLabelValues("Delete"))
-	defer func() {
-		timer.ObserveDuration()
-		if err != nil {
-			m.requestMetrics.FailedTotal.WithLabelValues("Delete").Inc()
-		}
-	}()
-	return m.next.Delete(ctx, orgId)
+	defer timer.ObserveDuration()
+	m.requestMetrics.Total.WithLabelValues("Delete").Inc()
+	err = m.next.Delete(ctx, orgId)
+	if err != nil {
+		m.requestMetrics.FailedTotal.WithLabelValues("Delete").Inc()
+		return
+	}
+	return
 }
 
 // Find implements organizations.Organizations
 func (m metricsMiddleware) Find(ctx context.Context, filter *organizations.Filter, opts *options.FindOptions) (orgs []*organizations.Organization, total int, err error) {
-	m.requestMetrics.Total.WithLabelValues("Find").Inc()
 	timer := prometheus.NewTimer(m.requestMetrics.DurationSeconds.WithLabelValues("Find"))
-	defer func() {
-		timer.ObserveDuration()
-		if err != nil {
-			m.requestMetrics.FailedTotal.WithLabelValues("Find").Inc()
-		}
-	}()
-	return m.next.Find(ctx, filter, opts)
+	defer timer.ObserveDuration()
+	m.requestMetrics.Total.WithLabelValues("Find").Inc()
+	orgs, total, err = m.next.Find(ctx, filter, opts)
+	if err != nil {
+		m.requestMetrics.FailedTotal.WithLabelValues("Find").Inc()
+		return
+	}
+	return
 }
 
 // Get implements organizations.Organizations
 func (m metricsMiddleware) Get(ctx context.Context, orgId string) (org *organizations.Organization, err error) {
-	m.requestMetrics.Total.WithLabelValues("Get").Inc()
 	timer := prometheus.NewTimer(m.requestMetrics.DurationSeconds.WithLabelValues("Get"))
-	defer func() {
-		timer.ObserveDuration()
-		if err != nil {
-			m.requestMetrics.FailedTotal.WithLabelValues("Get").Inc()
-		}
-	}()
-	return m.next.Get(ctx, orgId)
+	defer timer.ObserveDuration()
+	m.requestMetrics.Total.WithLabelValues("Get").Inc()
+	org, err = m.next.Get(ctx, orgId)
+	if err != nil {
+		m.requestMetrics.FailedTotal.WithLabelValues("Get").Inc()
+		return
+	}
+	return
 }
 
 // Update implements organizations.Organizations
 func (m metricsMiddleware) Update(ctx context.Context, org *organizations.Organization) (err error) {
-	m.requestMetrics.Total.WithLabelValues("Update").Inc()
 	timer := prometheus.NewTimer(m.requestMetrics.DurationSeconds.WithLabelValues("Update"))
-	defer func() {
-		timer.ObserveDuration()
-		if err != nil {
-			m.requestMetrics.FailedTotal.WithLabelValues("Update").Inc()
-		}
-	}()
-	return m.next.Update(ctx, org)
+	defer timer.ObserveDuration()
+	m.requestMetrics.Total.WithLabelValues("Update").Inc()
+	err = m.next.Update(ctx, org)
+	if err != nil {
+		m.requestMetrics.FailedTotal.WithLabelValues("Update").Inc()
+		return
+	}
+	return
 }
diff --git a/pkg/references/middleware/metrics_middleware.go b/pkg/references/middleware/metrics_middleware.go
new file mode 100644
index 0000000000000000000000000000000000000000..520dd7683f81531a9a206cf2e4207cadca302252
--- /dev/null
+++ b/pkg/references/middleware/metrics_middleware.go
@@ -0,0 +1,58 @@
+// Code generated by gowrap. DO NOT EDIT.
+// template: ../../../assets/templates/middleware/metrics
+// gowrap: http://github.com/hexdigest/gowrap
+
+package middleware
+
+//go:generate gowrap gen -p git.perx.ru/perxis/perxis-go/pkg/references -i References -t ../../../assets/templates/middleware/metrics -o metrics_middleware.go -l ""
+
+import (
+	"context"
+
+	"git.perx.ru/perxis/perxis-go/pkg/items"
+	"git.perx.ru/perxis/perxis-go/pkg/metrics"
+	"git.perx.ru/perxis/perxis-go/pkg/references"
+	"github.com/prometheus/client_golang/prometheus"
+)
+
+// metricsMiddleware implements references.References that is instrumented with metrics
+type metricsMiddleware struct {
+	requestMetrics *metrics.RequestMetrics
+	next           references.References
+}
+
+// MetricsMiddleware instruments an implementation of the metricsMiddleware with metrics
+func MetricsMiddleware(requestMetrics *metrics.RequestMetrics) Middleware {
+	return func(next references.References) references.References {
+		return &metricsMiddleware{
+			requestMetrics: requestMetrics,
+			next:           next,
+		}
+	}
+}
+
+// Get implements references.References
+func (m metricsMiddleware) Get(ctx context.Context, spaceId string, envId string, references []*references.Reference) (items []*items.Item, notfound []*references.Reference, err error) {
+	timer := prometheus.NewTimer(m.requestMetrics.DurationSeconds.WithLabelValues("Get"))
+	defer timer.ObserveDuration()
+	m.requestMetrics.Total.WithLabelValues("Get").Inc()
+	items, notfound, err = m.next.Get(ctx, spaceId, envId, references)
+	if err != nil {
+		m.requestMetrics.FailedTotal.WithLabelValues("Get").Inc()
+		return
+	}
+	return
+}
+
+// Publish implements references.References
+func (m metricsMiddleware) Publish(ctx context.Context, spaceId string, envId string, references []*references.Reference, recursive bool, force bool) (published []*references.Reference, notfound []*references.Reference, unpublished []*references.Reference, err error) {
+	timer := prometheus.NewTimer(m.requestMetrics.DurationSeconds.WithLabelValues("Publish"))
+	defer timer.ObserveDuration()
+	m.requestMetrics.Total.WithLabelValues("Publish").Inc()
+	published, notfound, unpublished, err = m.next.Publish(ctx, spaceId, envId, references, recursive, force)
+	if err != nil {
+		m.requestMetrics.FailedTotal.WithLabelValues("Publish").Inc()
+		return
+	}
+	return
+}
diff --git a/pkg/roles/middleware/metrics_middleware.go b/pkg/roles/middleware/metrics_middleware.go
index 1df246c1f84f3071be60e8b336dd26eb09fc9bd8..75e242ef5235e55cf9021e06ab7e9d1c9ed7f30c 100644
--- a/pkg/roles/middleware/metrics_middleware.go
+++ b/pkg/roles/middleware/metrics_middleware.go
@@ -32,65 +32,65 @@ func MetricsMiddleware(requestMetrics *metrics.RequestMetrics) Middleware {
 
 // Create implements roles.Roles
 func (m metricsMiddleware) Create(ctx context.Context, role *roles.Role) (created *roles.Role, err error) {
-	m.requestMetrics.Total.WithLabelValues("Create").Inc()
 	timer := prometheus.NewTimer(m.requestMetrics.DurationSeconds.WithLabelValues("Create"))
-	defer func() {
-		timer.ObserveDuration()
-		if err != nil {
-			m.requestMetrics.FailedTotal.WithLabelValues("Create").Inc()
-		}
-	}()
-	return m.next.Create(ctx, role)
+	defer timer.ObserveDuration()
+	m.requestMetrics.Total.WithLabelValues("Create").Inc()
+	created, err = m.next.Create(ctx, role)
+	if err != nil {
+		m.requestMetrics.FailedTotal.WithLabelValues("Create").Inc()
+		return
+	}
+	return
 }
 
 // Delete implements roles.Roles
 func (m metricsMiddleware) Delete(ctx context.Context, spaceId string, roleId string) (err error) {
-	m.requestMetrics.Total.WithLabelValues("Delete").Inc()
 	timer := prometheus.NewTimer(m.requestMetrics.DurationSeconds.WithLabelValues("Delete"))
-	defer func() {
-		timer.ObserveDuration()
-		if err != nil {
-			m.requestMetrics.FailedTotal.WithLabelValues("Delete").Inc()
-		}
-	}()
-	return m.next.Delete(ctx, spaceId, roleId)
+	defer timer.ObserveDuration()
+	m.requestMetrics.Total.WithLabelValues("Delete").Inc()
+	err = m.next.Delete(ctx, spaceId, roleId)
+	if err != nil {
+		m.requestMetrics.FailedTotal.WithLabelValues("Delete").Inc()
+		return
+	}
+	return
 }
 
 // Get implements roles.Roles
 func (m metricsMiddleware) Get(ctx context.Context, spaceId string, roleId string) (role *roles.Role, err error) {
-	m.requestMetrics.Total.WithLabelValues("Get").Inc()
 	timer := prometheus.NewTimer(m.requestMetrics.DurationSeconds.WithLabelValues("Get"))
-	defer func() {
-		timer.ObserveDuration()
-		if err != nil {
-			m.requestMetrics.FailedTotal.WithLabelValues("Get").Inc()
-		}
-	}()
-	return m.next.Get(ctx, spaceId, roleId)
+	defer timer.ObserveDuration()
+	m.requestMetrics.Total.WithLabelValues("Get").Inc()
+	role, err = m.next.Get(ctx, spaceId, roleId)
+	if err != nil {
+		m.requestMetrics.FailedTotal.WithLabelValues("Get").Inc()
+		return
+	}
+	return
 }
 
 // List implements roles.Roles
 func (m metricsMiddleware) List(ctx context.Context, spaceId string) (roles []*roles.Role, err error) {
-	m.requestMetrics.Total.WithLabelValues("List").Inc()
 	timer := prometheus.NewTimer(m.requestMetrics.DurationSeconds.WithLabelValues("List"))
-	defer func() {
-		timer.ObserveDuration()
-		if err != nil {
-			m.requestMetrics.FailedTotal.WithLabelValues("List").Inc()
-		}
-	}()
-	return m.next.List(ctx, spaceId)
+	defer timer.ObserveDuration()
+	m.requestMetrics.Total.WithLabelValues("List").Inc()
+	roles, err = m.next.List(ctx, spaceId)
+	if err != nil {
+		m.requestMetrics.FailedTotal.WithLabelValues("List").Inc()
+		return
+	}
+	return
 }
 
 // Update implements roles.Roles
 func (m metricsMiddleware) Update(ctx context.Context, role *roles.Role) (err error) {
-	m.requestMetrics.Total.WithLabelValues("Update").Inc()
 	timer := prometheus.NewTimer(m.requestMetrics.DurationSeconds.WithLabelValues("Update"))
-	defer func() {
-		timer.ObserveDuration()
-		if err != nil {
-			m.requestMetrics.FailedTotal.WithLabelValues("Update").Inc()
-		}
-	}()
-	return m.next.Update(ctx, role)
+	defer timer.ObserveDuration()
+	m.requestMetrics.Total.WithLabelValues("Update").Inc()
+	err = m.next.Update(ctx, role)
+	if err != nil {
+		m.requestMetrics.FailedTotal.WithLabelValues("Update").Inc()
+		return
+	}
+	return
 }
diff --git a/pkg/spaces/middleware/metrics_middleware.go b/pkg/spaces/middleware/metrics_middleware.go
index ba8d95a6665ce663162f8791ce54b22e938007f1..df81e592174cfc7d3c000ae7d617071d38ab5250 100644
--- a/pkg/spaces/middleware/metrics_middleware.go
+++ b/pkg/spaces/middleware/metrics_middleware.go
@@ -32,130 +32,130 @@ func MetricsMiddleware(requestMetrics *metrics.RequestMetrics) Middleware {
 
 // AbortTransfer implements spaces.Spaces
 func (m metricsMiddleware) AbortTransfer(ctx context.Context, spaceID string) (err error) {
-	m.requestMetrics.Total.WithLabelValues("AbortTransfer").Inc()
 	timer := prometheus.NewTimer(m.requestMetrics.DurationSeconds.WithLabelValues("AbortTransfer"))
-	defer func() {
-		timer.ObserveDuration()
-		if err != nil {
-			m.requestMetrics.FailedTotal.WithLabelValues("AbortTransfer").Inc()
-		}
-	}()
-	return m.next.AbortTransfer(ctx, spaceID)
+	defer timer.ObserveDuration()
+	m.requestMetrics.Total.WithLabelValues("AbortTransfer").Inc()
+	err = m.next.AbortTransfer(ctx, spaceID)
+	if err != nil {
+		m.requestMetrics.FailedTotal.WithLabelValues("AbortTransfer").Inc()
+		return
+	}
+	return
 }
 
 // Create implements spaces.Spaces
 func (m metricsMiddleware) Create(ctx context.Context, space *spaces.Space) (created *spaces.Space, err error) {
-	m.requestMetrics.Total.WithLabelValues("Create").Inc()
 	timer := prometheus.NewTimer(m.requestMetrics.DurationSeconds.WithLabelValues("Create"))
-	defer func() {
-		timer.ObserveDuration()
-		if err != nil {
-			m.requestMetrics.FailedTotal.WithLabelValues("Create").Inc()
-		}
-	}()
-	return m.next.Create(ctx, space)
+	defer timer.ObserveDuration()
+	m.requestMetrics.Total.WithLabelValues("Create").Inc()
+	created, err = m.next.Create(ctx, space)
+	if err != nil {
+		m.requestMetrics.FailedTotal.WithLabelValues("Create").Inc()
+		return
+	}
+	return
 }
 
 // Delete implements spaces.Spaces
 func (m metricsMiddleware) Delete(ctx context.Context, spaceId string) (err error) {
-	m.requestMetrics.Total.WithLabelValues("Delete").Inc()
 	timer := prometheus.NewTimer(m.requestMetrics.DurationSeconds.WithLabelValues("Delete"))
-	defer func() {
-		timer.ObserveDuration()
-		if err != nil {
-			m.requestMetrics.FailedTotal.WithLabelValues("Delete").Inc()
-		}
-	}()
-	return m.next.Delete(ctx, spaceId)
+	defer timer.ObserveDuration()
+	m.requestMetrics.Total.WithLabelValues("Delete").Inc()
+	err = m.next.Delete(ctx, spaceId)
+	if err != nil {
+		m.requestMetrics.FailedTotal.WithLabelValues("Delete").Inc()
+		return
+	}
+	return
 }
 
 // Get implements spaces.Spaces
 func (m metricsMiddleware) Get(ctx context.Context, spaceId string) (space *spaces.Space, err error) {
-	m.requestMetrics.Total.WithLabelValues("Get").Inc()
 	timer := prometheus.NewTimer(m.requestMetrics.DurationSeconds.WithLabelValues("Get"))
-	defer func() {
-		timer.ObserveDuration()
-		if err != nil {
-			m.requestMetrics.FailedTotal.WithLabelValues("Get").Inc()
-		}
-	}()
-	return m.next.Get(ctx, spaceId)
+	defer timer.ObserveDuration()
+	m.requestMetrics.Total.WithLabelValues("Get").Inc()
+	space, err = m.next.Get(ctx, spaceId)
+	if err != nil {
+		m.requestMetrics.FailedTotal.WithLabelValues("Get").Inc()
+		return
+	}
+	return
 }
 
 // List implements spaces.Spaces
 func (m metricsMiddleware) List(ctx context.Context, orgId string) (spaces []*spaces.Space, err error) {
-	m.requestMetrics.Total.WithLabelValues("List").Inc()
 	timer := prometheus.NewTimer(m.requestMetrics.DurationSeconds.WithLabelValues("List"))
-	defer func() {
-		timer.ObserveDuration()
-		if err != nil {
-			m.requestMetrics.FailedTotal.WithLabelValues("List").Inc()
-		}
-	}()
-	return m.next.List(ctx, orgId)
+	defer timer.ObserveDuration()
+	m.requestMetrics.Total.WithLabelValues("List").Inc()
+	spaces, err = m.next.List(ctx, orgId)
+	if err != nil {
+		m.requestMetrics.FailedTotal.WithLabelValues("List").Inc()
+		return
+	}
+	return
 }
 
 // ListTransfers implements spaces.Spaces
 func (m metricsMiddleware) ListTransfers(ctx context.Context, orgID string) (spaces []*spaces.Space, err error) {
-	m.requestMetrics.Total.WithLabelValues("ListTransfers").Inc()
 	timer := prometheus.NewTimer(m.requestMetrics.DurationSeconds.WithLabelValues("ListTransfers"))
-	defer func() {
-		timer.ObserveDuration()
-		if err != nil {
-			m.requestMetrics.FailedTotal.WithLabelValues("ListTransfers").Inc()
-		}
-	}()
-	return m.next.ListTransfers(ctx, orgID)
+	defer timer.ObserveDuration()
+	m.requestMetrics.Total.WithLabelValues("ListTransfers").Inc()
+	spaces, err = m.next.ListTransfers(ctx, orgID)
+	if err != nil {
+		m.requestMetrics.FailedTotal.WithLabelValues("ListTransfers").Inc()
+		return
+	}
+	return
 }
 
 // Move implements spaces.Spaces
 func (m metricsMiddleware) Move(ctx context.Context, spaceID string, orgID string) (err error) {
-	m.requestMetrics.Total.WithLabelValues("Move").Inc()
 	timer := prometheus.NewTimer(m.requestMetrics.DurationSeconds.WithLabelValues("Move"))
-	defer func() {
-		timer.ObserveDuration()
-		if err != nil {
-			m.requestMetrics.FailedTotal.WithLabelValues("Move").Inc()
-		}
-	}()
-	return m.next.Move(ctx, spaceID, orgID)
+	defer timer.ObserveDuration()
+	m.requestMetrics.Total.WithLabelValues("Move").Inc()
+	err = m.next.Move(ctx, spaceID, orgID)
+	if err != nil {
+		m.requestMetrics.FailedTotal.WithLabelValues("Move").Inc()
+		return
+	}
+	return
 }
 
 // Transfer implements spaces.Spaces
 func (m metricsMiddleware) Transfer(ctx context.Context, spaceID string, transferToOrg string) (err error) {
-	m.requestMetrics.Total.WithLabelValues("Transfer").Inc()
 	timer := prometheus.NewTimer(m.requestMetrics.DurationSeconds.WithLabelValues("Transfer"))
-	defer func() {
-		timer.ObserveDuration()
-		if err != nil {
-			m.requestMetrics.FailedTotal.WithLabelValues("Transfer").Inc()
-		}
-	}()
-	return m.next.Transfer(ctx, spaceID, transferToOrg)
+	defer timer.ObserveDuration()
+	m.requestMetrics.Total.WithLabelValues("Transfer").Inc()
+	err = m.next.Transfer(ctx, spaceID, transferToOrg)
+	if err != nil {
+		m.requestMetrics.FailedTotal.WithLabelValues("Transfer").Inc()
+		return
+	}
+	return
 }
 
 // Update implements spaces.Spaces
 func (m metricsMiddleware) Update(ctx context.Context, space *spaces.Space) (err error) {
-	m.requestMetrics.Total.WithLabelValues("Update").Inc()
 	timer := prometheus.NewTimer(m.requestMetrics.DurationSeconds.WithLabelValues("Update"))
-	defer func() {
-		timer.ObserveDuration()
-		if err != nil {
-			m.requestMetrics.FailedTotal.WithLabelValues("Update").Inc()
-		}
-	}()
-	return m.next.Update(ctx, space)
+	defer timer.ObserveDuration()
+	m.requestMetrics.Total.WithLabelValues("Update").Inc()
+	err = m.next.Update(ctx, space)
+	if err != nil {
+		m.requestMetrics.FailedTotal.WithLabelValues("Update").Inc()
+		return
+	}
+	return
 }
 
 // UpdateConfig implements spaces.Spaces
 func (m metricsMiddleware) UpdateConfig(ctx context.Context, spaceId string, config *spaces.Config) (err error) {
-	m.requestMetrics.Total.WithLabelValues("UpdateConfig").Inc()
 	timer := prometheus.NewTimer(m.requestMetrics.DurationSeconds.WithLabelValues("UpdateConfig"))
-	defer func() {
-		timer.ObserveDuration()
-		if err != nil {
-			m.requestMetrics.FailedTotal.WithLabelValues("UpdateConfig").Inc()
-		}
-	}()
-	return m.next.UpdateConfig(ctx, spaceId, config)
+	defer timer.ObserveDuration()
+	m.requestMetrics.Total.WithLabelValues("UpdateConfig").Inc()
+	err = m.next.UpdateConfig(ctx, spaceId, config)
+	if err != nil {
+		m.requestMetrics.FailedTotal.WithLabelValues("UpdateConfig").Inc()
+		return
+	}
+	return
 }
diff --git a/pkg/users/middleware/metrics_middleware.go b/pkg/users/middleware/metrics_middleware.go
index df214661bed36c3ddc4bd2489e1d513478de63dd..f1aa52ffc4758a41abe5560f55a1b9ce8616dce7 100644
--- a/pkg/users/middleware/metrics_middleware.go
+++ b/pkg/users/middleware/metrics_middleware.go
@@ -33,78 +33,78 @@ func MetricsMiddleware(requestMetrics *metrics.RequestMetrics) Middleware {
 
 // Create implements users.Users
 func (m metricsMiddleware) Create(ctx context.Context, create *users.User) (user *users.User, err error) {
-	m.requestMetrics.Total.WithLabelValues("Create").Inc()
 	timer := prometheus.NewTimer(m.requestMetrics.DurationSeconds.WithLabelValues("Create"))
-	defer func() {
-		timer.ObserveDuration()
-		if err != nil {
-			m.requestMetrics.FailedTotal.WithLabelValues("Create").Inc()
-		}
-	}()
-	return m.next.Create(ctx, create)
+	defer timer.ObserveDuration()
+	m.requestMetrics.Total.WithLabelValues("Create").Inc()
+	user, err = m.next.Create(ctx, create)
+	if err != nil {
+		m.requestMetrics.FailedTotal.WithLabelValues("Create").Inc()
+		return
+	}
+	return
 }
 
 // Delete implements users.Users
 func (m metricsMiddleware) Delete(ctx context.Context, userId string) (err error) {
-	m.requestMetrics.Total.WithLabelValues("Delete").Inc()
 	timer := prometheus.NewTimer(m.requestMetrics.DurationSeconds.WithLabelValues("Delete"))
-	defer func() {
-		timer.ObserveDuration()
-		if err != nil {
-			m.requestMetrics.FailedTotal.WithLabelValues("Delete").Inc()
-		}
-	}()
-	return m.next.Delete(ctx, userId)
+	defer timer.ObserveDuration()
+	m.requestMetrics.Total.WithLabelValues("Delete").Inc()
+	err = m.next.Delete(ctx, userId)
+	if err != nil {
+		m.requestMetrics.FailedTotal.WithLabelValues("Delete").Inc()
+		return
+	}
+	return
 }
 
 // Find implements users.Users
 func (m metricsMiddleware) Find(ctx context.Context, filter *users.Filter, options *options.FindOptions) (users []*users.User, total int, err error) {
-	m.requestMetrics.Total.WithLabelValues("Find").Inc()
 	timer := prometheus.NewTimer(m.requestMetrics.DurationSeconds.WithLabelValues("Find"))
-	defer func() {
-		timer.ObserveDuration()
-		if err != nil {
-			m.requestMetrics.FailedTotal.WithLabelValues("Find").Inc()
-		}
-	}()
-	return m.next.Find(ctx, filter, options)
+	defer timer.ObserveDuration()
+	m.requestMetrics.Total.WithLabelValues("Find").Inc()
+	users, total, err = m.next.Find(ctx, filter, options)
+	if err != nil {
+		m.requestMetrics.FailedTotal.WithLabelValues("Find").Inc()
+		return
+	}
+	return
 }
 
 // Get implements users.Users
 func (m metricsMiddleware) Get(ctx context.Context, userId string) (user *users.User, err error) {
-	m.requestMetrics.Total.WithLabelValues("Get").Inc()
 	timer := prometheus.NewTimer(m.requestMetrics.DurationSeconds.WithLabelValues("Get"))
-	defer func() {
-		timer.ObserveDuration()
-		if err != nil {
-			m.requestMetrics.FailedTotal.WithLabelValues("Get").Inc()
-		}
-	}()
-	return m.next.Get(ctx, userId)
+	defer timer.ObserveDuration()
+	m.requestMetrics.Total.WithLabelValues("Get").Inc()
+	user, err = m.next.Get(ctx, userId)
+	if err != nil {
+		m.requestMetrics.FailedTotal.WithLabelValues("Get").Inc()
+		return
+	}
+	return
 }
 
 // GetByIdentity implements users.Users
 func (m metricsMiddleware) GetByIdentity(ctx context.Context, identity string) (user *users.User, err error) {
-	m.requestMetrics.Total.WithLabelValues("GetByIdentity").Inc()
 	timer := prometheus.NewTimer(m.requestMetrics.DurationSeconds.WithLabelValues("GetByIdentity"))
-	defer func() {
-		timer.ObserveDuration()
-		if err != nil {
-			m.requestMetrics.FailedTotal.WithLabelValues("GetByIdentity").Inc()
-		}
-	}()
-	return m.next.GetByIdentity(ctx, identity)
+	defer timer.ObserveDuration()
+	m.requestMetrics.Total.WithLabelValues("GetByIdentity").Inc()
+	user, err = m.next.GetByIdentity(ctx, identity)
+	if err != nil {
+		m.requestMetrics.FailedTotal.WithLabelValues("GetByIdentity").Inc()
+		return
+	}
+	return
 }
 
 // Update implements users.Users
 func (m metricsMiddleware) Update(ctx context.Context, update *users.User) (err error) {
-	m.requestMetrics.Total.WithLabelValues("Update").Inc()
 	timer := prometheus.NewTimer(m.requestMetrics.DurationSeconds.WithLabelValues("Update"))
-	defer func() {
-		timer.ObserveDuration()
-		if err != nil {
-			m.requestMetrics.FailedTotal.WithLabelValues("Update").Inc()
-		}
-	}()
-	return m.next.Update(ctx, update)
+	defer timer.ObserveDuration()
+	m.requestMetrics.Total.WithLabelValues("Update").Inc()
+	err = m.next.Update(ctx, update)
+	if err != nil {
+		m.requestMetrics.FailedTotal.WithLabelValues("Update").Inc()
+		return
+	}
+	return
 }