@@ -190,47 +190,47 @@ function createSpanStartOptions(
190190 mountBase : string ,
191191 args : unknown [ ] ,
192192) : StartSpanOptions {
193- const key = normalizeKey ( args ?. [ 0 ] ) ;
193+ const keys = getCacheKeys ( args ?. [ 0 ] , mountBase ) ;
194+
194195 const attributes : SpanAttributes = {
195196 [ SEMANTIC_ATTRIBUTE_SENTRY_OP ] : `cache.${ normalizeMethodName ( methodName ) } ` ,
196197 [ SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN ] : 'auto.cache.nuxt' ,
198+ [ SEMANTIC_ATTRIBUTE_CACHE_KEY ] : keys . length > 1 ? keys : keys [ 0 ] ,
197199 'db.operation.name' : methodName ,
198- 'db.collection.name ' : mountBase ,
200+ 'db.collection.name' : mountBase . replace ( / : $ / , '' ) ,
199201 'db.system.name' : driver . name ?? 'unknown' ,
200202 } ;
201203
202- if ( key ) {
203- attributes [ SEMANTIC_ATTRIBUTE_CACHE_KEY ] = key ;
204- }
205-
206204 return {
207- name : ` ${ mountBase } ${ key } ` ,
205+ name : keys . join ( ', ' ) ,
208206 attributes,
209207 } ;
210208}
211209
212210/**
213- * Normalizes the key to a string for display purposes.
214- * @param key The key to normalize.
211+ * Gets a normalized array of cache keys.
215212 */
216- function normalizeKey ( key : unknown ) : string {
217- if ( isEmptyValue ( key ) ) {
218- return '' ;
213+ function getCacheKeys ( key : unknown , prefix : string ) : string [ ] {
214+ // Handles an array of keys
215+ if ( Array . isArray ( key ) ) {
216+ return key . map ( k => normalizeKey ( k , prefix ) ) ;
219217 }
220218
219+ return [ normalizeKey ( key , prefix ) ] ;
220+ }
221+
222+ /**
223+ * Normalizes the key to a string for `cache.key` attribute.
224+ */
225+ function normalizeKey ( key : unknown , prefix : string ) : string {
221226 if ( typeof key === 'string' ) {
222- return key ;
227+ return ` ${ prefix } ${ key } ` ;
223228 }
224229
225230 // Handles an object with a key property
226231 if ( typeof key === 'object' && key !== null && 'key' in key ) {
227- return `${ key . key } ` ;
228- }
229-
230- // Handles an array of keys
231- if ( Array . isArray ( key ) ) {
232- return key . map ( k => normalizeKey ( k ) ) . join ( ', ' ) ;
232+ return `${ prefix } ${ key . key } ` ;
233233 }
234234
235- return String ( key ) ;
235+ return ` ${ prefix } ${ isEmptyValue ( key ) ? '' : String ( key ) } ` ;
236236}
0 commit comments