From 99ec795aac9d3d5df45cb2ebf8df2d46b649e2b2 Mon Sep 17 00:00:00 2001 From: Yahor Yuzefovich Date: Sat, 20 Dec 2025 20:34:02 +0000 Subject: [PATCH] sql: attach opName string as pprof label for internal queries Every query that we run via the internal executor comes with "opName" string that is a short description of the query. We now will attach that string as a pprof label that can then be propagated into stack traces. Release note: None --- pkg/sql/conn_executor_exec.go | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/pkg/sql/conn_executor_exec.go b/pkg/sql/conn_executor_exec.go index 80ac8abd2aa0..f690a8886e02 100644 --- a/pkg/sql/conn_executor_exec.go +++ b/pkg/sql/conn_executor_exec.go @@ -4456,15 +4456,25 @@ func (ex *connExecutor) execWithProfiling( } // Compute fingerprint ID here since ih.Setup hasn't been called yet. fingerprintID := appstatspb.ConstructStatementFingerprintID( - stmtNoConstants, ex.implicitTxn(), ex.sessionData().Database) - pprofutil.Do(ctx, func(ctx context.Context) { - err = op(ctx) - }, + stmtNoConstants, ex.implicitTxn(), ex.sessionData().Database, + ) + labels := make([]string, 0, 12) + labels = append(labels, []string{ workloadid.ProfileTag, sqlstatsutil.EncodeStmtFingerprintIDToString(fingerprintID), "appname", ex.sessionData().ApplicationName, "addr", remoteAddr, "stmt.tag", ast.StatementTag(), "stmt.no.constants", stmtNoConstants, + }...) + if opName, ok := GetInternalOpName(ctx); ok { + labels = append(labels, "opname", opName) + } + pprofutil.Do( + ctx, + func(ctx context.Context) { + err = op(ctx) + }, + labels..., ) } else { err = op(ctx)