Pyroscope: Add error source (#112645)

* set downstream errors in pyroscope

* Update pkg/tsdb/grafana-pyroscope-datasource/instance.go

Co-authored-by: Gareth <email@garethdawson.xyz>

* Update pkg/tsdb/grafana-pyroscope-datasource/instance.go

Co-authored-by: Gareth <email@garethdawson.xyz>

* more error source

---------

Co-authored-by: Gareth <email@garethdawson.xyz>
This commit is contained in:
ismail simsek
2025-10-21 10:00:59 +02:00
committed by GitHub
co-authored by Gareth
parent ef2e62c852
commit 7c7c9490fb
3 changed files with 24 additions and 23 deletions
@@ -6,6 +6,7 @@ import (
"net/http"
"strings"
"github.com/grafana/grafana-plugin-sdk-go/backend"
"github.com/grafana/grafana-plugin-sdk-go/backend/tracing"
typesv1 "github.com/grafana/pyroscope/api/gen/proto/go/types/v1"
@@ -82,7 +83,7 @@ func (c *PyroscopeClient) ProfileTypes(ctx context.Context, start int64, end int
logger.Error("Received error from client", "error", err, "function", logEntrypoint())
span.RecordError(err)
span.SetStatus(codes.Error, err.Error())
return nil, err
return nil, backend.DownstreamError(fmt.Errorf("received error from client while getting profile types: %w", err))
}
if res.Msg.ProfileTypes == nil {
// Let's make sure we send at least empty array if we don't have any types
@@ -117,7 +118,7 @@ func (c *PyroscopeClient) GetSeries(ctx context.Context, profileTypeID string, l
logger.Error("Received error from client", "error", err, "function", logEntrypoint())
span.RecordError(err)
span.SetStatus(codes.Error, err.Error())
return nil, err
return nil, backend.DownstreamError(fmt.Errorf("received error from client while getting series: %w", err))
}
series := make([]*Series, len(resp.Msg.Series))
@@ -173,7 +174,7 @@ func (c *PyroscopeClient) GetProfile(ctx context.Context, profileTypeID, labelSe
logger.Error("Received error from client", "error", err, "function", logEntrypoint())
span.RecordError(err)
span.SetStatus(codes.Error, err.Error())
return nil, err
return nil, backend.DownstreamError(fmt.Errorf("received error from client while getting profile: %w", err))
}
if resp.Msg.Flamegraph == nil {
@@ -181,7 +182,7 @@ func (c *PyroscopeClient) GetProfile(ctx context.Context, profileTypeID, labelSe
return nil, nil
}
return profileQuery(ctx, err, span, resp.Msg.Flamegraph, profileTypeID)
return profileQuery(resp.Msg.Flamegraph, profileTypeID)
}
func (c *PyroscopeClient) GetSpanProfile(ctx context.Context, profileTypeID, labelSelector string, spanSelector []string, start, end int64, maxNodes *int64) (*ProfileResponse, error) {
@@ -202,7 +203,7 @@ func (c *PyroscopeClient) GetSpanProfile(ctx context.Context, profileTypeID, lab
if err != nil {
span.RecordError(err)
span.SetStatus(codes.Error, err.Error())
return nil, err
return nil, backend.DownstreamError(fmt.Errorf("received error from client while getting span profile: %w", err))
}
if resp.Msg.Flamegraph == nil {
@@ -210,10 +211,10 @@ func (c *PyroscopeClient) GetSpanProfile(ctx context.Context, profileTypeID, lab
return nil, nil
}
return profileQuery(ctx, err, span, resp.Msg.Flamegraph, profileTypeID)
return profileQuery(resp.Msg.Flamegraph, profileTypeID)
}
func profileQuery(ctx context.Context, err error, span trace.Span, flamegraph *querierv1.FlameGraph, profileTypeID string) (*ProfileResponse, error) {
func profileQuery(flamegraph *querierv1.FlameGraph, profileTypeID string) (*ProfileResponse, error) {
levels := make([]*Level, len(flamegraph.Levels))
for i, level := range flamegraph.Levels {
levels[i] = &Level{
@@ -256,7 +257,7 @@ func (c *PyroscopeClient) LabelNames(ctx context.Context, labelSelector string,
logger.Error("Received error from client", "error", err, "function", logEntrypoint())
span.RecordError(err)
span.SetStatus(codes.Error, err.Error())
return nil, fmt.Errorf("error sending LabelNames request %v", err)
return nil, backend.DownstreamError(fmt.Errorf("error sending LabelNames request %v", err))
}
if resp.Msg.Names == nil {
@@ -286,7 +287,7 @@ func (c *PyroscopeClient) LabelValues(ctx context.Context, label string, labelSe
logger.Error("Received error from client", "error", err, "function", logEntrypoint())
span.RecordError(err)
span.SetStatus(codes.Error, err.Error())
return nil, err
return nil, backend.DownstreamError(fmt.Errorf("received error from client while getting label values: %w", err))
}
if resp.Msg.Names == nil {
return []string{}, nil