Skip to content

Commit 2d302b2

Browse files
committed
Add Sentry
- Added Sentry debugging and performance monitoring - Performance monitoring records the time spend on the request to the backend server
1 parent f1f845b commit 2d302b2

6 files changed

Lines changed: 143 additions & 2 deletions

File tree

iOSSC.xcodeproj/project.pbxproj

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
136BCFE42539DAB900C77D96 /* APIResponse.swift in Sources */ = {isa = PBXBuildFile; fileRef = 136BCFE32539DAB900C77D96 /* APIResponse.swift */; };
3131
13709B57253C381000C422B8 /* SFSafeSymbols in Frameworks */ = {isa = PBXBuildFile; productRef = 13709B56253C381000C422B8 /* SFSafeSymbols */; };
3232
1373EE6B253CACD20088AB0F /* SwiftUIRefresh in Frameworks */ = {isa = PBXBuildFile; productRef = 1373EE6A253CACD20088AB0F /* SwiftUIRefresh */; };
33+
1375089827AB159E003B436C /* Sentry in Frameworks */ = {isa = PBXBuildFile; productRef = 1375089727AB159E003B436C /* Sentry */; };
3334
1380D10F272FD9A800B05ECF /* LogoutButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1380D10E272FD9A800B05ECF /* LogoutButton.swift */; };
3435
1380D111272FDC9D00B05ECF /* ContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1380D110272FDC9D00B05ECF /* ContentView.swift */; };
3536
1380D113272FDDBE00B05ECF /* BigButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1380D112272FDDBE00B05ECF /* BigButton.swift */; };
@@ -91,6 +92,7 @@
9192
138E846A253B04E600B1B8AD /* KeychainAccess in Frameworks */,
9293
13709B57253C381000C422B8 /* SFSafeSymbols in Frameworks */,
9394
136BCFDB2539D64300C77D96 /* Alamofire in Frameworks */,
95+
1375089827AB159E003B436C /* Sentry in Frameworks */,
9496
);
9597
runOnlyForDeploymentPostprocessing = 0;
9698
};
@@ -230,6 +232,7 @@
230232
13EB1D2B253B6C57007D79D8 /* Haptica */,
231233
13709B56253C381000C422B8 /* SFSafeSymbols */,
232234
1373EE6A253CACD20088AB0F /* SwiftUIRefresh */,
235+
1375089727AB159E003B436C /* Sentry */,
233236
);
234237
productName = iOSSC;
235238
productReference = 132160A92539BE74003D3489 /* iOSSC.app */;
@@ -264,6 +267,7 @@
264267
13EB1D2A253B6C57007D79D8 /* XCRemoteSwiftPackageReference "Haptica" */,
265268
13709B55253C381000C422B8 /* XCRemoteSwiftPackageReference "SFSafeSymbols" */,
266269
1373EE69253CACD20088AB0F /* XCRemoteSwiftPackageReference "SwiftUIRefresh" */,
270+
1375089627AB159E003B436C /* XCRemoteSwiftPackageReference "sentry-cocoa" */,
267271
);
268272
productRefGroup = 132160AA2539BE74003D3489 /* Products */;
269273
projectDirPath = "";
@@ -458,7 +462,7 @@
458462
"$(inherited)",
459463
"@executable_path/Frameworks",
460464
);
461-
MARKETING_VERSION = 0.2.4;
465+
MARKETING_VERSION = 0.2.5;
462466
PRODUCT_BUNDLE_IDENTIFIER = me.kuhlti.iOSSC;
463467
PRODUCT_NAME = "$(TARGET_NAME)";
464468
PROVISIONING_PROFILE_SPECIFIER = "";
@@ -483,7 +487,7 @@
483487
"$(inherited)",
484488
"@executable_path/Frameworks",
485489
);
486-
MARKETING_VERSION = 0.2.4;
490+
MARKETING_VERSION = 0.2.5;
487491
PRODUCT_BUNDLE_IDENTIFIER = me.kuhlti.iOSSC;
488492
PRODUCT_NAME = "$(TARGET_NAME)";
489493
PROVISIONING_PROFILE_SPECIFIER = "";
@@ -540,6 +544,14 @@
540544
minimumVersion = 0.0.3;
541545
};
542546
};
547+
1375089627AB159E003B436C /* XCRemoteSwiftPackageReference "sentry-cocoa" */ = {
548+
isa = XCRemoteSwiftPackageReference;
549+
repositoryURL = "https://github.com/getsentry/sentry-cocoa";
550+
requirement = {
551+
kind = upToNextMajorVersion;
552+
minimumVersion = 7.0.0;
553+
};
554+
};
543555
138E8468253B04E600B1B8AD /* XCRemoteSwiftPackageReference "KeychainAccess" */ = {
544556
isa = XCRemoteSwiftPackageReference;
545557
repositoryURL = "https://github.com/kishikawakatsumi/KeychainAccess";
@@ -574,6 +586,11 @@
574586
package = 1373EE69253CACD20088AB0F /* XCRemoteSwiftPackageReference "SwiftUIRefresh" */;
575587
productName = SwiftUIRefresh;
576588
};
589+
1375089727AB159E003B436C /* Sentry */ = {
590+
isa = XCSwiftPackageProductDependency;
591+
package = 1375089627AB159E003B436C /* XCRemoteSwiftPackageReference "sentry-cocoa" */;
592+
productName = Sentry;
593+
};
577594
138E8469253B04E600B1B8AD /* KeychainAccess */ = {
578595
isa = XCSwiftPackageProductDependency;
579596
package = 138E8468253B04E600B1B8AD /* XCRemoteSwiftPackageReference "KeychainAccess" */;

iOSSC.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<Scheme
3+
LastUpgradeVersion = "1320"
4+
version = "1.3">
5+
<BuildAction
6+
parallelizeBuildables = "YES"
7+
buildImplicitDependencies = "YES">
8+
<BuildActionEntries>
9+
<BuildActionEntry
10+
buildForTesting = "YES"
11+
buildForRunning = "YES"
12+
buildForProfiling = "YES"
13+
buildForArchiving = "YES"
14+
buildForAnalyzing = "YES">
15+
<BuildableReference
16+
BuildableIdentifier = "primary"
17+
BlueprintIdentifier = "132160A82539BE74003D3489"
18+
BuildableName = "iOSSC.app"
19+
BlueprintName = "iOSSC"
20+
ReferencedContainer = "container:iOSSC.xcodeproj">
21+
</BuildableReference>
22+
</BuildActionEntry>
23+
</BuildActionEntries>
24+
</BuildAction>
25+
<TestAction
26+
buildConfiguration = "Debug"
27+
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
28+
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
29+
shouldUseLaunchSchemeArgsEnv = "YES">
30+
<Testables>
31+
</Testables>
32+
</TestAction>
33+
<LaunchAction
34+
buildConfiguration = "Debug"
35+
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
36+
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
37+
launchStyle = "0"
38+
useCustomWorkingDirectory = "NO"
39+
ignoresPersistentStateOnLaunch = "NO"
40+
debugDocumentVersioning = "YES"
41+
debugServiceExtension = "internal"
42+
allowLocationSimulation = "YES">
43+
<BuildableProductRunnable
44+
runnableDebuggingMode = "0">
45+
<BuildableReference
46+
BuildableIdentifier = "primary"
47+
BlueprintIdentifier = "132160A82539BE74003D3489"
48+
BuildableName = "iOSSC.app"
49+
BlueprintName = "iOSSC"
50+
ReferencedContainer = "container:iOSSC.xcodeproj">
51+
</BuildableReference>
52+
</BuildableProductRunnable>
53+
<EnvironmentVariables>
54+
<EnvironmentVariable
55+
key = "SENTRY_DSN"
56+
value = "https://a15a2ce49b0645c6973d37f861f2b423@o459771.ingest.sentry.io/5469457"
57+
isEnabled = "YES">
58+
</EnvironmentVariable>
59+
</EnvironmentVariables>
60+
</LaunchAction>
61+
<ProfileAction
62+
buildConfiguration = "Release"
63+
shouldUseLaunchSchemeArgsEnv = "YES"
64+
savedToolIdentifier = ""
65+
useCustomWorkingDirectory = "NO"
66+
debugDocumentVersioning = "YES">
67+
<BuildableProductRunnable
68+
runnableDebuggingMode = "0">
69+
<BuildableReference
70+
BuildableIdentifier = "primary"
71+
BlueprintIdentifier = "132160A82539BE74003D3489"
72+
BuildableName = "iOSSC.app"
73+
BlueprintName = "iOSSC"
74+
ReferencedContainer = "container:iOSSC.xcodeproj">
75+
</BuildableReference>
76+
</BuildableProductRunnable>
77+
</ProfileAction>
78+
<AnalyzeAction
79+
buildConfiguration = "Debug">
80+
</AnalyzeAction>
81+
<ArchiveAction
82+
buildConfiguration = "Release"
83+
revealArchiveInOrganizer = "YES">
84+
</ArchiveAction>
85+
</Scheme>

iOSSC.xcodeproj/xcuserdata/kuhltime.xcuserdatad/xcschemes/xcschememanagement.plist

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,13 @@
3131
<integer>0</integer>
3232
</dict>
3333
</dict>
34+
<key>SuppressBuildableAutocreation</key>
35+
<dict>
36+
<key>132160A82539BE74003D3489</key>
37+
<dict>
38+
<key>primary</key>
39+
<true/>
40+
</dict>
41+
</dict>
3442
</dict>
3543
</plist>

iOSSC/Model/APIManager.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ import Foundation
99
import Combine
1010
import Alamofire
1111
import KeychainAccess
12+
import Sentry
13+
14+
// TODO: Add Sentry Performance Monitoring https://sentry.io/kuhltime/iossc/getting-started/apple-ios/
1215

1316
// Future Reference:
1417
// - https://medium.com/@rashidium/generic-api-response-handling-with-codable-in-swift-5-using-alamofire-5-9809522de87
@@ -149,6 +152,8 @@ class APIManager: ObservableObject {
149152
return
150153
}
151154

155+
let sentryTransaction = SentrySDK.startTransaction(name: "Fetch Modules", operation: "modules")
156+
152157
let jsonDecoder = JSONDecoder()
153158
jsonDecoder.dateDecodingStrategy = .formatted(DateFormatter.iso8601Full)
154159

@@ -168,20 +173,23 @@ class APIManager: ObservableObject {
168173
guard let data = apiResponse.data else {
169174
print("No data in APIResponse")
170175
completion?()
176+
sentryTransaction.finish(status: .dataLoss)
171177
return
172178
}
173179

174180
print("Recieved Data")
175181
self.data = data
176182
self.loginState = .loggedIn
177183

184+
sentryTransaction.finish(status: .ok)
178185
completion?()
179186

180187
case .failed:
181188
print("API error with message: \(apiResponse.message ?? "NO MESSAGE PROVIDED")")
182189
self.logout()
183190
self.loginState = .error
184191

192+
sentryTransaction.finish(status: .dataLoss)
185193
completion?()
186194
}
187195
}

iOSSC/iOSSCApp.swift

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,27 @@
77

88
import SwiftUI
99
import SFSafeSymbols
10+
import Sentry
1011

1112
@main
1213
struct iOSSCApp: App {
1314

1415
@ObservedObject
1516
private var manager = APIManager(enviorment: .production)
1617

18+
init() {
19+
SentrySDK.start { options in
20+
// Set the SENTRY_DSN inside your Schema
21+
options.dsn = ProcessInfo.processInfo.environment["SENTRY_DSN"]
22+
23+
options.debug = true // Enabled debug when first installing is always helpful
24+
25+
// Set tracesSampleRate to 1.0 to capture 100% of transactions for performance monitoring.
26+
// We recommend adjusting this value in production.
27+
options.tracesSampleRate = 1.0
28+
}
29+
}
30+
1731
var body: some Scene {
1832
WindowGroup {
1933
ZStack {

0 commit comments

Comments
 (0)