tracing

package
v1.1.0-beta.0...-adfb9d8 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 6, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const AllCategories = traceCategorySentinel - 1

AllCategories can be used to enable every known trace category.

View Source
const TiDBTrace = "tr"

TiDBTrace is set as Baggage on traces which are used for tidb tracing.

Variables

This section is empty.

Functions

func ChildSpanFromContxt

func ChildSpanFromContxt(ctx context.Context, opName string) (opentracing.Span, context.Context)

ChildSpanFromContxt return a non-nil span. If span can be got from ctx, then returned span is a child of such span. Otherwise, returned span is a noop span.

func ContextWithTraceInfo

func ContextWithTraceInfo(ctx context.Context, info *TraceInfo) context.Context

ContextWithTraceInfo creates a new `model.TraceInfo` for context

func Disable

func Disable(categories TraceCategory)

Disable disables trace events for the specified categories.

func Enable

func Enable(categories TraceCategory)

Enable enables trace events for the specified categories.

func ExtractTraceID

func ExtractTraceID(ctx context.Context) []byte

ExtractTraceID returns the trace identifier from ctx if present. It delegates to client-go's TraceIDFromContext implementation.

func GetSink

func GetSink(ctx context.Context) any

GetSink returns the Sink from the context.

func IsEnabled

func IsEnabled(category TraceCategory) bool

IsEnabled returns whether the specified category is enabled. This function is inline-friendly for hot paths. Trace events only work for next-gen kernel.

func NewRecordedTrace

func NewRecordedTrace(opName string, callback func(sp basictracer.RawSpan)) opentracing.Span

NewRecordedTrace returns a Span which records directly via the specified callback.

func SetCategories

func SetCategories(categories TraceCategory)

SetCategories sets the enabled categories to exactly the specified value.

func SpanFromContext

func SpanFromContext(ctx context.Context) (sp opentracing.Span)

SpanFromContext returns the span obtained from the context or, if none is found, a new one started through tracer.

func WithFlightRecorder

func WithFlightRecorder(ctx context.Context, sink FlightRecorder) context.Context

WithFlightRecorder creates a context with the given FlightRecorder.

Types

type CETraceRecord

type CETraceRecord struct {
	TableName string `json:"table_name"`
	Type      string `json:"type"`
	Expr      string `json:"expr"`
	TableID   int64  `json:"-"`
	RowCount  uint64 `json:"row_count"`
}

CETraceRecord records an expression and related cardinality estimation result.

func DedupCETrace

func DedupCETrace(records []*CETraceRecord) []*CETraceRecord

DedupCETrace deduplicate a slice of *CETraceRecord and return the deduplicated slice

type CallbackRecorder

type CallbackRecorder func(sp basictracer.RawSpan)

A CallbackRecorder immediately invokes itself on received trace spans.

func (CallbackRecorder) RecordSpan

func (cr CallbackRecorder) RecordSpan(sp basictracer.RawSpan)

RecordSpan implements basictracer.SpanRecorder.

type Event

type Event struct {
	Timestamp time.Time
	Name      string
	Phase
	TraceID  []byte
	Fields   []zap.Field
	Category TraceCategory
}

Event represents a traced event. INVARIANT: Event.Fields must be treated as immutable once created, as the underlying array may be shared across multiple goroutines (e.g., flight recorder, log sink, context-specific sinks). Modifications to Fields must allocate a new slice to avoid data races.

type FlightRecorder

type FlightRecorder interface {
	Sink
}

FlightRecorder defines the flight recorder interface.

type OptimizeTracer

type OptimizeTracer struct {
}

OptimizeTracer indicates tracer for optimizer

type Phase

type Phase string

Phase represents the phase of an event.

const (
	PhaseBegin      Phase = "B"
	PhaseEnd        Phase = "E"
	PhaseAsyncBegin Phase = "b"
	PhaseAsyncEnd   Phase = "e"
	PhaseFlowBegin  Phase = "s"
	PhaseFlowEnd    Phase = "f"
	PhaseInstant    Phase = "i"
)

The value definition for Phase.

type Region

type Region struct {
	*trace.Region
	opentracing.Span
	// contains filtered or unexported fields
}

Region is a region of code whose execution time interval is traced.

func StartRegion

func StartRegion(ctx context.Context, regionType string) Region

StartRegion provides better API, integrating both opentracing and runtime.trace facilities into one. Recommended usage is

defer tracing.StartRegion(ctx, "myTracedRegion").End()

func StartRegionEx

func StartRegionEx(ctx context.Context, regionType string) (Region, context.Context)

StartRegionEx returns Region together with the context. Recommended usage is

	r, ctx := tracing.StartRegionEx(ctx, "myTracedRegion")
     defer r.End()

func StartRegionWithNewRootSpan

func StartRegionWithNewRootSpan(ctx context.Context, regionType string) (Region, context.Context)

StartRegionWithNewRootSpan return Region together with the context. It create and start a new span by globalTracer and store it into `ctx`.

func (Region) End

func (r Region) End()

End marks the end of the traced code region.

type Sink

type Sink interface {
	Record(ctx context.Context, event Event)
}

Sink records trace events.

type TraceCategory

type TraceCategory uint64

TraceCategory represents different trace event categories.

const (
	// TxnLifecycle traces transaction begin/commit/rollback events.
	TxnLifecycle TraceCategory = 1 << iota
	// Txn2PC traces two-phase commit prewrite and commit phases.
	Txn2PC
	// TxnLockResolve traces lock resolution and conflict handling.
	TxnLockResolve
	// StmtLifecycle traces statement start/finish events.
	StmtLifecycle
	// StmtPlan traces statement plan digest and optimization.
	StmtPlan
	// KvRequest traces client-go kv request and responses
	KvRequest
	// UnknownClient is the fallback category for unmapped client-go trace events.
	// Used when client-go emits events with categories not yet mapped in adapter.go.
	// This provides forward compatibility if client-go adds new categories.
	UnknownClient
	// General is used by tracing API
	General
	// DDLJob traces DDL job events.
	DDLJob
	// DevDebug traces development/debugging events.
	DevDebug
	// TiKVRequest maps to client-go's FlagTiKVCategoryRequest.
	// Controls request-level tracing in TiKV.
	TiKVRequest
	// TiKVWriteDetails maps to client-go's FlagTiKVCategoryWriteDetails.
	// Controls detailed write operation tracing in TiKV.
	TiKVWriteDetails
	// TiKVReadDetails maps to client-go's FlagTiKVCategoryReadDetails.
	// Controls detailed read operation tracing in TiKV.
	TiKVReadDetails
	// RegionCache traces region cache events.
	RegionCache
)

func GetEnabledCategories

func GetEnabledCategories() TraceCategory

GetEnabledCategories returns the currently enabled categories.

func ParseTraceCategory

func ParseTraceCategory(category string) TraceCategory

ParseTraceCategory parses a trace category string representation and returns the corresponding TraceCategory.

func (TraceCategory) String

func (c TraceCategory) String() string

String returns the string representation of a TraceCategory.

type TraceInfo

type TraceInfo struct {
	// SessionAlias is the alias of session
	SessionAlias string `json:"session_alias"`
	// TraceID is the trace id for every SQL statement
	TraceID []byte `json:"trace_id"`
	// ConnectionID is the id of the connection
	ConnectionID uint64 `json:"connection_id"`
}

TraceInfo is the information for trace.

func TraceInfoFromContext

func TraceInfoFromContext(ctx context.Context) *TraceInfo

TraceInfoFromContext returns the `model.TraceInfo` in context

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL