@@ -117,12 +117,23 @@ func TestTracingHook_DialHook(t *testing.T) {
117117 }
118118}
119119
120+ func customAttrFn (ctx context.Context ) []attribute.KeyValue {
121+
122+ attributes := make ([]attribute.KeyValue , 0 )
123+
124+ if method , ok := ctx .Value (semconv .RPCMethodKey ).(string ); ok {
125+ attributes = append (attributes , semconv .RPCMethodKey .String (method ))
126+ }
127+
128+ return attributes
129+ }
120130func TestTracingHook_ProcessHook (t * testing.T ) {
121131 imsb := tracetest .NewInMemoryExporter ()
122132 provider := sdktrace .NewTracerProvider (sdktrace .WithSyncer (imsb ))
123133 hook := newTracingHook (
124134 "redis://localhost:6379" ,
125135 WithTracerProvider (provider ),
136+ WithAttributesFunc (customAttrFn ),
126137 )
127138
128139 tests := []struct {
@@ -141,7 +152,9 @@ func TestTracingHook_ProcessHook(t *testing.T) {
141152 processHook := hook .ProcessHook (func (ctx context.Context , cmd redis.Cmder ) error {
142153 return tt .errTest
143154 })
144- assertEqual (t , tt .errTest , processHook (context .Background (), cmd ))
155+
156+ ctx := context .WithValue (context .Background (), semconv .RPCMethodKey , "ping" )
157+ assertEqual (t , tt .errTest , processHook (ctx , cmd ))
145158 assertEqual (t , 1 , len (imsb .GetSpans ()))
146159
147160 spanData := imsb .GetSpans ()[0 ]
@@ -151,6 +164,8 @@ func TestTracingHook_ProcessHook(t *testing.T) {
151164 assertAttributeContains (t , spanData .Attributes , semconv .DBSystemRedis )
152165 assertAttributeContains (t , spanData .Attributes , semconv .DBConnectionStringKey .String ("redis://localhost:6379" ))
153166 assertAttributeContains (t , spanData .Attributes , semconv .DBStatementKey .String ("ping" ))
167+ // check for custom attribute
168+ assertAttributeContains (t , spanData .Attributes , semconv .RPCMethodKey .String ("ping" ))
154169
155170 if tt .errTest == nil {
156171 assertEqual (t , 0 , len (spanData .Events ))
0 commit comments