@@ -42,7 +42,7 @@ describe('redis cache auto instrumentation', () => {
4242 . start ( done ) ;
4343 } ) ;
4444
45- test ( 'should create cache spans for prefixed keys' , done => {
45+ test ( 'should create cache spans for prefixed keys (ioredis) ' , done => {
4646 const EXPECTED_TRANSACTION = {
4747 transaction : 'Test Span' ,
4848 spans : expect . arrayContaining ( [
@@ -139,4 +139,102 @@ describe('redis cache auto instrumentation', () => {
139139 . expect ( { transaction : EXPECTED_TRANSACTION } )
140140 . start ( done ) ;
141141 } ) ;
142+
143+ test ( 'should create cache spans for prefixed keys (redis-4)' , done => {
144+ const EXPECTED_TRANSACTION = {
145+ transaction : 'Test Span' ,
146+ spans : expect . arrayContaining ( [
147+ // SET
148+ expect . objectContaining ( {
149+ description : 'redis-cache:test-key' ,
150+ op : 'cache.put' ,
151+ origin : 'auto.db.otel.redis' ,
152+ data : expect . objectContaining ( {
153+ 'sentry.origin' : 'auto.db.otel.redis' ,
154+ 'db.statement' : 'SET redis-cache:test-key [1 other arguments]' ,
155+ 'cache.key' : [ 'redis-cache:test-key' ] ,
156+ 'cache.item_size' : 2 ,
157+ 'network.peer.address' : 'localhost' ,
158+ 'network.peer.port' : 6379 ,
159+ } ) ,
160+ } ) ,
161+ // SET (with EX)
162+ expect . objectContaining ( {
163+ description : 'redis-cache:test-key-set-EX' ,
164+ op : 'cache.put' ,
165+ origin : 'auto.db.otel.redis' ,
166+ data : expect . objectContaining ( {
167+ 'sentry.origin' : 'auto.db.otel.redis' ,
168+ 'db.statement' : 'SET redis-cache:test-key-set-EX [3 other arguments]' ,
169+ 'cache.key' : [ 'redis-cache:test-key-set-EX' ] ,
170+ 'cache.item_size' : 2 ,
171+ 'network.peer.address' : 'localhost' ,
172+ 'network.peer.port' : 6379 ,
173+ } ) ,
174+ } ) ,
175+ // SETEX
176+ expect . objectContaining ( {
177+ description : 'redis-cache:test-key-setex' ,
178+ op : 'cache.put' ,
179+ origin : 'auto.db.otel.redis' ,
180+ data : expect . objectContaining ( {
181+ 'sentry.origin' : 'auto.db.otel.redis' ,
182+ 'db.statement' : 'SETEX redis-cache:test-key-setex [2 other arguments]' ,
183+ 'cache.key' : [ 'redis-cache:test-key-setex' ] ,
184+ 'cache.item_size' : 2 ,
185+ 'network.peer.address' : 'localhost' ,
186+ 'network.peer.port' : 6379 ,
187+ } ) ,
188+ } ) ,
189+ // GET
190+ expect . objectContaining ( {
191+ description : 'redis-cache:test-key' ,
192+ op : 'cache.get' ,
193+ origin : 'auto.db.otel.redis' ,
194+ data : expect . objectContaining ( {
195+ 'sentry.origin' : 'auto.db.otel.redis' ,
196+ 'db.statement' : 'GET redis-cache:test-key' ,
197+ 'cache.hit' : true ,
198+ 'cache.key' : [ 'redis-cache:test-key' ] ,
199+ 'cache.item_size' : 10 ,
200+ 'network.peer.address' : 'localhost' ,
201+ 'network.peer.port' : 6379 ,
202+ } ) ,
203+ } ) ,
204+ // GET (unavailable - no cache hit)
205+ expect . objectContaining ( {
206+ description : 'redis-cache:unavailable-data' ,
207+ op : 'cache.get' ,
208+ origin : 'auto.db.otel.redis' ,
209+ data : expect . objectContaining ( {
210+ 'sentry.origin' : 'auto.db.otel.redis' ,
211+ 'db.statement' : 'GET redis-cache:unavailable-data' ,
212+ 'cache.hit' : false ,
213+ 'cache.key' : [ 'redis-cache:unavailable-data' ] ,
214+ 'network.peer.address' : 'localhost' ,
215+ 'network.peer.port' : 6379 ,
216+ } ) ,
217+ } ) ,
218+ // MGET
219+ expect . objectContaining ( {
220+ description : 'redis-test-key, redis-cache:test-key, redis-cache:unavailable-data' ,
221+ op : 'cache.get' ,
222+ origin : 'auto.db.otel.redis' ,
223+ data : expect . objectContaining ( {
224+ 'sentry.origin' : 'auto.db.otel.redis' ,
225+ 'db.statement' : 'MGET [3 other arguments]' ,
226+ 'cache.hit' : true ,
227+ 'cache.key' : [ 'redis-test-key' , 'redis-cache:test-key' , 'redis-cache:unavailable-data' ] ,
228+ 'network.peer.address' : 'localhost' ,
229+ 'network.peer.port' : 6379 ,
230+ } ) ,
231+ } ) ,
232+ ] ) ,
233+ } ;
234+
235+ createRunner ( __dirname , 'scenario-redis-4.js' )
236+ . withDockerCompose ( { workingDirectory : [ __dirname ] , readyMatches : [ 'port=6379' ] } )
237+ . expect ( { transaction : EXPECTED_TRANSACTION } )
238+ . start ( done ) ;
239+ } ) ;
142240} ) ;
0 commit comments