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 Generate(ctx context.Context) context.Context
- func InitMOCtledSpan()
- func IsEnable(opts ...SpanStartOption) bool
- func IsMOCtledSpan(kind SpanKind) (exist bool, enable bool, threshold time.Duration)
- func IsSpanField(field zapcore.Field) bool
- func SetDefaultTracer(tracer Tracer)
- func SetMoCtledSpanState(name string, enable bool, threshold int64) (succeed bool)
- func SpanField(sc SpanContext) zap.Field
- func WithKind(kind SpanKind) spanOptionFunc
- func WithNewRoot(newRoot bool) spanOptionFunc
- type IDGenerator
- type ITracerHolder
- type MONodeResource
- type MoCtledState
- type NonRecordingSpan
- type NoopSpan
- type NoopTracer
- type Resource
- type Span
- type SpanConfig
- func (c *SpanConfig) GetLongTimeThreshold() time.Duration
- func (c *SpanConfig) HungThreshold() time.Duration
- func (c *SpanConfig) NeedProfile() bool
- func (c *SpanConfig) ProfileAllocs() bool
- func (c *SpanConfig) ProfileBlock() bool
- func (c *SpanConfig) ProfileCpuSecs() time.Duration
- func (c *SpanConfig) ProfileGoroutine() bool
- func (c *SpanConfig) ProfileHeap() bool
- func (c *SpanConfig) ProfileMutex() bool
- func (c *SpanConfig) ProfileThreadCreate() bool
- func (c *SpanConfig) ProfileTraceSecs() time.Duration
- func (c *SpanConfig) Reset()
- type SpanContext
- func (c *SpanContext) Clone() (sc 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
- func WithHungThreshold(d time.Duration) SpanStartOption
- func WithLongTimeThreshold(d time.Duration) SpanStartOption
- func WithProfileAllocs() SpanStartOption
- func WithProfileBlock() SpanStartOption
- func WithProfileCpuSecs(d time.Duration) SpanStartOption
- func WithProfileGoroutine() SpanStartOption
- func WithProfileHeap() SpanStartOption
- func WithProfileMutex() SpanStartOption
- func WithProfileThreadCreate() SpanStartOption
- func WithProfileTraceSecs(d time.Duration) SpanStartOption
- type TraceFlags
- type TraceID
- type Tracer
- type TracerConfig
- type TracerOption
- type TracerProvider
Constants ¶
const ( FlagProfileGoroutine = 1 << iota FlagProfileHeap FlagProfileCpu )
const ( ProfileFlagGoroutine = 1 << iota ProfileFlagThreadcreate ProfileFlagHeap ProfileFlagAllocs ProfileFlagBlock ProfileFlagMutex ProfileFlagCpu ProfileFlagTrace )
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 MOCtledSpanEnableConfig struct { sync.Mutex NameToKind map[string]SpanKind KindToState map[SpanKind]*MoCtledState }
Functions ¶
func ContextWithSpanContext ¶
func ContextWithSpanContext(parent context.Context, sc SpanContext) context.Context
func InitMOCtledSpan ¶ added in v1.0.0
func InitMOCtledSpan()
InitMOCtledSpan registers all mo_ctl controlled span
func IsEnable ¶ added in v0.7.0
func IsEnable(opts ...SpanStartOption) bool
func IsMOCtledSpan ¶ added in v1.0.0
IsMOCtledSpan first checks if this kind exists in mo_ctl controlled spans, if it is, return it's current state, or return not exist
func IsSpanField ¶
func SetDefaultTracer ¶ added in v0.7.0
func SetDefaultTracer(tracer Tracer)
func SetMoCtledSpanState ¶ added in v1.0.0
SetMoCtledSpanState first checks if this kind exists in mo_ctl controlled spans, if it is, reset it's state to the specified and return succeed, or return not succeed
func SpanField ¶
func SpanField(sc SpanContext) zap.Field
func WithNewRoot ¶
func WithNewRoot(newRoot bool) spanOptionFunc
Types ¶
type IDGenerator ¶
type ITracerHolder ¶ added in v0.8.0
type ITracerHolder interface {
GetTracer() Tracer
}
type MONodeResource ¶
type MoCtledState ¶ added in v1.0.0
type NonRecordingSpan ¶ added in v0.7.0
type NonRecordingSpan struct { NoopSpan // contains filtered or unexported fields }
NonRecordingSpan keep SpanContext{TraceID, SpanID}
func (*NonRecordingSpan) ParentSpanContext ¶ added in v0.7.0
func (s *NonRecordingSpan) ParentSpanContext() SpanContext
func (*NonRecordingSpan) SpanContext ¶ added in v0.7.0
func (s *NonRecordingSpan) SpanContext() SpanContext
type NoopSpan ¶ added in v0.7.0
type NoopSpan struct{}
NoopSpan is an implementation of Span that preforms no operations.
func (NoopSpan) AddExtraFields ¶ added in v0.8.0
func (NoopSpan) ParentSpanContext ¶ added in v0.7.0
func (NoopSpan) ParentSpanContext() SpanContext
func (NoopSpan) SpanContext ¶ added in v0.7.0
func (NoopSpan) SpanContext() SpanContext
SpanContext returns an empty span context.
func (NoopSpan) TracerProvider ¶ added in v0.7.0
func (NoopSpan) TracerProvider() TracerProvider
TracerProvider returns a no-op TracerProvider.
type NoopTracer ¶ added in v0.7.0
type NoopTracer struct{}
NoopTracer is an implementation of Tracer that preforms no operations.
func (NoopTracer) Debug ¶ added in v0.7.0
func (t NoopTracer) Debug(ctx context.Context, name string, opts ...SpanStartOption) (context.Context, Span)
func (NoopTracer) IsEnable ¶ added in v0.7.0
func (t NoopTracer) IsEnable(opts ...SpanStartOption) bool
func (NoopTracer) Start ¶ added in v0.7.0
func (t NoopTracer) Start(ctx context.Context, name string, opts ...SpanStartOption) (context.Context, Span)
Start carries forward a non-recording Span, if one is present in the context, otherwise it creates a no-op Span.
type Resource ¶
type Resource struct {
// contains filtered or unexported fields
}
func NewResource ¶ added in v0.7.0
func NewResource() *Resource
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) // AddExtraFields inject more details for span. AddExtraFields(fields ...zap.Field) // 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 Parent Span `json:"-"` // LongTimeThreshold set by WithLongTimeThreshold LongTimeThreshold time.Duration `json:"-"` Extra []zap.Field `json:"-"` // contains filtered or unexported fields }
SpanConfig is a group of options for a Span.
func (*SpanConfig) GetLongTimeThreshold ¶ added in v0.8.0
func (c *SpanConfig) GetLongTimeThreshold() time.Duration
func (*SpanConfig) HungThreshold ¶ added in v1.0.0
func (c *SpanConfig) HungThreshold() time.Duration
func (*SpanConfig) NeedProfile ¶ added in v1.0.0
func (c *SpanConfig) NeedProfile() bool
NeedProfile return true if set profileGoroutine, profileHeap, profileCpuDur
func (*SpanConfig) ProfileAllocs ¶ added in v1.0.0
func (c *SpanConfig) ProfileAllocs() bool
func (*SpanConfig) ProfileBlock ¶ added in v1.0.0
func (c *SpanConfig) ProfileBlock() bool
func (*SpanConfig) ProfileCpuSecs ¶ added in v0.8.0
func (c *SpanConfig) ProfileCpuSecs() time.Duration
ProfileCpuSecs return the value set by WithProfileCpuSecs
func (*SpanConfig) ProfileGoroutine ¶ added in v0.8.0
func (c *SpanConfig) ProfileGoroutine() bool
ProfileGoroutine return the value set by WithProfileGoroutine
func (*SpanConfig) ProfileHeap ¶ added in v0.8.0
func (c *SpanConfig) ProfileHeap() bool
ProfileHeap return the value set by WithProfileHeap
func (*SpanConfig) ProfileMutex ¶ added in v1.0.0
func (c *SpanConfig) ProfileMutex() bool
func (*SpanConfig) ProfileThreadCreate ¶ added in v1.0.0
func (c *SpanConfig) ProfileThreadCreate() bool
func (*SpanConfig) ProfileTraceSecs ¶ added in v1.0.0
func (c *SpanConfig) ProfileTraceSecs() time.Duration
ProfileTraceSecs return the value set by WithProfileTraceSecs
func (*SpanConfig) Reset ¶ added in v0.8.0
func (c *SpanConfig) Reset()
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 SpanContextWithID ¶
func SpanContextWithID(id TraceID, kind SpanKind) SpanContext
func SpanContextWithIDs ¶
func SpanContextWithIDs(tid TraceID, sid SpanID) SpanContext
SpanContextWithIDs with default Kind: SpanKindInternal
func (*SpanContext) Clone ¶ added in v1.1.0
func (c *SpanContext) Clone() (sc SpanContext)
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 {
ApplySpanEnd(*SpanConfig)
}
func WithFSReadWriteExtra ¶ added in v1.0.0
func WithFSReadWriteExtra(fileName string, status error, size int64) SpanEndOption
func WithStatementExtra ¶ added in v1.0.0
type SpanID ¶
type SpanID [8]byte
var NilSpanID SpanID
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 // SpanKindSession is a SpanKind for a Span that represents the operation // start from session SpanKindSession SpanKind = 3 // SpanKindRemoteFSVis is a SpanKind for a Span that needs to collect info of // remote object operation SpanKindRemoteFSVis SpanKind = 4 // SpanKindLocalFSVis is a SpanKind for a Span that needs to collect info of // local object operation SpanKindLocalFSVis SpanKind = 5 // SpanKindTNRPCHandle is a SpanKind for TN service to control // the enable or disable of debug logs recording when it handles the RPC requests, like HandleCommit. // not for trace or span for now SpanKindTNRPCHandle SpanKind = 6 )
type SpanOption ¶
type SpanOption interface { SpanStartOption SpanEndOption }
SpanOption applies an option to a SpanConfig.
type SpanProcessor ¶
type SpanStartOption ¶
type SpanStartOption interface {
ApplySpanStart(*SpanConfig)
}
SpanStartOption applies an option to a SpanConfig. These options are applicable only when the span is created.
func WithHungThreshold ¶ added in v1.0.0
func WithHungThreshold(d time.Duration) SpanStartOption
WithHungThreshold please be careful to using this option. It will create a new goroutine to check hung deadline while calling Tracer.Start().
func WithLongTimeThreshold ¶ added in v0.8.0
func WithLongTimeThreshold(d time.Duration) SpanStartOption
WithLongTimeThreshold set timeout threshold. Span.End will check the Span duration value.
func WithProfileAllocs ¶ added in v1.0.0
func WithProfileAllocs() SpanStartOption
WithProfileAllocs requests dump pprof/allocs. It will trigger profile.ProfileAllocs() in Span.End(). more details in MOSpan.doProfile.
func WithProfileBlock ¶ added in v1.0.0
func WithProfileBlock() SpanStartOption
WithProfileBlock requests dump pprof/block. It will trigger profile.ProfileBlock() in Span.End(). More details in MOSpan.doProfile.
func WithProfileCpuSecs ¶ added in v0.8.0
func WithProfileCpuSecs(d time.Duration) SpanStartOption
WithProfileCpuSecs requests dump pprof/cpu, and specify the time to profile. Please carefully to set this value, it is a sync profile.ProfileCPU() op. More details in MOSpan.doProfile.
func WithProfileGoroutine ¶ added in v0.8.0
func WithProfileGoroutine() SpanStartOption
WithProfileGoroutine requests dump pprof/mutex. It will trigger profile.ProfileGoroutine() in Span.End(). More details in MOSpan.doProfile.
func WithProfileHeap ¶ added in v0.8.0
func WithProfileHeap() SpanStartOption
WithProfileHeap requests dump pprof/heap. It will trigger profile.ProfileHeap() in Span.End(). More details in MOSpan.doProfile.
func WithProfileMutex ¶ added in v1.0.0
func WithProfileMutex() SpanStartOption
WithProfileMutex requests dump pprof/mutex. It will trigger profile.ProfileMutex() in Span.End(). More details in MOSpan.doProfile.
func WithProfileThreadCreate ¶ added in v1.0.0
func WithProfileThreadCreate() SpanStartOption
WithProfileThreadCreate requests dump pprof/threadcreate. It will trigger profile.ProfileThreadcreate() in Span.End(). More details in MOSpan.doProfile.
func WithProfileTraceSecs ¶ added in v1.0.0
func WithProfileTraceSecs(d time.Duration) SpanStartOption
WithProfileTraceSecs requests dump pprof/trace, and specify the time to profile. Please carefully to use, it is a sync profile.ProfileTrace() op More details in MOSpan.doProfile.
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
var NilTraceID TraceID
type Tracer ¶
type Tracer interface { // Start creates a span and a context.Context containing the newly-created span. // // If the context.Context provided in `ctx` contains a Span then the newly-created // Span will be a child of that span, otherwise it will be a root span. This behavior // can be overridden by providing `WithNewRoot()` as a SpanOption, causing the // newly-created Span to be a root span even if `ctx` contains a Span. // // Any Span that is created MUST also be ended. This is the responsibility of the user. // Implementations of this API may leak memory or other resources if Spans are not ended. Start(ctx context.Context, spanName string, opts ...SpanStartOption) (context.Context, Span) // Debug creates a span only with DebugMode Debug(ctx context.Context, spanName string, opts ...SpanStartOption) (context.Context, Span) // IsEnable return true, means do record IsEnable(opts ...SpanStartOption) bool }
func DefaultTracer ¶ added in v0.7.0
func DefaultTracer() Tracer
type TracerConfig ¶
type TracerConfig struct {
Name string
}
TracerConfig is a group of options for a Tracer.
type TracerOption ¶
type TracerOption interface {
Apply(*TracerConfig)
}
TracerOption applies an option to a TracerConfig.
type TracerProvider ¶
type TracerProvider interface {
Tracer(instrumentationName string, opts ...TracerOption) Tracer
}