dropbox1111 2019-05-10 17:18
浏览 67
已采纳

在一个Docker容器中进行Opentracing go代码,在另一个容器中进行jaegertracing

I have my go project which sends OpenTracing spans in one docker container and the jaegertracing running in it's own container using the following command:

docker run -p 6831:6831/udp -p 16686:16686 jaegertracing/all-in-one:latest

When I run the following go test code I can see them in the jaegerui:

 import (
    "testing"
    //"fmt"
    "io"

    opentracing "github.com/opentracing/opentracing-go"
    jaeger "github.com/uber/jaeger-client-go"
    config "github.com/uber/jaeger-client-go/config"
    log2 "github.com/sirupsen/logrus"
   // olog"github.com/opentracing/opentracing-go/log"
    jaegerlog "github.com/uber/jaeger-client-go/log"
    "github.com/uber/jaeger-lib/metrics"
)

func TestSum(t *testing.T) {
     log2.Info("start opentracing")
   // helloTo := "sonam"
    tracer, closer := initJaeger("opentracing_test")
    defer closer.Close()

    helloStr := "Sonam"
    //tracer := opentracing.GlobalTracer()

    span := tracer.StartSpan("TestSum")
    println(helloStr)
    span.Finish()
}


// initJaeger returns an instance of Jaeger Tracer that samples 100% of traces and logs all spans to stdout.
func initJaeger(service string) (opentracing.Tracer, io.Closer) {
    cfg := config.Configuration{
        ServiceName: service,
        Sampler:     &config.SamplerConfig{
            Type:  jaeger.SamplerTypeConst,
            Param: 1,
        },
        Reporter:    &config.ReporterConfig{
            LogSpans: true,
        },
    }

    //add
    jLogger := jaegerlog.StdLogger
    jMetricsFactory := metrics.NullFactory

    // Initialize tracer with a logger and a metrics factory
    tracer, closer, _ := cfg.NewTracer(
        config.Logger(jLogger),
        config.Metrics(jMetricsFactory),
    )
    // Set the singleton opentracing.Tracer with the Jaeger tracer.
    opentracing.SetGlobalTracer(tracer)
    return tracer, closer
}

but not when the code executes in a separate docker container.

Any ideas what I need to pass in my go app docker container?

  • 写回答

1条回答 默认 最新

  • dpcnm2132 2019-05-20 14:58
    关注

    My problem was with the configuration. The environment variables were not getting read using the above config. I had to use the following to read the environment variables in open tracing:

    cfg, err := jconfig.FromEnv()
        if err != nil {
            log.Error("cannot parse Jaeger env vars")
        }
    
        cfg.ServiceName = service
        cfg.Sampler.Type = jaeger.SamplerTypeConst
        cfg.Sampler.Param = 1
        cfg.Reporter.LogSpans = true
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?