aitracer

package
v1.3.11 Latest Latest
Warning

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

Go to latest
Published: Oct 21, 2022 License: Apache-2.0 Imports: 30 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Web      = "web"
	Http     = "http"
	RPC      = "rpc"
	GRPC     = "grpc"
	Consumer = "consumer"

	MySQL   = "mysql"
	Redis   = "redis"
	Kafka   = "kafka"
	Mongodb = "mongodb"
)
View Source
const (
	LogLevelTrace  = "trace"
	LogLevelDebug  = "debug"
	LogLevelInfo   = "info"
	LogLevelNotice = "notice"
	LogLevelWarn   = "warn"
	LogLevelError  = "error"
	LogLevelFatal  = "fatal"
)

log level

View Source
const (
	HttpScheme     = "http.scheme"
	HttpMethod     = "http.method"
	HttpHost       = "http.host"
	HttpPath       = "http.path"
	HttpStatusCode = "http.status_code"
)

http field

View Source
const (
	StatusCodeOK    = 0
	StatusCodeError = 1
)
View Source
const (
	DbStatement = "db.statement"
)

Variables

View Source
var (
	ErrUnsupportedFormat = errors.New("Unknown or unsupported Inject/Extract format")
	ErrInvalidCarrier    = errors.New("Invalid Inject/Extract carrier")
)

Functions

func ContextWithSpan

func ContextWithSpan(ctx context.Context, sc Span) context.Context

func InitGlobalTracer

func InitGlobalTracer(tracer Tracer)

func Inject

func Inject(sc SpanContext, format interface{}, carrier interface{}) error

func IsGlobalTracerRegistered

func IsGlobalTracerRegistered() bool

func Log

func Log(ctx context.Context, data LogData)

func SetGlobalTracer

func SetGlobalTracer(tracer Tracer)

Types

type BinaryCarrier added in v1.3.2

type BinaryCarrier = *bytes.Buffer

type BinaryCarrierExtractor added in v1.3.2

type BinaryCarrierExtractor struct{}

func (*BinaryCarrierExtractor) Extract added in v1.3.2

func (e *BinaryCarrierExtractor) Extract(carrier interface{}) (SpanContext, error)

type BinaryCarrierInjector added in v1.3.2

type BinaryCarrierInjector struct{}

func (*BinaryCarrierInjector) Inject added in v1.3.2

func (i *BinaryCarrierInjector) Inject(sc SpanContext, carrier interface{}) error

type BinaryExtractSpanContext added in v1.3.2

type BinaryExtractSpanContext struct {
	// contains filtered or unexported fields
}

func (*BinaryExtractSpanContext) ClientSampled added in v1.3.4

func (sc *BinaryExtractSpanContext) ClientSampled() bool

func (*BinaryExtractSpanContext) ForeachBaggageItem added in v1.3.2

func (sc *BinaryExtractSpanContext) ForeachBaggageItem(f func(string, string) bool)

func (*BinaryExtractSpanContext) Sample added in v1.3.2

func (*BinaryExtractSpanContext) SampleFlags added in v1.3.4

func (sc *BinaryExtractSpanContext) SampleFlags() SampleFlags

func (*BinaryExtractSpanContext) SpanID added in v1.3.2

func (sc *BinaryExtractSpanContext) SpanID() string

func (*BinaryExtractSpanContext) TraceID added in v1.3.2

func (sc *BinaryExtractSpanContext) TraceID() string

type BuiltinFormat

type BuiltinFormat byte
const (
	HTTPHeaders BuiltinFormat = iota
	Binary
)

type ErrorInfo added in v1.2.0

type ErrorInfo struct {
	ErrorKind              ErrorKind
	ErrorMessage           string
	ErrorStack             []string
	ErrorOccurTimeMilliSec int64
	ErrorTags              map[string]string
}

type ErrorKind added in v1.2.0

type ErrorKind int32
const (
	ErrorKindDbError ErrorKind = iota
	ErrorKindExternalServiceError
	ErrorKindHttpCodeError
	ErrorKindNoSqlError
	ErrorKindMqError
	ErrorKindUncaughtException
	ErrorKindBusinessError
	ErrorKindPanic
)

type Extractor

type Extractor interface {
	Extract(carrier interface{}) (SpanContext, error)
}

type FinishSpanOption

type FinishSpanOption struct {
	FinishTime          time.Time
	Status              int64
	DisablePanicCapture bool // By default panic is captured, set True to disable
}

type HTTPHeaderExtractSpanContext

type HTTPHeaderExtractSpanContext struct {
	// contains filtered or unexported fields
}

func (*HTTPHeaderExtractSpanContext) ClientSampled added in v1.3.4

func (sc *HTTPHeaderExtractSpanContext) ClientSampled() bool

func (*HTTPHeaderExtractSpanContext) ForeachBaggageItem

func (sc *HTTPHeaderExtractSpanContext) ForeachBaggageItem(h func(string, string) bool)

func (*HTTPHeaderExtractSpanContext) Sample

func (*HTTPHeaderExtractSpanContext) SampleFlags added in v1.3.4

func (sc *HTTPHeaderExtractSpanContext) SampleFlags() SampleFlags

func (*HTTPHeaderExtractSpanContext) SpanID

func (sc *HTTPHeaderExtractSpanContext) SpanID() string

func (*HTTPHeaderExtractSpanContext) TraceID

func (sc *HTTPHeaderExtractSpanContext) TraceID() string

type HTTPHeadersCarrier

type HTTPHeadersCarrier http.Header

func (HTTPHeadersCarrier) ForeachKey

func (c HTTPHeadersCarrier) ForeachKey(handler func(key, val string) error) error

func (HTTPHeadersCarrier) Set

func (c HTTPHeadersCarrier) Set(key, val string)

type HTTPHeadersExtractor

type HTTPHeadersExtractor struct {
}

func (*HTTPHeadersExtractor) Extract

func (extractor *HTTPHeadersExtractor) Extract(carrier interface{}) (SpanContext, error)

type HTTPHeadersInjector

type HTTPHeadersInjector struct {
}

func (*HTTPHeadersInjector) Inject

func (injector *HTTPHeadersInjector) Inject(sc SpanContext, carrier interface{}) error

type Injector

type Injector interface {
	Inject(sc SpanContext, carrier interface{}) error
}

type LogData

type LogData struct {
	Message   []byte
	Timestamp time.Time
	FileName  string
	FileLine  int64
	LogLevel  string
	Source    string
}

type PropagatorConfig

type PropagatorConfig struct {
	Format    interface{}
	Injector  Injector
	Extractor Extractor
}

type RecordConfig added in v1.2.0

type RecordConfig struct {
	ErrorKind   ErrorKind
	RecordStack bool   // record stack is expensive and is disabled by default
	Stack       string // stack passed in. which is useful where RecordError being called is different from error occurred
}

func NewDefaultRecordConfig added in v1.2.0

func NewDefaultRecordConfig() RecordConfig

type RecordOption added in v1.2.0

type RecordOption func(*RecordConfig)

func WithErrorKind added in v1.2.0

func WithErrorKind(t ErrorKind) RecordOption

func WithRecordStack added in v1.2.0

func WithRecordStack(b bool) RecordOption

func WithStack added in v1.3.2

func WithStack(stack string) RecordOption

type SampleFlags added in v1.3.4

type SampleFlags int32

SampleFlags intersects with other tracing systems, should be explicitly defined.

const (
	SampleFlagsUnknown                SampleFlags = -1 // SampleFlags is determined by SampleStrategy and clientSampled
	SampleFlagsNotSampled             SampleFlags = 0
	SampleFlagsClientSampled          SampleFlags = 1
	SampleFlagsServerSampled          SampleFlags = 2
	SampleFlagsClientAndServerSampled SampleFlags = 3
)

func SampleFlagsFromInt32 added in v1.3.4

func SampleFlagsFromInt32(flag int32) SampleFlags

func (SampleFlags) Sampled added in v1.3.4

func (s SampleFlags) Sampled() bool

func (SampleFlags) ToString added in v1.3.4

func (s SampleFlags) ToString() string

type SampleStrategy

type SampleStrategy byte
const (
	SampleStrategyUnknown SampleStrategy = iota
	SampleStrategyNotSampled
	SampleStrategySampled
)

type Span

type Span interface {
	Finish()
	FinishWithOption(opt FinishSpanOption)
	Context() SpanContext

	SetBaggageItem(restrictedKey, value string) Span
	BaggageItem(restrictedKey string) string

	SetTag(key string, value interface{}) Span
	SetTagString(key string, value string) Span
	SetTagFloat64(key string, value float64) Span
	SetTagInt64(key string, value int64) Span

	RecordError(err error, opt ...RecordOption)
	SetStatus(status int64)
}

func GetSpanFromContext

func GetSpanFromContext(ctx context.Context) Span

Deprecated. use aitracer.GetSpanFromContext instead

func StartClientSpan

func StartClientSpan(operationName string, opts ...StartSpanOption) Span

func StartClientSpanFromContext

func StartClientSpanFromContext(ctx context.Context, operationName string, opts ...StartSpanOption) (Span, context.Context)

func StartServerSpan

func StartServerSpan(operationName string, opts ...StartSpanOption) Span

func StartServerSpanFromContext

func StartServerSpanFromContext(ctx context.Context, operationName string, opts ...StartSpanOption) (Span, context.Context)

func StartSpan

func StartSpan(operationName string, opts ...StartSpanOption) Span

func StartSpanFromContext

func StartSpanFromContext(ctx context.Context, operationName string, opts ...StartSpanOption) (Span, context.Context)

type SpanContext

type SpanContext interface {
	TraceID() string
	SpanID() string
	Sample() (strategy SampleStrategy, weight int)
	ClientSampled() bool
	SampleFlags() SampleFlags
	ForeachBaggageItem(func(string, string) bool)
}

func Extract

func Extract(format interface{}, carrier interface{}) (SpanContext, error)

type StartSpanConfig

type StartSpanConfig struct {
	ServerResource string

	ClientResource    string
	ClientService     string
	ClientServiceType string
	// contains filtered or unexported fields
}

type StartSpanOption

type StartSpanOption func(*StartSpanConfig)

func ChildOf

func ChildOf(sc SpanContext) StartSpanOption

func ClientResourceAs

func ClientResourceAs(clientServiceType string, clientService string, clientResource string) StartSpanOption

func ServerResourceAs

func ServerResourceAs(resource string) StartSpanOption

type Tracer

type Tracer interface {
	Start()
	Extract(format interface{}, carrier interface{}) (SpanContext, error)
	Inject(sc SpanContext, format interface{}, carrier interface{}) error

	StartServerSpan(operationName string, opts ...StartSpanOption) Span
	StartServerSpanFromContext(ctx context.Context, operationName string, opts ...StartSpanOption) (Span, context.Context)

	StartClientSpan(operationName string, opts ...StartSpanOption) Span
	StartClientSpanFromContext(ctx context.Context, operationName string, opts ...StartSpanOption) (Span, context.Context)

	StartSpan(operationName string, opts ...StartSpanOption) Span
	StartSpanFromContext(ctx context.Context, operationName string, opts ...StartSpanOption) (Span, context.Context)

	Log(ctx context.Context, data LogData)
	Stop()
}

func GlobalTracer

func GlobalTracer() Tracer

func NewTracer

func NewTracer(serviceType, service string, opts ...TracerOption) Tracer

type TracerConfig

type TracerConfig struct {
	ServiceType string
	Service     string

	SenderChanSize int
	SenderSock     string
	SenderNumber   int

	Logger logger.Logger

	EnableMetric bool
	MetricSock   string

	EnableLogSender bool
	LogSenderDebug  bool // for safety, can not use incoming logger.Logger in LogCollector

	LogSenderSock     string
	LogSenderNumber   int
	LogSenderChanSize int

	EnableRuntimeMetric bool

	SettingsFetcherSock string

	PropagatorConfigs []PropagatorConfig

	ServerRegisterSock string

	ContextAdapter func(context.Context) context.Context
}

type TracerOption

type TracerOption func(*TracerConfig)

func WithContextAdapter added in v1.1.1

func WithContextAdapter(contextAdapter func(context.Context) context.Context) TracerOption

func WithLogSender

func WithLogSender(enable bool) TracerOption

func WithLogSenderDebug added in v1.3.9

func WithLogSenderDebug(enable bool) TracerOption

func WithLogger

func WithLogger(logger logger.Logger) TracerOption

func WithMetrics

func WithMetrics(enable bool) TracerOption

func WithMetricsAddress

func WithMetricsAddress(metricAddress string) TracerOption

func WithPropagator

func WithPropagator(format interface{}, injector Injector, extractor Extractor) TracerOption

func WithRuntimeMetric added in v1.3.0

func WithRuntimeMetric(enable bool) TracerOption

func WithSenderChanSize

func WithSenderChanSize(chanSize int) TracerOption

func WithSenderNumber

func WithSenderNumber(senderNumber int) TracerOption

func WithSenderSock

func WithSenderSock(senderSock string) TracerOption

func WithService

func WithService(serviceType string, service string) TracerOption

Jump to

Keyboard shortcuts

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