Skip to content

fix(profiling): Don't crash when ProfilingManager can't be loaded - #6742

Merged
romtsn merged 5 commits into
mainfrom
fix/perfetto-profiling-manager-ncdfe
Nov 23, 2026
Merged

romtsn merged 5 commits into
mainfrom
fix/perfetto-profiling-manager-ncdfe

Conversation

@sentry-junior

@sentry-junior sentry-junior Bot commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

📜 Description

PerfettoProfiler now gets ProfilingManager through a guarded helper. If getSystemService fails, the helper logs a warning and returns null. start() already handles a null manager by returning false, so Perfetto continuous profiling turns itself off on that device instead of crashing the app.

The catches follow the exception-handling rules in AGENTS.md. getSystemService is a system-service boundary, so it gets a broad catch that calls ExceptionUtils.rethrowIfFatal first. rethrowIfFatal rethrows every LinkageError, so a separate LinkageError catch comes before it. That catch covers the failure seen in the wild (NoClassDefFoundError) and a framework whose ProfilingManager fails to initialize (ExceptionInInitializerError). Other fatal errors, such as OutOfMemoryError, still propagate. Comments at both catches say why they exist, and the Javadoc says what happens on failure: no profiles are recorded on that device.

💡 Motivation and Context

Datadog found that some API 36 devices throw NoClassDefFoundError: android.os.ProfilingManager when their SDK resolves the service, and the error takes down the host app (DataDog/dd-sdk-android#4168). We have the same exposure. On API 35+, AndroidOptionsInitializer always installs PerfettoContinuousProfiler, and its factory builds PerfettoProfiler, which cast context.getSystemService(Context.PROFILING_SERVICE) to ProfilingManager with nothing to catch the error. That path runs from startProfiler() and from the chunk restart, and neither has a catch around it.

Open question for review: on affected devices, failing to load ProfilingManager is visible only in debug logs, and PerfettoContinuousProfiling is still reported as an integration. Is that enough, or should we surface it some other way?

📝 Checklist

  • I added GH Issue ID & Linear ID
  • I added tests to verify the 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.
  • Review from the native team if needed.
  • No breaking change or entry added to the changelog.
  • No breaking change for hybrid SDKs or communicated to hybrid SDKs.
  • Public API changes reviewed by another Mobile SDK team member or implemented according to the develop docs spec.

via roman.

--

View Session [Sentry]

sentry-junior Bot and others added 2 commits November 23, 2026 14:12
Co-Authored-By: Roman Zavarnitsyn <roman.zavarnitsyn@sentry.io>
Co-Authored-By: Roman Zavarnitsyn <roman.zavarnitsyn@sentry.io>
@github-actions github-actions Bot added the risk: medium PR risk score: medium label Nov 23, 2026
@github-actions

github-actions Bot commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

PR risk: medium

For commit 9a446ea.

Main concerns: reach, host performance, data sent to Sentry.

This label is a hint for reviewers, not an approval.

…g-manager-ncdfe

Co-Authored-By: Roman Zavarnitsyn <roman.zavarnitsyn@sentry.io>

# Conflicts:
#	CHANGELOG.md
@github-actions github-actions Bot added risk: medium PR risk score: medium and removed risk: medium PR risk score: medium labels Nov 23, 2026
@sentry

sentry Bot commented Nov 23, 2026 •

Copy link
Copy Markdown

📲 Install Builds

Android

🔗 App Name App ID Version Configuration
SDK Size io.sentry.tests.size 8.65.1 (1) release

⚙️ sentry-android Build Distribution Settings

…ndary

Co-Authored-By: Roman Zavarnitsyn <roman.zavarnitsyn@sentry.io>
@github-actions github-actions Bot added risk: medium PR risk score: medium and removed risk: medium PR risk score: medium labels Nov 23, 2026
@romtsn romtsn added the ship-it PR is ready to merge from a reviewer perspective label Nov 23, 2026
@romtsn
romtsn marked this pull request as ready for review November 23, 2026 14:24
@romtsn
romtsn requested review from a team and adinauer as code owners November 23, 2026 14:24
@romtsn
romtsn requested review from 0xadam-brown and markushi and removed request for a team November 23, 2026 14:25
@github-actions github-actions Bot added risk: medium PR risk score: medium and removed risk: medium PR risk score: medium labels Nov 23, 2026

@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 using default effort and found 1 potential issue.

Fix All in Cursor

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

Reviewed by Cursor Bugbot for commit 090fa0f. Configure here.

@github-actions github-actions Bot added risk: medium PR risk score: medium and removed risk: medium PR risk score: medium labels Nov 23, 2026
@romtsn
romtsn merged commit 8884e89 into main Nov 23, 2026
48 of 49 checks passed
@romtsn
romtsn deleted the fix/perfetto-profiling-manager-ncdfe branch November 23, 2026 18:23
@sentry-junior sentry-junior Bot mentioned this pull request Nov 24, 2026
1 task done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

risk: medium PR risk score: medium ship-it PR is ready to merge from a reviewer perspective

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants