Skip to content

fix(profiling-node): Use safeDateNow for profile envelope timestamps - #26474

Merged
chargome merged 1 commit into
getsentry:developfrom
JavierCane:feat/profiling-safe-envelope-timestamp
Nov 17, 2026
Merged

chargome merged 1 commit into
getsentry:developfrom
JavierCane:feat/profiling-safe-envelope-timestamp

Conversation

@JavierCane

Copy link
Copy Markdown
Contributor

What

Prevent CPU profile flushes from reading the ambient clock during Next.js Cache Components prerendering. The regression test rejects both zero-argument new Date() and Date.now() outside the safe context and verifies a valid envelope timestamp.

Why

The profiling package has its own envelope-header builder, which was not covered by the core timestamp fix in #21351 for #21333. #21510 and #21573 address random-ID setup in build workers; this path already has the safe runner available but bypasses it when creating sent_at.

Using core's existing safeDateNow() follows the responsibility split in #18700: Next.js supplies the safe context and shared SDK code uses it without importing the framework. It also keeps the escape limited to a telemetry timestamp, consistent with gnoff's warning about broader context escapes.

Maintainer go-ahead.

Validated with pnpm run format, pnpm run build:dev, pnpm run lint, and the profiling package's type-aware lint and full test suite (27 tests, including worker integration). The regression fails before the fix and passes after it. An additional test-program typecheck reports the same five pre-existing diagnostics with and without this test; the new test typechecks independently.

Closes #26431

Use the existing safe clock for the profile envelope timestamp so CPU profile flushes do not violate Cache Components prerender restrictions. Cover the read with a guarded-clock regression test.

Co-Authored-By: OpenAI GPT-6 <codex@openai.com>
@github-actions github-actions Bot added the external PR from an external contributor label Nov 17, 2026
@JavierCane

Copy link
Copy Markdown
Contributor Author

@chargome, thanks for the go-ahead in #26431. The draft PR includes the safe timestamp change and a guarded-clock regression test that fails before the fix and passes after it; the full profiling suite also passes.

GitHub did not allow me to submit a reviewer request with my current permissions, so I am mentioning you here as invited.

@andreiborza

Copy link
Copy Markdown
Member

bugbot run

@andreiborza andreiborza 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.

LGTM, thank you for the contribution @JavierCane.

@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.

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit 255e083. Configure here.

@chargome chargome self-assigned this Nov 17, 2026

@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!

@chargome
chargome merged commit abdc5dd into getsentry:develop Nov 17, 2026
48 checks passed
msonnb pushed a commit that referenced this pull request Nov 17, 2026
This PR adds the external contributor to the CHANGELOG.md file, so that
they are credited for their contribution. See #26474

Co-authored-by: chargome <20254395+chargome@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

external PR from an external contributor

Projects

None yet

Development

Successfully merging this pull request may close these issues.

profiling-node: profile envelope timestamp breaks Next.js Cache Components prerendering

3 participants