skywalking go agent configuration


skywalking is an open source APM system based on OpenTracing specification. It is specially designed for micro service architecture and cloud native architecture. It supports clients in multiple languages. It is simple and fast to deploy. At present, it is widely used in the industry. For specific skywalking installation and deployment, please refer to the previous blog post: SkyWalking.
Since some of our underlying services are implemented by golang, skywalking go agent needs to be integrated for apm analysis.

Environment construction

go2sky agent
go2sky-plugins access plug-in

go framework: gin
Installation command:

go get -u 
go get -u

Code integration

Package import:

import (
	v3 ""

Used in gin:

	r := gin.New()
	rp, err := reporter.NewGRPCReporter("", reporter.WithCheckInterval(time.Second))
	if err != nil{
		logging.Info("create gosky reporter failed!")
	tracer, err := go2sky.NewTracer("test-demo", go2sky.WithReporter(rp))
	#If we use the middleware of go2sky plugins, we don't need to write the span ourselves. The plug-in helps us complete it
	r.Use(v3.Middleware(r, tracer))


Processing of plug-in span:

func Middleware(engine *gin.Engine, tracer *go2sky.Tracer) gin.HandlerFunc {
	# You need to use the tracer created by the upper layer
	if engine == nil || tracer == nil {
		return func(c *gin.Context) {

	return func(c *gin.Context) {
	# Create span. EntrySpan is used here
		span, ctx, err := tracer.CreateEntrySpan(c.Request.Context(), getOperationName(c), func(key string) (string, error) {
			return c.Request.Header.Get(key), nil
		if err != nil {
		span.Tag(go2sky.TagHTTPMethod, c.Request.Method)
		span.Tag(go2sky.TagURL, c.Request.Host+c.Request.URL.Path)

		c.Request = c.Request.WithContext(ctx)
		#Request to continue execution in gin

		if len(c.Errors) > 0 {
			span.Error(time.Now(), c.Errors.String())
		#End span
		span.Tag(go2sky.TagStatusCode, strconv.Itoa(c.Writer.Status()))

Call effect

Tracking chart:

What is Opentracing

Opentracing is a standard of distributed link tracing and one of the projects under CNCF (cloud native Computing Foundation). Different from the general specification standards, opentracing is not a specification standard at the level of transmission protocol and message format, but an API standard at the level of language.


Trace is a description of the movement of things in the distributed system. A trace represents the execution process of a transaction, request or process in the distributed system. A trace in OpenTracing is considered as a directed acyclic graph (DAG graph) composed of multiple spans. As shown in the following figure, multiple spans form a trace:


Span represents the logical units with start time and execution time in the system. Logical causality is established between spans through nesting or sequential arrangement.
Each Span encapsulates the following states:

  • Operation name
  • Start timestamp
  • Completion timestamp
  • A group of Span Tags with zero or more keys: values. Keys must be strings, and values can be strings, bools and numeric
  • A set of zero or more Span Logs. The log itself is a key:value pair matching the timestamp. The key must be a string, although the value can be of any type. Not all opentracing implementations must support each value type
  • A SpanContext
  • Reference zero or more causal Spans through SpanContext

Relationship between span s in a Trace:



Added by Pezmc on Mon, 07 Feb 2022 11:44:07 +0200