SQL Expressions: Add internal GMS traces (#104836)

get trace from inside GMS
This commit is contained in:
Kyle Brandt
2025-05-09 14:48:47 -04:00
committed by GitHub
parent feb1ac5ba7
commit 6a6ba723a9
4 changed files with 49 additions and 11 deletions
+8 -2
View File
@@ -11,6 +11,7 @@ import (
"github.com/dolthub/go-mysql-server/sql/analyzer"
"github.com/grafana/grafana-plugin-sdk-go/data"
"github.com/grafana/grafana/pkg/infra/tracing"
)
// DB is a database that can execute SQL queries against a set of Frames.
@@ -56,7 +57,7 @@ func isFunctionNotFoundError(err error) bool {
// The RefID of each frame becomes a table in the database.
// It is expected that there is only one frame per RefID.
// The name becomes the name and RefID of the returned frame.
func (db *DB) QueryFrames(ctx context.Context, name string, query string, frames []*data.Frame) (*data.Frame, error) {
func (db *DB) QueryFrames(ctx context.Context, tracer tracing.Tracer, name string, query string, frames []*data.Frame) (*data.Frame, error) {
// We are parsing twice due to TablesList, but don't care fow now. We can save the parsed query and reuse it later if we want.
if allow, err := AllowQuery(query); err != nil || !allow {
if err != nil {
@@ -65,9 +66,14 @@ func (db *DB) QueryFrames(ctx context.Context, name string, query string, frames
return nil, err
}
_, span := tracer.Start(ctx, "SSE.ExecuteGMSQuery")
defer span.End()
pro := NewFramesDBProvider(frames)
session := mysql.NewBaseSession()
mCtx := mysql.NewContext(ctx, mysql.WithSession(session))
// Create a new context with the session and tracer
mCtx := mysql.NewContext(ctx, mysql.WithSession(session), mysql.WithTracer(tracer))
// Select the database in the context
mCtx.SetCurrentDatabase(dbName)