Loading...
Loading...
Setup Sentry in iOS/Swift apps. Use when asked to add Sentry to iOS, install sentry-cocoa SDK, or configure error monitoring for iOS applications using Swift and SwiftUI.
npx skill4agent add getsentry/sentry-agent-skills sentry-ios-swift-setuphttps://github.com/getsentry/sentry-cocoa.git9.5.0| Product | Use Case |
|---|---|
| Default (static linking) |
| Dynamic framework |
| SwiftUI view performance tracking |
| App extensions or CLI tools |
# Podfile
pod 'Sentry', :git => 'https://github.com/getsentry/sentry-cocoa.git', :tag => '9.5.0'pod installimport SwiftUI
import Sentry
@main
struct YourApp: App {
init() {
SentrySDK.start { options in
options.dsn = "YOUR_SENTRY_DSN"
options.debug = true
// Tracing
options.tracesSampleRate = 1.0
// Profiling
options.configureProfiling = {
$0.sessionSampleRate = 1.0
$0.lifecycle = .trace
}
// Session Replay
options.sessionReplay.sessionSampleRate = 1.0
options.sessionReplay.onErrorSampleRate = 1.0
// Logs (SDK 9.0.0+; for 8.55.0-8.x use options.experimental.enableLogs)
options.enableLogs = true
// Error context
options.attachScreenshot = true
options.attachViewHierarchy = true
}
}
var body: some Scene {
WindowGroup { ContentView() }
}
}import UIKit
import Sentry
@main
class AppDelegate: UIResponder, UIApplicationDelegate {
func application(_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
SentrySDK.start { options in
options.dsn = "YOUR_SENTRY_DSN"
options.debug = true
options.tracesSampleRate = 1.0
options.enableLogs = true
}
return true
}
}| Option | Description | Default |
|---|---|---|
| Sentry DSN | Required |
| % of transactions traced | |
| % of sessions replayed | |
| % of error sessions replayed | |
| Send logs to Sentry | |
| Attach screenshot on error | |
| Attach view hierarchy on error | |
| Feature | What's Captured |
|---|---|
| App Launches | Cold/warm start times |
| Network | URLSession requests |
| UI | UIViewController loads, user interactions |
| File I/O | Read/write operations |
| Core Data | Fetch/save operations |
| Frames | Slow and frozen frame detection |
let logger = SentrySDK.logger
logger.info("User action", attributes: [
"userId": "123",
"action": "checkout"
])
// Log levels: trace, debug, info, warn, error, fataloptions.experimental.enableSessionReplayInUnreliableEnvironment = true// SwiftUI modifiers
Text("Safe content").sentryReplayUnmask()
Text(user.email).sentryReplayMask()let user = User()
user.userId = "user_123"
user.email = "user@example.com"
SentrySDK.setUser(user)
// Clear on logout
SentrySDK.setUser(nil)// Test error capture
SentrySDK.capture(message: "Test from iOS")
// Or trigger a test error
do {
try someFailingFunction()
} catch {
SentrySDK.capture(error: error)
}SentrySDK.start { options in
options.dsn = "YOUR_SENTRY_DSN"
options.debug = false
options.tracesSampleRate = 0.2 // 20%
options.sessionReplay.sessionSampleRate = 0.1 // 10%
options.sessionReplay.onErrorSampleRate = 1.0 // 100% on error
options.enableLogs = true
}bundle exec fastlane add_plugin fastlane-plugin-sentry# Environment variable (recommended for CI)
export SENTRY_AUTH_TOKEN=your_token_here.sentryclirc.gitignore[auth]
token=YOUR_SENTRY_AUTH_TOKENlane :sentry_size do
build_app(
scheme: "YourApp",
configuration: "Release",
export_method: "app-store"
)
sentry_upload_build(
org_slug: "your-org",
project_slug: "your-project",
build_configuration: "Release"
)
endbundle exec fastlane sentry_size| Issue | Solution |
|---|---|
| Events not appearing | Check DSN, enable |
| No traces | Set |
| No replays | Set |
| No logs | Set |
| CocoaPods fails | Run |
| Size upload fails | Check |