diff --git a/pkg/bench/bench_test.go b/pkg/bench/bench_test.go index 2d3a624f2273..f5638c391933 100644 --- a/pkg/bench/bench_test.go +++ b/pkg/bench/bench_test.go @@ -437,12 +437,8 @@ func BenchmarkSampling(b *testing.B) { } } -// BenchmarkTracing measures the overhead of always-on tracing. It also reports -// the memory utilization. -// -// TODO(irfansharif): This benchmark is only useful while we transition between -// the legacy trace.mode, and the "always-on" mode introduced in 21.1. We can -// remove it in 21.2. +// BenchmarkTracing measures the overhead of tracing. It also +// reports the memory utilization. func BenchmarkTracing(b *testing.B) { skip.UnderShort(b) defer log.Scope(b).Close(b) @@ -456,15 +452,11 @@ func BenchmarkTracing(b *testing.B) { b.Run(dbName, func(b *testing.B) { dbFn(b, func(b *testing.B, db *sqlutils.SQLRunner) { - for _, tracingEnabled := range []bool{true, false} { - var tracingMode string - if tracingEnabled { - tracingMode = "background" - } else { - tracingMode = "legacy" - } - db.Exec(b, fmt.Sprintf("SET CLUSTER SETTING trace.mode = %s", tracingMode)) - b.Run(fmt.Sprintf("tracing=%s", tracingMode[:1]), func(b *testing.B) { + for _, tracingEnabled := range []bool{false, true} { + // Disable statement sampling to de-noise this benchmark. + db.Exec(b, "SET CLUSTER SETTING sql.txn_stats.sample_rate = 0.0") + db.Exec(b, fmt.Sprintf("SET CLUSTER SETTING sql.trace.debug_force_real_spans.enabled = %t", tracingEnabled)) + b.Run(fmt.Sprintf("tracing=%s", fmt.Sprintf("%t", tracingEnabled)[:1]), func(b *testing.B) { for _, runFn := range []func(*testing.B, *sqlutils.SQLRunner, int){ runBenchmarkScan1, runBenchmarkInsert, diff --git a/pkg/sql/exec_util.go b/pkg/sql/exec_util.go index 49c52087225b..0eb0cd54b7af 100644 --- a/pkg/sql/exec_util.go +++ b/pkg/sql/exec_util.go @@ -190,6 +190,15 @@ var traceSessionEventLogEnabled = settings.RegisterBoolSetting( false, ).WithPublic() +// debugForceRealSpans can be used to force the use of real tracing spans for +// every statement. It's used primarily to measure the tracing overhead in +// BenchmarkTracing. +var debugForceRealSpans = settings.RegisterBoolSetting( + "sql.trace.debug_force_real_spans.enabled", + "set to true to force the use of real tracing spans for every statement", + false, +) + // ReorderJoinsLimitClusterSettingName is the name of the cluster setting for // the maximum number of joins to reorder. const ReorderJoinsLimitClusterSettingName = "sql.defaults.reorder_joins_limit" diff --git a/pkg/sql/txn_state.go b/pkg/sql/txn_state.go index 0e0af21b2dd8..cc76a734bb99 100644 --- a/pkg/sql/txn_state.go +++ b/pkg/sql/txn_state.go @@ -157,10 +157,11 @@ func (ts *txnState) resetForNewSQLTxn( // (automatic or user-directed) retries. The span is closed by finishSQLTxn(). opName := sqlTxnName alreadyRecording := tranCtx.sessionTracing.Enabled() + debugForceRealSpan := debugForceRealSpans.Get(&tranCtx.settings.SV) var txnCtx context.Context var sp *tracing.Span - if alreadyRecording { + if alreadyRecording || debugForceRealSpan { // WithForceRealSpan is used to support the use of session tracing, // which will start recording on this span. txnCtx, sp = createRootOrChildSpan(connCtx, opName, tranCtx.tracer, tracing.WithForceRealSpan()) diff --git a/pkg/util/tracing/span.go b/pkg/util/tracing/span.go index 17f0c051a2bf..fedec29a8e69 100644 --- a/pkg/util/tracing/span.go +++ b/pkg/util/tracing/span.go @@ -255,8 +255,7 @@ func (sm *SpanMeta) String() string { } // Structured is an opaque protobuf that can be attached to a trace via -// `Span.RecordStructured`. This is the only kind of data a Span carries when -// `trace.mode = background`. +// `Span.RecordStructured`. type Structured interface { protoutil.Message }