go2skyx

package module
v0.0.0-...-85d4525 Latest Latest
Warning

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

Go to latest
Published: Jun 20, 2022 License: MIT Imports: 8 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

go2skyx

go2skyx is a tool library, based on GO2Sky, to report tracing infos to SkyWalking by gRPC.

Motivation

GO2Sky is excellent to use SkyWalking with Go. But it is not easy enough for developers who do not know a lot concept of SkyWalking to use. And because of high encapsulation, GO2Sky is very hard to extend with business. So go2skyx makes some api for easily using and also provides some new feature (e.g. custom TraceID).

Feature

  • report tracing infos to SkyWalking by gRPC
  • create and setup tracer and span with function options
  • customize traceID, spanLayer, component, endpoint, peer, tags and anything

Usage

You can create a tracer by default:

tracer, cleanup, err := NewTracer()

Then use tracer to report a span:

xCtx, span, errCreateSpan := tracer.CreateSpan(context.Background())
span.Log("key", "value")
span.End()

By two functions, everything is done. But unfortunately, using default options is not enough for your business most time. So you should pass some optional parameters to customize your tracing infos.

For tracer:

tracer, cleanup, err := NewTracer(
    // SkyWalking gRPC addr, default 127.0.0.1:11800
    WithAddr(addr),
    // service, default go2skyx
    WithService("go2skyx"),
    // samplingRate, default 1.0
    WithSamplingRate(samplingRate),
)

For local span:

xCtx, spanLocal, errLocal := tracer.CreateSpan(context.Background(),
    WithSpanLayer(SpanLayerRPCFramework),
    WithEndpoint("local invoke"),
)

For client span:

tagMap := map[string]string{}
xCtx, span, errCreateSpan := tracer.CreateSpan(context.Background(),
    WithInjector(func(headerKey, headerValue string) error {
        // inject function for propagation with cross_processing
        return nil
    }),
    WithSpanLayer(SpanLayerRPCFramework),
    WithEndpoint("test go2skyx"),
    WithTraceID("TraceID_"+time.Now().Format(time.RFC3339)),
    // you can add any tag
    WithTagMap(tagMap),
}

For server span:

xCtx, spanServer, errServer := tracer.CreateSpan(context.Background(),
    WithExtractor(func(headerKey string) (string, error) {
        // extract function for propagation with cross_processing
        return propagationMap[headerKey], nil
    }),
    WithSpanLayer(SpanLayerRPCFramework),
    WithEndpoint(endpoint),
)

We provide a full trace usage by mocking invocation with go2skyx_test.go. Run it and you can see tracing info by SkyWalking Web UI like: SkyWalkingUI.png

TODO

  • fix documents
  • add golangci

Reference

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func WithAddr

func WithAddr(addr string) tracerOption

WithAddr set addr

func WithComponent

func WithComponent(component int32) spanOption

WithComponent set component

func WithEndpoint

func WithEndpoint(endpoint string) spanOption

WithEndpoint set endpoint

func WithExtractor

func WithExtractor(extractor func(headerKey string) (string, error)) spanOption

WithExtractor set extractor

func WithInjector

func WithInjector(injector func(headerKey, headerValue string) error) spanOption

WithInjector set injector

func WithPeer

func WithPeer(peer string) spanOption

WithPeer set peer

func WithSamplingRate

func WithSamplingRate(samplingRate float64) tracerOption

WithSamplingRate set samplingRate

func WithService

func WithService(service string) tracerOption

WithService set service

func WithSpanLayer

func WithSpanLayer(spanLayer SpanLayer) spanOption

WithSpanLayer set span layer

func WithTagMap

func WithTagMap(tagMap map[string]string) spanOption

WithTagMap set tagMap

func WithTraceID

func WithTraceID(traceID string) spanOption

WithTraceID set traceID

Types

type Span

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

func (*Span) End

func (span *Span) End()

func (*Span) Error

func (span *Span) Error(s ...string)

func (*Span) GetOperationName

func (span *Span) GetOperationName()

func (*Span) Log

func (span *Span) Log(s ...string)

type SpanLayer

type SpanLayer agentV3.SpanLayer

SpanLayer Map to the layer of span see https://github.com/apache/skywalking-goapi/blob/main/collect/language/agent/v3/Tracing.pb.go

const (
	// SpanLayerUnknown Unknown layer. Could be anything.
	SpanLayerUnknown SpanLayer = 0
	// SpanLayerDatabase A database layer, used in tracing the database client component.
	SpanLayerDatabase SpanLayer = 1
	// SpanLayerRPCFramework A RPC layer, used in both client and server sides of RPC component.
	SpanLayerRPCFramework SpanLayer = 2
	// SpanLayerHttp HTTP is a more specific RPCFramework.
	SpanLayerHttp SpanLayer = 3
	// SpanLayerMQ A MQ layer, used in both producer and consumer sides of the MQ component.
	SpanLayerMQ SpanLayer = 4
	// SpanLayerCache A cache layer, used in tracing the cache client component.
	SpanLayerCache SpanLayer = 5
	// SpanLayerFAAS A FAASlayer, used in function-as-a-Service platform.
	SpanLayerFAAS SpanLayer = 6
)

type Tag

type Tag go2sky.Tag

Tag are supported by sky-walking engine. As default, all Tags will be stored, but these have particular meanings. see https://github.com/SkyAPM/go2sky/blob/master/span.go

const (
	TagURL             Tag = "url"
	TagStatusCode      Tag = "status_code"
	TagHTTPMethod      Tag = "http.method"
	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
}

func NewTracer

func NewTracer(options ...tracerOption) (tracer *Tracer, cleanup func(), err error)

NewTracer new tracer

func (*Tracer) CreateSpan

func (t *Tracer) CreateSpan(ctx context.Context, options ...spanOption) (xCtx context.Context, span *Span, err error)

Jump to

Keyboard shortcuts

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