@@ -80,7 +80,7 @@ def test_redis_pipeline(
8080 }
8181
8282
83- def test_sensitive_data (sentry_init , capture_events ):
83+ def test_sensitive_data (sentry_init , capture_events , render_span_tree ):
8484 # fakeredis does not support the AUTH command, so we need to mock it
8585 with mock .patch (
8686 "sentry_sdk.integrations.redis.utils._COMMANDS_INCLUDING_SENSITIVE_DATA" ,
@@ -100,12 +100,16 @@ def test_sensitive_data(sentry_init, capture_events):
100100 ) # because fakeredis does not support AUTH we use GET instead
101101
102102 (event ,) = events
103- spans = event ["spans" ]
104- assert spans [0 ]["op" ] == "db.redis"
105- assert spans [0 ]["description" ] == "GET [Filtered]"
103+ assert (
104+ render_span_tree (event )
105+ == """\
106+ - op="": description=null
107+ - op="db.redis": description="GET [Filtered]"\
108+ """
109+ )
106110
107111
108- def test_pii_data_redacted (sentry_init , capture_events ):
112+ def test_pii_data_redacted (sentry_init , capture_events , render_span_tree ):
109113 sentry_init (
110114 integrations = [RedisIntegration ()],
111115 traces_sample_rate = 1.0 ,
@@ -120,15 +124,19 @@ def test_pii_data_redacted(sentry_init, capture_events):
120124 connection .delete ("somekey1" , "somekey2" )
121125
122126 (event ,) = events
123- spans = event ["spans" ]
124- assert spans [0 ]["op" ] == "db.redis"
125- assert spans [0 ]["description" ] == "SET 'somekey1' [Filtered]"
126- assert spans [1 ]["description" ] == "SET 'somekey2' [Filtered]"
127- assert spans [2 ]["description" ] == "GET 'somekey2'"
128- assert spans [3 ]["description" ] == "DEL 'somekey1' [Filtered]"
127+ assert (
128+ render_span_tree (event )
129+ == """\
130+ - op="": description=null
131+ - op="db.redis": description="SET 'somekey1' [Filtered]"
132+ - op="db.redis": description="SET 'somekey2' [Filtered]"
133+ - op="db.redis": description="GET 'somekey2'"
134+ - op="db.redis": description="DEL 'somekey1' [Filtered]"\
135+ """
136+ )
129137
130138
131- def test_pii_data_sent (sentry_init , capture_events ):
139+ def test_pii_data_sent (sentry_init , capture_events , render_span_tree ):
132140 sentry_init (
133141 integrations = [RedisIntegration ()],
134142 traces_sample_rate = 1.0 ,
@@ -144,15 +152,19 @@ def test_pii_data_sent(sentry_init, capture_events):
144152 connection .delete ("somekey1" , "somekey2" )
145153
146154 (event ,) = events
147- spans = event ["spans" ]
148- assert spans [0 ]["op" ] == "db.redis"
149- assert spans [0 ]["description" ] == "SET 'somekey1' 'my secret string1'"
150- assert spans [1 ]["description" ] == "SET 'somekey2' 'my secret string2'"
151- assert spans [2 ]["description" ] == "GET 'somekey2'"
152- assert spans [3 ]["description" ] == "DEL 'somekey1' 'somekey2'"
155+ assert (
156+ render_span_tree (event )
157+ == """\
158+ - op="": description=null
159+ - op="db.redis": description="SET 'somekey1' 'my secret string1'"
160+ - op="db.redis": description="SET 'somekey2' 'my secret string2'"
161+ - op="db.redis": description="GET 'somekey2'"
162+ - op="db.redis": description="DEL 'somekey1' 'somekey2'"\
163+ """
164+ )
153165
154166
155- def test_data_truncation (sentry_init , capture_events ):
167+ def test_data_truncation (sentry_init , capture_events , render_span_tree ):
156168 sentry_init (
157169 integrations = [RedisIntegration ()],
158170 traces_sample_rate = 1.0 ,
@@ -168,15 +180,17 @@ def test_data_truncation(sentry_init, capture_events):
168180 connection .set ("somekey2" , short_string )
169181
170182 (event ,) = events
171- spans = event ["spans" ]
172- assert spans [0 ]["op" ] == "db.redis"
173- assert spans [0 ]["description" ] == "SET 'somekey1' '%s..." % (
174- long_string [: 1024 - len ("..." ) - len ("SET 'somekey1' '" )],
183+ assert (
184+ render_span_tree (event )
185+ == f"""\
186+ - op="": description=null
187+ - op="db.redis": description="SET 'somekey1' '{ long_string [: 1024 - len ("..." ) - len ("SET 'somekey1' '" )]} ..."
188+ - op="db.redis": description="SET 'somekey2' 'bbbbbbbbbb'"\
189+ """
175190 )
176- assert spans [1 ]["description" ] == "SET 'somekey2' '%s'" % (short_string ,)
177191
178192
179- def test_data_truncation_custom (sentry_init , capture_events ):
193+ def test_data_truncation_custom (sentry_init , capture_events , render_span_tree ):
180194 sentry_init (
181195 integrations = [RedisIntegration (max_data_size = 30 )],
182196 traces_sample_rate = 1.0 ,
@@ -192,12 +206,14 @@ def test_data_truncation_custom(sentry_init, capture_events):
192206 connection .set ("somekey2" , short_string )
193207
194208 (event ,) = events
195- spans = event ["spans" ]
196- assert spans [0 ]["op" ] == "db.redis"
197- assert spans [0 ]["description" ] == "SET 'somekey1' '%s..." % (
198- long_string [: 30 - len ("..." ) - len ("SET 'somekey1' '" )],
209+ assert (
210+ render_span_tree (event )
211+ == f"""\
212+ - op="": description=null
213+ - op="db.redis": description="SET 'somekey1' '{ long_string [: 30 - len ("..." ) - len ("SET 'somekey1' '" )]} ..."
214+ - op="db.redis": description="SET 'somekey2' '{ short_string } '"\
215+ """
199216 )
200- assert spans [1 ]["description" ] == "SET 'somekey2' '%s'" % (short_string ,)
201217
202218
203219def test_breadcrumbs (sentry_init , capture_events ):
0 commit comments