in tools/go-agent/instrument/agentcore/instrument.go [155:203]
func (i *Instrument) writeTracerInitLink(dir string) (string, error) {
return tools.WriteFile(dir, "tracer_init.go", html.UnescapeString(tools.ExecuteTemplate(`package core
import (
"github.com/apache/skywalking-go/agent/reporter"
"github.com/apache/skywalking-go/agent/core/operator"
"fmt"
"os"
"strconv"
_ "unsafe"
)
//go:linkname {{.GetGlobalLoggerLinkMethod}} {{.GetGlobalLoggerLinkMethod}}
var {{.GetGlobalLoggerLinkMethod}} func() interface{}
func (t *Tracer) InitTracer(extend map[string]interface{}) {
rep, err := reporter.{{.GRPCReporterFuncName}}(t.Log)
if err != nil {
t.Log.Errorf("cannot initialize the reporter: %v", err)
return
}
entity := NewEntity({{.Config.Agent.ServiceName.ToGoStringValue}}, {{.Config.Agent.InstanceEnvName.ToGoStringValue}})
samp := NewDynamicSampler({{.Config.Agent.Sampler.ToGoFloatValue "loading the agent sampler error"}}, t)
meterCollectInterval := {{.Config.Agent.Meter.CollectInterval.ToGoIntValue "loading the agent meter interval error"}}
var logger operator.LogOperator
if {{.GetGlobalLoggerLinkMethod}} != nil {
if l, ok := {{.GetGlobalLoggerLinkMethod}}().(operator.LogOperator); ok && l != nil {
logger = l
}
}
correlation := &CorrelationConfig{
MaxKeyCount : {{.Config.Agent.Correlation.MaxKeyCount.ToGoIntValue "loading the agent correlation maxKeyCount error"}},
MaxValueSize : {{.Config.Agent.Correlation.MaxValueSize.ToGoIntValue "loading the agent correlation maxValueSize error"}},
}
ignoreSuffixStr := {{.Config.Agent.IgnoreSuffix.ToGoStringValue}}
ignorePath := {{.Config.Agent.TraceIgnorePath.ToGoStringValue}}
if err := t.Init(entity, rep, samp, logger, meterCollectInterval, correlation, ignoreSuffixStr, ignorePath); err != nil {
t.Log.Errorf("cannot initialize the SkyWalking Tracer: %v", err)
}
}`, struct {
GRPCReporterFuncName string
GetGlobalLoggerLinkMethod string
Config *config.Config
}{
GRPCReporterFuncName: consts.GRPCInitFuncName,
GetGlobalLoggerLinkMethod: consts.GlobalLoggerGetMethodName,
Config: config.GetConfig(),
})))
}