Tracing: Standardize on otel tracing (#75528)
This commit is contained in:
@@ -13,6 +13,7 @@ import (
|
||||
"github.com/lib/pq"
|
||||
"github.com/mattn/go-sqlite3"
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
"go.opentelemetry.io/otel/attribute"
|
||||
"go.opentelemetry.io/otel/trace"
|
||||
"xorm.io/core"
|
||||
|
||||
@@ -100,10 +101,11 @@ func (h *databaseQueryWrapper) instrument(ctx context.Context, status string, qu
|
||||
_, span := h.tracer.Start(ctx, "database query", trace.WithTimestamp(begin))
|
||||
defer span.End()
|
||||
|
||||
span.AddEvents([]string{"query", "status"}, []tracing.EventValue{{Str: query}, {Str: status}})
|
||||
span.AddEvent("query", trace.WithAttributes(attribute.String("query", query)))
|
||||
span.AddEvent("status", trace.WithAttributes(attribute.String("status", status)))
|
||||
|
||||
if err != nil {
|
||||
span.AddEvents([]string{"error"}, []tracing.EventValue{{Str: err.Error()}})
|
||||
span.RecordError(err)
|
||||
}
|
||||
|
||||
ctxLogger := h.log.FromContext(ctx)
|
||||
|
||||
@@ -9,6 +9,7 @@ import (
|
||||
|
||||
"github.com/mattn/go-sqlite3"
|
||||
"go.opentelemetry.io/otel/attribute"
|
||||
"go.opentelemetry.io/otel/trace"
|
||||
"xorm.io/xorm"
|
||||
|
||||
"github.com/grafana/grafana/pkg/infra/log"
|
||||
@@ -37,7 +38,7 @@ func (sess *DBSession) PublishAfterCommit(msg any) {
|
||||
sess.events = append(sess.events, msg)
|
||||
}
|
||||
|
||||
func startSessionOrUseExisting(ctx context.Context, engine *xorm.Engine, beginTran bool, tracer tracing.Tracer) (*DBSession, bool, tracing.Span, error) {
|
||||
func startSessionOrUseExisting(ctx context.Context, engine *xorm.Engine, beginTran bool, tracer tracing.Tracer) (*DBSession, bool, trace.Span, error) {
|
||||
value := ctx.Value(ContextSessionKey{})
|
||||
var sess *DBSession
|
||||
sess, ok := value.(*DBSession)
|
||||
@@ -50,7 +51,7 @@ func startSessionOrUseExisting(ctx context.Context, engine *xorm.Engine, beginTr
|
||||
}
|
||||
|
||||
tctx, span := tracer.Start(ctx, "open session")
|
||||
span.SetAttributes("transaction", beginTran, attribute.Key("transaction").Bool(beginTran))
|
||||
span.SetAttributes(attribute.Bool("transaction", beginTran))
|
||||
|
||||
newSess := &DBSession{Session: engine.NewSession(), transactionOpen: beginTran}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user