Created
January 18, 2021 15:15
-
-
Save RohitRox/c7f8d94f251868535f4361e170de65fb to your computer and use it in GitHub Desktop.
Golang Jaeger Integration
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"context" | |
"fmt" | |
"github.com/opentracing/opentracing-go" | |
"github.com/uber/jaeger-client-go" | |
"github.com/uber/jaeger-client-go/config" | |
) | |
const COLLECTOR_URL = "http://localhost:14268/api/traces" | |
const FRONTEND_URL = "http://localhost:16686" | |
func main() { | |
cfg := &config.Configuration{ | |
ServiceName: "TestService", | |
Sampler: &config.SamplerConfig{ | |
Type: jaeger.SamplerTypeConst, | |
Param: 1, | |
}, | |
Reporter: &config.ReporterConfig{ | |
CollectorEndpoint: COLLECTOR_URL, | |
LogSpans: true, | |
}, | |
} | |
tracer, closer, _ := cfg.NewTracer(config.Logger(jaeger.StdLogger)) | |
opentracing.SetGlobalTracer(tracer) | |
baseSpan, ctx := opentracing.StartSpanFromContext(context.Background(), "Base Span") | |
fmt.Printf("Do work 1") | |
span1, _ := opentracing.StartSpanFromContext(ctx, "Work1Span1") | |
fmt.Printf("Work 1 span 1") | |
span1.Finish() | |
span2, _ := opentracing.StartSpanFromContext(ctx, "Work1Span2") | |
fmt.Printf("Work 1 span 2") | |
span2.Finish() | |
baseSpan.Finish() | |
closer.Close() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment