Connecting jaegertracing-client-go from WSL2
isogram opened this issue · comments
Hi All,
Has anyone experience with jaegertracing-client-go in WSL2?
Architecture
I've a problem here. First of all, I want to share my current development architecture.
- Currently I develop an application using Golang
- I used several devices to develop. Sometimes I use macbook, PC or Windows laptop
- For non-macbook I'm using WSL2 to run the app
- With my current code, everything is ok in Macbook
- Problem raised in WSL2
- I'm installing jaeger-all-in-one using docker on my raspberry pi so I can connect using that host. E.g: 192.168.100.66 , It's open all port from jaeger-all-in-one.
- I've test same configuration in Python script and I executed it from WSL2 and it works without any issues.
Jaeger host: 192.168.100.66
Problem
Trace ID created by jaeger but not shown in jaeger UI
here is the console log if the app:
{"time":"2021-09-13T12:28:29.630291088+07:00","id":"","remote_ip":"::1","host":"localhost:8000","method":"GET","uri":"/customer/v1/static/bantuan-modal/calculate?tenor=48&total=500000","user_agent":"PostmanRuntime/7.28.4","status":200,"error":"","latency":706421802,"latency_human":"706.421802ms","bytes_in":0,"bytes_out":1109}
rest_api > trace_url: http://192.168.100.66:16686/trace/7b6b8278ce1138c5
when i check it out in browser:
Code
Config Function:
// InitOpenTracing init jaeger tracing
func InitOpenTracing(serviceName string, opts ...OptionFunc) error {
option := Option{
AgentHost: env.BaseEnv().JaegerTracingHost,
Level: env.BaseEnv().Environment,
BuildNumberTag: env.BaseEnv().BuildNumber,
MaxGoroutineTag: env.BaseEnv().MaxGoroutines,
}
for _, opt := range opts {
opt(&option)
}
if option.Level != "" {
serviceName = fmt.Sprintf("%s-%s", serviceName, strings.ToLower(option.Level))
}
defaultTags := []opentracing.Tag{
{Key: "num_cpu", Value: runtime.NumCPU()},
{Key: "go_version", Value: runtime.Version()},
{Key: "candi_version", Value: candi.Version},
}
if option.MaxGoroutineTag != 0 {
defaultTags = append(defaultTags, opentracing.Tag{
Key: "max_goroutines", Value: option.MaxGoroutineTag,
})
}
if option.BuildNumberTag != "" {
defaultTags = append(defaultTags, opentracing.Tag{
Key: "build_number", Value: option.BuildNumberTag,
})
}
cfg := &config.Configuration{
Sampler: &config.SamplerConfig{
Type: "const",
Param: 1,
},
Reporter: &config.ReporterConfig{
LogSpans: true,
BufferFlushInterval: 1 * time.Second,
LocalAgentHostPort: option.AgentHost,
},
ServiceName: serviceName,
Tags: defaultTags,
}
tracer, _, err := cfg.NewTracer(config.MaxTagValueLength(math.MaxInt32))
if err != nil {
log.Printf("ERROR: cannot init opentracing connection: %v\n", err)
return err
}
opentracing.SetGlobalTracer(tracer)
return nil
}
Initializer:
.....
tracer.InitOpenTracing(baseCfg.ServiceName)
.....
Caller:
func (uc *staticUsecaseImpl) GetBantuanModalCalculate(ctx context.Context, tenor, total int) (data []domain.BantuanModalCalculate, err error) {
trace, ctx := tracer.StartTraceWithContext(ctx, "StaticUsecase:GetBantuanModalCalculate")
defer trace.Finish()
resp, err := uc.sampleUsecase.Calculate(ctx, tenor, total)
if err != nil {
return data, err
}
.....
}
Env:
JAEGER_TRACING_HOST=192.168.100.66:6831
Self Debug
I wrap Finish
statement
// Finish trace with additional tags data, must in deferred function
func (t *jaegerImpl) Finish(additionalTags ...map[string]interface{}) {
if t.span == nil {
return
}
defer t.span.Finish()
if additionalTags != nil && t.tags == nil {
t.tags = make(map[string]interface{})
}
for _, tag := range additionalTags {
for k, v := range tag {
t.tags[k] = v
}
}
for k, v := range t.tags {
t.span.SetTag(k, toString(v))
}
}
I tried to add time.Sleep
when I call Finish
statement in tracer
helper, then my code become:
// Finish trace with additional tags data, must in deferred function
func (t *jaegerImpl) Finish(additionalTags ...map[string]interface{}) {
if t.span == nil {
return
}
time.Sleep(time.Second * 1)
defer t.span.Finish()
if additionalTags != nil && t.tags == nil {
t.tags = make(map[string]interface{})
}
for _, tag := range additionalTags {
for k, v := range tag {
t.tags[k] = v
}
}
for k, v := range t.tags {
t.span.SetTag(k, toString(v))
}
}
It's sent a span to jager when I add time.Sleep
but not full cycle of span as I expected.
And It raised warning
invalid parent span IDs=XXXXXXX; skipping clock skew adjustment
Here is the span that I expect to be shown in Jaeger UI:
Questions
- Why span not shown in the Jaeger UI?
- Why adding
time.Sleep
inFinish
statement trigger a span even it's not "full-cycle"? - How to make it works like "normal"?
Originally posted by @isogram in jaegertracing/jaeger#3260