@@ -446,6 +446,37 @@ func Test_clientHook_ProcessHook(t *testing.T) { //nolint:maintidx //table drive
446
446
attribute .String ("status" , "ok" ),
447
447
})
448
448
},
449
+ }, {
450
+ name : "DisableMetrics option" ,
451
+ fields : fields {
452
+ rdsOpt : & redis.Options {Addr : "10.1.1.1:6379" , DB : 3 },
453
+ opts : []Option {DisableMetrics ()},
454
+ },
455
+ args : args {
456
+ hook : func (ctx context.Context , cmd redis.Cmder ) error { return nil },
457
+ cmd : redis .NewCmd (context .Background (), "set" , "key" , "value" ),
458
+ },
459
+ checkSpan : func (t * testing.T , span sdktrace.ReadOnlySpan ) {
460
+ t .Helper ()
461
+ assert .Equal (t , "set" , span .Name ())
462
+ assert .Equal (t , sdktrace.Status {Code : codes .Unset }, span .Status ())
463
+ t .Logf ("attrs: %v" , span .Attributes ())
464
+
465
+ wantAttrs := []attribute.KeyValue {
466
+ semconv .DBSystemNameRedis ,
467
+ semconv .DBNamespace ("3" ),
468
+ semconv .DBOperationName ("set" ),
469
+ semconv .ServerAddress ("10.1.1.1" ),
470
+ semconv .ServerPort (6379 ),
471
+ }
472
+ assert .Subset (t , span .Attributes (), wantAttrs )
473
+
474
+ wantNotExistAttrs := []attribute.Key {semconv .DBResponseStatusCodeKey , semconv .DBQueryTextKey }
475
+ attrs := attrMap (span .Attributes ())
476
+ for _ , key := range wantNotExistAttrs {
477
+ assert .NotContains (t , attrs , key )
478
+ }
479
+ },
449
480
},
450
481
}
451
482
for _ , tt := range tests {
@@ -468,6 +499,10 @@ func Test_clientHook_ProcessHook(t *testing.T) { //nolint:maintidx //table drive
468
499
469
500
rm := metricdata.ResourceMetrics {}
470
501
require .NoError (t , mr .Collect (context .Background (), & rm ))
502
+ if tt .checkMetrics == nil { // DisableMetrics
503
+ require .Empty (t , rm .ScopeMetrics )
504
+ return
505
+ }
471
506
require .Len (t , rm .ScopeMetrics , 1 )
472
507
tt .checkMetrics (t , rm .ScopeMetrics [0 ])
473
508
})
0 commit comments