Documentation
¶
Index ¶
- Constants
- func ChildSpanFromContxt(ctx context.Context, opName string) (opentracing.Span, context.Context)
- func ContextWithTraceInfo(ctx context.Context, info *TraceInfo) context.Context
- func Disable(categories TraceCategory)
- func Enable(categories TraceCategory)
- func ExtractTraceID(ctx context.Context) []byte
- func GetSink(ctx context.Context) any
- func IsEnabled(category TraceCategory) bool
- func NewRecordedTrace(opName string, callback func(sp basictracer.RawSpan)) opentracing.Span
- func SetCategories(categories TraceCategory)
- func SpanFromContext(ctx context.Context) (sp opentracing.Span)
- func WithFlightRecorder(ctx context.Context, sink FlightRecorder) context.Context
- type CETraceRecord
- type CallbackRecorder
- type Event
- type FlightRecorder
- type OptimizeTracer
- type Phase
- type Region
- type Sink
- type TraceCategory
- type TraceInfo
Constants ¶
const AllCategories = traceCategorySentinel - 1
AllCategories can be used to enable every known trace category.
const TiDBTrace = "tr"
TiDBTrace is set as Baggage on traces which are used for tidb tracing.
Variables ¶
This section is empty.
Functions ¶
func ChildSpanFromContxt ¶
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 ¶
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 ¶
ExtractTraceID returns the trace identifier from ctx if present. It delegates to client-go's TraceIDFromContext implementation.
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 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 ¶
StartRegion provides better API, integrating both opentracing and runtime.trace facilities into one. Recommended usage is
defer tracing.StartRegion(ctx, "myTracedRegion").End()
func StartRegionEx ¶
StartRegionEx returns Region together with the context. Recommended usage is
r, ctx := tracing.StartRegionEx(ctx, "myTracedRegion")
defer r.End()
func StartRegionWithNewRootSpan ¶
StartRegionWithNewRootSpan return Region together with the context. It create and start a new span by globalTracer and store it into `ctx`.
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 ¶
TraceInfoFromContext returns the `model.TraceInfo` in context