我打算Jaeger
在我的Golang
服务器上使用跟踪。一切都很好,但我还没有找到处理Jaeger
错误的方法。例如,我想Jaeger
在发送跟踪时捕获到后端的连接错误并将其写入loggly
.
代码示例:
package main
import (
"fmt"
"log"
"golang.org/x/net/context"
"contrib.go.opencensus.io/exporter/jaeger"
"go.opencensus.io/trace"
)
func main() {
agentEndpointURI := "localhost:6831"
collectorEndpointURI := "http://localhost:14268/api/traces"
je, err := jaeger.NewExporter(jaeger.Options{
AgentEndpoint: agentEndpointURI,
CollectorEndpoint: collectorEndpointURI,
ServiceName: "example",
})
if err != nil {
log.Fatalf("Failed to create the Jaeger exporter: %v", err)
}
trace.RegisterExporter(je)
trace.ApplyConfig(trace.Config{
DefaultSampler: trace.AlwaysSample(),
})
traceMethod()
}
func traceMethod() {
ctx := context.Background()
ctx, span := trace.StartSpan(ctx, "traceMethod")
// Do something here if the trace doesn't reach jaeger backend, write error to loggly
fmt.Println("send trace")
defer span.End()
}