-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
feat(node,server-utils): Set cache.key on dataloader spans and capture redis delete operations as cache.remove
#22389
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
93a9dab
0af75dc
ece7d46
d4fe083
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 |
|---|---|---|
|
|
@@ -9,6 +9,7 @@ | |
| */ | ||
|
|
||
| import { InstrumentationBase, InstrumentationNodeModuleDefinition, isWrapped } from '@opentelemetry/instrumentation'; | ||
| import { CACHE_KEY } from '@sentry/conventions/attributes'; | ||
| import type { BatchLoadFn, DataLoader, DataLoaderConstructor } from './types'; | ||
| import { | ||
| SDK_VERSION, | ||
|
isaacs marked this conversation as resolved.
|
||
|
|
@@ -59,6 +60,16 @@ function getSpanOp(operation: 'load' | 'loadMany' | 'batch' | 'prime' | 'clear' | |
| return undefined; | ||
| } | ||
|
|
||
| // `load` receives a single key, `loadMany`/`batch` receive a key array. Normalize both to the | ||
| // `string[]` shape `cache.key` expects. | ||
| function getCacheKey(keyArg: unknown): string[] | undefined { | ||
| if (Array.isArray(keyArg)) { | ||
| return keyArg.map(key => String(key)); | ||
| } | ||
|
|
||
| return keyArg == null ? undefined : [String(keyArg)]; | ||
| } | ||
|
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. Array keys mishandled on loadMedium Severity
Additional Locations (1)Reviewed by Cursor Bugbot for commit ece7d46. Configure here. |
||
|
|
||
| export class DataloaderInstrumentation extends InstrumentationBase { | ||
| constructor(config = {}) { | ||
| super(PACKAGE_NAME, SDK_VERSION, config); | ||
|
|
@@ -107,6 +118,7 @@ export class DataloaderInstrumentation extends InstrumentationBase { | |
| attributes: { | ||
| [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: ORIGIN, | ||
| [SEMANTIC_ATTRIBUTE_SENTRY_OP]: getSpanOp('batch'), | ||
| [CACHE_KEY]: getCacheKey(args[0]), | ||
| }, | ||
| onlyIfParent: true, | ||
| }, | ||
|
|
@@ -161,6 +173,7 @@ export class DataloaderInstrumentation extends InstrumentationBase { | |
| attributes: { | ||
| [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: ORIGIN, | ||
| [SEMANTIC_ATTRIBUTE_SENTRY_OP]: getSpanOp('load'), | ||
| [CACHE_KEY]: getCacheKey(args[0]), | ||
| }, | ||
| onlyIfParent: true, | ||
| }, | ||
|
|
@@ -199,6 +212,7 @@ export class DataloaderInstrumentation extends InstrumentationBase { | |
| attributes: { | ||
| [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: ORIGIN, | ||
| [SEMANTIC_ATTRIBUTE_SENTRY_OP]: getSpanOp('loadMany'), | ||
| [CACHE_KEY]: getCacheKey(args[0]), | ||
| }, | ||
| onlyIfParent: true, | ||
| }, | ||
|
|
||


There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing remove size assertion
Low Severity
This violates the testing rule about
expect.objectContainingwhen a payload must omit a field: the new DEL expectations never assert thatcache.item_sizeis absent, even though remove responses are intentionally excluded from size calculation. A regression that sets size again would still pass. Flagged because it was mentioned in this rules file.Additional Locations (2)
dev-packages/node-integration-tests/suites/tracing/redis-cache/test.ts#L273-L284dev-packages/node-integration-tests/suites/tracing/redis-cache/test.ts#L426-L437Triggered by project rule: PR Review Guidelines for Cursor Bot
Reviewed by Cursor Bugbot for commit d4fe083. Configure here.