@@ -18,17 +18,19 @@ test.describe('Storage Instrumentation', () => {
1818 const transaction = await transactionPromise ;
1919
2020 // Helper to find spans by operation
21- const findSpansByOp = ( op : string ) => {
22- return transaction . spans ?. filter ( span => span . data ?. [ SEMANTIC_ATTRIBUTE_SENTRY_OP ] === op ) || [ ] ;
21+ // Several unstorage methods share one convention op (e.g. hasItem/getItem/getKeys are all
22+ // `cache.get`), so spans are located by `db.operation.name`, which stays unique per method.
23+ const findSpansByMethod = ( method : string ) => {
24+ return transaction . spans ?. filter ( span => span . data ?. [ 'db.operation.name' ] === method ) || [ ] ;
2325 } ;
2426
2527 // Test setItem spans
26- const setItemSpans = findSpansByOp ( 'cache.set_item ') ;
28+ const setItemSpans = findSpansByMethod ( 'setItem ') ;
2729 expect ( setItemSpans . length ) . toBeGreaterThanOrEqual ( 1 ) ;
2830 const setItemSpan = setItemSpans . find ( span => span . data ?. [ SEMANTIC_ATTRIBUTE_CACHE_KEY ] === prefixKey ( 'user:123' ) ) ;
2931 expect ( setItemSpan ) . toBeDefined ( ) ;
3032 expect ( setItemSpan ?. data ) . toMatchObject ( {
31- [ SEMANTIC_ATTRIBUTE_SENTRY_OP ] : 'cache.set_item ' ,
33+ [ SEMANTIC_ATTRIBUTE_SENTRY_OP ] : 'cache.put ' ,
3234 [ SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN ] : 'auto.cache.nitro' ,
3335 [ SEMANTIC_ATTRIBUTE_CACHE_KEY ] : prefixKey ( 'user:123' ) ,
3436 'db.operation.name' : 'setItem' ,
@@ -37,27 +39,27 @@ test.describe('Storage Instrumentation', () => {
3739 expect ( setItemSpan ?. description ) . toBe ( prefixKey ( 'user:123' ) ) ;
3840
3941 // Test setItemRaw spans
40- const setItemRawSpans = findSpansByOp ( 'cache.set_item_raw ') ;
42+ const setItemRawSpans = findSpansByMethod ( 'setItemRaw ') ;
4143 expect ( setItemRawSpans . length ) . toBeGreaterThanOrEqual ( 1 ) ;
4244 const setItemRawSpan = setItemRawSpans . find (
4345 span => span . data ?. [ SEMANTIC_ATTRIBUTE_CACHE_KEY ] === prefixKey ( 'raw:data' ) ,
4446 ) ;
4547 expect ( setItemRawSpan ) . toBeDefined ( ) ;
4648 expect ( setItemRawSpan ?. data ) . toMatchObject ( {
47- [ SEMANTIC_ATTRIBUTE_SENTRY_OP ] : 'cache.set_item_raw ' ,
49+ [ SEMANTIC_ATTRIBUTE_SENTRY_OP ] : 'cache.put ' ,
4850 [ SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN ] : 'auto.cache.nitro' ,
4951 [ SEMANTIC_ATTRIBUTE_CACHE_KEY ] : prefixKey ( 'raw:data' ) ,
5052 'db.operation.name' : 'setItemRaw' ,
5153 'db.system.name' : expect . any ( String ) ,
5254 } ) ;
5355
5456 // Test hasItem spans - should have cache hit attribute
55- const hasItemSpans = findSpansByOp ( 'cache.has_item ') ;
57+ const hasItemSpans = findSpansByMethod ( 'hasItem ') ;
5658 expect ( hasItemSpans . length ) . toBeGreaterThanOrEqual ( 1 ) ;
5759 const hasItemSpan = hasItemSpans . find ( span => span . data ?. [ SEMANTIC_ATTRIBUTE_CACHE_KEY ] === prefixKey ( 'user:123' ) ) ;
5860 expect ( hasItemSpan ) . toBeDefined ( ) ;
5961 expect ( hasItemSpan ?. data ) . toMatchObject ( {
60- [ SEMANTIC_ATTRIBUTE_SENTRY_OP ] : 'cache.has_item ' ,
62+ [ SEMANTIC_ATTRIBUTE_SENTRY_OP ] : 'cache.get ' ,
6163 [ SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN ] : 'auto.cache.nitro' ,
6264 [ SEMANTIC_ATTRIBUTE_CACHE_KEY ] : prefixKey ( 'user:123' ) ,
6365 [ SEMANTIC_ATTRIBUTE_CACHE_HIT ] : true ,
@@ -66,12 +68,12 @@ test.describe('Storage Instrumentation', () => {
6668 } ) ;
6769
6870 // Test getItem spans - should have cache hit attribute
69- const getItemSpans = findSpansByOp ( 'cache.get_item ') ;
71+ const getItemSpans = findSpansByMethod ( 'getItem ') ;
7072 expect ( getItemSpans . length ) . toBeGreaterThanOrEqual ( 1 ) ;
7173 const getItemSpan = getItemSpans . find ( span => span . data ?. [ SEMANTIC_ATTRIBUTE_CACHE_KEY ] === prefixKey ( 'user:123' ) ) ;
7274 expect ( getItemSpan ) . toBeDefined ( ) ;
7375 expect ( getItemSpan ?. data ) . toMatchObject ( {
74- [ SEMANTIC_ATTRIBUTE_SENTRY_OP ] : 'cache.get_item ' ,
76+ [ SEMANTIC_ATTRIBUTE_SENTRY_OP ] : 'cache.get ' ,
7577 [ SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN ] : 'auto.cache.nitro' ,
7678 [ SEMANTIC_ATTRIBUTE_CACHE_KEY ] : prefixKey ( 'user:123' ) ,
7779 [ SEMANTIC_ATTRIBUTE_CACHE_HIT ] : true ,
@@ -81,14 +83,14 @@ test.describe('Storage Instrumentation', () => {
8183 expect ( getItemSpan ?. description ) . toBe ( prefixKey ( 'user:123' ) ) ;
8284
8385 // Test getItemRaw spans - should have cache hit attribute
84- const getItemRawSpans = findSpansByOp ( 'cache.get_item_raw ') ;
86+ const getItemRawSpans = findSpansByMethod ( 'getItemRaw ') ;
8587 expect ( getItemRawSpans . length ) . toBeGreaterThanOrEqual ( 1 ) ;
8688 const getItemRawSpan = getItemRawSpans . find (
8789 span => span . data ?. [ SEMANTIC_ATTRIBUTE_CACHE_KEY ] === prefixKey ( 'raw:data' ) ,
8890 ) ;
8991 expect ( getItemRawSpan ) . toBeDefined ( ) ;
9092 expect ( getItemRawSpan ?. data ) . toMatchObject ( {
91- [ SEMANTIC_ATTRIBUTE_SENTRY_OP ] : 'cache.get_item_raw ' ,
93+ [ SEMANTIC_ATTRIBUTE_SENTRY_OP ] : 'cache.get ' ,
9294 [ SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN ] : 'auto.cache.nitro' ,
9395 [ SEMANTIC_ATTRIBUTE_CACHE_KEY ] : prefixKey ( 'raw:data' ) ,
9496 [ SEMANTIC_ATTRIBUTE_CACHE_HIT ] : true ,
@@ -97,35 +99,35 @@ test.describe('Storage Instrumentation', () => {
9799 } ) ;
98100
99101 // Test getKeys spans
100- const getKeysSpans = findSpansByOp ( 'cache.get_keys ') ;
102+ const getKeysSpans = findSpansByMethod ( 'getKeys ') ;
101103 expect ( getKeysSpans . length ) . toBeGreaterThanOrEqual ( 1 ) ;
102104 expect ( getKeysSpans [ 0 ] ?. data ) . toMatchObject ( {
103- [ SEMANTIC_ATTRIBUTE_SENTRY_OP ] : 'cache.get_keys ' ,
105+ [ SEMANTIC_ATTRIBUTE_SENTRY_OP ] : 'cache.get ' ,
104106 [ SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN ] : 'auto.cache.nitro' ,
105107 'db.operation.name' : 'getKeys' ,
106108 'db.system.name' : expect . any ( String ) ,
107109 } ) ;
108110
109111 // Test removeItem spans
110- const removeItemSpans = findSpansByOp ( 'cache.remove_item ') ;
112+ const removeItemSpans = findSpansByMethod ( 'removeItem ') ;
111113 expect ( removeItemSpans . length ) . toBeGreaterThanOrEqual ( 1 ) ;
112114 const removeItemSpan = removeItemSpans . find (
113115 span => span . data ?. [ SEMANTIC_ATTRIBUTE_CACHE_KEY ] === prefixKey ( 'batch:1' ) ,
114116 ) ;
115117 expect ( removeItemSpan ) . toBeDefined ( ) ;
116118 expect ( removeItemSpan ?. data ) . toMatchObject ( {
117- [ SEMANTIC_ATTRIBUTE_SENTRY_OP ] : 'cache.remove_item ' ,
119+ [ SEMANTIC_ATTRIBUTE_SENTRY_OP ] : 'cache.remove ' ,
118120 [ SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN ] : 'auto.cache.nitro' ,
119121 [ SEMANTIC_ATTRIBUTE_CACHE_KEY ] : prefixKey ( 'batch:1' ) ,
120122 'db.operation.name' : 'removeItem' ,
121123 'db.system.name' : expect . any ( String ) ,
122124 } ) ;
123125
124126 // Test clear spans
125- const clearSpans = findSpansByOp ( 'cache. clear') ;
127+ const clearSpans = findSpansByMethod ( ' clear') ;
126128 expect ( clearSpans . length ) . toBeGreaterThanOrEqual ( 1 ) ;
127129 expect ( clearSpans [ 0 ] ?. data ) . toMatchObject ( {
128- [ SEMANTIC_ATTRIBUTE_SENTRY_OP ] : 'cache.clear ' ,
130+ [ SEMANTIC_ATTRIBUTE_SENTRY_OP ] : 'cache.remove ' ,
129131 [ SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN ] : 'auto.cache.nitro' ,
130132 'db.operation.name' : 'clear' ,
131133 'db.system.name' : expect . any ( String ) ,
0 commit comments