Skip to content

fix(cli): Send the iOS wizard's test event only in Debug builds - #2798

Merged
antonis merged 1 commit into
mainfrom
fix/apple-wizard-debug-only-test-event
Dec 2, 2026
Merged

antonis merged 1 commit into
mainfrom
fix/apple-wizard-debug-only-test-event

Conversation

@sentry-junior

@sentry-junior sentry-junior Bot commented Dec 2, 2026

Copy link
Copy Markdown
Contributor

Testing sentry wizard ios on real projects showed that the snippet it writes ends with a test event right after SentrySDK.start. A comment asks people to remove it once the integration works, but when they don't, every launch of the shipped app sends that event to Sentry, using quota and adding noise. @sentry/wizard behaves the same.

The capture line is now wrapped in #if DEBUG … #endif in both the Swift and Objective-C snippets. Xcode's templates define DEBUG for the Debug configuration in both languages, so the test event still arrives from Debug builds but not from Release builds. The #if/#endif lines use the capture line's indentation, like the profiling guard in #2791, and the comment now says the event is Debug-only (the Objective-C comment also gets its missing space after //).

Detection of an existing SentrySDK.start / [SentrySDK start in code-tools.ts is unaffected, since the start call is unchanged.

via Antonis Lilis.

--

View Session [Sentry]

The snippet that sentry wizard ios writes captured a test message right
after SentrySDK.start. Apps that kept the line sent that event on every
launch in production. Wrap it in #if DEBUG so Release builds leave it out.

Co-Authored-By: Antonis Lilis <antonis.lilis@sentry.io>
@vercel

vercel Bot commented Dec 2, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
cli Ready Ready Preview Dec 2, 2026 2:42pm UTC
1 Skipped Deployment
Project Deployment Actions Updated
sentry-local Skipped Skipped Dec 2, 2026 2:42pm UTC

Request Review

@antonis
antonis enabled auto-merge December 2, 2026 14:47
@github-actions github-actions Bot added the risk: low PR risk score: low label Dec 2, 2026
@antonis
antonis added this pull request to the merge queue Dec 2, 2026
Merged via the queue into main with commit d150951 Dec 2, 2026
32 checks passed
@antonis
antonis deleted the fix/apple-wizard-debug-only-test-event branch December 2, 2026 15:03
antonis added a commit that referenced this pull request Dec 2, 2026
…est event

#2798 wraps the test event at the end of both snippets in #if DEBUG.
Update the expected snippets for the tracing and profiling answers, and
check for the profiling #if line instead of any #if, since every snippet
now has one. Pass options to the snippet functions in #2798's test.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
github-actions Bot pushed a commit to Fields-Education/sentry-mcp that referenced this pull request Dec 3, 2026
…ilds (getsentry#2803)

This comes from testing `sentry wizard android` on fresh Android Studio
projects (getsentry/sentry-java#6797).

The wizard adds a test error to the main Activity's `onCreate` through
an `OnGlobalLayoutListener` that it never removes. A global layout
listener fires on every layout pass, not just the first: rotation, the
keyboard, insets, any view change. So the app sends a stream of test
errors, and keeps doing it in Release builds if the snippet ships.

The test error is now sent once per Activity creation, in debuggable
builds only, like the iOS wizard's `#if DEBUG` (getsentry#2798):

- The Java and Kotlin snippets use an anonymous
`ViewTreeObserver.OnGlobalLayoutListener` that calls
`removeOnGlobalLayoutListener(this)` first in `onGlobalLayout()`. It
still waits for the first layout, so the error's screenshot shows the
UI. It removes itself through `contentView.getViewTreeObserver()` rather
than a saved observer, because the observer you get in `onCreate`,
before the view is attached, is merged into the window's observer later,
and removing from the old one would throw.
- The snippet runs only when `ApplicationInfo.FLAG_DEBUGGABLE` is set.
It doesn't use `BuildConfig.DEBUG`, because AGP 8 and later don't
generate `BuildConfig` unless `buildFeatures.buildConfig` is on.
- `android.content.pm.ApplicationInfo` and
`android.view.ViewTreeObserver` are fully qualified, like
`android.R.id.content`, so the wizard still adds only the
`io.sentry.Sentry` import.
- The comment now says what the snippet does and to remove it after
confirming the integration works.
- The snippet indents each nesting level by 4 spaces, matching Android
Studio's default for Java and Kotlin and the `sentry {}` block the
wizard already writes. It used to start at 4 spaces but nest by 2. The
first line stays at 4 spaces, in line with `onCreate`'s body.

`code-tools.ts` is unchanged and still inserts the snippet right after
`super.onCreate(...)`.

`@sentry/wizard` has the same snippet and needs the same fix.

Open decision: whether this is ready for review. It stays a draft until
then.

<!-- junior-request-attribution:start -->
via **Antonis Lilis**.
<!-- junior-request-attribution:end -->

<!-- junior-session-footer:start -->
<!-- junior-conversation-id:slack%3AD0CAPGCFLSC%3A1796224967.137949 -->

--

[View
Session](https://junior-prod.sentry.dev/conversations/slack%3AD0CAPGCFLSC%3A1796224967.137949)
[[Sentry]](https://sentry.sentry.io/explore/conversations/slack%3AD0CAPGCFLSC%3A1796224967.137949/?project=4510944073809921)

<!-- junior-session-footer:end -->

---------

Co-authored-by: sentry-junior[bot] <264270552+sentry-junior[bot]@users.noreply.github.com>
Co-authored-by: Antonis Lilis <antonis.lilis@sentry.io>

This branch was successfully deployed

1 active and 1 inactive deployments
Preview – cli — 4533999c Deployed Dec 2, 2026 by vercel[bot]
Preview – sentry-local — 4533999c Deployed Dec 2, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

risk: low PR risk score: low

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant