Skip to content

Commit ed41023

Browse files
fix(cli): Leave visionOS out of the Apple wizard's Replay check
sentry-cocoa defines options.sessionReplay on visionOS only since 9.28.0, and the wizard accepts any 9.x, so a visionOS project resolved below that wouldn't compile the snippet. Compile Replay in on iOS and tvOS only. Co-Authored-By: Antonis Lilis <antonis.lilis@sentry.io>
1 parent 643694b commit ed41023

4 files changed

Lines changed: 26 additions & 23 deletions

File tree

‎packages/cli/src/lib/wizard/apple/templates.ts‎

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -109,9 +109,12 @@ export function getSwiftSnippet({
109109
`;
110110
}
111111

112+
// sentry-cocoa 9.x defines `sessionReplay` only on iOS, tvOS, and, since
113+
// 9.28.0, visionOS. visionOS is left out on purpose: the wizard accepts any
114+
// 9.x, so a visionOS project resolved below 9.28.0 wouldn't compile it.
112115
if (enableReplay) {
113116
snippet += `
114-
#if os(iOS) || os(tvOS) || os(visionOS)
117+
#if os(iOS) || os(tvOS)
115118
// Record Session Replays for 10% of sessions and 100% of sessions with an error.
116119
// Visit ${SESSION_REPLAY_DOCS_URL} to learn more.
117120
options.sessionReplay.sessionSampleRate = 0.1
@@ -177,12 +180,13 @@ export function getObjcSnippet({
177180
`;
178181
}
179182

180-
// The platforms of sentry-cocoa's own `sessionReplay` guard. Its
181-
// `SENTRY_OBJC_HAS_UIKIT` half is defined only by the SentryObjC headers, not
182-
// by the `@import Sentry` the snippet uses, so it would compile Replay out.
183+
// sentry-cocoa's `sessionReplay` guard, minus visionOS (see the Swift
184+
// snippet) and minus `SENTRY_OBJC_HAS_UIKIT`: only the SentryObjC headers
185+
// define that macro, not the `@import Sentry` the snippet uses, so it would
186+
// compile Replay out.
183187
if (enableReplay) {
184188
snippet += `
185-
#if TARGET_OS_IOS || TARGET_OS_TV || TARGET_OS_VISION
189+
#if TARGET_OS_IOS || TARGET_OS_TV
186190
// Record Session Replays for 10% of sessions and 100% of sessions with an error.
187191
// Visit ${SESSION_REPLAY_DOCS_URL} to learn more.
188192
options.sessionReplay.sessionSampleRate = 0.1;

‎packages/cli/test/lib/wizard/apple/apple-wizard.test.ts‎

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -329,9 +329,7 @@ describe("runAppleWizard", () => {
329329

330330
expect(asked).toEqual(["tracing", "logs", "profiling"]);
331331
expect(mainAppSource()).not.toContain("sessionReplay");
332-
expect(mainAppSource()).not.toContain(
333-
"#if os(iOS) || os(tvOS) || os(visionOS)",
334-
);
332+
expect(mainAppSource()).not.toContain("#if os(iOS) || os(tvOS)");
335333
// The other answers still go in.
336334
expect(mainAppSource()).toContain("options.configureProfiling");
337335
expect(setTag).toHaveBeenCalledWith("enable-session-replay", false);
@@ -344,9 +342,9 @@ describe("runAppleWizard", () => {
344342
await runWizard();
345343

346344
expect(asked).toEqual([]);
347-
expect(mainAppSource()).toContain(
348-
"#if os(iOS) || os(tvOS) || os(visionOS)",
349-
);
345+
expect(mainAppSource()).toContain("#if os(iOS) || os(tvOS)\n");
346+
// Replay on visionOS needs sentry-cocoa 9.28.0, so the snippet leaves it out.
347+
expect(mainAppSource()).not.toContain("visionOS");
350348
expect(mainAppSource()).toContain(
351349
"options.sessionReplay.sessionSampleRate = 0.1",
352350
);

‎packages/cli/test/lib/wizard/apple/code-tools.test.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1330,7 +1330,7 @@ describe("code-tools", () => {
13301330
language: "Swift",
13311331
content: validAppDelegateSwift,
13321332
ext: "swift" as const,
1333-
ifLine: "#if os(iOS) || os(tvOS) || os(visionOS)",
1333+
ifLine: "#if os(iOS) || os(tvOS)",
13341334
replayLines: [
13351335
"options.sessionReplay.sessionSampleRate = 0.1",
13361336
"options.sessionReplay.onErrorSampleRate = 1.0",
@@ -1340,7 +1340,7 @@ describe("code-tools", () => {
13401340
language: "Objective-C",
13411341
content: validAppDelegateObjC,
13421342
ext: "m" as const,
1343-
ifLine: "#if TARGET_OS_IOS || TARGET_OS_TV || TARGET_OS_VISION",
1343+
ifLine: "#if TARGET_OS_IOS || TARGET_OS_TV",
13441344
replayLines: [
13451345
"options.sessionReplay.sessionSampleRate = 0.1;",
13461346
"options.sessionReplay.onErrorSampleRate = 1.0;",

‎packages/cli/test/lib/wizard/apple/templates.test.ts‎

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,7 @@ fi
407407
getSnippet: getSwiftSnippet,
408408
tracesLine: "options.tracesSampleRate = 1.0",
409409
profilingIfLine: "#if !(os(watchOS) || os(tvOS) || os(visionOS))",
410-
replayIfLine: "#if os(iOS) || os(tvOS) || os(visionOS)",
410+
replayIfLine: "#if os(iOS) || os(tvOS)",
411411
logsLine: "options.enableLogs = true",
412412
},
413413
{
@@ -416,7 +416,7 @@ fi
416416
tracesLine: "options.tracesSampleRate = @1.0;",
417417
profilingIfLine:
418418
"#if !(TARGET_OS_WATCH || TARGET_OS_TV || TARGET_OS_VISION)",
419-
replayIfLine: "#if TARGET_OS_IOS || TARGET_OS_TV || TARGET_OS_VISION",
419+
replayIfLine: "#if TARGET_OS_IOS || TARGET_OS_TV",
420420
logsLine: "options.enableLogs = YES;",
421421
},
422422
];
@@ -496,7 +496,7 @@ fi
496496
}
497497
#endif
498498
499-
#if os(iOS) || os(tvOS) || os(visionOS)
499+
#if os(iOS) || os(tvOS)
500500
// Record Session Replays for 10% of sessions and 100% of sessions with an error.
501501
// Visit https://docs.sentry.io/platforms/apple/guides/ios/session-replay/ to learn more.
502502
options.sessionReplay.sessionSampleRate = 0.1
@@ -532,7 +532,7 @@ fi
532532
// For more information, visit: https://docs.sentry.io/platforms/apple/data-management/data-collected/
533533
options.sendDefaultPii = true
534534
535-
#if os(iOS) || os(tvOS) || os(visionOS)
535+
#if os(iOS) || os(tvOS)
536536
// Record Session Replays for 10% of sessions and 100% of sessions with an error.
537537
// Visit https://docs.sentry.io/platforms/apple/guides/ios/session-replay/ to learn more.
538538
options.sessionReplay.sessionSampleRate = 0.1
@@ -574,7 +574,7 @@ fi
574574
};
575575
#endif
576576
577-
#if TARGET_OS_IOS || TARGET_OS_TV || TARGET_OS_VISION
577+
#if TARGET_OS_IOS || TARGET_OS_TV
578578
// Record Session Replays for 10% of sessions and 100% of sessions with an error.
579579
// Visit https://docs.sentry.io/platforms/apple/guides/ios/session-replay/ to learn more.
580580
options.sessionReplay.sessionSampleRate = 0.1;
@@ -610,7 +610,7 @@ fi
610610
// For more information, visit: https://docs.sentry.io/platforms/apple/data-management/data-collected/
611611
options.sendDefaultPii = YES;
612612
613-
#if TARGET_OS_IOS || TARGET_OS_TV || TARGET_OS_VISION
613+
#if TARGET_OS_IOS || TARGET_OS_TV
614614
// Record Session Replays for 10% of sessions and 100% of sessions with an error.
615615
// Visit https://docs.sentry.io/platforms/apple/guides/ios/session-replay/ to learn more.
616616
options.sessionReplay.sessionSampleRate = 0.1;
@@ -630,19 +630,20 @@ fi
630630
});
631631
});
632632

633-
// sentry-cocoa 9.x only defines `sessionReplay` on iOS, tvOS, and visionOS,
634-
// so the snippet must compile it out elsewhere, such as in macOS apps.
633+
// sentry-cocoa 9.x only defines `sessionReplay` on iOS and tvOS (visionOS
634+
// only since 9.28.0), so the snippet must compile it out elsewhere, such as
635+
// in macOS and visionOS apps.
635636
describe("Session Replay platform check", () => {
636637
const variations = [
637638
{
638639
language: "Swift",
639640
getSnippet: getSwiftSnippet,
640-
ifLine: "#if os(iOS) || os(tvOS) || os(visionOS)",
641+
ifLine: "#if os(iOS) || os(tvOS)",
641642
},
642643
{
643644
language: "Objective-C",
644645
getSnippet: getObjcSnippet,
645-
ifLine: "#if TARGET_OS_IOS || TARGET_OS_TV || TARGET_OS_VISION",
646+
ifLine: "#if TARGET_OS_IOS || TARGET_OS_TV",
646647
},
647648
];
648649

0 commit comments

Comments
 (0)