0

我打算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()
}
4

0 回答 0