sentry-cocoa-sdk은(는) 무엇을 하나요?
Apple 플랫폼(iOS, macOS, tvOS, watchOS, visionOS)을 위한 완전한 Sentry SDK 설정입니다. "iOS에 Sentry 추가", "Swift에 Sentry 추가", "sentry-cocoa 설치" 요청 또는 Apple 애플리케이션의 오류 모니터링, 추적, 프로파일링, 세션 리플레이, 로깅, 메트릭스 구성을 위해 사용하세요. SwiftUI 및 UIKit을 지원합니다.
개요
이 SDK는 Apple 플랫폼 애플리케이션에 Sentry를 통합하여 충돌 보고, 성능 추적, 프로파일링, 세션 리플레이, 로깅 및 메트릭스를 제공합니다.
설치 방법
Swift Package Manager
Package.swift 파일에 다음을 추가하세요:
// swift-tools-version:5.5
import PackageDescription
let package = Package(
name: "MyApp",
dependencies: [
.package(url: "https://github.com/getsentry/sentry-cocoa.git", from: "8.0.0")
],
targets: [
.target(
name: "MyApp",
dependencies: ["Sentry"])
]
)
CocoaPods
Podfile에 다음을 추가하세요:
platform :ios, '12.0'
use_frameworks!
target 'YourApp' do
pod 'Sentry', '~> 8.0'
end
Carthage
Cartfile에 다음을 추가하세요:
binary "https://raw.githubusercontent.com/getsentry/sentry-cocoa/main/Sentry.json" ~> 8.0
기본 설정
초기화
앱의 AppDelegate 또는 @main 구조체에서 Sentry를 초기화하세요.
iOS 14+ / SwiftUI
import SwiftUI
import Sentry
@main
struct MyApp: App {
init() {
SentrySDK.start { options in
options.dsn = "https://[email protected]/0"
options.tracesSampleRate = 1.0 // 추적 샘플링 비율 (0.0 ~ 1.0)
options.profilesSampleRate = 1.0 // 프로파일링 샘플링 비율
options.enableSessionReplay = true // 세션 리플레이 활성화
options.sessionReplayConfiguration.sessionSampleRate = 0.1
options.sessionReplayConfiguration.errorSampleRate = 1.0
options.attachScreenshot = true // 스크린샷 첨부
options.attachViewHierarchy = true // 뷰 계층 첨부
options.enableTracing = true // 추적 활성화
}
}
var body: some Scene {
WindowGroup {
ContentView()
}
}
}
UIKit (iOS 13+)
import UIKit
import Sentry
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
SentrySDK.start { options in
options.dsn = "https://[email protected]/0"
options.tracesSampleRate = 1.0
options.profilesSampleRate = 1.0
options.enableAutoPerformanceTracing = true
options.enableUIViewControllerTracing = true
}
return true
}
}
주요 기능
오류 및 예외 모니터링
// 수동 오류 보고
SentrySDK.capture(error: error)
// 메시지 로깅
SentrySDK.capture(message: "사용자 작업 실행됨")
성능 추적 (Tracing)
// 사용자 정의 트랜잭션
let transaction = SentrySDK.startTransaction(name: "장바구니 체크아웃", operation: "checkout")
// ... 작업 수행 ...
transaction.finish()
프로파일링 (Profiling)
프로파일링은 options.profilesSampleRate 설정을 통해 자동으로 활성화됩니다. 코드 변경 없이 성능 병목 지점을 식별할 수 있습니다.
세션 리플레이 (Session Replay)
사용자 세션을 녹화하여 오류 발생 시점의 정확한 사용자 동작을 재생합니다.
options.enableSessionReplay = true
options.sessionReplayConfiguration.sessionSampleRate = 0.2 // 20% 세션 샘플링
로깅 (Logging)
import Sentry
// Sentry에 로그 전송
SentrySDK.capture(message: "정보 메시지") { scope in
scope.setLevel(.info)
}
메트릭스 (Metrics)
// 사용자 정의 메트릭 전송
SentrySDK.metrics.increment(key: "button.click")
SentrySDK.metrics.distribution(key: "response.time", value: 350.0)
고급 설정
DSN 구성
DSN은 Sentry 프로젝트의 고유 식별자입니다. 환경 변수 또는 직접 문자열로 설정할 수 있습니다.
options.dsn = ProcessInfo.processInfo.environment["SENTRY_DSN"] ?? "https://[email protected]/0"
환경 및 릴리스 설정
options.environment = "production"
options.releaseName = "[email protected]"
options.dist = "1"
사전 및 사후 이벤트 처리
options.beforeSend = { event in
// 이벤트 필터링 또는 수정
return event
}
options.beforeBreadcrumb = { breadcrumb in
// Breadcrumb 필터링 또는 수정
return breadcrumb
}
플랫폼 지원
| 플랫폼 | 최소 배포 타겟 |
|---|---|
| iOS | 12.0 |
| macOS | 10.13 |
| tvOS | 12.0 |
| watchOS | 7.0 |
| visionOS | 1.0 |