Tracing: Standardize on otel tracing (#75528)
This commit is contained in:
@@ -212,9 +212,9 @@ func (s *QueryData) exemplarQuery(ctx context.Context, c *client.Client, q *mode
|
||||
}
|
||||
|
||||
func (s *QueryData) trace(ctx context.Context, q *models.Query) (context.Context, func()) {
|
||||
return utils.StartTrace(ctx, s.tracer, "datasource.prometheus", []utils.Attribute{
|
||||
{Key: "expr", Value: q.Expr, Kv: attribute.Key("expr").String(q.Expr)},
|
||||
{Key: "start_unixnano", Value: q.Start, Kv: attribute.Key("start_unixnano").Int64(q.Start.UnixNano())},
|
||||
{Key: "stop_unixnano", Value: q.End, Kv: attribute.Key("stop_unixnano").Int64(q.End.UnixNano())},
|
||||
})
|
||||
return utils.StartTrace(ctx, s.tracer, "datasource.prometheus",
|
||||
attribute.String("expr", q.Expr),
|
||||
attribute.Int64("start_unixnano", q.Start.UnixNano()),
|
||||
attribute.Int64("stop_unixnano", q.End.UnixNano()),
|
||||
)
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@ func (s *QueryData) parseResponse(ctx context.Context, q *models.Query, res *htt
|
||||
}
|
||||
}()
|
||||
|
||||
ctx, endSpan := utils.StartTrace(ctx, s.tracer, "datasource.prometheus.parseResponse", []utils.Attribute{})
|
||||
ctx, endSpan := utils.StartTrace(ctx, s.tracer, "datasource.prometheus.parseResponse")
|
||||
defer endSpan()
|
||||
|
||||
iter := jsoniter.Parse(jsoniter.ConfigDefault, res.Body, 1024)
|
||||
@@ -54,7 +54,7 @@ func (s *QueryData) parseResponse(ctx context.Context, q *models.Query, res *htt
|
||||
}
|
||||
|
||||
func (s *QueryData) processExemplars(ctx context.Context, q *models.Query, dr backend.DataResponse) backend.DataResponse {
|
||||
_, endSpan := utils.StartTrace(ctx, s.tracer, "datasource.prometheus.processExemplars", []utils.Attribute{})
|
||||
_, endSpan := utils.StartTrace(ctx, s.tracer, "datasource.prometheus.processExemplars")
|
||||
defer endSpan()
|
||||
sampler := s.exemplarSampler()
|
||||
labelTracker := exemplar.NewLabelTracker()
|
||||
|
||||
@@ -7,6 +7,7 @@ import (
|
||||
|
||||
"github.com/grafana/grafana-plugin-sdk-go/backend"
|
||||
"go.opentelemetry.io/otel/attribute"
|
||||
"go.opentelemetry.io/otel/trace"
|
||||
|
||||
"github.com/grafana/grafana/pkg/infra/tracing"
|
||||
)
|
||||
@@ -22,21 +23,12 @@ func GetJsonData(settings backend.DataSourceInstanceSettings) (map[string]any, e
|
||||
return jsonData, nil
|
||||
}
|
||||
|
||||
type Attribute struct {
|
||||
Key string
|
||||
Value any
|
||||
Kv attribute.KeyValue
|
||||
}
|
||||
|
||||
// StartTrace setups a trace but does not panic if tracer is nil which helps with testing
|
||||
func StartTrace(ctx context.Context, tracer tracing.Tracer, name string, attributes []Attribute) (context.Context, func()) {
|
||||
func StartTrace(ctx context.Context, tracer tracing.Tracer, name string, attributes ...attribute.KeyValue) (context.Context, func()) {
|
||||
if tracer == nil {
|
||||
return ctx, func() {}
|
||||
}
|
||||
ctx, span := tracer.Start(ctx, name)
|
||||
for _, attr := range attributes {
|
||||
span.SetAttributes(attr.Key, attr.Value, attr.Kv)
|
||||
}
|
||||
ctx, span := tracer.Start(ctx, name, trace.WithAttributes(attributes...))
|
||||
return ctx, func() {
|
||||
span.End()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user