mcpField
S
sentry-ios-swift-setup

sentry-ios-swift-setup

github.com/getsentryDevelopment2597 installsUpdated 35w ago
Repository

About sentry-ios-swift-setup

A setup skill for adding Sentry to iOS projects built with Swift or SwiftUI. It guides developers through installation, monitoring configuration, session replay, and troubleshooting.

Key features

  1. 01Swift Package Manager and CocoaPods installation
  2. 02SwiftUI and UIKit initialization
  3. 03Error, tracing, and log settings
  4. 04Session replay and content masking
  5. 05Automatic performance and network capture
  6. 06Fastlane build-size analysis

Use cases

  1. 01Add Sentry to a SwiftUI or UIKit app
  2. 02Configure iOS error and performance monitoring
  3. 03Set up session replay and sensitive-content masking
  4. 04Upload build-size data with Fastlane

Install

Copy the command and run it in a terminal.

$npx skills add https://github.com/getsentry/sentry-agent-skills --skill sentry-ios-swift-setup

After installing, type/sentry-ios-swift-setupin Claude Code to confirm it loaded.

Details

From the project README

Sentry iOS Swift Setup

Install and configure Sentry in iOS projects using Swift and SwiftUI.

Invoke This Skill When

  • User asks to "add Sentry to iOS" or "install Sentry" in a Swift app
  • User wants error monitoring, tracing, or session replay in iOS
  • User mentions "sentry-cocoa" or iOS crash reporting

Important: The configuration options and code samples below are examples. Always verify against docs.sentry.io before implementing, as APIs and defaults may have changed.

Requirements

  • iOS 15.0+, macOS 12.0+, tvOS 15.0+, watchOS 8.0+

Install

Swift Package Manager (Recommended)
  1. File > Add Package Dependencies
  2. Enter: https://github.com/getsentry/sentry-cocoa.git
  3. Select version rule: "Up to Next Major" from 9.5.0

SPM Products: Choose based on your needs:

ProductUse Case
SentryDefault (static linking)
Sentry-DynamicDynamic framework
SentrySwiftUISwiftUI view performance tracking
Sentry-WithoutUIKitOrAppKitApp extensions or CLI tools
CocoaPods
# Podfile
pod 'Sentry', :git => 'https://github.com/getsentry/sentry-cocoa.git', :tag => '9.5.0'

Then run pod install.

Configure

SwiftUI App
import 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() }
    }
}
UIKit App
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
    }
}

Configuration Options

OptionDescriptionDefault
dsnSentry DSNRequired
tracesSampleRate% of transactions traced0
sessionReplay.sessionSampleRate% of sessions replayed0
sessionReplay.onErrorSampleRate% of error sessions replayed0
enableLogsSend logs to Sentryfalse
attachScreenshotAttach screenshot on errorfalse
attachViewHierarchyAttach view hierarchy on errorfalse

Auto-Instrumented Features

FeatureWhat's Captured
App LaunchesCold/warm start times
NetworkURLSession requests
UIUIViewController loads, user interactions
File I/ORead/write operations
Core DataFetch/save operations
FramesSlow and frozen frame detection

Logging

let logger = SentrySDK.logger

logger.info("User action", attributes: [
    "userId": "123",
    "action": "checkout"
])

// Log levels: trace, debug, info, warn, error, fatal

Session Replay

iOS 26+ / Xcode 26+ caveat: SDK 8.57.0+ automatically disables Session Replay on iOS 26.0+ when built with Xcode 26.0+ due to Apple's Liquid Glass rendering breaking masking reliability. Replay still works on iOS < 26 or Xcode < 26. To force-enable (use with caution): options.experimental.enableSessionReplayInUnreliableEnvironment = true.

Masking
// SwiftUI modifiers
Text("Safe content").sentryReplayUnmask()
Text(user.email).sentryReplayMask()

User Context

let user = User()
user.userId = "user_123"
user.email = "[email protected]"
SentrySDK.setUser(user)

// Clear on logout
SentrySDK.setUser(nil)

Verification

// Test error capture
SentrySDK.capture(message: "Test from iOS")

// Or trigger a test error
do {
    try someFailingFunction()
} catch {
    SentrySDK.capture(error: error)
}

Production Settings

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
}

Size Analysis (Fastlane)

Track app bundle size with Sentry using the Fastlane plugin.

Install Plugin
bundle exec fastlane add_plugin fastlane-plugin-sentry
Configure Authentication
# Environment variable (recommended for CI)
export SENTRY_AUTH_TOKEN=your_token_here

Or create .sentryclirc (add to .gitignore):

[auth]
token=YOUR_SENTRY_AUTH_TOKEN
Fastfile Lane
lane :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"
  )
end
Run Size Analysis
bundle exec fastlane sentry_size

View results in the Sentry UI after the upload completes.

Troubleshooting

IssueSolution
Events not appearingCheck DSN, enable debug = true
No tracesSet tracesSampleRate > 0
No replaysSet sessionSampleRate > 0, check SDK 8.31.1+. On iOS 26+/Xcode 26+ see Liquid Glass caveat above
No logsSet enableLogs = true (SDK 9.0.0+) or experimental.enableLogs = true (SDK 8.55.0-8.x)
CocoaPods failsRun pod repo update, check iOS 15+ target
Size upload failsCheck SENTRY_AUTH_TOKEN, verify org/project slugs

Comments

Markdown supported