Install the swift-sentry package.
Add it to your Package.swift:
dependencies: [
.package(url: "https://github.com/nicklama/swift-sentry.git", from: "0.5.0")
]
Initialize the SDK:
import Sentry
let dsn = ProcessInfo.processInfo.environment["SENTRY_DSN"] ?? "YOUR_DSN"
let sentry = try Sentry(dsn: dsn)
Capture errors:
do {
try riskyOperation()
} catch {
try await sentry.capture(error: error)
}
Shut down cleanly:
try await sentry.close()
SENTRY_DSN environment variable to avoid hardcoding it.