我试图在Jaeger的Go中使用检测。
我正在像这样用docker运行Jaeger后端(如https://www.jaegertracing.io/docs/1.15/getting-started/中所述):
docker run -d --name jaeger \
-e COLLECTOR_ZIPKIN_HTTP_PORT=9411 \
-p 5775:5775/udp \
-p 6831:6831/udp \
-p 6832:6832/udp \
-p 5778:5778 \
-p 16686:16686 \
-p 14268:14268 \
-p 9411:9411 \
jaegertracing/all-in-one:1.15
但是,在运行以下Go代码之后,我无法在Jaeger UI的http://localhost:16686上看到跨度,并且不确定此代码有什么问题吗?我从类似的Python代码开始,并且能够在Jaeger UI上发布跨度。
package main
import (
"fmt"
"io"
opentracing "github.com/opentracing/opentracing-go"
jaeger "github.com/uber/jaeger-client-go"
jaegercfg "github.com/uber/jaeger-client-go/config"
)
func initJaeger(service string) (opentracing.Tracer, io.Closer) {
agentIP := "localhost"
agentPort := "5775"
so := jaeger.SamplerOptionsFactory{}
logger := jaeger.StdLogger
logger.Infof("Sending Traces to %s %s", agentIP, agentPort)
cfg := &jaegercfg.Configuration{
Sampler: &jaegercfg.SamplerConfig{
Type: "const",
Param: 1,
Options: []jaeger.SamplerOption{so.Logger(logger)},
},
ServiceName: service,
Reporter: &jaegercfg.ReporterConfig{
LogSpans: true,
LocalAgentHostPort: agentIP + ":" + agentPort,
},
}
tracer, closer, err := cfg.NewTracer(jaegercfg.Logger(logger))
if err != nil {
panic(fmt.Sprintf("ERROR: cannot init Jaeger: %v\n", err))
}
opentracing.SetGlobalTracer(tracer)
return opentracing.GlobalTracer(), closer
}
func main() {
tracer, closer := initJaeger("foo-go-service")
span := tracer.StartSpan("GoTestSpan")
var myMap = make(map[string]interface{})
myMap["foo"] = 42
myMap["bar"] = "42"
span.LogKV(myMap)
childSpanRef := opentracing.ChildOf(span.Context())
childSpan := tracer.StartSpan("GoChildSpan", childSpanRef)
var myMap2 = make(map[string]interface{})
myMap2["foo2"] = 42
myMap2["bar2"] = "42"
childSpan.LogKV(myMap2)
closer.Close()
}
我在这里https://godoc.org/github.com/uber/jaeger-client-go挖掘文档,在这里https://godoc.org/github.com/opentracing/opentracing-go挖掘开放跟踪项目的文档,但是我对行话和库函数/方法感到有些困惑。
最佳答案
我能够发布一些跨度,以便可以在http://localhost:16686上看到它们
SetOperationName
,以便我们可以在用户界面上以易于识别的名称来标识它span.Finish()
调用,看来这就是为什么我无法在UI上看到任何内容这是更新的主要功能:
func main() {
tracer, closer := initJaeger("foo-go-service")
defer closer.Close()
span := tracer.StartSpan("GoTestSpan")
defer span.Finish()
span.SetOperationName("opNameGoTestSpan")
var myMap = make(map[string]interface{})
myMap["foo"] = 42
myMap["bar"] = "42"
span.LogKV(myMap)
// time.Sleep(2 * time.Second)
childSpanRef := opentracing.ChildOf(span.Context())
childSpan := tracer.StartSpan("GoChildSpan", childSpanRef)
defer childSpan.Finish()
childSpan.SetOperationName("opNameGoChildSpan")
var myMap2 = make(map[string]interface{})
myMap2["foo2"] = 42
myMap2["bar2"] = "42"
childSpan.LogKV(myMap2)
}
关于go - 跟踪器发送跨度,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/58999288/