trace

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Feb 18, 2023 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

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

This section is empty.

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

func IsEnable() bool

func IsSpanField

func IsSpanField(field zapcore.Field) bool

func SetDefaultTracer added in v0.7.0

func SetDefaultTracer(tracer Tracer)

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 MONodeResource

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

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) 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 ...SpanOption) (context.Context, Span)

func (NoopTracer) IsEnable added in v0.7.0

func (t NoopTracer) IsEnable() bool

func (NoopTracer) Start added in v0.7.0

func (t NoopTracer) Start(ctx context.Context, name string, _ ...SpanOption) (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)

	// 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 ...SpanOption) (context.Context, Span)

func SpanFromContext

func SpanFromContext(ctx context.Context) Span

func Start

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

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

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

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
)

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.

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.
	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)
	// IsEnable return true, means do record
	IsEnable() 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