在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
GO2SkyGO2Sky is an instrument SDK library, written in Go, by following Apache SkyWalking tracing and metrics formats. Installation$ go get -u github.com/SkyAPM/go2sky The API of this project is still evolving. The use of vendoring tool is recommended. QuickstartBy completing this quickstart, you will learn how to trace local methods. For more details, please viewthe example. ConfigurationGO2Sky can export traces to Apache SkyWalking OAP server or local logger. In the following example, we configure GO2Sky to export to OAP server,which is listening on r, err := reporter.NewGRPCReporter("oap-skywalking:11800")if err != nil { log.Fatalf("new reporter error %v \n", err)}defer r.Close()tracer, err := go2sky.NewTracer("example", go2sky.WithReporter(r))// create with sampler// tracer, err := go2sky.NewTracer("example", go2sky.WithReporter(r), go2sky.WithSampler(0.5)) You can also create tracer with sampling rate. It supports decimals between 0-1 (two decimal places), representing the sampling percentage of trace. ....tracer, err := go2sky.NewTracer("example", go2sky.WithReporter(r), go2sky.WithSampler(0.5)) Also could customize correlation context config. tracer, err := go2sky.NewTracer("example", go2sky.WithReporter(r), go2sky.WithSampler(0.5), go2sky.WithCorrelation(3, 128)) Create spanTo create a span in a trace, we used the span, ctx, err := tracer.CreateLocalSpan(context.Background()) Create a sub spanA sub span created as the children of root span links to its parent with subSpan, newCtx, err := tracer.CreateLocalSpan(ctx) Get correlationGet custom data from tracing context. value := go2sky.GetCorrelation(ctx, key) Put correlationPut custom data to tracing context. success := go2sky.PutCorrelation(ctx, key, value) End spanWe must end the spans so they becomes available for sending to the backend by a reporter. subSpan.End()span.End() Get Global Service NameGet the go2sky.ServiceName(ctx) Get Global Service Instance NameGet the go2sky.ServiceInstanceName(ctx) Get Global TraceIDGet the go2sky.TraceID(ctx) Get Global TraceSegmentIDGet the go2sky.TraceSegmentID(ctx) Get Global SpanIDGet the go2sky.SpanID(ctx) Periodically ReportGo2sky agent reports the segments periodically.It would not wait for all finished segments reported when the service exits. Advanced ConceptsWe cover some advanced topics about GO2Sky. Context propagationTrace links spans belong to it by using context propagation which varies between different scenario. In processWe use //Create a new contextentrySpan, entryCtx, err := tracer.CreateEntrySpan(context.Background(), ...)// Some operation...// Link two spans by injecting entrySpan context into exitSpanexitSpan, err := tracer.CreateExitSpan(entryCtx, ...) Crossing processWe use
//Extract context from HTTP request header `sw8`span, ctx, err := tracer.CreateEntrySpan(r.Context(), "/api/login", func(key string) (string, error) { return r.Header.Get(key), nil})// Some operation...// Inject context into HTTP request header `sw8`span, err := tracer.CreateExitSpan(req.Context(), "/service/validate", "tomcat-service:8080", func(key, value string) error { req.Header.Set(key, value) return nil}) TagWe set tags into a span which is stored in the backend, but some tags have special purpose. OAP servermay use them to aggregate metrics, generate topology map and etc. They are defined as constant in root package with prefix Log x Trace contextInject trace context into the log text. SkyWalking LAL(log analysis language) engine could extract the context from the text and correlate trace and logs. // Get trace context dataimport go2skylog "github.com/SkyAPM/go2sky/log"logContext = go2skylog.FromContext(ctx)// Build context data string// Inject context string into log// Context format string: [$serviceName,$instanceName,$traceId,$traceSegmentId,$spanId]contextString := logContext.String() PluginsGo to go2sky-plugins repo to see all the plugins, click here. CDS - Configuration Discovery ServiceConfiguration Discovery Service provides the dynamic configuration for the agent, defined in gRPC and stored in the backend. Available key(s) and value(s) in Golang Agent.Golang agent supports the following dynamic configurations.
LicenseApache License 2.0. See LICENSE file for details. |
请发表评论