Skip to content

fix(profiling): Fix app start transaction profile timestamp offset#5962

Open
antonis wants to merge 5 commits intomainfrom
fix/profile-app-start-timestamp-offset
Open

fix(profiling): Fix app start transaction profile timestamp offset#5962
antonis wants to merge 5 commits intomainfrom
fix/profile-app-start-timestamp-offset

Conversation

@antonis
Copy link
Copy Markdown
Contributor

@antonis antonis commented Apr 7, 2026

📢 Type of change

  • Bugfix
  • New feature
  • Enhancement
  • Refactoring

📜 Description

Uses the actual profiling start timestamp for the profile's timestamp field instead of the adjusted event.start_timestamp.

For app start transactions, the SDK adjusts the transaction's start_timestamp backward to the app start time. However, profile samples use elapsed_since_start_ns relative to when profiling actually started (JS VM start), not the app start time. This mismatch caused the profile to appear misaligned in the Sentry UI.

Changes:

  • Added profilingStartTimestampNs field to HermesProfileEvent and AndroidCombinedProfileEvent types
  • stopProfiling now stores the profiling start timestamp on the returned profile event
  • enrichCombinedProfileWithEventContext and enrichAndroidProfileWithEventContext prefer the stored profiling start timestamp over event.start_timestamp
  • The internal field is stripped before serialization via destructuring

💡 Motivation and Context

Fixes #4511

When an app start transaction has its start time adjusted, the profile timestamp was incorrectly set to the app start time, while profile samples were relative to the JS VM start. This caused a visual offset in the Sentry profiling UI.

Relay does not validate the profile timestamp against the transaction start_timestamp, so this change is safe from the ingestion side.

💚 How did you test it?

  • All existing tests pass (196 tests)
  • Build succeeds
  • For non-app-start transactions: no behavior change (profiling start ≈ transaction start)
  • For app start transactions: profile timestamp now correctly reflects when profiling started

📝 Checklist

  • I added tests to verify changes
  • No new PII added or SDK only sends newly added PII if sendDefaultPII is enabled
  • I updated the docs if needed.
  • I updated the wizard if needed.
  • All tests passing
  • No breaking changes

🔮 Next steps

Use the actual profiling start timestamp for the profile's timestamp
field instead of the adjusted transaction start_timestamp. For app start
transactions, the transaction start is adjusted backward to the app
start time, but the profile samples are relative to when profiling
actually started (JS VM start). This caused a misalignment in the
Sentry UI.

Fixes #4511

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 7, 2026

Semver Impact of This PR

None (no version bump detected)

📋 Changelog Preview

This is how your changes will appear in the changelog.
Entries from this PR are highlighted with a left border (blockquote style).


  • fix(profiling): Fix app start transaction profile timestamp offset by antonis in #5962
  • fix(ios): Add SENTRY_PROJECT_ROOT env var for monorepo support by antonis in #5961
  • feat(ios): Add attachAllThreads option by antonis in #5960
  • fix(core): Lazy-load Metro internal modules to prevent Expo 55 import errors by lucas-zimerman in #5958
  • chore(deps): update Cocoa SDK to v9.9.0 by github-actions in #5956
  • chore(deps): update Maestro to v2.4.0 by github-actions in #5955
  • Feat: Fallback to stacktrace parsing by lucas-zimerman in #5946
  • fix(ci): Bump Node to 22 in size-analysis and testflight workflows by antonis in #5954
  • feat(playground): Open Sentry in desktop browser from Expo apps by antonis in #5947
  • chore(core): Bump sample app to React Native 0.84.1 by antonis in #5941
  • Size analysis for React Native SDK by alwx in #5949
  • chore(deps): bump lodash from 4.17.23 to 4.18.1 by dependabot in #5953
  • chore(deps): bump yauzl to ^3.2.1 by antonis in #5950
  • chore(deps): bump brace-expansion to ^2.0.3 by antonis in #5951
  • chore(deps): bump @xmldom/xmldom to fix XML injection by antonis in #5952

🤖 This preview updates automatically when you update the PR.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 7, 2026

Fails
🚫 Pull request is not ready for merge, please add the "ready-to-merge" label to the pull request

Generated by 🚫 dangerJS against 02906de

antonis and others added 2 commits April 7, 2026 12:00
Add unit tests for enrichCombinedProfileWithEventContext and
enrichAndroidProfileWithEventContext verifying that:
- profilingStartTimestampNs is used for the profile timestamp when set
- Falls back to event.start_timestamp when not set
- profilingStartTimestampNs is stripped from serialized output

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@sentry
Copy link
Copy Markdown

sentry bot commented Apr 7, 2026

Sentry Build Distribution

App Name App ID Version Configuration Install Page
Sentry RN io.sentry.reactnative.sample 8.7.0 (82) Release Install Build

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@antonis antonis marked this pull request as ready for review April 7, 2026 10:51
Copy link
Copy Markdown
Collaborator

@lucas-zimerman lucas-zimerman left a comment

Choose a reason for hiding this comment

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

LGTM!

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.

Fix App Start Transaction Profile offset

2 participants