Skip to content

Commit bd1012a

Browse files
nicohrubeccodex
andauthored
ref(core): Use cache attribute constants from conventions (#24973)
Uses `CACHE_HIT`, `CACHE_KEY`, and `CACHE_ITEM_SIZE` from `@sentry/conventions/attributes`. Deprecates the existing core constants while preserving their public exports and identical attribute keys; emitted values and cache behavior remain unchanged. Part of #24961 / [JS-3868](https://linear.app/getsentry/issue/JS-3868). Co-authored-by: GPT-6 <codex@openai.com>
1 parent 7f4df48 commit bd1012a

4 files changed

Lines changed: 21 additions & 16 deletions

File tree

‎packages/core/src/semanticAttributes.ts‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,10 +102,19 @@ export const SEMANTIC_ATTRIBUTE_PROFILE_ID = 'sentry.profile_id';
102102
*/
103103
export const SEMANTIC_ATTRIBUTE_EXCLUSIVE_TIME = 'sentry.exclusive_time';
104104

105+
/**
106+
* @deprecated Use `CACHE_HIT` from `@sentry/conventions/attributes` instead.
107+
*/
105108
export const SEMANTIC_ATTRIBUTE_CACHE_HIT = 'cache.hit';
106109

110+
/**
111+
* @deprecated Use `CACHE_KEY` from `@sentry/conventions/attributes` instead.
112+
*/
107113
export const SEMANTIC_ATTRIBUTE_CACHE_KEY = 'cache.key';
108114

115+
/**
116+
* @deprecated Use `CACHE_ITEM_SIZE` from `@sentry/conventions/attributes` instead.
117+
*/
109118
export const SEMANTIC_ATTRIBUTE_CACHE_ITEM_SIZE = 'cache.item_size';
110119

111120
/** TODO: Remove these once we update to latest semantic conventions */

‎packages/nitro/src/runtime/hooks/captureStorageEvents.ts‎

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
import * as dc from 'node:diagnostics_channel';
2-
import { CACHE_OPERATION, SENTRY_OP } from '@sentry/conventions/attributes';
2+
import { CACHE_HIT, CACHE_KEY, CACHE_OPERATION, SENTRY_OP } from '@sentry/conventions/attributes';
33
import { CACHE_GET, CACHE_PUT, CACHE_REMOVE } from '@sentry/conventions/op';
44
import {
55
CACHE_OPERATION_NAMES,
66
getClient,
77
GLOBAL_OBJ,
88
hasSpanStreamingEnabled,
99
isObjectLike,
10-
SEMANTIC_ATTRIBUTE_CACHE_HIT,
11-
SEMANTIC_ATTRIBUTE_CACHE_KEY,
1210
SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN,
1311
startInactiveSpan,
1412
} from '@sentry/core';
@@ -98,7 +96,7 @@ function setupStorageTracingChannel(operation: TracedOperation): void {
9896
[SENTRY_OP]: OPERATION_SPAN_OPS[operation],
9997
[CACHE_OPERATION]: cacheOperationName,
10098
[SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: ORIGIN,
101-
[SEMANTIC_ATTRIBUTE_CACHE_KEY]: cacheKeys.length > 1 ? cacheKeys : cacheKeys[0],
99+
[CACHE_KEY]: cacheKeys.length > 1 ? cacheKeys : cacheKeys[0],
102100
'db.operation.name': operation,
103101
'db.collection.name': mountBase(data),
104102
'db.system.name': data.driver?.name ?? 'unknown',
@@ -112,7 +110,7 @@ function setupStorageTracingChannel(operation: TracedOperation): void {
112110
if (!('error' in data)) {
113111
const result = (data as { result?: unknown }).result;
114112
if (CACHE_HIT_OPERATIONS.has(operation)) {
115-
span.setAttribute(SEMANTIC_ATTRIBUTE_CACHE_HIT, resolveCacheHit(operation, data.keys?.[0], result));
113+
span.setAttribute(CACHE_HIT, resolveCacheHit(operation, data.keys?.[0], result));
116114
}
117115
}
118116

‎packages/nuxt/src/runtime/utils/instrumentStorage.ts‎

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { CACHE_OPERATION, SENTRY_OP } from '@sentry/conventions/attributes';
1+
import { CACHE_HIT, CACHE_KEY, CACHE_OPERATION, SENTRY_OP } from '@sentry/conventions/attributes';
22
import { CACHE_GET, CACHE_PUT, CACHE_REMOVE } from '@sentry/conventions/op';
33
import {
44
CACHE_OPERATION_NAMES,
@@ -7,8 +7,6 @@ import {
77
getClient,
88
hasSpanStreamingEnabled,
99
isObjectLike,
10-
SEMANTIC_ATTRIBUTE_CACHE_HIT,
11-
SEMANTIC_ATTRIBUTE_CACHE_KEY,
1210
SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN,
1311
SPAN_STATUS_ERROR,
1412
SPAN_STATUS_OK,
@@ -180,7 +178,7 @@ function createMethodWrapper(
180178
span.setStatus({ code: SPAN_STATUS_OK });
181179

182180
if (CACHE_HIT_METHODS.has(methodName)) {
183-
span.setAttribute(SEMANTIC_ATTRIBUTE_CACHE_HIT, resolveCacheHit(methodName, args[0], result));
181+
span.setAttribute(CACHE_HIT, resolveCacheHit(methodName, args[0], result));
184182
}
185183

186184
return result;
@@ -242,7 +240,7 @@ function createSpanStartOptions(
242240
[SENTRY_OP]: cacheOperation,
243241
[CACHE_OPERATION]: cacheOperationName,
244242
[SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.cache.nuxt',
245-
[SEMANTIC_ATTRIBUTE_CACHE_KEY]: keys.length > 1 ? keys : keys[0],
243+
[CACHE_KEY]: keys.length > 1 ? keys : keys[0],
246244
'db.operation.name': methodName,
247245
'db.collection.name': mountBase.replace(/:$/, ''),
248246
'db.system.name': driver.name ?? 'unknown',

‎packages/server-utils/src/integrations/redis/redis-cache.ts‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
import {
2+
CACHE_HIT,
3+
CACHE_ITEM_SIZE,
4+
CACHE_KEY,
25
CACHE_OPERATION,
36
NETWORK_PEER_ADDRESS,
47
NETWORK_PEER_PORT,
@@ -11,9 +14,6 @@ import {
1114
CACHE_OPERATION_NAMES,
1215
getClient,
1316
hasSpanStreamingEnabled,
14-
SEMANTIC_ATTRIBUTE_CACHE_HIT,
15-
SEMANTIC_ATTRIBUTE_CACHE_ITEM_SIZE,
16-
SEMANTIC_ATTRIBUTE_CACHE_KEY,
1717
SEMANTIC_ATTRIBUTE_SENTRY_OP,
1818
spanToJSON,
1919
truncate,
@@ -175,7 +175,7 @@ export function getRedisCacheAttributes(
175175

176176
const attributes: SpanAttributes = {
177177
[SEMANTIC_ATTRIBUTE_SENTRY_OP]: cacheOperation,
178-
[SEMANTIC_ATTRIBUTE_CACHE_KEY]: safeKey,
178+
[CACHE_KEY]: safeKey,
179179
[CACHE_OPERATION]: CACHE_OPERATION_NAMES[cacheOperation],
180180
};
181181

@@ -216,11 +216,11 @@ export function applyCacheResponseAttributes(span: Span, response: unknown): voi
216216
const cacheItemSize = calculateCacheItemSize(response);
217217

218218
if (cacheItemSize) {
219-
span.setAttribute(SEMANTIC_ATTRIBUTE_CACHE_ITEM_SIZE, cacheItemSize);
219+
span.setAttribute(CACHE_ITEM_SIZE, cacheItemSize);
220220
}
221221

222222
if (op === CACHE_GET && cacheItemSize !== undefined) {
223-
span.setAttribute(SEMANTIC_ATTRIBUTE_CACHE_HIT, cacheItemSize > 0);
223+
span.setAttribute(CACHE_HIT, cacheItemSize > 0);
224224
}
225225
}
226226

0 commit comments

Comments
 (0)