mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Add error information to graphite queries tracing (#55249)
This commit extends graphite QueryData() instrumentation to include in the traces information about possible errors. I've added an attribute about the graphite response code as well as records for errors if there are any.
This commit is contained in:
parent
317b353b34
commit
cb99b94b01
@ -14,12 +14,12 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"go.opentelemetry.io/otel/attribute"
|
||||
|
||||
"github.com/grafana/grafana-plugin-sdk-go/backend"
|
||||
"github.com/grafana/grafana-plugin-sdk-go/backend/datasource"
|
||||
"github.com/grafana/grafana-plugin-sdk-go/backend/instancemgmt"
|
||||
"github.com/grafana/grafana-plugin-sdk-go/data"
|
||||
"go.opentelemetry.io/otel/attribute"
|
||||
"go.opentelemetry.io/otel/codes"
|
||||
|
||||
"github.com/grafana/grafana/pkg/components/simplejson"
|
||||
"github.com/grafana/grafana/pkg/infra/httpclient"
|
||||
@ -153,22 +153,30 @@ func (s *Service) QueryData(ctx context.Context, req *backend.QueryDataRequest)
|
||||
}
|
||||
|
||||
ctx, span := s.tracer.Start(ctx, "graphite query")
|
||||
defer span.End()
|
||||
|
||||
span.SetAttributes("target", target, attribute.Key("target").String(target))
|
||||
span.SetAttributes("from", from, attribute.Key("from").String(from))
|
||||
span.SetAttributes("until", until, attribute.Key("until").String(until))
|
||||
span.SetAttributes("datasource_id", dsInfo.Id, attribute.Key("datasource_id").Int64(dsInfo.Id))
|
||||
span.SetAttributes("org_id", req.PluginContext.OrgID, attribute.Key("org_id").Int64(req.PluginContext.OrgID))
|
||||
|
||||
defer span.End()
|
||||
s.tracer.Inject(ctx, graphiteReq.Header, span)
|
||||
|
||||
res, err := dsInfo.HTTPClient.Do(graphiteReq)
|
||||
if res != nil {
|
||||
span.SetAttributes("graphite.response.code", res.StatusCode, attribute.Key("graphite.response.code").Int(res.StatusCode))
|
||||
}
|
||||
if err != nil {
|
||||
span.RecordError(err)
|
||||
span.SetStatus(codes.Error, err.Error())
|
||||
return &result, err
|
||||
}
|
||||
|
||||
frames, err := s.toDataFrames(res)
|
||||
if err != nil {
|
||||
span.RecordError(err)
|
||||
span.SetStatus(codes.Error, err.Error())
|
||||
return &result, err
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user