Skip to content

Commit 4e4d46a

Browse files
authored
docs: Add Objective C examples to cocoa onboarding + non UI verification options (#92506)
Apple onboarding only had Swift + UIKit verification steps. Added: - Objective C code - Non UI options to verify the setup Fixes [getsentry/sentry-cocoa#4991](getsentry/sentry-cocoa#4991) ### Legal Boilerplate Look, I get it. The entity doing business as "Sentry" was incorporated in the State of Delaware in 2015 as Functional Software, Inc. and is gonna need some rights from me in order to utilize my contributions in this here PR. So here's the deal: I retain all rights, title and interest in and to my contributions, and by keeping this boilerplate intact I confirm that Sentry can use, modify, copy, and redistribute my contributions, under Sentry's choice of terms.
1 parent fd2bb76 commit 4e4d46a

File tree

2 files changed

+160
-41
lines changed

2 files changed

+160
-41
lines changed

static/app/gettingStartedDocs/apple/ios.spec.tsx

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,26 @@ describe('apple-ios onboarding docs', function () {
1818
expect(screen.getByRole('heading', {name: 'Verify'})).toBeInTheDocument();
1919
});
2020

21+
it('renders swift onboarding docs correctly', async function () {
22+
renderWithOnboardingLayout(docs, {
23+
selectedProducts: [ProductSolution.ERROR_MONITORING],
24+
selectedOptions: {
25+
installationMode: InstallationMode.MANUAL_SWIFT,
26+
},
27+
});
28+
29+
expect(
30+
await screen.findAllByText(
31+
textWithMarkupMatcher(/throw MyCustomError\.myFirstIssue/)
32+
)
33+
).toHaveLength(1);
34+
});
35+
2136
it('renders performance onboarding docs correctly', async function () {
2237
renderWithOnboardingLayout(docs, {
2338
selectedProducts: [ProductSolution.PERFORMANCE_MONITORING],
2439
selectedOptions: {
25-
installationMode: InstallationMode.MANUAL,
40+
installationMode: InstallationMode.MANUAL_SWIFT,
2641
},
2742
});
2843

@@ -34,7 +49,7 @@ describe('apple-ios onboarding docs', function () {
3449
it('renders transaction profiling', async function () {
3550
renderWithOnboardingLayout(docs, {
3651
selectedOptions: {
37-
installationMode: InstallationMode.MANUAL,
52+
installationMode: InstallationMode.MANUAL_SWIFT,
3853
},
3954
});
4055

@@ -61,7 +76,7 @@ describe('apple-ios onboarding docs', function () {
6176
docs,
6277
{
6378
selectedOptions: {
64-
installationMode: InstallationMode.MANUAL,
79+
installationMode: InstallationMode.MANUAL_SWIFT,
6580
},
6681
},
6782
{
@@ -87,4 +102,17 @@ describe('apple-ios onboarding docs', function () {
87102
expect(lifecycleElements).toHaveLength(2);
88103
lifecycleElements.forEach(element => expect(element).toBeInTheDocument());
89104
});
105+
106+
it('renders manual objective-c docs correctly', async function () {
107+
renderWithOnboardingLayout(docs, {
108+
selectedProducts: [ProductSolution.ERROR_MONITORING],
109+
selectedOptions: {
110+
installationMode: InstallationMode.MANUAL_OBJECTIVE_C,
111+
},
112+
});
113+
114+
expect(
115+
await screen.findAllByText(textWithMarkupMatcher(/@import Sentry;/))
116+
).toHaveLength(1);
117+
});
90118
});

static/app/gettingStartedDocs/apple/ios.tsx

Lines changed: 129 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ import {getWizardInstallSnippet} from 'sentry/utils/gettingStartedDocs/mobileWiz
2020

2121
export enum InstallationMode {
2222
AUTO = 'auto',
23-
MANUAL = 'manual',
23+
MANUAL_SWIFT = 'manual-swift',
24+
MANUAL_OBJECTIVE_C = 'manual-objective-c',
2425
}
2526

2627
const platformOptions = {
@@ -32,8 +33,12 @@ const platformOptions = {
3233
value: InstallationMode.AUTO,
3334
},
3435
{
35-
label: t('Manual'),
36-
value: InstallationMode.MANUAL,
36+
label: t('Manual (Swift)'),
37+
value: InstallationMode.MANUAL_SWIFT,
38+
},
39+
{
40+
label: t('Manual (Objective-C)'),
41+
value: InstallationMode.MANUAL_OBJECTIVE_C,
3742
},
3843
],
3944
defaultValue: InstallationMode.AUTO,
@@ -46,14 +51,19 @@ type Params = DocsParams<PlatformOptions>;
4651
const isAutoInstall = (params: Params) =>
4752
params.platformOptions.installationMode === InstallationMode.AUTO;
4853

54+
const isManualSwift = (params: Params) =>
55+
params.platformOptions.installationMode === InstallationMode.MANUAL_SWIFT;
56+
57+
const selectedLanguage = (params: Params) => (isManualSwift(params) ? 'swift' : 'objc');
58+
4959
const getManualInstallSnippet = (params: Params) => `
5060
.package(url: "https://github.com/getsentry/sentry-cocoa", from: "${getPackageVersion(
5161
params,
5262
'sentry.cocoa',
5363
'8.49.0'
5464
)}"),`;
5565

56-
const getConfigurationSnippet = (params: Params) => `
66+
const getConfigurationSnippetSwift = (params: Params) => `
5767
import Sentry
5868
5969
// ....
@@ -108,6 +118,58 @@ func application(_ application: UIApplication,
108118
return true
109119
}`;
110120

121+
const getConfigurationSnippetObjectiveC = (params: Params) => `
122+
@import Sentry;
123+
124+
// ....
125+
126+
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
127+
[SentrySDK startWithConfigureOptions:^(SentryOptions *options) {
128+
options.dsn = "${params.dsn.public}";
129+
options.debug = YES; // Enabling debug when first installing is always helpful
130+
131+
// Adds IP for users.
132+
// For more information, visit: https://docs.sentry.io/platforms/apple/data-management/data-collected/
133+
options.sendDefaultPii = YES;${
134+
params.isPerformanceSelected
135+
? `
136+
137+
// Set tracesSampleRate to 1.0 to capture 100% of transactions for tracing.
138+
// We recommend adjusting this value in production.
139+
options.tracesSampleRate = @1.0;`
140+
: ''
141+
}${
142+
params.isProfilingSelected &&
143+
params.profilingOptions?.defaultProfilingMode !== 'continuous'
144+
? `
145+
146+
// Set tracesSampleRate to 1.0 to capture 100% of transactions for tracing.
147+
// We recommend adjusting this value in production.
148+
options.tracesSampleRate = @1.0;`
149+
: params.isProfilingSelected &&
150+
params.profilingOptions?.defaultProfilingMode === 'continuous'
151+
? `
152+
153+
// Configure the profiler to start profiling when there is an active root span
154+
// For more information, visit: https://docs.sentry.io/platforms/apple/profiling/
155+
[options setConfigureProfiling:^(SentryProfileOptions * _Nonnull profiling) {
156+
profiling.lifecycle = SentryProfileLifecycleTrace;
157+
profiling.sessionSampleRate = 1.0;
158+
}];`
159+
: ''
160+
}${
161+
params.isReplaySelected
162+
? `
163+
164+
// Record Session Replays for 100% of Errors and 10% of Sessions
165+
options.sessionReplay.onErrorSampleRate = 1.0;
166+
options.sessionReplay.sessionSampleRate = 0.1;`
167+
: ''
168+
}
169+
}];
170+
return YES;
171+
}`;
172+
111173
const getConfigurationSnippetSwiftUi = (params: Params) => `
112174
import Sentry
113175
@@ -160,15 +222,37 @@ struct SwiftUIApp: App {
160222
}
161223
}`;
162224

163-
const getVerifySnippet = () => `
164-
let button = UIButton(type: .roundedRect)
165-
button.frame = CGRect(x: 20, y: 50, width: 100, height: 30)
166-
button.setTitle("Break the world", for: [])
167-
button.addTarget(self, action: #selector(self.breakTheWorld(_:)), for: .touchUpInside)
168-
view.addSubview(button)
225+
const getVerifySnippet = (params: Params) =>
226+
isManualSwift(params)
227+
? `
228+
enum MyCustomError: Error {
229+
case myFirstIssue
230+
}
231+
232+
func thisFunctionThrows() throws {
233+
throw MyCustomError.myFirstIssue
234+
}
169235
170-
@IBAction func breakTheWorld(_ sender: AnyObject) {
171-
fatalError("Break the world")
236+
func verifySentrySDK() {
237+
do {
238+
try thisFunctionThrows()
239+
} catch {
240+
SentrySDK.capture(error: error)
241+
}
242+
}`
243+
: `
244+
- (void)thisFunctionReturnsAnError:(NSError **)error {
245+
*error = [NSError errorWithDomain:@"com.example.myapp"
246+
code:1001
247+
userInfo:@{
248+
NSLocalizedDescriptionKey: @"Something went wrong."
249+
}];
250+
}
251+
252+
- (void)verifySentrySDK {
253+
NSError *error = nil;
254+
[self thisFunctionReturnsAnError:&error];
255+
[SentrySDK captureError:error];
172256
}`;
173257

174258
const getReplaySetupSnippet = (params: Params) => `
@@ -314,28 +398,35 @@ const onboarding: OnboardingConfig<PlatformOptions> = {
314398
)}
315399
</p>
316400
),
317-
configurations: [
318-
{
319-
language: 'swift',
320-
code: getConfigurationSnippet(params),
321-
},
322-
{
323-
description: (
324-
<p>
325-
{tct(
326-
"When using SwiftUI and your app doesn't implement an app delegate, initialize the SDK within the [initializer: App conformer's initializer]:",
327-
{
328-
initializer: (
329-
<ExternalLink href="https://developer.apple.com/documentation/swiftui/app/main()" />
330-
),
331-
}
332-
)}
333-
</p>
334-
),
335-
language: 'swift',
336-
code: getConfigurationSnippetSwiftUi(params),
337-
},
338-
],
401+
configurations: isManualSwift(params)
402+
? [
403+
{
404+
language: 'swift',
405+
code: getConfigurationSnippetSwift(params),
406+
},
407+
{
408+
description: (
409+
<p>
410+
{tct(
411+
"When using SwiftUI and your app doesn't implement an app delegate, initialize the SDK within the [initializer: App conformer's initializer]:",
412+
{
413+
initializer: (
414+
<ExternalLink href="https://developer.apple.com/documentation/swiftui/app/main()" />
415+
),
416+
}
417+
)}
418+
</p>
419+
),
420+
language: 'swift',
421+
code: getConfigurationSnippetSwiftUi(params),
422+
},
423+
]
424+
: [
425+
{
426+
language: 'objc',
427+
code: getConfigurationSnippetObjectiveC(params),
428+
},
429+
],
339430
},
340431
],
341432
verify: params =>
@@ -354,17 +445,17 @@ const onboarding: OnboardingConfig<PlatformOptions> = {
354445
description: (
355446
<p>
356447
{tct(
357-
'This snippet contains an intentional error you can use to test that errors are uploaded to Sentry correctly. You can add it to your main [viewController: ViewController].',
448+
'This snippet contains an intentional error you can use to test that errors are uploaded to Sentry correctly. You can call [verifySentrySDK: verifySentrySDK()] from where you want to test it.',
358449
{
359-
viewController: <code />,
450+
verifySentrySDK: <code />,
360451
}
361452
)}
362453
</p>
363454
),
364455
configurations: [
365456
{
366-
language: 'swift',
367-
code: getVerifySnippet(),
457+
language: selectedLanguage(params),
458+
code: getVerifySnippet(params),
368459
},
369460
],
370461
},

0 commit comments

Comments
 (0)