@@ -415,6 +415,83 @@ func TestTracingHook_ProcessPipelineHook_LongCommands(t *testing.T) {
415
415
}
416
416
}
417
417
418
+ func TestTracingHook_ProcessHook_LongCommand_WithExlusions (t * testing.T ) {
419
+ imsb := tracetest .NewInMemoryExporter ()
420
+ provider := sdktrace .NewTracerProvider (sdktrace .WithSyncer (imsb ))
421
+ hook := newTracingHook (
422
+ "redis://localhost:6379" ,
423
+ WithTracerProvider (provider ),
424
+ )
425
+ longValue := strings .Repeat ("a" , 102400 )
426
+
427
+ tests := []struct {
428
+ name string
429
+ cmd redis.Cmder
430
+ expected string
431
+ }{
432
+ {
433
+ name : "short command" ,
434
+ cmd : redis .NewCmd (context .Background (), "SET" , "key" , "value" ),
435
+ expected : "SET key value" ,
436
+ },
437
+ {
438
+ name : "set command with long key" ,
439
+ cmd : redis .NewCmd (context .Background (), "SET" , longValue , "value" ),
440
+ expected : "SET " + longValue + " value" ,
441
+ },
442
+ {
443
+ name : "set command with long value" ,
444
+ cmd : redis .NewCmd (context .Background (), "SET" , "key" , longValue ),
445
+ expected : "SET key " + longValue ,
446
+ },
447
+ {
448
+ name : "set command with long key and value" ,
449
+ cmd : redis .NewCmd (context .Background (), "SET" , longValue , longValue ),
450
+ expected : "SET " + longValue + " " + longValue ,
451
+ },
452
+ {
453
+ name : "short command with many arguments" ,
454
+ cmd : redis .NewCmd (context .Background (), "MSET" , "key1" , "value1" , "key2" , "value2" , "key3" , "value3" , "key4" , "value4" , "key5" , "value5" ),
455
+ expected : "MSET key1 value1 key2 value2 key3 value3 key4 value4 key5 value5" ,
456
+ },
457
+ {
458
+ name : "long command" ,
459
+ cmd : redis .NewCmd (context .Background (), longValue , "key" , "value" ),
460
+ expected : longValue + " key value" ,
461
+ },
462
+ }
463
+
464
+ for _ , tt := range tests {
465
+ t .Run (tt .name , func (t * testing.T ) {
466
+ defer imsb .Reset ()
467
+
468
+ processHook := hook .ProcessHook (func (ctx context.Context , cmd redis.Cmder ) error {
469
+ return nil
470
+ })
471
+
472
+ if err := processHook (context .Background (), tt .cmd ); err != nil {
473
+ t .Fatal (err )
474
+ }
475
+
476
+ assertEqual (t , 1 , len (imsb .GetSpans ()))
477
+
478
+ spanData := imsb .GetSpans ()[0 ]
479
+
480
+ var dbStatement string
481
+ for _ , attr := range spanData .Attributes {
482
+ if attr .Key == semconv .DBStatementKey {
483
+ dbStatement = attr .Value .AsString ()
484
+ break
485
+ }
486
+ }
487
+
488
+ if dbStatement != tt .expected {
489
+ t .Errorf ("Expected DB statement: %q\n Got: %q" , tt .expected , dbStatement )
490
+ }
491
+ })
492
+ }
493
+ }
494
+
418
495
func assertEqual (t * testing.T , expected , actual interface {}) {
419
496
t .Helper ()
420
497
if expected != actual {
0 commit comments