go4sky

package module
v1.1.5 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2022 License: Apache-2.0 Imports: 22 Imported by: 3

README

go4sky

go4sky

Documentation

Overview

Package go4sky implements a native Apache SkyWalking agent library for Go.

See http://skywalking.apache.org/ for more information about Apache SkyWalking.

Index

Constants

View Source
const (
	InstanceGolangHeap         = "instance_golang_heap_alloc"
	InstanceGolangStack        = "instance_golang_stack_used"
	InstanceGolangGCTime       = "instance_golang_gc_pause_time"
	InstanceGolangGCCount      = "instance_golang_gc_count"
	InstanceGolangThreadNum    = "instance_golang_os_threads_num"
	InstanceGolangGoroutineNum = "instance_golang_live_goroutines_num"
	InstanceCPUUsedRate        = "instance_host_cpu_used_rate"
	InstanceMemUsedRate        = "instance_host_mem_used_rate"
)
View Source
const (
	EmptyServiceName         = ""
	EmptyServiceInstanceName = ""
	EmptyTraceID             = "N/A"
	EmptyTraceSegmentID      = "N/A"
	EmptySpanID              = -1
)
View Source
const (
	ComponentIDHttpServer int32 = 49
)

Variables

This section is empty.

Functions

func GetCorrelation

func GetCorrelation(ctx context.Context, key string) string

func InitMetricCollector

func InitMetricCollector(reporter MetricsReporter, interval *time.Duration, cancelCtx context.Context)

func PutCorrelation

func PutCorrelation(ctx context.Context, key, value string) bool

func ServiceInstanceName

func ServiceInstanceName(ctx context.Context) string

func ServiceName

func ServiceName(ctx context.Context) string

func SetGlobalTracer

func SetGlobalTracer(tracer *Tracer)

SetGlobalTracer registers `tracer` as the global Tracer.

func SpanID

func SpanID(ctx context.Context) int32

func TraceID

func TraceID(ctx context.Context) string

func TraceSegmentID

func TraceSegmentID(ctx context.Context) string

func WithSpan

func WithSpan(ctx context.Context, span Span) context.Context

Types

type AgentConfigChangeWatcher

type AgentConfigChangeWatcher interface {
	Key() string
	Notify(eventType AgentConfigEventType, newValue string)
	Value() string
}

type AgentConfigEventType

type AgentConfigEventType int32
const (
	MODIFY AgentConfigEventType = iota
	DELETED
)

type ConfigDiscoveryService

type ConfigDiscoveryService struct {
	UUID string
	// contains filtered or unexported fields
}

func NewConfigDiscoveryService

func NewConfigDiscoveryService() *ConfigDiscoveryService

func (*ConfigDiscoveryService) BindWatchers

func (s *ConfigDiscoveryService) BindWatchers(watchers []AgentConfigChangeWatcher)

func (*ConfigDiscoveryService) HandleCommand

func (s *ConfigDiscoveryService) HandleCommand(command *common.Command)

type ConstSampler

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

func NewConstSampler

func NewConstSampler(sample bool) *ConstSampler

NewConstSampler creates a ConstSampler.

func (*ConstSampler) IsSampled

func (s *ConstSampler) IsSampled(operation string) bool

IsSampled implements IsSampled() of Sampler.

type CorrelationConfig

type CorrelationConfig struct {
	MaxKeyCount  int
	MaxValueSize int
}

type DefaultLogData

type DefaultLogData struct {
	LogCtx      context.Context
	LogErrLevel string
	LogContent  string
}

func (*DefaultLogData) Context

func (l *DefaultLogData) Context() context.Context

func (*DefaultLogData) Data

func (l *DefaultLogData) Data() string

func (*DefaultLogData) ErrorLevel

func (l *DefaultLogData) ErrorLevel() string

type DynamicSampler

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

func NewDynamicSampler

func NewDynamicSampler(samplingRate float64, tracer *Tracer) *DynamicSampler

func (*DynamicSampler) IsSampled

func (s *DynamicSampler) IsSampled(operation string) bool

IsSampled implements IsSampled() of Sampler.

func (*DynamicSampler) Key

func (s *DynamicSampler) Key() string

func (*DynamicSampler) Notify

func (s *DynamicSampler) Notify(eventType AgentConfigEventType, newValue string)

func (*DynamicSampler) Value

func (s *DynamicSampler) Value() string

type MetricCollector

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

type MetricsReporter

type MetricsReporter interface {
	SendMetrics(runTimeMeter RunTimeMetric)
}

type NoopSpan

type NoopSpan struct {
}

func (*NoopSpan) End

func (*NoopSpan) End()

func (*NoopSpan) Error

func (*NoopSpan) Error(time.Time, ...string)

func (*NoopSpan) GetOperationName

func (*NoopSpan) GetOperationName() string

func (*NoopSpan) IsEntry

func (*NoopSpan) IsEntry() bool

func (*NoopSpan) IsExit

func (*NoopSpan) IsExit() bool

func (*NoopSpan) IsValid

func (*NoopSpan) IsValid() bool

func (*NoopSpan) Log

func (*NoopSpan) Log(time.Time, ...string)

func (*NoopSpan) SetComponent

func (*NoopSpan) SetComponent(int32)

func (*NoopSpan) SetOperationName

func (*NoopSpan) SetOperationName(string)

func (*NoopSpan) SetPeer

func (*NoopSpan) SetPeer(string)

func (*NoopSpan) SetSpanLayer

func (*NoopSpan) SetSpanLayer(agentv3.SpanLayer)

func (*NoopSpan) Tag

func (*NoopSpan) Tag(Tag, string)

type RandomSampler

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

RandomSampler Use sync.Pool to implement concurrent-safe for randomizer.

func NewRandomSampler

func NewRandomSampler(samplingRate float64) *RandomSampler

func (*RandomSampler) IsSampled

func (s *RandomSampler) IsSampled(operation string) bool

IsSampled implements IsSampled() of Sampler.

type ReportedLogData

type ReportedLogData interface {
	Context() context.Context
	ErrorLevel() string
	Data() string
}

type ReportedSpan

type ReportedSpan interface {
	Context() *SegmentContext
	Refs() []*propagation.SpanContext
	StartTime() int64
	EndTime() int64
	OperationName() string
	Peer() string
	SpanType() agentv3.SpanType
	SpanLayer() agentv3.SpanLayer
	IsError() bool
	Tags() []*commonv3.KeyStringValuePair
	Logs() []*agentv3.Log
	ComponentID() int32
}

ReportedSpan is accessed by Reporter to load reported data

type Reporter

type Reporter interface {
	Boot(service string, serviceInstance string, cdsWatchers []AgentConfigChangeWatcher)
	Send(spans []ReportedSpan)
	SendLog(logData ReportedLogData)
	Close()
}

Reporter is a data transit specification

type RunTimeMetric

type RunTimeMetric struct {
	// the Unix time when metrics were collected
	Time int64
	// the bytes of allocated heap objects
	HeapAlloc int64
	// the bytes in stack spans.
	StackInUse int64
	// the number of completed GC cycles since instance started
	GCCount int64
	// the total gc pause time(NS) since instance started
	GCPauseTime int64
	// the number of goroutines that currently exist
	GoroutineNum int64
	// the number of records in the thread creation profile
	ThreadNum int64
	// the cpu Used float64
	CpuUsedRate float64
	// the Percentage of RAM used by programs
	MemUsedRate float64
}

type Sampler

type Sampler interface {
	IsSampled(operation string) (sampled bool)
}

type SegmentContext

type SegmentContext struct {
	TraceID         string
	SegmentID       string
	SpanID          int32
	ParentSpanID    int32
	ParentSegmentID string

	FirstSpan          Span `json:"-"`
	CorrelationContext map[string]string
	// contains filtered or unexported fields
}

SegmentContext is the context in a segment

type SkyLogger

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

func NewSkyLogger

func NewSkyLogger(reporter Reporter) (error, *SkyLogger)

func (*SkyLogger) WriteLogWithContext

func (l *SkyLogger) WriteLogWithContext(ctx context.Context, level string, data string)

type Span

type Span interface {
	SetOperationName(string)
	GetOperationName() string
	SetPeer(string)
	SetSpanLayer(agentv3.SpanLayer)
	SetComponent(int32)
	Tag(Tag, string)
	Log(time.Time, ...string)
	Error(time.Time, ...string)
	End()
	IsEntry() bool
	IsExit() bool
	IsValid() bool
}

Span interface as commonv3 span specification

func ActiveSpan

func ActiveSpan(ctx context.Context) Span

type SpanOption

type SpanOption func(s *defaultSpan)

SpanOption allows for functional options to adjust behaviour of a Span to be created by CreateLocalSpan

func WithContext

func WithContext(sc *propagation.SpanContext) SpanOption

WithContext setup trace sc from propagation

func WithOperationName

func WithOperationName(operationName string) SpanOption

WithOperationName setup span OperationName of a span

func WithSpanType

func WithSpanType(spanType SpanType) SpanOption

WithSpanType setup span type of a span

type SpanType

type SpanType int32

SpanType is used to identify entry, exit and local

const (
	// SpanTypeEntry is a entry span, eg http server
	SpanTypeEntry SpanType = 0
	// SpanTypeExit is a exit span, eg http client
	SpanTypeExit SpanType = 1
	// SpanTypeLocal is a local span, eg local method invoke
	SpanTypeLocal SpanType = 2
)

type Tag

type Tag string

Tag are supported by sky-walking engine. As default, all Tags will be stored, but these ones have particular meanings.

const (
	TagURL             Tag = "url"
	TagHTTPStatusCode  Tag = "http.status_code"
	TagStatusCode      Tag = "http.status_code"
	TagHTTPMethod      Tag = "http.method"
	TagRPCStatusCode   Tag = "rpc.status_code"
	TagDBType          Tag = "db.type"
	TagDBInstance      Tag = "db.instance"
	TagDBStatement     Tag = "db.statement"
	TagDBSqlParameters Tag = "db.sql.parameters"
	TagMQQueue         Tag = "mq.queue"
	TagMQBroker        Tag = "mq.broker"
	TagMQTopic         Tag = "mq.topic"
)

type Tracer

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

Tracer is go4sky tracer implementation.

func GetGlobalTracer

func GetGlobalTracer() *Tracer

GetGlobalTracer returns the registered global Tracer. If none is registered then an instance of `nil` is returned.

func NewTracer

func NewTracer(service string, opts ...TracerOption) (tracer *Tracer, err error)

NewTracer return a new go4sky Tracer

func (*Tracer) CreateEntrySpan

func (t *Tracer) CreateEntrySpan(ctx context.Context, operationName string, extractor propagation.Extractor) (s Span, nCtx context.Context, err error)

CreateEntrySpan creates and starts an entry span for incoming request

func (*Tracer) CreateExitSpan

func (t *Tracer) CreateExitSpan(ctx context.Context, operationName string, peer string, injector propagation.Injector) (s Span, err error)

CreateExitSpan creates and starts an exit span for client

func (*Tracer) CreateExitSpanWithContext

func (t *Tracer) CreateExitSpanWithContext(ctx context.Context, operationName string, peer string,
	injector propagation.Injector) (s Span, nCtx context.Context, err error)

CreateExitSpanWithContext creates and starts an exit span for client with context

func (*Tracer) CreateLocalSpan

func (t *Tracer) CreateLocalSpan(ctx context.Context, opts ...SpanOption) (s Span, c context.Context, err error)

CreateLocalSpan creates and starts a span for local usage

type TracerOption

type TracerOption func(t *Tracer)

TracerOption allows for functional options to adjust behaviour of a Tracer to be created by NewTracer

func WithCorrelation

func WithCorrelation(keyCount, valueSize int) TracerOption

func WithCustomSampler

func WithCustomSampler(sampler Sampler) TracerOption

WithCustomSampler setup custom sampler

func WithInstance

func WithInstance(instance string) TracerOption

WithInstance setup instance identify

func WithReporter

func WithReporter(reporter Reporter) TracerOption

WithReporter setup report pipeline for tracer

func WithSampler

func WithSampler(samplingRate float64) TracerOption

WithSampler setup sampler

Directories

Path Synopsis
internal
Package log help to build trace context data into log plugins.
Package log help to build trace context data into log plugins.
plugins
http
Package http contains several client/server http plugin which can be used for integration with net/http.
Package http contains several client/server http plugin which can be used for integration with net/http.
Package propagation holds the required function signatures for Injection and Extraction.
Package propagation holds the required function signatures for Injection and Extraction.
Package reporter holds reporters contain official reporter implementations.
Package reporter holds reporters contain official reporter implementations.

Jump to

Keyboard shortcuts

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