trace

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Dec 29, 2023 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	FlagProfileGoroutine = 1 << iota
	FlagProfileHeap
	FlagProfileCpu
)
View Source
const (
	ProfileFlagGoroutine = 1 << iota
	ProfileFlagThreadcreate
	ProfileFlagHeap
	ProfileFlagAllocs
	ProfileFlagBlock
	ProfileFlagMutex
	ProfileFlagCpu
	ProfileFlagTrace
	ProfileFlagSystemStatus
)
View Source
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)
)
View Source
const NodeTypeStandalone = "Standalone"
View Source
const SpanFieldKey = "span"

Variables

View Source
var MOCtledSpanEnableConfig struct {
	sync.Mutex
	NameToKind  map[string]SpanKind
	KindToState map[SpanKind]*MoCtledState
}

Functions

func ContextField

func ContextField(ctx context.Context) zap.Field

func ContextWithSpan

func ContextWithSpan(parent context.Context, span Span) context.Context

func ContextWithSpanContext

func ContextWithSpanContext(parent context.Context, sc SpanContext) context.Context

func Generate added in v0.7.0

func Generate(ctx context.Context) 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

func IsMOCtledSpan(kind SpanKind) (exist bool, enable bool, threshold time.Duration)

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 IsSpanField(field zapcore.Field) bool

func SetDefaultTracer added in v0.7.0

func SetDefaultTracer(tracer Tracer)

func SetMoCtledSpanState added in v1.0.0

func SetMoCtledSpanState(name string, enable bool, threshold int64) (succeed bool)

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 WithKind added in v0.7.0

func WithKind(kind SpanKind) spanOptionFunc

func WithNewRoot

func WithNewRoot(newRoot bool) spanOptionFunc

Types

type IDGenerator

type IDGenerator interface {
	NewIDs() (TraceID, SpanID)
	NewSpanID() SpanID
}

type ITracerHolder added in v0.8.0

type ITracerHolder interface {
	GetTracer() Tracer
}

type MONodeResource

type MONodeResource struct {
	NodeUuid string `json:"node_uuid"`
	NodeType string `json:"node_type"`
}

type MoCtledState added in v1.0.0

type MoCtledState struct {
	Enable    bool
	Threshold time.Duration
}

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) AddExtraFields(...zap.Field)

func (NoopSpan) End added in v0.7.0

func (NoopSpan) End(...SpanEndOption)

End does nothing.

func (NoopSpan) ParentSpanContext added in v0.7.0

func (NoopSpan) ParentSpanContext() SpanContext

func (NoopSpan) SetName added in v0.7.0

func (NoopSpan) SetName(string)

SetName does nothing.

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

func (*Resource) Get

func (r *Resource) Get(key string) (any, bool)

func (*Resource) Put

func (r *Resource) Put(key string, val any)

func (*Resource) String

func (r *Resource) String() string

String need to improve

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 Debug

func Debug(ctx context.Context, spanName string, opts ...SpanStartOption) (context.Context, Span)

func SpanFromContext

func SpanFromContext(ctx context.Context) Span

func Start

func Start(ctx context.Context, spanName string, opts ...SpanStartOption) (context.Context, Span)

Start starts a default span entity

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:"-"`

	// ProfileSystemStatusFn is used to get status information.
	ProfileSystemStatusFn func() ([]byte, error)
	// 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) ProfileSystemStatus added in v1.1.0

func (c *SpanConfig) ProfileSystemStatus() bool

ProfileSystemStatus return the value set by WithProfileSystemStatus.

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) MarshalTo

func (c *SpanContext) MarshalTo(dAtA []byte) (int, error)

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

func WithStatementExtra(txnID uuid.UUID, stmID uuid.UUID, stm string) SpanEndOption

type SpanID

type SpanID [8]byte
var NilSpanID SpanID

func (*SpanID) IsZero

func (s *SpanID) IsZero() bool

func (*SpanID) SetByUUID

func (s *SpanID) SetByUUID(id string)

SetByUUID use prefix of uuid as value

func (SpanID) String

func (s SpanID) String() string

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
)

func (SpanKind) String

func (k SpanKind) String() string

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
}

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 WithProfileSystemStatus added in v1.1.0

func WithProfileSystemStatus(f func() ([]byte, error)) SpanStartOption

WithProfileSystemStatus requests dump system status. It will trigger SystemStatus() 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

func (TraceID) IsZero

func (t TraceID) IsZero() bool

IsZero checks whether the trace TraceID is 0 value.

func (TraceID) String

func (t TraceID) String() string

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
}

Directories

Path Synopsis
impl

Jump to

Keyboard shortcuts

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