jaegertracing / jaeger-client-go

🛑 This library is DEPRECATED!
https://jaegertracing.io/
Apache License 2.0
1.39k stars 288 forks source link

Connecting jaegertracing-client-go from WSL2 #600

Closed isogram closed 2 years ago

isogram commented 3 years ago

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.

  1. Currently I develop an application using Golang
  2. I used several devices to develop. Sometimes I use macbook, PC or Windows laptop
  3. For non-macbook I'm using WSL2 to run the app
  4. With my current code, everything is ok in Macbook
  5. Problem raised in WSL2
  6. 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.
  7. 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:

Screenshot 2021-09-13 123129
{"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:

Screenshot 2021-09-13 123043

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 screenshot:

Screenshot 2021-09-13 124226

Here is the span that I expect to be shown in Jaeger UI:

Screenshot 2021-09-13 125233

Questions

  1. Why span not shown in the Jaeger UI?
  2. Why adding time.Sleep in Finish statement trigger a span even it's not "full-cycle"?
  3. How to make it works like "normal"?

Originally posted by @isogram in https://github.com/jaegertracing/jaeger/discussions/3260