@@ -399,10 +399,10 @@ func Test_clientHook_ProcessHook(t *testing.T) { //nolint:maintidx //table drive
399
399
})
400
400
},
401
401
}, {
402
- name : "enable WithDBStatement option" ,
402
+ name : "enable DBQueryText option" ,
403
403
fields : fields {
404
404
rdsOpt : & redis.Options {Addr : "10.1.1.1:6379" , DB : 3 },
405
- opts : []Option {WithDBStatement ( true )},
405
+ opts : []Option {EnableDBQueryText ( )},
406
406
},
407
407
args : args {
408
408
hook : func (ctx context.Context , cmd redis.Cmder ) error { return nil },
@@ -537,6 +537,61 @@ func Test_clientHook_ProcessPipelineHook(t *testing.T) {
537
537
semconv .ServerPort (6379 ),
538
538
})
539
539
540
+ assertUseTime (t , sm .Metrics [1 ], []attribute.KeyValue {
541
+ semconv .DBSystemNameRedis ,
542
+ semconv .DBClientConnectionPoolName ("10.1.1.1:6379/3" ),
543
+ attribute .String ("status" , "ok" ),
544
+ })
545
+ },
546
+ }, {
547
+ name : "enable DBQueryText option" ,
548
+ fields : fields {
549
+ rdsOpt : & redis.Options {Addr : "10.1.1.1:6379" , DB : 3 },
550
+ opts : []Option {EnableDBQueryText ()},
551
+ },
552
+ args : args {
553
+ hook : func (ctx context.Context , cmds []redis.Cmder ) error { return nil },
554
+ cmds : []redis.Cmder {
555
+ redis .NewCmd (context .Background (), "set" , "key" , "value" ),
556
+ redis .NewCmd (context .Background (), "get" , "key1" ),
557
+ redis .NewCmd (context .Background (), "get" , "key2" ),
558
+ },
559
+ },
560
+ checkSpan : func (t * testing.T , span sdktrace.ReadOnlySpan ) {
561
+ t .Helper ()
562
+ assert .Equal (t , "pipeline set get" , span .Name ())
563
+ assert .Equal (t , sdktrace.Status {Code : codes .Unset }, span .Status ())
564
+ t .Logf ("attrs: %v" , span .Attributes ())
565
+
566
+ wantAttrs := []attribute.KeyValue {
567
+ semconv .DBSystemNameRedis ,
568
+ semconv .DBNamespace ("3" ),
569
+ semconv .DBOperationName ("pipeline set get" ),
570
+ semconv .ServerAddress ("10.1.1.1" ),
571
+ semconv .ServerPort (6379 ),
572
+ semconv .DBQueryText ("set key value\n get key1\n get key2" ),
573
+ }
574
+ assert .Subset (t , span .Attributes (), wantAttrs )
575
+
576
+ wantNotExistAttrs := []attribute.Key {semconv .DBResponseStatusCodeKey }
577
+ attrs := attrMap (span .Attributes ())
578
+ for _ , key := range wantNotExistAttrs {
579
+ assert .NotContains (t , attrs , key )
580
+ }
581
+ },
582
+ checkMetrics : func (t * testing.T , sm metricdata.ScopeMetrics ) {
583
+ t .Helper ()
584
+ require .Len (t , sm .Metrics , 2 )
585
+
586
+ assertOprDuration (t , sm .Metrics [0 ], []attribute.KeyValue {
587
+ semconv .DBSystemNameRedis ,
588
+ semconv .DBNamespace ("3" ),
589
+ semconv .DBOperationName ("pipeline set get" ),
590
+ semconv .DBOperationBatchSize (3 ),
591
+ semconv .ServerAddress ("10.1.1.1" ),
592
+ semconv .ServerPort (6379 ),
593
+ })
594
+
540
595
assertUseTime (t , sm .Metrics [1 ], []attribute.KeyValue {
541
596
semconv .DBSystemNameRedis ,
542
597
semconv .DBClientConnectionPoolName ("10.1.1.1:6379/3" ),
0 commit comments