@@ -4,13 +4,15 @@ import (
4
4
"context"
5
5
"fmt"
6
6
"log"
7
+ "strconv"
7
8
"sync"
8
9
"time"
9
10
10
11
"github.com/uptrace/uptrace-go/uptrace"
11
12
"go.opentelemetry.io/otel"
12
13
"go.opentelemetry.io/otel/attribute"
13
14
"go.opentelemetry.io/otel/codes"
15
+ semconv "go.opentelemetry.io/otel/semconv/v1.4.0"
14
16
15
17
"github.com/redis/go-redis/extra/redisotel/v9"
16
18
"github.com/redis/go-redis/v9"
@@ -19,9 +21,14 @@ import (
19
21
var tracer = otel .Tracer ("github.com/redis/go-redis/example/otel" )
20
22
21
23
func 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 ))
24
29
}
30
+
31
+ return attributes
25
32
}
26
33
func main () {
27
34
ctx := context .Background ()
@@ -48,7 +55,8 @@ func main() {
48
55
49
56
for i := 0 ; i < 1e6 ; i ++ {
50
57
ctx , rootSpan := tracer .Start (ctx , "handleRequest" )
51
-
58
+ ctx = context .WithValue (ctx , semconv .RPCMethodKey , "handleRequest " + strconv .Itoa (i ))
59
+
52
60
if err := handleRequest (ctx , rdb ); err != nil {
53
61
rootSpan .RecordError (err )
54
62
rootSpan .SetStatus (codes .Error , err .Error ())
0 commit comments