Documentation
¶
Index ¶
- Constants
- Variables
- func ContextField(ctx context.Context) zap.Field
- func ContextWithSpan(parent context.Context, span Span) context.Context
- func ContextWithSpanContext(parent context.Context, sc SpanContext) context.Context
- func ContextWithStatement(parent context.Context, s *StatementInfo) context.Context
- func DebugMode(debug bool) tracerProviderOption
- func DefaultContext() context.Context
- func EnableTracer(enable bool) tracerProviderOption
- func GetSchemaForAccount(account string) []string
- func Init(ctx context.Context, opts ...TracerProviderOption) (context.Context, error)
- func InitSchema(ctx context.Context, sqlExecutor func() ie.InternalExecutor) error
- func InitSchemaByInnerExecutor(ctx context.Context, ieFactory func() ie.InternalExecutor) error
- func IsSpanField(field zapcore.Field) bool
- func NewBufferPipe2CSVWorker(opt ...bufferOption) bp.PipeImpl[bp.HasName, any]
- func ReportError(ctx context.Context, err error, depth int)
- func ReportZap(jsonEncoder zapcore.Encoder, entry zapcore.Entry, fields []zapcore.Field) (*buffer.Buffer, error)
- func SetDefaultContext(ctx context.Context)
- func SetDefaultSerializeExecPlan(f SerializeExecPlanFunc)
- func SetDefaultSpanContext(sc *SpanContext)
- func SetTracerProvider(p *MOTracerProvider)
- func Shutdown(ctx context.Context) error
- func SpanField(sc SpanContext) zap.Field
- func WithBatchProcessMode(mode string) tracerProviderOption
- func WithExportInterval(secs int) tracerProviderOption
- func WithFSWriterFactory(f export.FSWriterFactory) tracerProviderOption
- func WithInitAction(init bool) tracerProviderOption
- func WithLongQueryTime(secs float64) tracerProviderOption
- func WithMOVersion(v string) tracerProviderOption
- func WithNewRoot(newRoot bool) spanOptionFunc
- func WithNode(uuid string, t string) tracerProviderOption
- func WithSQLExecutor(f func() ie.InternalExecutor) tracerProviderOption
- func WithSpanID(id SpanID) spanOptionFunc
- func WithTraceID(id TraceID) spanOptionFunc
- type CSVRequest
- type CSVRequests
- type CsvFields
- type IBuffer2SqlItem
- type IDGenerator
- type MOErrorHolder
- type MONodeResource
- type MOSpan
- func (s *MOSpan) CsvFields(row *export.Row) []string
- func (s *MOSpan) End(options ...SpanEndOption)
- func (s *MOSpan) Free()
- func (s *MOSpan) GetName() string
- func (s *MOSpan) GetRow() *export.Row
- func (s *MOSpan) ParentSpanContext() SpanContext
- func (s *MOSpan) Size() int64
- func (s *MOSpan) SpanContext() SpanContext
- type MOTracer
- type MOTracerProvider
- type MOZapLog
- type Resource
- type SerializeExecPlanFunc
- type Span
- type SpanConfig
- type SpanContext
- func (c SpanContext) GetIDs() (TraceID, SpanID)
- func (c *SpanContext) IsEmpty() bool
- func (c *SpanContext) MarshalLogObject(enc zapcore.ObjectEncoder) error
- func (c *SpanContext) MarshalTo(dAtA []byte) (int, error)
- func (c *SpanContext) Reset()
- func (c *SpanContext) Size() (n int)
- func (c *SpanContext) Unmarshal(dAtA []byte) error
- type SpanEndOption
- type SpanID
- type SpanKind
- type SpanOption
- type SpanProcessor
- type SpanStartOption
- type StatementInfo
- func (s *StatementInfo) CsvFields(row *export.Row) []string
- func (s *StatementInfo) ExecPlan2Json() string
- func (s *StatementInfo) Free()
- func (s *StatementInfo) GetName() string
- func (s *StatementInfo) GetRow() *export.Row
- func (s *StatementInfo) IsZeroTxnID() bool
- func (s *StatementInfo) Report(ctx context.Context)
- func (s *StatementInfo) SetExecPlan(execPlan any, SerializeFunc SerializeExecPlanFunc)
- func (s *StatementInfo) SetTxnID(id []byte)
- func (s *StatementInfo) Size() int64
- type StatementInfoStatus
- type StatementOption
- type StatementOptionFunc
- type TraceFlags
- type TraceID
- type Tracer
- type TracerConfig
- type TracerOption
- type TracerProvider
- type TracerProviderOption
Constants ¶
const ( InternalExecutor = "InternalExecutor" FileService = "FileService" )
const ( MOStatementType = "statement" MOSpanType = "span" MOLogType = "log" MOErrorType = "error" MORawLogType = rawLogTbl )
const ( SystemDBConst = "system" StatsDatabase = SystemDBConst )
const ( // FlagsSampled is a bitmask with the sampled bit set. A SpanContext // with the sampling bit set means the span is sampled. FlagsSampled = TraceFlags(0x01) )
const NodeTypeStandalone = "Standalone"
const SpanFieldKey = "span"
Variables ¶
var ( SingleStatementTable = &export.Table{ Account: export.AccountAll, Database: StatsDatabase, Table: statementInfoTbl, Columns: []export.Column{ stmtIDCol, txnIDCol, sesIDCol, accountCol, userCol, hostCol, dbCol, stmtCol, stmtTagCol, stmtFgCol, nodeUUIDCol, nodeTypeCol, reqAtCol, respAtCol, durationCol, statusCol, errCodeCol, errorCol, execPlanCol, rowsReadCol, bytesScanCol, }, PrimaryKeyColumn: []export.Column{stmtIDCol}, Engine: export.ExternalTableEngine, Comment: "record each statement and stats info", PathBuilder: export.NewAccountDatePathBuilder(), AccountColumn: &accountCol, SupportUserAccess: true, } SingleRowLogTable = &export.Table{ Account: export.AccountAll, Database: StatsDatabase, Table: rawLogTbl, Columns: []export.Column{ rawItemCol, nodeUUIDCol, nodeTypeCol, spanIDCol, traceIDCol, loggerNameCol, timestampCol, levelCol, callerCol, messageCol, extraCol, errCodeCol, errorCol, stackCol, spanNameCol, parentSpanIDCol, startTimeCol, endTimeCol, durationCol, resourceCol, spanKindCol, }, PrimaryKeyColumn: nil, Engine: export.ExternalTableEngine, Comment: "read merge data from log, error, span", PathBuilder: export.NewAccountDatePathBuilder(), AccountColumn: nil, SupportUserAccess: false, } )
var EndStatement = func(ctx context.Context, err error) { if !GetTracerProvider().IsEnable() { return } s := StatementFromContext(ctx) if s == nil { panic(moerr.NewInternalError("no statement info in context")) } s.mux.Lock() defer s.mux.Unlock() if !s.end { s.end = true s.ResponseAt = time.Now() s.Duration = s.ResponseAt.Sub(s.RequestAt) s.Status = StatementStatusSuccess if err != nil { s.Error = err s.Status = StatementStatusFailed } if !s.reported || s.exported { s.Report(ctx) } } }
var QuoteFieldFunc = func(buf *bytes.Buffer, value string, enclose rune) string { replaceRules := map[rune]string{ '"': `""`, '\'': `\'`, } quotedClose, hasRule := replaceRules[enclose] if !hasRule { panic(moerr.NewInternalError("not support csv enclose: %c", enclose)) } for _, c := range value { if c == enclose { buf.WriteString(quotedClose) } else { buf.WriteRune(c) } } return value }
var ReportStatement = func(ctx context.Context, s *StatementInfo) error { if !GetTracerProvider().IsEnable() { return nil } return export.GetGlobalBatchProcessor().Collect(ctx, s) }
Functions ¶
func ContextWithSpanContext ¶
func ContextWithSpanContext(parent context.Context, sc SpanContext) context.Context
func ContextWithStatement ¶
func ContextWithStatement(parent context.Context, s *StatementInfo) context.Context
func DefaultContext ¶
func EnableTracer ¶
func EnableTracer(enable bool) tracerProviderOption
func GetSchemaForAccount ¶
GetSchemaForAccount return account's table, and view's schema
func InitSchema ¶
func InitSchema(ctx context.Context, sqlExecutor func() ie.InternalExecutor) error
InitSchema PS: only in standalone or CN node can init schema
func InitSchemaByInnerExecutor ¶
func InitSchemaByInnerExecutor(ctx context.Context, ieFactory func() ie.InternalExecutor) error
InitSchemaByInnerExecutor init schema, which can access db by io.InternalExecutor on any Node.
func IsSpanField ¶
func NewBufferPipe2CSVWorker ¶
func ReportError ¶
ReportError send to BatchProcessor
func SetDefaultContext ¶
func SetDefaultSerializeExecPlan ¶
func SetDefaultSerializeExecPlan(f SerializeExecPlanFunc)
func SetDefaultSpanContext ¶
func SetDefaultSpanContext(sc *SpanContext)
func SetTracerProvider ¶
func SetTracerProvider(p *MOTracerProvider)
func SpanField ¶
func SpanField(sc SpanContext) zap.Field
func WithBatchProcessMode ¶
func WithBatchProcessMode(mode string) tracerProviderOption
func WithExportInterval ¶
func WithExportInterval(secs int) tracerProviderOption
func WithFSWriterFactory ¶
func WithFSWriterFactory(f export.FSWriterFactory) tracerProviderOption
func WithInitAction ¶
func WithInitAction(init bool) tracerProviderOption
func WithLongQueryTime ¶
func WithLongQueryTime(secs float64) tracerProviderOption
func WithMOVersion ¶
func WithMOVersion(v string) tracerProviderOption
func WithNewRoot ¶
func WithNewRoot(newRoot bool) spanOptionFunc
func WithSQLExecutor ¶
func WithSQLExecutor(f func() ie.InternalExecutor) tracerProviderOption
func WithSpanID ¶
func WithSpanID(id SpanID) spanOptionFunc
func WithTraceID ¶
func WithTraceID(id TraceID) spanOptionFunc
Types ¶
type CSVRequest ¶
type CSVRequest struct {
// contains filtered or unexported fields
}
func NewCSVRequest ¶
func NewCSVRequest(writer io.StringWriter, content string) *CSVRequest
func (*CSVRequest) Content ¶
func (r *CSVRequest) Content() string
func (*CSVRequest) Handle ¶
func (r *CSVRequest) Handle() (int, error)
type CSVRequests ¶
type CSVRequests []*CSVRequest
type IBuffer2SqlItem ¶
type IDGenerator ¶
type MOErrorHolder ¶
func (*MOErrorHolder) Free ¶
func (h *MOErrorHolder) Free()
func (*MOErrorHolder) GetName ¶
func (h *MOErrorHolder) GetName() string
func (*MOErrorHolder) GetRow ¶
func (h *MOErrorHolder) GetRow() *export.Row
func (*MOErrorHolder) Size ¶
func (h *MOErrorHolder) Size() int64
type MONodeResource ¶
type MONodeResource struct {
NodeUuid string `json:"node_uuid"`
NodeType string `json:"node_type"`
}
func GetNodeResource ¶
func GetNodeResource() *MONodeResource
type MOSpan ¶
type MOSpan struct {
SpanConfig
Name bytes.Buffer `json:"name"`
StartTime time.Time `json:"start_time"`
EndTime time.Time `jons:"end_time"`
Duration uint64 `json:"duration"`
// contains filtered or unexported fields
}
func (*MOSpan) End ¶
func (s *MOSpan) End(options ...SpanEndOption)
func (*MOSpan) ParentSpanContext ¶
func (s *MOSpan) ParentSpanContext() SpanContext
func (*MOSpan) SpanContext ¶
func (s *MOSpan) SpanContext() SpanContext
type MOTracer ¶
type MOTracer struct {
TracerConfig
// contains filtered or unexported fields
}
MOTracer is the creator of Spans.
type MOTracerProvider ¶
type MOTracerProvider struct {
// contains filtered or unexported fields
}
func GetTracerProvider ¶
func GetTracerProvider() *MOTracerProvider
func (*MOTracerProvider) GetSqlExecutor ¶
func (cfg *MOTracerProvider) GetSqlExecutor() func() ie.InternalExecutor
func (*MOTracerProvider) Tracer ¶
func (p *MOTracerProvider) Tracer(instrumentationName string, opts ...TracerOption) Tracer
type MOZapLog ¶
type MOZapLog struct {
Level zapcore.Level `json:"Level"`
SpanContext *SpanContext `json:"span"`
Timestamp time.Time `json:"timestamp"`
LoggerName string
Caller string `json:"caller"` // like "util/trace/trace.go:666"
Message string `json:"message"`
Extra string `json:"extra"` // like json text
Stack string `json:"stack"`
}
type SerializeExecPlanFunc ¶
type Span ¶
type Span interface {
// End completes the Span. The Span is considered complete and ready to be
// delivered through the rest of the telemetry pipeline after this method
// is called. Therefore, updates to the Span are not allowed after this
// method has been called.
End(options ...SpanEndOption)
// SpanContext returns the SpanContext of the Span. The returned SpanContext
// is usable even after the End method has been called for the Span.
SpanContext() SpanContext
ParentSpanContext() SpanContext
}
func SpanFromContext ¶
type SpanConfig ¶
type SpanConfig struct {
SpanContext
// NewRoot identifies a Span as the root Span for a new trace. This is
// commonly used when an existing trace crosses trust boundaries and the
// remote parent span context should be ignored for security.
NewRoot bool `json:"NewRoot"` // WithNewRoot
// contains filtered or unexported fields
}
SpanConfig is a group of options for a Span.
type SpanContext ¶
type SpanContext struct {
TraceID TraceID `json:"trace_id"`
SpanID SpanID `json:"span_id"`
// Kind default SpanKindInternal
Kind SpanKind `json:"span_kind"`
}
SpanContext contains identifying trace information about a Span.
func DefaultSpanContext ¶
func DefaultSpanContext() *SpanContext
func SpanContextWithID ¶
func SpanContextWithID(id TraceID, kind SpanKind) SpanContext
func SpanContextWithIDs ¶
func SpanContextWithIDs(tid TraceID, sid SpanID) SpanContext
SpanContextWithIDs with default Kind: SpanKindInternal
func (SpanContext) GetIDs ¶
func (c SpanContext) GetIDs() (TraceID, SpanID)
func (*SpanContext) IsEmpty ¶
func (c *SpanContext) IsEmpty() bool
func (*SpanContext) MarshalLogObject ¶
func (c *SpanContext) MarshalLogObject(enc zapcore.ObjectEncoder) error
MarshalLogObject implement zapcore.ObjectMarshaler
func (*SpanContext) Reset ¶
func (c *SpanContext) Reset()
func (*SpanContext) Size ¶
func (c *SpanContext) Size() (n int)
func (*SpanContext) Unmarshal ¶
func (c *SpanContext) Unmarshal(dAtA []byte) error
Unmarshal with default Kind: SpanKindRemote
type SpanEndOption ¶
type SpanEndOption interface {
// contains filtered or unexported methods
}
type SpanKind ¶
type SpanKind int
SpanKind is the role a Span plays in a Trace.
const ( // SpanKindInternal is a SpanKind for a Span that represents an internal // operation within MO. SpanKindInternal SpanKind = 0 // SpanKindStatement is a SpanKind for a Span that represents the operation // belong to statement query SpanKindStatement SpanKind = 1 // SpanKindRemote is a SpanKind for a Span that represents the operation // cross rpc SpanKindRemote SpanKind = 2 )
type SpanOption ¶
type SpanOption interface {
SpanStartOption
SpanEndOption
}
SpanOption applies an option to a SpanConfig.
type SpanProcessor ¶
type SpanProcessor interface {
OnStart(ctx context.Context, s Span)
OnEnd(s Span)
Shutdown(ctx context.Context) error
}
func NewBatchSpanProcessor ¶
func NewBatchSpanProcessor(exporter export.BatchProcessor) SpanProcessor
type SpanStartOption ¶
type SpanStartOption interface {
// contains filtered or unexported methods
}
SpanStartOption applies an option to a SpanConfig. These options are applicable only when the span is created.
type StatementInfo ¶
type StatementInfo struct {
StatementID [16]byte `json:"statement_id"`
TransactionID [16]byte `json:"transaction_id"`
SessionID [16]byte `jons:"session_id"`
Account string `json:"account"`
User string `json:"user"`
Host string `json:"host"`
Database string `json:"database"`
Statement string `json:"statement"`
StatementFingerprint string `json:"statement_fingerprint"`
StatementTag string `json:"statement_tag"`
RequestAt time.Time `json:"request_at"` // see WithRequestAt
// after
Status StatementInfoStatus `json:"status"`
Error error `json:"error"`
ResponseAt time.Time `json:"response_at"`
Duration time.Duration `json:"duration"` // unit: ns
ExecPlan any `json:"exec_plan"`
// RowsRead, BytesScan generated from ExecPlan
RowsRead int64 `json:"rows_read"` // see ExecPlan2Json
BytesScan int64 `json:"bytes_scan"` // see ExecPlan2Json
// SerializeExecPlan
SerializeExecPlan SerializeExecPlanFunc // see SetExecPlan, ExecPlan2Json
// contains filtered or unexported fields
}
func StatementFromContext ¶
func StatementFromContext(ctx context.Context) *StatementInfo
func (*StatementInfo) ExecPlan2Json ¶
func (s *StatementInfo) ExecPlan2Json() string
ExecPlan2Json return ExecPlan Serialized json-str and set RowsRead, BytesScan from ExecPlan
func (*StatementInfo) Free ¶
func (s *StatementInfo) Free()
func (*StatementInfo) GetName ¶
func (s *StatementInfo) GetName() string
func (*StatementInfo) GetRow ¶
func (s *StatementInfo) GetRow() *export.Row
func (*StatementInfo) IsZeroTxnID ¶
func (s *StatementInfo) IsZeroTxnID() bool
func (*StatementInfo) Report ¶
func (s *StatementInfo) Report(ctx context.Context)
func (*StatementInfo) SetExecPlan ¶
func (s *StatementInfo) SetExecPlan(execPlan any, SerializeFunc SerializeExecPlanFunc)
SetExecPlan record execPlan should be TxnComputationWrapper.plan obj, which support 2json.
func (*StatementInfo) SetTxnID ¶
func (s *StatementInfo) SetTxnID(id []byte)
func (*StatementInfo) Size ¶
func (s *StatementInfo) Size() int64
type StatementInfoStatus ¶
type StatementInfoStatus int
const ( StatementStatusRunning StatementInfoStatus = iota StatementStatusSuccess StatementStatusFailed )
func (StatementInfoStatus) String ¶
func (s StatementInfoStatus) String() string
type StatementOption ¶
type StatementOption interface {
Apply(*StatementInfo)
}
type StatementOptionFunc ¶
type StatementOptionFunc func(*StatementInfo)
type TraceFlags ¶
type TraceFlags byte //nolint:revive // revive complains about stutter of `trace.TraceFlags`.
TraceFlags contains flags that can be set on a SpanContext.
func (TraceFlags) IsSampled ¶
func (tf TraceFlags) IsSampled() bool
IsSampled returns if the sampling bit is set in the TraceFlags.
func (TraceFlags) String ¶
func (tf TraceFlags) String() string
String returns the hex string representation form of TraceFlags.
func (TraceFlags) WithSampled ¶
func (tf TraceFlags) WithSampled(sampled bool) TraceFlags
WithSampled sets the sampling bit in a new copy of the TraceFlags.
type TraceID ¶
type TraceID [16]byte
type Tracer ¶
type Tracer interface {
// Start creates a span and a context.Context containing the newly-created span.
Start(ctx context.Context, spanName string, opts ...SpanOption) (context.Context, Span)
// Debug creates a span only with DebugMode
Debug(ctx context.Context, spanName string, opts ...SpanOption) (context.Context, Span)
}
type TracerConfig ¶
type TracerConfig struct {
Name string
}
TracerConfig is a group of options for a Tracer.
type TracerOption ¶
type TracerOption interface {
// contains filtered or unexported methods
}
TracerOption applies an option to a TracerConfig.
type TracerProvider ¶
type TracerProvider interface {
Tracer(instrumentationName string, opts ...TracerOption) Tracer
}
type TracerProviderOption ¶
type TracerProviderOption interface {
// contains filtered or unexported methods
}
TracerProviderOption configures a TracerProvider.