Skip to content

Commit d9e29ee

Browse files
committed
set cache hit for all get commands
1 parent d0f8f84 commit d9e29ee

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

packages/node/src/integrations/tracing/redis.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
import type { IntegrationFn } from '@sentry/types';
1212
import { generateInstrumentOnce } from '../../otel/instrument';
1313
import {
14+
GET_COMMANDS,
1415
calculateCacheItemSize,
1516
getCacheKeySafely,
1617
getCacheOperation,
@@ -60,7 +61,7 @@ export const instrumentRedis = generateInstrumentOnce(INTEGRATION_NAME, () => {
6061
span.setAttribute(SEMANTIC_ATTRIBUTE_CACHE_ITEM_SIZE, cacheItemSize);
6162
}
6263

63-
if (cacheOperation === 'cache.get' && cacheItemSize !== undefined) {
64+
if (GET_COMMANDS.includes(redisCommand) && cacheItemSize !== undefined) {
6465
span.setAttribute(SEMANTIC_ATTRIBUTE_CACHE_HIT, cacheItemSize > 0);
6566
}
6667

packages/opentelemetry/src/utils/parseSpanDescription.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import {
1414
import type { TransactionSource } from '@sentry/types';
1515
import { getSanitizedUrlString, parseUrl, stripUrlQueryAndFragment } from '@sentry/utils';
1616

17-
import { SEMANTIC_ATTRIBUTE_CACHE_HIT } from '@sentry/core';
17+
import { SEMANTIC_ATTRIBUTE_SENTRY_OP } from '@sentry/core';
1818
import type { AbstractSpan } from '../types';
1919
import { getSpanKind } from './getSpanKind';
2020
import { spanHasAttributes, spanHasName } from './spanTypes';
@@ -44,9 +44,14 @@ export function parseSpanDescription(span: AbstractSpan): SpanDescription {
4444
return descriptionForHttpMethod({ attributes, name, kind: getSpanKind(span) }, httpMethod);
4545
}
4646

47-
// If db.type exists then this is a database call span (unless it is cache)
4847
const dbSystem = attributes[SEMATTRS_DB_SYSTEM];
49-
if (dbSystem && typeof attributes[SEMANTIC_ATTRIBUTE_CACHE_HIT] !== 'boolean') {
48+
const opIsCache =
49+
typeof attributes[SEMANTIC_ATTRIBUTE_SENTRY_OP] === 'string' &&
50+
attributes[SEMANTIC_ATTRIBUTE_SENTRY_OP].startsWith('cache.');
51+
52+
// If db.type exists then this is a database call span
53+
// If the Redis DB is used as a cache, the span description should not be changed
54+
if (dbSystem && (!attributes[SEMANTIC_ATTRIBUTE_SENTRY_OP] || !opIsCache)) {
5055
return descriptionForDbSystem({ attributes, name });
5156
}
5257

0 commit comments

Comments
 (0)