$npx -y skills add rshankras/claude-code-apple-skills --skill error-monitoringGenerates protocol-based error/crash monitoring with swappable providers (Sentry, Crashlytics). Use when user wants to add crash reporting, error tracking, or production monitoring.
| 1 | # Error Monitoring Generator |
| 2 | |
| 3 | Generates a production-ready error monitoring infrastructure with protocol-based architecture for easy provider swapping. |
| 4 | |
| 5 | ## When This Skill Activates |
| 6 | |
| 7 | - User asks to "add crash reporting" or "error monitoring" |
| 8 | - User mentions "Sentry", "Crashlytics", or "crash analytics" |
| 9 | - User wants to "track errors in production" |
| 10 | - User asks about "debugging production issues" |
| 11 | |
| 12 | ## Pre-Generation Checks (CRITICAL) |
| 13 | |
| 14 | ### 1. Project Context Detection |
| 15 | |
| 16 | Before generating, ALWAYS check: |
| 17 | |
| 18 | ```bash |
| 19 | # Check for existing crash reporting |
| 20 | rg -l "Sentry|Crashlytics|CrashReporter" --type swift |
| 21 | |
| 22 | # Check Package.swift for existing SDKs |
| 23 | cat Package.swift | grep -i "sentry\|firebase\|crashlytics" |
| 24 | |
| 25 | # Check for existing error handling patterns |
| 26 | rg "captureError|recordError|logError" --type swift | head -5 |
| 27 | ``` |
| 28 | |
| 29 | ### 2. Conflict Detection |
| 30 | |
| 31 | If existing crash reporting found: |
| 32 | - Ask: Replace, wrap existing, or create parallel system? |
| 33 | |
| 34 | ## Configuration Questions |
| 35 | |
| 36 | Ask user via AskUserQuestion: |
| 37 | |
| 38 | 1. **Initial provider?** |
| 39 | - Sentry (recommended for indie devs) |
| 40 | - Firebase Crashlytics (if already using Firebase) |
| 41 | - None (set up infrastructure only) |
| 42 | |
| 43 | 2. **Include breadcrumbs?** |
| 44 | - Yes (track navigation, user actions) |
| 45 | - No (errors only) |
| 46 | |
| 47 | 3. **Include user context?** |
| 48 | - Yes (anonymized user ID, app state) |
| 49 | - No (minimal data collection) |
| 50 | |
| 51 | ## Generation Process |
| 52 | |
| 53 | ### Step 1: Create Core Files |
| 54 | |
| 55 | **Always generate:** |
| 56 | ``` |
| 57 | Sources/ErrorMonitoring/ |
| 58 | ├── ErrorMonitoringService.swift # Protocol |
| 59 | ├── ErrorContext.swift # Breadcrumbs, user info |
| 60 | └── NoOpErrorMonitoring.swift # Testing/privacy |
| 61 | ``` |
| 62 | |
| 63 | **Based on provider selection:** |
| 64 | ``` |
| 65 | Sources/ErrorMonitoring/Providers/ |
| 66 | ├── SentryErrorMonitoring.swift # If Sentry selected |
| 67 | └── CrashlyticsErrorMonitoring.swift # If Crashlytics selected |
| 68 | ``` |
| 69 | |
| 70 | ### Step 2: Read Templates |
| 71 | |
| 72 | Read templates from this skill: |
| 73 | - `templates/ErrorMonitoringService.swift` |
| 74 | - `templates/ErrorContext.swift` |
| 75 | - `templates/NoOpErrorMonitoring.swift` |
| 76 | - `templates/SentryErrorMonitoring.swift` (if selected) |
| 77 | - `templates/CrashlyticsErrorMonitoring.swift` (if selected) |
| 78 | |
| 79 | ### Step 3: Customize for Project |
| 80 | |
| 81 | Adapt templates to match: |
| 82 | - Project naming conventions |
| 83 | - Existing error types |
| 84 | - Bundle identifier for Sentry DSN |
| 85 | |
| 86 | ### Step 4: Integration |
| 87 | |
| 88 | **In App.swift:** |
| 89 | ```swift |
| 90 | import SwiftUI |
| 91 | |
| 92 | @main |
| 93 | struct MyApp: App { |
| 94 | init() { |
| 95 | // Configure error monitoring |
| 96 | ErrorMonitoring.shared.configure() |
| 97 | } |
| 98 | |
| 99 | var body: some Scene { |
| 100 | WindowGroup { |
| 101 | ContentView() |
| 102 | .environment(\.errorMonitoring, ErrorMonitoring.shared.service) |
| 103 | } |
| 104 | } |
| 105 | } |
| 106 | ``` |
| 107 | |
| 108 | **Capturing errors:** |
| 109 | ```swift |
| 110 | do { |
| 111 | try await riskyOperation() |
| 112 | } catch { |
| 113 | ErrorMonitoring.shared.service.captureError(error) |
| 114 | } |
| 115 | ``` |
| 116 | |
| 117 | **Adding breadcrumbs:** |
| 118 | ```swift |
| 119 | ErrorMonitoring.shared.service.addBreadcrumb( |
| 120 | Breadcrumb(category: "navigation", message: "Opened settings") |
| 121 | ) |
| 122 | ``` |
| 123 | |
| 124 | ## Provider Setup |
| 125 | |
| 126 | ### Sentry |
| 127 | |
| 128 | 1. **Create account** at [sentry.io](https://sentry.io) |
| 129 | 2. **Create project** for iOS/macOS |
| 130 | 3. **Get DSN** from Project Settings > Client Keys |
| 131 | 4. **Add to Package.swift:** |
| 132 | ```swift |
| 133 | .package(url: "https://github.com/getsentry/sentry-cocoa", from: "8.0.0") |
| 134 | ``` |
| 135 | |
| 136 | ### Firebase Crashlytics |
| 137 | |
| 138 | 1. **Add Firebase** to your project via [console.firebase.google.com](https://console.firebase.google.com) |
| 139 | 2. **Download** GoogleService-Info.plist |
| 140 | 3. **Add Firebase SDK** via SPM or CocoaPods |
| 141 | 4. **Enable Crashlytics** in Firebase console |
| 142 | |
| 143 | ## Generated Code Patterns |
| 144 | |
| 145 | ### Protocol (Stable Interface) |
| 146 | ```swift |
| 147 | protocol ErrorMonitoringService: Sendable { |
| 148 | func configure() |
| 149 | func captureError(_ error: Error, context: ErrorContext?) |
| 150 | func captureMessage(_ message: String, level: ErrorLevel) |
| 151 | func addBreadcrumb(_ breadcrumb: Breadcrumb) |
| 152 | func setUser(_ user: MonitoringUser?) |
| 153 | func reset() |
| 154 | } |
| 155 | ``` |
| 156 | |
| 157 | ### Swapping Providers |
| 158 | ```swift |
| 159 | // In ErrorMonitoring.swift |
| 160 | final class ErrorMonitoring { |
| 161 | static let shared = ErrorMonitoring() |
| 162 | |
| 163 | // Change this ONE line to swap providers: |
| 164 | let service: ErrorMonitoringService = SentryErrorMonitoring() |
| 165 | // let service: ErrorMonitoringService = CrashlyticsErrorMonitoring() |
| 166 | // let service: ErrorMonitoringService = NoOpErrorMonitoring() |
| 167 | } |
| 168 | ``` |
| 169 | |
| 170 | ### Breadcrumb Tracking |
| 171 | ```swift |
| 172 | // Automatic navigation breadcrumbs |
| 173 | struct ContentView: View { |
| 174 | @Environment(\.errorMonitoring) var errorMonitoring |
| 175 | |
| 176 | var body: some View { |
| 177 | Button("Open Details") { |
| 178 | errorMonitoring.addBreadcrumb( |
| 179 | Breadcrumb(category: "ui", message: "Tapped details button") |
| 180 | ) |
| 181 | showDetai |