@@ -4,13 +4,15 @@ import (
44 "context"
55 "fmt"
66 "log"
7+ "strconv"
78 "sync"
89 "time"
910
1011 "github.com/uptrace/uptrace-go/uptrace"
1112 "go.opentelemetry.io/otel"
1213 "go.opentelemetry.io/otel/attribute"
1314 "go.opentelemetry.io/otel/codes"
15+ semconv "go.opentelemetry.io/otel/semconv/v1.4.0"
1416
1517 "github.com/redis/go-redis/extra/redisotel/v9"
1618 "github.com/redis/go-redis/v9"
@@ -19,9 +21,14 @@ import (
1921var tracer = otel .Tracer ("github.com/redis/go-redis/example/otel" )
2022
2123func customAttrFn (ctx context.Context ) []attribute.KeyValue {
22- return []attribute.KeyValue {
23- attribute .String ("custom_attr" , "custom_value" ),
24+
25+ attributes := make ([]attribute.KeyValue , 0 )
26+
27+ if method , ok := ctx .Value (semconv .RPCMethodKey ).(string ); ok {
28+ attributes = append (attributes , semconv .RPCMethodKey .String (method ))
2429 }
30+
31+ return attributes
2532}
2633func main () {
2734 ctx := context .Background ()
@@ -48,7 +55,8 @@ func main() {
4855
4956 for i := 0 ; i < 1e6 ; i ++ {
5057 ctx , rootSpan := tracer .Start (ctx , "handleRequest" )
51-
58+ ctx = context .WithValue (ctx , semconv .RPCMethodKey , "handleRequest " + strconv .Itoa (i ))
59+
5260 if err := handleRequest (ctx , rdb ); err != nil {
5361 rootSpan .RecordError (err )
5462 rootSpan .SetStatus (codes .Error , err .Error ())
0 commit comments