MCPcopy
hub / github.com/redis/go-redis / main

Function main

example/otel/client.go:21–59  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

19var tracer = otel.Tracer("github.com/redis/go-redis/example/otel")
20
21func main() {
22 ctx := context.Background()
23
24 uptrace.ConfigureOpentelemetry(
25 // copy your project DSN here or use UPTRACE_DSN env var
26 uptrace.WithDSN("http://project1_secret@localhost:14318/2?grpc=14317"),
27
28 uptrace.WithServiceName("myservice"),
29 uptrace.WithServiceVersion("v1.0.0"),
30 )
31 defer uptrace.Shutdown(ctx)
32
33 rdb := redis.NewClient(&redis.Options{
34 Addr: ":6379",
35 })
36 if err := redisotel.InstrumentTracing(rdb); err != nil {
37 panic(err)
38 }
39 if err := redisotel.InstrumentMetrics(rdb); err != nil {
40 panic(err)
41 }
42
43 for i := 0; i < 1e6; i++ {
44 ctx, rootSpan := tracer.Start(ctx, "handleRequest")
45
46 if err := handleRequest(ctx, rdb); err != nil {
47 rootSpan.RecordError(err)
48 rootSpan.SetStatus(codes.Error, err.Error())
49 }
50
51 rootSpan.End()
52
53 if i == 0 {
54 fmt.Printf("view trace: %s\n", uptrace.TraceURL(rootSpan))
55 }
56
57 time.Sleep(time.Second)
58 }
59}
60
61func handleRequest(ctx context.Context, rdb *redis.Client) error {
62 if err := rdb.Set(ctx, "First value", "value_1", 0).Err(); err != nil {

Callers

nothing calls this directly

Calls 6

handleRequestFunction · 0.85
ShutdownMethod · 0.65
StartMethod · 0.65
RecordErrorMethod · 0.65
PrintfMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected