Skip to content

Commit f4818f4

Browse files
committed
fix: show global key path on span name and adjust operation attrs
1 parent c145c32 commit f4818f4

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

packages/nuxt/src/runtime/plugins/storage.server.ts

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,24 @@ type MaybeInstrumentedDriver = Driver & {
2121
__sentry_instrumented__?: boolean;
2222
};
2323

24+
/**
25+
* Methods that should have a key argument.
26+
*/
27+
const KEYED_METHODS = new Set([
28+
'hasItem',
29+
'getItem',
30+
'getItemRaw',
31+
'getItems',
32+
'setItem',
33+
'setItemRaw',
34+
'setItems',
35+
'removeItem',
36+
]);
37+
2438
/**
2539
* Methods that should have a attribute to indicate a cache hit.
2640
*/
27-
const KEYED_METHODS = new Set(['hasItem', 'getItem', 'getItemRaw', 'getItems']);
41+
const CACHE_HIT_METHODS = new Set(['hasItem', 'getItem', 'getKeys']);
2842

2943
/**
3044
* Creates a Nitro plugin that instruments the storage driver.
@@ -70,6 +84,7 @@ function instrumentDriver(driver: MaybeInstrumentedDriver, mountBase: string): D
7084
debug.log(`[storage] Instrumenting driver: "${driver.name}" on mount: "${mountBase}"`);
7185

7286
// List of driver methods to instrument
87+
// get/set/remove are aliases and already use their {method}Item methods
7388
const methodsToInstrument: (keyof Driver)[] = [
7489
'hasItem',
7590
'getItem',
@@ -115,7 +130,9 @@ function createMethodWrapper(
115130

116131
debug.log(`[storage] Running method: "${methodName}" on driver: "${driver.name ?? 'unknown'}"`);
117132

118-
const spanName = KEYED_METHODS.has(methodName) ? String(args?.[0]) : `storage.${normalizeMethodName(methodName)}`;
133+
const spanName = KEYED_METHODS.has(methodName)
134+
? `${mountBase}${args?.[0]}`
135+
: `storage.${normalizeMethodName(methodName)}`;
119136

120137
return startSpan(
121138
{
@@ -127,7 +144,7 @@ function createMethodWrapper(
127144
const result = await target.apply(thisArg, args);
128145
span.setStatus({ code: SPAN_STATUS_OK });
129146

130-
if (KEYED_METHODS.has(methodName)) {
147+
if (CACHE_HIT_METHODS.has(methodName)) {
131148
span.setAttribute(SEMANTIC_ATTRIBUTE_CACHE_HIT, true);
132149
}
133150

0 commit comments

Comments
 (0)