Plugins: Add tracing to pipeline (#115448)

This commit is contained in:
Todd Treece
2025-12-17 09:08:17 -05:00
committed by GitHub
parent af85563527
commit 33e53db53a
13 changed files with 168 additions and 13 deletions
@@ -3,9 +3,14 @@ package termination
import (
"context"
"go.opentelemetry.io/otel"
"go.opentelemetry.io/otel/trace"
"github.com/grafana/grafana/pkg/infra/tracing"
"github.com/grafana/grafana/pkg/plugins"
"github.com/grafana/grafana/pkg/plugins/config"
"github.com/grafana/grafana/pkg/plugins/log"
"github.com/grafana/grafana/pkg/semconv"
)
// Terminator is responsible for the Termination stage of the plugin loader pipeline.
@@ -20,6 +25,7 @@ type Terminate struct {
cfg *config.PluginManagementCfg
terminateSteps []TerminateFunc
log log.Logger
tracer trace.Tracer
}
type Opts struct {
@@ -36,14 +42,20 @@ func New(cfg *config.PluginManagementCfg, opts Opts) (*Terminate, error) {
cfg: cfg,
terminateSteps: opts.TerminateFuncs,
log: log.New("plugins.termination"),
tracer: otel.Tracer("github.com/grafana/grafana/pkg/plugins/manager/pipeline/termination"),
}, nil
}
// Terminate will execute the Terminate steps of the Termination stage.
func (t *Terminate) Terminate(ctx context.Context, p *plugins.Plugin) (*plugins.Plugin, error) {
ctx, span := t.tracer.Start(ctx, "termination.Terminate", trace.WithAttributes(
semconv.GrafanaPluginId(p.ID),
))
defer span.End()
for _, terminate := range t.terminateSteps {
if err := terminate(ctx, p); err != nil {
return nil, err
return nil, tracing.Error(span, err)
}
}
return p, nil