Created
August 6, 2021 05:43
-
-
Save rubenvp8510/d6b12a1fcbcff56af5126b99fe7cd9db to your computer and use it in GitHub Desktop.
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 ( | |
"fmt" | |
"io" | |
"time" | |
"crypto/rand" | |
"github.com/opentracing/opentracing-go" | |
"github.com/uber/jaeger-client-go" | |
"github.com/uber/jaeger-client-go/config" | |
) | |
func Init(service string) (opentracing.Tracer, io.Closer) { | |
cfg := &config.Configuration{ | |
Sampler: &config.SamplerConfig{ | |
Type: "const", | |
Param: 1, | |
}, | |
Reporter: &config.ReporterConfig{ | |
LogSpans: true, | |
}, | |
} | |
tracer, closer, err := cfg.New(service, config.Logger(jaeger.StdLogger)) | |
if err != nil { | |
panic(fmt.Sprintf("ERROR: cannot init Jaeger: %v\n", err)) | |
} | |
return tracer, closer | |
} | |
func randString(n int) string { | |
const alphanum = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz" | |
var bytes = make([]byte, n) | |
rand.Read(bytes) | |
for i, b := range bytes { | |
bytes[i] = alphanum[b%byte(len(alphanum))] | |
} | |
return string(bytes) | |
} | |
func main() { | |
tracer, closer := Init("hello-world") | |
defer closer.Close() | |
helloTo := "ruben" | |
for i := 0; i < 1000; i++ { | |
span := tracer.StartSpan("say-hello") | |
span.SetTag("hello-to", helloTo) | |
span.LogKV("log1", "hello") | |
if i%2 == 0 { | |
span.LogKV("log2", "world") | |
} else { | |
span.LogKV("log2", randString(5000)) | |
} | |
span.Finish() | |
} | |
time.Sleep(time.Duration(1 * time.Second)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment