Skip to content

feat(nextjs): Add code.file.path to use cache fill spans - #24988

Merged
s1gr1d merged 6 commits into
developfrom
sig/span-link-cache-naming
Oct 5, 2026
Merged

s1gr1d merged 6 commits into
developfrom
sig/span-link-cache-naming

Conversation

@s1gr1d

@s1gr1d s1gr1d commented Oct 2, 2026 •

Copy link
Copy Markdown
Member

Adds code.file.path to cache.put spans, so use cache spans show which function they belong to.

The cache key contains the function id. Next.js' server-reference manifest maps it to the source file. Keys come in two forms:

  • JSON: ["buildId","c0a941ad…",[args]] (start with [)
  • multipart, when args don't serialize to JSON (params, children):
    1:069:["buildId","c0a941ad…",[…]]1:1c:{"id":"123"} (length-prefixed fields)

Logged real-world data to use this in the unit tests (from 16.3 and canary version).

Linear: https://linear.app/getsentry/issue/JSSDK-31/add-cache-source-file-to-trace-back-where-the-cache-was-created

@s1gr1d
s1gr1d requested a review from a team as a code owner October 2, 2026 12:11
@s1gr1d
s1gr1d requested review from chargome and nicohrubec and removed request for a team October 2, 2026 12:11

fill(handler, 'set', (originalSet: UseCacheHandler['set']) => {
return function (this: UseCacheHandler, cacheKey: string, pendingEntry: Promise<unknown>): Promise<void> {
const digest = keyDigest(cacheKey);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

m: Can we gate this with shouldRecordCacheSpan again?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah sure! seems like the conflicts merge got it wrong

@s1gr1d

s1gr1d commented Oct 2, 2026

Copy link
Copy Markdown
Member Author

bugbot run

@s1gr1d
s1gr1d requested a review from chargome October 2, 2026 13:37

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 2 potential issues.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Want reviews to match your repository better? Bugbot Learning can learn team-specific rules from PR activity. A team admin can enable Learning in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit b2703e7. Configure here.

return startCacheSpan(CACHE_PUT, digest, span => {
if (sourceFile) {
span.setAttribute(CODE_FILE_PATH, sourceFile);
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Span attribute set after start

Medium Severity

sourceFile is already resolved before startCacheSpan runs, but code.file.path is attached afterward with span.setAttribute. tracesSampler and ignoreSpans only see attributes passed into startSpan, so they cannot filter these cache fill spans by source file.

Fix in Cursor Fix in Web

Triggered by project rule: PR Review Guidelines for Cursor Bot

Reviewed by Cursor Bugbot for commit b2703e7. Configure here.

@chargome chargome left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!!

@s1gr1d
s1gr1d enabled auto-merge (squash) October 5, 2026 10:37
@s1gr1d
s1gr1d merged commit 3a7ad4b into develop Oct 5, 2026
689 of 694 checks passed
@s1gr1d
s1gr1d deleted the sig/span-link-cache-naming branch October 5, 2026 11:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants