Skip to content

Commit

Permalink
add client trace info through session variable
Browse files Browse the repository at this point in the history
  • Loading branch information
taloric committed Mar 16, 2024
1 parent 999e0bd commit e9afc05
Show file tree
Hide file tree
Showing 17 changed files with 103 additions and 35 deletions.
24 changes: 12 additions & 12 deletions DEPS.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -5637,13 +5637,13 @@ def go_deps():
name = "com_github_opentracing_basictracer_go",
build_file_proto_mode = "disable_global",
importpath = "github.com/opentracing/basictracer-go",
sha256 = "a908957c8e55b7b036b4761fb64c643806fcb9b59d4e7c6fcd03fca1105a9156",
strip_prefix = "github.com/opentracing/basictracer-go@v1.0.0",
sha256 = "4e45569502570eebe6de7ebaebce706ccd0b5bdc3d6efca6268128f217ce5bd7",
strip_prefix = "github.com/opentracing/basictracer-go@v1.1.0",
urls = [
"http://bazel-cache.pingcap.net:8080/gomod/github.com/opentracing/basictracer-go/com_github_opentracing_basictracer_go-v1.0.0.zip",
"http://ats.apps.svc/gomod/github.com/opentracing/basictracer-go/com_github_opentracing_basictracer_go-v1.0.0.zip",
"https://cache.hawkingrei.com/gomod/github.com/opentracing/basictracer-go/com_github_opentracing_basictracer_go-v1.0.0.zip",
"https://storage.googleapis.com/pingcapmirror/gomod/github.com/opentracing/basictracer-go/com_github_opentracing_basictracer_go-v1.0.0.zip",
"http://bazel-cache.pingcap.net:8080/gomod/github.com/opentracing/basictracer-go/com_github_opentracing_basictracer_go-v1.1.0.zip",
"http://ats.apps.svc/gomod/github.com/opentracing/basictracer-go/com_github_opentracing_basictracer_go-v1.1.0.zip",
"https://cache.hawkingrei.com/gomod/github.com/opentracing/basictracer-go/com_github_opentracing_basictracer_go-v1.1.0.zip",
"https://storage.googleapis.com/pingcapmirror/gomod/github.com/opentracing/basictracer-go/com_github_opentracing_basictracer_go-v1.1.0.zip",
],
)
go_repository(
Expand Down Expand Up @@ -7184,13 +7184,13 @@ def go_deps():
name = "com_github_uber_jaeger_client_go",
build_file_proto_mode = "disable_global",
importpath = "github.com/uber/jaeger-client-go",
sha256 = "5c837b40527bd3a61b37f5c39739568b22fb72cbbad654931a567842c266a477",
strip_prefix = "github.com/uber/jaeger-client-go@v2.22.1+incompatible",
sha256 = "cdff0ed648316985b8df4f60489b371231da265f11fbe4f6a9e45f17fe723481",
strip_prefix = "github.com/uber/jaeger-client-go@v2.26.0+incompatible",
urls = [
"http://bazel-cache.pingcap.net:8080/gomod/github.com/uber/jaeger-client-go/com_github_uber_jaeger_client_go-v2.22.1+incompatible.zip",
"http://ats.apps.svc/gomod/github.com/uber/jaeger-client-go/com_github_uber_jaeger_client_go-v2.22.1+incompatible.zip",
"https://cache.hawkingrei.com/gomod/github.com/uber/jaeger-client-go/com_github_uber_jaeger_client_go-v2.22.1+incompatible.zip",
"https://storage.googleapis.com/pingcapmirror/gomod/github.com/uber/jaeger-client-go/com_github_uber_jaeger_client_go-v2.22.1+incompatible.zip",
"http://bazel-cache.pingcap.net:8080/gomod/github.com/uber/jaeger-client-go/com_github_uber_jaeger_client_go-v2.26.0+incompatible.zip",
"http://ats.apps.svc/gomod/github.com/uber/jaeger-client-go/com_github_uber_jaeger_client_go-v2.26.0+incompatible.zip",
"https://cache.hawkingrei.com/gomod/github.com/uber/jaeger-client-go/com_github_uber_jaeger_client_go-v2.26.0+incompatible.zip",
"https://storage.googleapis.com/pingcapmirror/gomod/github.com/uber/jaeger-client-go/com_github_uber_jaeger_client_go-v2.26.0+incompatible.zip",
],
)
go_repository(
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ require (
github.com/ngaut/pools v0.0.0-20180318154953-b7bc8c42aac7
github.com/ngaut/sync2 v0.0.0-20141008032647-7a24ed77b2ef
github.com/nishanths/predeclared v0.2.2
github.com/opentracing/basictracer-go v1.0.0
github.com/opentracing/basictracer-go v1.1.0
github.com/opentracing/opentracing-go v1.2.0
github.com/otiai10/copy v1.2.0
github.com/phayes/freeport v0.0.0-20180830031419-95f893ade6f2
Expand Down Expand Up @@ -111,7 +111,7 @@ require (
github.com/tikv/pd/client v0.0.0-20240229065730-92a31c12238e
github.com/timakin/bodyclose v0.0.0-20240125160201-f835fa56326a
github.com/twmb/murmur3 v1.1.6
github.com/uber/jaeger-client-go v2.22.1+incompatible
github.com/uber/jaeger-client-go v2.26.0+incompatible
github.com/vbauerster/mpb/v7 v7.5.3
github.com/wangjohn/quickselect v0.0.0-20161129230411-ed8402a42d5f
github.com/xitongsys/parquet-go v1.5.5-0.20201110004701-b09c49d6d457
Expand Down
9 changes: 5 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -679,8 +679,8 @@ github.com/onsi/gomega v1.7.1/go.mod h1:XdKZgCCFLUoM/7CFJVPcG8C1xQ1AJ0vpAezJrB7J
github.com/onsi/gomega v1.10.1/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1ybHNo=
github.com/onsi/gomega v1.20.1 h1:PA/3qinGoukvymdIDV8pii6tiZgC8kbmJO6Z5+b002Q=
github.com/onsi/gomega v1.20.1/go.mod h1:DtrZpjmvpn2mPm4YWQa0/ALMDj9v4YxLgojwPeREyVo=
github.com/opentracing/basictracer-go v1.0.0 h1:YyUAhaEfjoWXclZVJ9sGoNct7j4TVk7lZWlQw5UXuoo=
github.com/opentracing/basictracer-go v1.0.0/go.mod h1:QfBfYuafItcjQuMwinw9GhYKwFXS9KnPs5lxoYwgW74=
github.com/opentracing/basictracer-go v1.1.0 h1:Oa1fTSBvAl8pa3U+IJYqrKm0NALwH9OsgwOqDv4xJW0=
github.com/opentracing/basictracer-go v1.1.0/go.mod h1:V2HZueSJEp879yv285Aap1BS69fQMD+MNP1mRs6mBQc=
github.com/opentracing/opentracing-go v1.1.0/go.mod h1:UkNAQd3GIcIGf0SeVgPpRdFStlNbqXla1AfSYxPUl2o=
github.com/opentracing/opentracing-go v1.2.0 h1:uEJPy/1a5RIPAJ0Ov+OIO8OxWu77jEv+1B0VhjKrZUs=
github.com/opentracing/opentracing-go v1.2.0/go.mod h1:GxEUsuufX4nBwe+T+Wl9TAgYrxe9dPLANfrWvHYVTgc=
Expand Down Expand Up @@ -884,8 +884,8 @@ github.com/tmc/grpc-websocket-proxy v0.0.0-20220101234140-673ab2c3ae75 h1:6fotK7
github.com/tmc/grpc-websocket-proxy v0.0.0-20220101234140-673ab2c3ae75/go.mod h1:KO6IkyS8Y3j8OdNO85qEYBsRPuteD+YciPomcXdrMnk=
github.com/twmb/murmur3 v1.1.6 h1:mqrRot1BRxm+Yct+vavLMou2/iJt0tNVTTC0QoIjaZg=
github.com/twmb/murmur3 v1.1.6/go.mod h1:Qq/R7NUyOfr65zD+6Q5IHKsJLwP7exErjN6lyyq3OSQ=
github.com/uber/jaeger-client-go v2.22.1+incompatible h1:NHcubEkVbahf9t3p75TOCR83gdUHXjRJvjoBh1yACsM=
github.com/uber/jaeger-client-go v2.22.1+incompatible/go.mod h1:WVhlPFC8FDjOFMMWRy2pZqQJSXxYSwNYOkTr/Z6d3Kk=
github.com/uber/jaeger-client-go v2.26.0+incompatible h1:h285ag9YqU5dfE+D2tc2mL93wjg1YLveCCDgm2y4Rsg=
github.com/uber/jaeger-client-go v2.26.0+incompatible/go.mod h1:WVhlPFC8FDjOFMMWRy2pZqQJSXxYSwNYOkTr/Z6d3Kk=
github.com/uber/jaeger-lib v2.4.1+incompatible h1:td4jdvLcExb4cBISKIpHuGoVXh+dVKhn2Um6rjCsSsg=
github.com/uber/jaeger-lib v2.4.1+incompatible/go.mod h1:ComeNDZlWwrWnDv8aPp0Ba6+uUTzImX/AauajbLI56U=
github.com/ugorji/go v1.1.4/go.mod h1:uQMGLiO92mf5W77hV/PUCpI3pbzQx3CRekS0kk+RGrc=
Expand Down Expand Up @@ -1097,6 +1097,7 @@ golang.org/x/net v0.0.0-20200222125558-5a598a2470a0/go.mod h1:z5CRVTTTmAJ677TzLL
golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20200301022130-244492dfa37a/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20200324143707-d3edc9973b7e/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A=
golang.org/x/net v0.0.0-20200421231249-e086a090c8fd/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A=
golang.org/x/net v0.0.0-20200501053045-e0ff5e5a1de5/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A=
golang.org/x/net v0.0.0-20200506145744-7e3656a0809f/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A=
golang.org/x/net v0.0.0-20200513185701-a91f0712d120/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A=
Expand Down
1 change: 1 addition & 0 deletions pkg/config/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ go_test(
"@com_github_pingcap_errors//:errors",
"@com_github_pingcap_log//:log",
"@com_github_stretchr_testify//require",
"@com_github_uber_jaeger_client_go//:jaeger-client-go",
"@com_github_uber_jaeger_client_go//config",
"@org_uber_go_goleak//:goleak",
],
Expand Down
1 change: 1 addition & 0 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -1467,6 +1467,7 @@ func (t *OpenTracing) ToTracingConfig() *tracing.Configuration {
ret.Sampler.SamplingServerURL = t.Sampler.SamplingServerURL
ret.Sampler.MaxOperations = t.Sampler.MaxOperations
ret.Sampler.SamplingRefreshInterval = t.Sampler.SamplingRefreshInterval
ret, _ = ret.FromEnv()
return ret
}

Expand Down
8 changes: 6 additions & 2 deletions pkg/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import (
zaplog "github.com/pingcap/log"
"github.com/pingcap/tidb/pkg/util/logutil"
"github.com/stretchr/testify/require"
"github.com/uber/jaeger-client-go"
tracing "github.com/uber/jaeger-client-go/config"
)

Expand Down Expand Up @@ -915,8 +916,11 @@ spilled-file-encryption-method = "aes128-ctr"
// Test for tracing config.
tracingConf := &tracing.Configuration{
Disabled: true,
Reporter: &tracing.ReporterConfig{},
Sampler: &tracing.SamplerConfig{Type: "const", Param: 1.0},
Reporter: &tracing.ReporterConfig{
// when configure `local-agent-host-port` to empty, jaeger will set `localhost:6831` as default
LocalAgentHostPort: fmt.Sprintf("%s:%d", jaeger.DefaultUDPSpanServerHost, jaeger.DefaultUDPSpanServerPort),
},
Sampler: &tracing.SamplerConfig{Type: "const", Param: 1.0},
}
require.Equal(t, conf.OpenTracing.ToTracingConfig(), tracingConf)

Expand Down
1 change: 1 addition & 0 deletions pkg/executor/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,7 @@ go_library(
"@com_github_tikv_pd_client//:client",
"@com_github_tikv_pd_client//http",
"@com_github_twmb_murmur3//:murmur3",
"@com_github_uber_jaeger_client_go//:jaeger-client-go",
"@com_sourcegraph_sourcegraph_appdash//:appdash",
"@com_sourcegraph_sourcegraph_appdash//opentracing",
"@org_golang_google_grpc//:grpc",
Expand Down
10 changes: 10 additions & 0 deletions pkg/executor/adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"sync/atomic"
"time"

"github.com/opentracing/opentracing-go"
"github.com/pingcap/errors"
"github.com/pingcap/failpoint"
"github.com/pingcap/log"
Expand Down Expand Up @@ -76,6 +77,7 @@ import (
tikverr "github.com/tikv/client-go/v2/error"
"github.com/tikv/client-go/v2/oracle"
"github.com/tikv/client-go/v2/util"
"github.com/uber/jaeger-client-go"
"go.uber.org/zap"
"go.uber.org/zap/zapcore"
)
Expand Down Expand Up @@ -1549,6 +1551,13 @@ func (a *ExecStmt) LogSlowQuery(txnTS uint64, succ bool, hasMoreResults bool) {
memMax := sessVars.MemTracker.MaxConsumed()
diskMax := sessVars.DiskTracker.MaxConsumed()
_, planDigest := GetPlanDigest(stmtCtx)
span := opentracing.SpanFromContext(a.GoCtx)
var traceID string
if span != nil {
if sc, ok := span.Context().(jaeger.SpanContext); ok {
traceID = sc.TraceID().String()
}
}

binaryPlan := ""
if variable.GenerateBinaryPlan.Load() {
Expand Down Expand Up @@ -1609,6 +1618,7 @@ func (a *ExecStmt) LogSlowQuery(txnTS uint64, succ bool, hasMoreResults bool) {
RRU: ruDetails.RRU(),
WRU: ruDetails.WRU(),
WaitRUDuration: ruDetails.RUWaitDuration(),
TraceID: traceID,
}
failpoint.Inject("assertSyncStatsFailed", func(val failpoint.Value) {
if val.(bool) {
Expand Down
5 changes: 5 additions & 0 deletions pkg/executor/slow_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -730,6 +730,11 @@ func getColumnValueFactoryByName(colName string, columnIdx int) (slowQueryColumn
row[columnIdx] = types.NewStringDatum(backoffDetail)
return true, nil
}, nil
case variable.SlowLogTraceID:
return func(row []types.Datum, value string, tz *time.Location, checker *slowLogChecker) (bool, error) {
row[columnIdx] = types.NewStringDatum(value)
return true, nil
}, nil
case variable.SlowLogPlan:
return func(row []types.Datum, value string, _ *time.Location, _ *slowLogChecker) (bool, error) {
plan := parsePlan(value)
Expand Down
1 change: 1 addition & 0 deletions pkg/infoschema/tables.go
Original file line number Diff line number Diff line change
Expand Up @@ -948,6 +948,7 @@ var slowQueryCols = []columnInfo{
{name: variable.SlowLogWaitRUDuration, tp: mysql.TypeDouble, size: 22},
{name: variable.SlowLogPlan, tp: mysql.TypeLongBlob, size: types.UnspecifiedLength},
{name: variable.SlowLogPlanDigest, tp: mysql.TypeVarchar, size: 128},
{name: variable.SlowLogTraceID, tp: mysql.TypeVarchar, size: 64, flag: mysql.UnsignedFlag},
{name: variable.SlowLogBinaryPlan, tp: mysql.TypeLongBlob, size: types.UnspecifiedLength},
{name: variable.SlowLogPrevStmt, tp: mysql.TypeLongBlob, size: types.UnspecifiedLength},
{name: variable.SlowLogQuerySQLStr, tp: mysql.TypeLongBlob, size: types.UnspecifiedLength},
Expand Down
1 change: 1 addition & 0 deletions pkg/server/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ go_library(
"@com_github_blacktear23_go_proxyprotocol//:go-proxyprotocol",
"@com_github_gorilla_mux//:mux",
"@com_github_klauspost_compress//zstd",
"@com_github_opentracing_opentracing_go//:opentracing-go",
"@com_github_pingcap_errors//:errors",
"@com_github_pingcap_failpoint//:failpoint",
"@com_github_pingcap_fn//:fn",
Expand Down
42 changes: 29 additions & 13 deletions pkg/server/conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ import (
"unsafe"

"github.com/klauspost/compress/zstd"
"github.com/opentracing/opentracing-go"
"github.com/pingcap/errors"
"github.com/pingcap/failpoint"
"github.com/pingcap/tidb/pkg/config"
Expand Down Expand Up @@ -1120,7 +1121,19 @@ func (cc *clientConn) Run(ctx context.Context) {
}

startTime := time.Now()
cfg := config.GetGlobalConfig()
var r tracing.Region
if cfg.OpenTracing.Enable {
sc := cc.ctx.GetSessionVars().SpanContext
opts := make([]opentracing.StartSpanOption, 0, 1)
if sc.TraceID().IsValid() {
opts = append(opts, opentracing.ChildOf(sc))
}
r, ctx = tracing.StartRegionWithNewRootSpan(ctx, "server.conn", opts...)
r.Span.SetTag("client.sql", cc.packetToSQL(data))
}
err = cc.dispatch(ctx, data)
r.End()
cc.ctx.GetSessionVars().ClearAlloc(&cc.chunkAlloc, err != nil)
cc.chunkAlloc.Reset()
if err != nil {
Expand Down Expand Up @@ -1263,8 +1276,7 @@ func (cc *clientConn) dispatch(ctx context.Context, data []byte) error {

cfg := config.GetGlobalConfig()
if cfg.OpenTracing.Enable {
var r tracing.Region
r, ctx = tracing.StartRegionWithNewRootSpan(ctx, "server.dispatch")
r := tracing.StartRegion(ctx, "server.dispatch")
defer r.End()
}

Expand Down Expand Up @@ -2595,17 +2607,8 @@ func (cc *clientConn) handleRefresh(ctx context.Context, subCommand byte) error
return cc.writeOK(ctx)
}

var _ fmt.Stringer = getLastStmtInConn{}

type getLastStmtInConn struct {
*clientConn
}

func (cc getLastStmtInConn) String() string {
if len(cc.lastPacket) == 0 {
return ""
}
cmd, data := cc.lastPacket[0], cc.lastPacket[1:]
func (cc *clientConn) packetToSQL(pkg []byte) string {
cmd, data := pkg[0], pkg[1:]
switch cmd {
case mysql.ComInitDB:
return "Use " + string(data)
Expand All @@ -2629,6 +2632,19 @@ func (cc getLastStmtInConn) String() string {
}
}

var _ fmt.Stringer = getLastStmtInConn{}

type getLastStmtInConn struct {
*clientConn
}

func (cc getLastStmtInConn) String() string {
if len(cc.lastPacket) == 0 {
return ""
}
return cc.packetToSQL(cc.lastPacket)
}

// PProfLabel return sql label used to tag pprof.
func (cc getLastStmtInConn) PProfLabel() string {
if len(cc.lastPacket) == 0 {
Expand Down
1 change: 1 addition & 0 deletions pkg/sessionctx/variable/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ go_library(
"@com_github_tikv_client_go_v2//tikv",
"@com_github_tikv_client_go_v2//util",
"@com_github_twmb_murmur3//:murmur3",
"@com_github_uber_jaeger_client_go//:jaeger-client-go",
"@org_golang_x_exp//maps",
"@org_uber_go_atomic//:atomic",
"@org_uber_go_zap//:zap",
Expand Down
11 changes: 11 additions & 0 deletions pkg/sessionctx/variable/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ import (
tikvstore "github.com/tikv/client-go/v2/kv"
"github.com/tikv/client-go/v2/tikv"
"github.com/twmb/murmur3"
"github.com/uber/jaeger-client-go"
atomic2 "go.uber.org/atomic"
"golang.org/x/exp/maps"
)
Expand Down Expand Up @@ -1253,6 +1254,9 @@ type SessionVars struct {
// TrackAggregateMemoryUsage indicates whether to track the memory usage of aggregate function.
TrackAggregateMemoryUsage bool

// SpanContext is the external trace context.
SpanContext jaeger.SpanContext

// TiDBEnableExchangePartition indicates whether to enable exchange partition
TiDBEnableExchangePartition bool

Expand Down Expand Up @@ -2038,6 +2042,7 @@ func NewSessionVars(hctx HookContext) *SessionVars {
TiFlashComputeDispatchPolicy: tiflashcompute.DispatchPolicyConsistentHash,
ResourceGroupName: resourcegroup.DefaultResourceGroupName,
DefaultCollationForUTF8MB4: mysql.DefaultCollationName,
SpanContext: jaeger.SpanContext{},
}
vars.status.Store(uint32(mysql.ServerStatusAutocommit))
vars.StmtCtx.ResourceGroupName = resourcegroup.DefaultResourceGroupName
Expand Down Expand Up @@ -3148,6 +3153,8 @@ const (
SlowLogWRU = "Request_unit_write"
// SlowLogWaitRUDuration is the total duration for kv requests to wait available request-units.
SlowLogWaitRUDuration = "Time_queued_by_rc"
// SlowLogTraceID is the trace ID of the timeline tracing.
SlowLogTraceID = "Trace_ID"
)

// GenerateBinaryPlan decides whether we should record binary plan in slow log and stmt summary.
Expand Down Expand Up @@ -3207,6 +3214,7 @@ type SlowQueryLogItems struct {
RRU float64
WRU float64
WaitRUDuration time.Duration
TraceID string
}

// SlowLogFormat uses for formatting slow log.
Expand Down Expand Up @@ -3421,6 +3429,9 @@ func (s *SessionVars) SlowLogFormat(logItems *SlowQueryLogItems) string {
if logItems.PrevStmt != "" {
writeSlowLogItem(&buf, SlowLogPrevStmt, logItems.PrevStmt)
}
if logItems.TraceID != "" {
writeSlowLogItem(&buf, SlowLogTraceID, logItems.TraceID)
}

if s.CurrentDBChanged {
buf.WriteString(fmt.Sprintf("use %s;\n", strings.ToLower(s.CurrentDB)))
Expand Down
13 changes: 13 additions & 0 deletions pkg/sessionctx/variable/sysvar.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ import (
tikvcfg "github.com/tikv/client-go/v2/config"
tikvstore "github.com/tikv/client-go/v2/kv"
tikvcliutil "github.com/tikv/client-go/v2/util"
"github.com/uber/jaeger-client-go"
"go.uber.org/zap"
)

Expand Down Expand Up @@ -3157,6 +3158,18 @@ var defaultSysVars = []*SysVar{
},
IsHintUpdatableVerified: true,
},
{Scope: ScopeSession, Name: TiDBTraceID, Value: "", Type: TypeStr, AllowEmpty: true, SetSession: func(sv *SessionVars, s string) error {
if len(s) != 0 {
sc, err := jaeger.ContextFromString(s)
if err != nil {
return err
}
sv.SpanContext = sc
} else {
sv.SpanContext = jaeger.SpanContext{}
}
return nil
}},
}

// GlobalSystemVariableInitialValue gets the default value for a system variable including ones that are dynamically set (e.g. based on the store)
Expand Down
2 changes: 2 additions & 0 deletions pkg/sessionctx/variable/tidb_vars.go
Original file line number Diff line number Diff line change
Expand Up @@ -1160,6 +1160,8 @@ const (
// The value can be STANDARD, BULK.
// Currently, the BULK mode only affects auto-committed DML.
TiDBDMLType = "tidb_dml_type"
// TiDBTraceID is the trace id of the current tracing context.
TiDBTraceID = "tidb_trace_id"
)

// TiDB intentional limits
Expand Down
4 changes: 2 additions & 2 deletions pkg/util/tracing/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ func ChildSpanFromContxt(ctx context.Context, opName string) (opentracing.Span,

// StartRegionWithNewRootSpan return Region together with the context.
// It create and start a new span by globalTracer and store it into `ctx`.
func StartRegionWithNewRootSpan(ctx context.Context, regionType string) (Region, context.Context) {
span := opentracing.GlobalTracer().StartSpan(regionType)
func StartRegionWithNewRootSpan(ctx context.Context, regionType string, options ...opentracing.StartSpanOption) (Region, context.Context) {
span := opentracing.GlobalTracer().StartSpan(regionType, options...)
r := Region{
Region: trace.StartRegion(ctx, regionType),
Span: span,
Expand Down

0 comments on commit e9afc05

Please sign in to comment.