@@ -663,6 +663,102 @@ describe('ioredis', () => {
663663 } ) ;
664664 } ) ;
665665 } ) ;
666+
667+ describe ( 'sensitive command sanitization' , function ( ) {
668+ after ( async ( ) => {
669+ // cleanup added user
670+ client . acl ( 'DELUSER' , 'testuser' ) ;
671+ } ) ;
672+
673+ it ( 'should redact CONFIG SET arguments in db.statement' , async function ( ) {
674+ const span = provider
675+ . getTracer ( 'ioredis-test' )
676+ . startSpan ( 'test span' ) ;
677+ await context . with (
678+ trace . setSpan ( context . active ( ) , span ) ,
679+ async function ( ) {
680+ await client . config ( 'SET' , 'hz' , '15' ) ;
681+ span . end ( ) ;
682+ const endedSpans = memoryExporter . getFinishedSpans ( ) ;
683+ assert . strictEqual (
684+ endedSpans [ 0 ] . attributes [ ATTR_DB_STATEMENT ] ,
685+ 'config SET [2 other arguments]'
686+ ) ;
687+ assert . strictEqual (
688+ endedSpans [ 0 ] . attributes [ ATTR_DB_QUERY_TEXT ] ,
689+ 'config SET [2 other arguments]'
690+ ) ;
691+ }
692+ ) ;
693+ } ) ;
694+
695+ it ( 'should redact ACL SETUSER arguments in db.statement' , async function ( ) {
696+ const span = provider
697+ . getTracer ( 'ioredis-test' )
698+ . startSpan ( 'test span' ) ;
699+ await context . with (
700+ trace . setSpan ( context . active ( ) , span ) ,
701+ async function ( ) {
702+ await ( client as any ) . acl ( 'setuser' , 'testuser' ) ;
703+ span . end ( ) ;
704+ const endedSpans = memoryExporter . getFinishedSpans ( ) ;
705+ assert . strictEqual (
706+ endedSpans [ 0 ] . attributes [ ATTR_DB_STATEMENT ] ,
707+ 'acl setuser [1 other arguments]'
708+ ) ;
709+ assert . strictEqual (
710+ endedSpans [ 0 ] . attributes [ ATTR_DB_QUERY_TEXT ] ,
711+ 'acl setuser [1 other arguments]'
712+ ) ;
713+ }
714+ ) ;
715+ await ( client as any ) . acl ( 'deluser' , 'testuser' ) ; // cleanup
716+ } ) ;
717+
718+ it ( 'should redact GETSET value in db.statement' , async function ( ) {
719+ const span = provider
720+ . getTracer ( 'ioredis-test' )
721+ . startSpan ( 'test span' ) ;
722+ await context . with (
723+ trace . setSpan ( context . active ( ) , span ) ,
724+ async function ( ) {
725+ await client . getset ( testKeyName , 'secret-value' ) ;
726+ span . end ( ) ;
727+ const endedSpans = memoryExporter . getFinishedSpans ( ) ;
728+ assert . strictEqual (
729+ endedSpans [ 0 ] . attributes [ ATTR_DB_STATEMENT ] ,
730+ `getset ${ testKeyName } [1 other arguments]`
731+ ) ;
732+ assert . strictEqual (
733+ endedSpans [ 0 ] . attributes [ ATTR_DB_QUERY_TEXT ] ,
734+ `getset ${ testKeyName } [1 other arguments]`
735+ ) ;
736+ }
737+ ) ;
738+ } ) ;
739+
740+ it ( 'should redact PSETEX value in db.statement' , async function ( ) {
741+ const span = provider
742+ . getTracer ( 'ioredis-test' )
743+ . startSpan ( 'test span' ) ;
744+ await context . with (
745+ trace . setSpan ( context . active ( ) , span ) ,
746+ async function ( ) {
747+ await client . psetex ( testKeyName , 60000 , 'secret-value' ) ;
748+ span . end ( ) ;
749+ const endedSpans = memoryExporter . getFinishedSpans ( ) ;
750+ assert . strictEqual (
751+ endedSpans [ 0 ] . attributes [ ATTR_DB_STATEMENT ] ,
752+ `psetex ${ testKeyName } [2 other arguments]`
753+ ) ;
754+ assert . strictEqual (
755+ endedSpans [ 0 ] . attributes [ ATTR_DB_QUERY_TEXT ] ,
756+ `psetex ${ testKeyName } [2 other arguments]`
757+ ) ;
758+ }
759+ ) ;
760+ } ) ;
761+ } ) ;
666762 } ) ;
667763
668764 describe ( 'Instrumenting without parent span' , ( ) => {
0 commit comments