-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
feat(node): Add maxCacheKeyLength to Redis integration (remove truncation)
#18045
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
7f030e8
7b87870
1bb037f
f32141b
dc0f0cc
0ae8180
29bdf86
778e047
d0c9e8b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -24,14 +24,34 @@ import { | |
| } from '../../utils/redisCache'; | ||
|
|
||
| interface RedisOptions { | ||
| /** | ||
| * Define cache prefixes for cache keys that should be captured as a cache span. | ||
| * | ||
| * Setting this to, for example, `['user:']` will capture cache keys that start with `user:`. | ||
| */ | ||
| cachePrefixes?: string[]; | ||
| /** | ||
| * Maximum length of the cache key added to the span description. If the key exceeds this length, it will be truncated. | ||
| * | ||
| * Passing `0` will use the full cache key without truncation. | ||
| * | ||
| * By default, the full cache key is used. | ||
| */ | ||
| maxCacheKeyLength?: number; | ||
| } | ||
|
|
||
| const INTEGRATION_NAME = 'Redis'; | ||
|
|
||
| let _redisOptions: RedisOptions = {}; | ||
| /* Only exported for testing purposes */ | ||
| export let _redisOptions: RedisOptions = {}; | ||
|
|
||
| const cacheResponseHook: RedisResponseCustomAttributeFunction = (span: Span, redisCommand, cmdArgs, response) => { | ||
| /* Only exported for testing purposes */ | ||
| export const cacheResponseHook: RedisResponseCustomAttributeFunction = ( | ||
| span: Span, | ||
| redisCommand, | ||
| cmdArgs, | ||
| response, | ||
| ) => { | ||
| span.setAttribute(SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, 'auto.db.otel.redis'); | ||
|
|
||
| const safeKey = getCacheKeySafely(redisCommand, cmdArgs); | ||
|
|
@@ -70,9 +90,12 @@ const cacheResponseHook: RedisResponseCustomAttributeFunction = (span: Span, red | |
| [SEMANTIC_ATTRIBUTE_CACHE_KEY]: safeKey, | ||
| }); | ||
|
|
||
| // todo: change to string[] once EAP supports it | ||
| const spanDescription = safeKey.join(', '); | ||
|
|
||
| span.updateName(truncate(spanDescription, 1024)); | ||
| span.updateName( | ||
| _redisOptions.maxCacheKeyLength ? truncate(spanDescription, _redisOptions.maxCacheKeyLength) : spanDescription, | ||
| ); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Adding a new comment here since the previous one was marked as outdated. Setting
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's the default behavior of our |
||
| }; | ||
|
|
||
| const instrumentIORedis = generateInstrumentOnce(`${INTEGRATION_NAME}.IORedis`, () => { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.