You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Jul 31, 2023. It is now read-only.
my code is come from quickstart
I replace openzipkin with jaeger:
package main
import (
"bytes""context""encoding/binary""fmt""log""time""contrib.go.opencensus.io/exporter/jaeger""go.opencensus.io/trace"
)
funcmain() {
//// 1. Configure exporter to export traces to Zipkin.//localEndpoint, err := openzipkin.NewEndpoint("go-quickstart", "192.168.1.5:5454")//if err != nil {// log.Fatalf("Failed to create the local zipkinEndpoint: %v", err)//}//reporter := zipkinHTTP.NewReporter("http://localhost:9411/api/v2/spans")//ze := zipkin.NewExporter(reporter, localEndpoint)//trace.RegisterExporter(ze)////// 2. Configure 100% sample rate, otherwise, few traces will be sampled.//trace.ApplyConfig(trace.Config{DefaultSampler: trace.AlwaysSample()})agentEndpointURI:="http://localhost:6831"collectorEndpointURI:="http://localhost/api/traces"je, err:=jaeger.NewExporter(jaeger.Options{
AgentEndpoint: agentEndpointURI,
CollectorEndpoint: collectorEndpointURI,
ServiceName: "demo",
})
iferr!=nil {
log.Fatalf("Failed to create the Jaeger exporter: %v", err)
}
// 3. Create a span with the background context, making this the parent span.// A span must be closed.ctx, span:=trace.StartSpan(context.Background(), "main")
// 5b. Make the span close at the end of this function.deferspan.End()
fori:=0; i<10; i++ {
doWork(ctx)
}
}
funcdoWork(ctx context.Context) {
// 4. Start a child span. This will be a child span because we've passed// the parent span's ctx._, span:=trace.StartSpan(ctx, "doWork")
// 5a. Make the span close at the end of this function.deferspan.End()
fmt.Println("doing busy work")
time.Sleep(80*time.Millisecond)
buf:=bytes.NewBuffer([]byte{0xFF, 0x00, 0x00, 0x00})
num, err:=binary.ReadVarint(buf)
iferr!=nil {
// 6. Set status upon errorspan.SetStatus(trace.Status{
Code: trace.StatusCodeUnknown,
Message: err.Error(),
})
}
// 7. Annotate our span to capture metadata about our operationspan.Annotate([]trace.Attribute{
trace.Int64Attribute("bytes to int", num),
}, "Invoking doWork")
time.Sleep(20*time.Millisecond)
}
when I run my program and access port 16686 of the Jaeger UI,I can't find my service registered in jaeger on the Jaeger UI
solution
just replace "time.Sleep(20 * time.Millisecond)" with "time.Sleep(time.Second)"
problem
my code is come from quickstart
I replace openzipkin with jaeger:
when I run my program and access port 16686 of the Jaeger UI,I can't find my service registered in jaeger on the Jaeger UI
solution
why is that?