@@ -198,6 +198,43 @@ def test_cache_data(sentry_init, capture_events):
198198 assert spans [5 ]["op" ] == "db.redis" # we ignore db spans in this test.
199199
200200
201+ def test_cache_prefixes (sentry_init , capture_events ):
202+ sentry_init (
203+ integrations = [
204+ RedisIntegration (
205+ cache_prefixes = ["yes" ],
206+ ),
207+ ],
208+ traces_sample_rate = 1.0 ,
209+ )
210+ events = capture_events ()
211+
212+ connection = FakeStrictRedis ()
213+ with sentry_sdk .start_transaction ():
214+ connection .mget ("yes" , "no" )
215+ connection .mget ("no" , 1 , "yes" )
216+ connection .mget ("no" , "yes.1" , "yes.2" )
217+ connection .mget ("no.1" , "no.2" , "no.3" )
218+ connection .mget ("no.1" , "no.2" , "no.actually.yes" )
219+ connection .mget (b"no.3" , b"yes.5" )
220+ connection .mget (uuid .uuid4 ().bytes )
221+ connection .mget (uuid .uuid4 ().bytes , "yes" )
222+
223+ (event ,) = events
224+
225+ spans = event ["spans" ]
226+ assert len (spans ) == 13 # 8 db spans + 5 cache spans
227+
228+ cache_spans = [span for span in spans if span ["op" ] == "cache.get" ]
229+ assert len (cache_spans ) == 5
230+
231+ assert cache_spans [0 ]["description" ] == "yes, no"
232+ assert cache_spans [1 ]["description" ] == "no, 1, yes"
233+ assert cache_spans [2 ]["description" ] == "no, yes.1, yes.2"
234+ assert cache_spans [3 ]["description" ] == "no.3, yes.5"
235+ assert cache_spans [4 ]["description" ] == ", yes"
236+
237+
201238@pytest .mark .parametrize (
202239 "method_name,args,kwargs,expected_key" ,
203240 [
0 commit comments