Skip to content

🎧 Your Personal Streaming Service

fix(plugins): report metrics for all plugin types, not only MetadataAgents (#4303)

Deluan Quintão9b3d3d15a164
diff --git a/plugins/api/errors.go b/plugins/api/errors.go
index e6d952b4f..796774b15 100644
--- a/plugins/api/errors.go
+++ b/plugins/api/errors.go
@@ -3,6 +3,10 @@ package api
import "errors"
var (
- ErrNotFound = errors.New("plugin:not_found")
+ // ErrNotImplemented indicates that the plugin does not implement the requested method.
+ // No logic should be executed by the plugin.
ErrNotImplemented = errors.New("plugin:not_implemented")
+
+ // ErrNotFound indicates that the requested resource was not found by the plugin.
+ ErrNotFound = errors.New("plugin:not_found")
)
diff --git a/plugins/wasm_base_plugin.go b/plugins/wasm_base_plugin.go
index bc1f1d2f5..ef53fc59a 100644
--- a/plugins/wasm_base_plugin.go
+++ b/plugins/wasm_base_plugin.go
@@ -6,10 +6,10 @@ import (
"fmt"
"time"
- "github.com/navidrome/navidrome/core/agents"
"github.com/navidrome/navidrome/core/metrics"
"github.com/navidrome/navidrome/log"
"github.com/navidrome/navidrome/model/id"
+ "github.com/navidrome/navidrome/plugins/api"
)
// newWasmBasePlugin creates a new instance of wasmBasePlugin with the required parameters.
@@ -101,19 +101,18 @@ func callMethod[S any, R any](ctx context.Context, w wasmPlugin[S], methodName s
elapsed := time.Since(start)
if em, ok := any(w).(errorMapper); ok {
- mappedErr := em.mapError(err)
-
- if !errors.Is(mappedErr, agents.ErrNotFound) {
- id := w.PluginID()
- isOk := mappedErr == nil
- metrics := w.getMetrics()
- if metrics != nil {
- metrics.RecordPluginRequest(ctx, id, methodName, isOk, elapsed.Milliseconds())
- }
- log.Trace(ctx, "callMethod", "plugin", id, "method", methodName, "ok", isOk, elapsed)
- }
+ err = em.mapError(err)
+ }
- return r, mappedErr
+ if !errors.Is(err, api.ErrNotImplemented) {
+ id := w.PluginID()
+ isOk := err == nil
+ metrics := w.getMetrics()
+ if metrics != nil {
+ metrics.RecordPluginRequest(ctx, id, methodName, isOk, elapsed.Milliseconds())
+ log.Trace(ctx, "callMethod: sending metrics", "plugin", id, "method", methodName, "ok", isOk, elapsed)
+ }
}
+
return r, err
}