sentry-cocoa-sdk

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Sentry Cocoa SDK

Sentry Cocoa SDK

Opinionated wizard that scans your Apple project and guides you through complete Sentry setup.
这是一个带有预设规则的向导,可扫描你的Apple项目并引导你完成完整的Sentry设置。

Invoke This Skill When

何时调用此技能

  • User asks to "add Sentry to iOS/macOS/tvOS" or "set up Sentry" in an Apple app
  • User wants error monitoring, tracing, profiling, session replay, or logging in Swift/ObjC
  • User mentions
    sentry-cocoa
    ,
    SentrySDK
    , or the Apple/iOS Sentry SDK
  • User wants to monitor crashes, app hangs, watchdog terminations, or performance
Note: SDK versions and APIs below reflect Sentry docs at time of writing (sentry-cocoa 9.5.1). Always verify against docs.sentry.io/platforms/apple/ before implementing.

  • 用户要求“为iOS/macOS/tvOS添加Sentry”或在Apple应用中“设置Sentry”
  • 用户希望在Swift/ObjC中实现错误监控、追踪、性能分析、会话重放或日志功能
  • 用户提到
    sentry-cocoa
    SentrySDK
    或Apple/iOS Sentry SDK
  • 用户希望监控崩溃、应用挂起、看门狗终止或性能
注意: 以下SDK版本和API反映了编写时Sentry文档的内容(sentry-cocoa 9.5.1)。 在实施前,请务必对照docs.sentry.io/platforms/apple/进行验证。

Phase 1: Detect

阶段1:检测

Run these commands to understand the project before making any recommendations:
bash
undefined
在提出任何建议之前,运行以下命令来了解项目情况:
bash
undefined

Check existing Sentry dependency

检查现有的Sentry依赖

grep -i sentry Package.swift Podfile Cartfile 2>/dev/null
grep -i sentry Package.swift Podfile Cartfile 2>/dev/null

Detect UI framework (SwiftUI vs UIKit)

检测UI框架(SwiftUI vs UIKit)

grep -rE "@main|struct.App.:.App" --include=".swift" . 2>/dev/null | head -5 grep -rE "AppDelegate|UIApplicationMain" --include="*.swift" . 2>/dev/null | head -5
grep -rE "@main|struct.App.:.App" --include=".swift" . 2>/dev/null | head -5 grep -rE "AppDelegate|UIApplicationMain" --include="*.swift" . 2>/dev/null | head -5

Detect platform and deployment targets

检测平台和部署目标

grep -E "platforms:|.iOS|.macOS|.tvOS|.watchOS|.visionOS" Package.swift 2>/dev/null grep -E "platform :ios|platform :osx|platform :tvos|platform :watchos" Podfile 2>/dev/null
grep -E "platforms:|.iOS|.macOS|.tvOS|.watchOS|.visionOS" Package.swift 2>/dev/null grep -E "platform :ios|platform :osx|platform :tvos|platform :watchos" Podfile 2>/dev/null

Detect logging

检测日志工具

grep -rE "import OSLog|os.log|CocoaLumberjack|DDLog" --include="*.swift" . 2>/dev/null | head -5
grep -rE "import OSLog|os.log|CocoaLumberjack|DDLog" --include="*.swift" . 2>/dev/null | head -5

Detect companion backend

检测配套后端服务

ls ../backend ../server ../api 2>/dev/null ls ../go.mod ../requirements.txt ../Gemfile ../package.json 2>/dev/null

**What to note:**
- Is `sentry-cocoa` already in `Package.swift` or `Podfile`? If yes, skip to Phase 2 (configure features).
- SwiftUI (`@main App` struct) or UIKit (`AppDelegate`)? Determines init pattern.
- Which Apple platforms? (Affects which features are available — see Platform Support Matrix.)
- Existing logging library? (Enables structured log capture.)
- Companion backend? (Triggers Phase 4 cross-link for distributed tracing.)

---
ls ../backend ../server ../api 2>/dev/null ls ../go.mod ../requirements.txt ../Gemfile ../package.json 2>/dev/null

**需要注意的点:**
- `sentry-cocoa`是否已在`Package.swift`或`Podfile`中?如果是,直接跳到阶段2(配置功能)。
- 是SwiftUI(`@main App`结构体)还是UIKit(`AppDelegate`)?这决定了初始化方式。
- 目标是哪些Apple平台?(会影响可用功能——参见平台支持矩阵。)
- 是否有现有的日志库?(可启用结构化日志捕获。)
- 是否有配套后端服务?(会触发阶段4的跨链路配置以实现分布式追踪。)

---

Phase 2: Recommend

阶段2:推荐

Based on what you found, present a concrete recommendation. Don't ask open-ended questions — lead with a proposal:
Recommended (core coverage):
  • Error Monitoring — always; crash reporting, app hangs, watchdog terminations, NSError/Swift errors
  • Tracing — always for apps; auto-instruments app launch, network, UIViewController, file I/O, Core Data
  • Profiling — production apps; continuous profiling with minimal overhead
Optional (enhanced observability):
  • Session Replay — user-facing apps; ⚠️ disabled by default on iOS 26+ (Liquid Glass rendering)
  • Logging — when structured log capture is needed
  • User Feedback — apps that want crash/error feedback forms from users
Not available for Cocoa:
  • ❌ Metrics — use custom spans instead
  • ❌ Crons — backend only
  • ❌ AI Monitoring — JS/Python only
Recommendation logic:
FeatureRecommend when...
Error MonitoringAlways — non-negotiable baseline
TracingAlways for apps — rich auto-instrumentation out of the box
ProfilingProduction apps where performance matters
Session ReplayiOS only user-facing apps (check iOS 26+ caveat; not tvOS/macOS/watchOS/visionOS)
LoggingExisting
os.log
/ CocoaLumberjack usage, or structured logs needed
User FeedbackApps wanting in-app bug reports with screenshots
Propose: "I recommend Error Monitoring + Tracing + Profiling. Want me to also add Session Replay and Logging?"

根据检测结果,给出具体的建议。不要提出开放式问题,直接给出方案:
推荐(核心覆盖):
  • 错误监控 — 必选;包含崩溃报告、应用挂起、看门狗终止、NSError/Swift错误捕获
  • 追踪 — 应用必选;自动检测应用启动、网络请求、UIViewController、文件I/O、Core Data等环节
  • 性能分析 — 生产环境应用必选;低开销的持续性能分析
可选(增强可观测性):
  • 会话重放 — 面向用户的应用可选;⚠️ iOS 26+默认禁用(Liquid Glass渲染限制)
  • 日志 — 需要结构化日志捕获时可选
  • 用户反馈 — 希望收集用户崩溃/错误反馈表单的应用可选
Cocoa平台不支持的功能:
  • ❌ 指标 — 请使用自定义span替代
  • ❌ 定时任务监控 — 仅后端支持
  • ❌ AI监控 — 仅JS/Python支持
推荐逻辑:
功能推荐场景
错误监控必选 — 基础监控能力,不可或缺
追踪应用必选 — 开箱即用的丰富自动检测能力
性能分析对性能有要求的生产环境应用
会话重放仅iOS 面向用户的应用(注意iOS 26+限制;tvOS/macOS/watchOS/visionOS不支持)
日志已使用
os.log
/CocoaLumberjack,或需要结构化日志时
用户反馈希望提供应用内报错反馈表单的应用
建议话术:"我推荐启用错误监控 + 追踪 + 性能分析。是否需要同时添加会话重放和日志功能?"

Phase 3: Guide

阶段3:指导

Install

安装

Option 1 — Sentry Wizard (recommended): Walks you through login, org/project selection, and auth token setup interactively. Then installs the SDK, updates AppDelegate, adds dSYM/debug symbol upload build phases, and configures everything automatically.
bash
brew install getsentry/tools/sentry-wizard && sentry-wizard -i ios
Option 2 — Swift Package Manager: File → Add Packages → enter:
https://github.com/getsentry/sentry-cocoa.git
Or in
Package.swift
:
swift
.package(url: "https://github.com/getsentry/sentry-cocoa", from: "9.5.1"),
SPM Products — choose exactly one per target:
ProductUse Case
Sentry
Recommended — static framework, fast app start
Sentry-Dynamic
Dynamic framework alternative
SentrySwiftUI
SwiftUI view performance tracking (
SentryTracedView
)
Sentry-WithoutUIKitOrAppKit
watchOS, app extensions, CLI tools
⚠️ Xcode allows selecting multiple products — choose only one.
Option 3 — CocoaPods:
ruby
platform :ios, '11.0'
use_frameworks!

target 'YourApp' do
  pod 'Sentry', :git => 'https://github.com/getsentry/sentry-cocoa.git', :tag => '9.5.1'
end
Known issue (Xcode 14+): Sandbox
rsync.samba
error → Target Settings → "Enable User Script Sandbox" →
NO
.

选项1 — Sentry Wizard(推荐): 交互式引导你完成登录、组织/项目选择和授权令牌设置。随后自动安装SDK、更新AppDelegate、添加dSYM/调试符号上传构建阶段,并完成所有配置。
bash
brew install getsentry/tools/sentry-wizard && sentry-wizard -i ios
选项2 — Swift Package Manager: 点击File → Add Packages → 输入:
https://github.com/getsentry/sentry-cocoa.git
或在
Package.swift
中添加:
swift
.package(url: "https://github.com/getsentry/sentry-cocoa", from: "9.5.1"),
SPM产品选择 — 每个目标仅选一个
产品使用场景
Sentry
推荐 — 静态框架,应用启动速度快
Sentry-Dynamic
动态框架替代方案
SentrySwiftUI
SwiftUI视图性能追踪(
SentryTracedView
Sentry-WithoutUIKitOrAppKit
watchOS、应用扩展、CLI工具
⚠️ Xcode允许选择多个产品 — 请仅选一个。
选项3 — CocoaPods:
ruby
platform :ios, '11.0'
use_frameworks!

target 'YourApp' do
  pod 'Sentry', :git => 'https://github.com/getsentry/sentry-cocoa.git', :tag => '9.5.1'
end
已知问题(Xcode 14+): 出现Sandbox
rsync.samba
错误 → 目标设置 → "Enable User Script Sandbox" → 设置为
NO

Quick Start — Recommended Init

快速开始 — 推荐初始化方式

Full config enabling the most features with sensible defaults. Add before any other code at app startup.
SwiftUI — App entry point:
swift
import SwiftUI
import Sentry

@main
struct MyApp: App {
    init() {
        SentrySDK.start { options in
            options.dsn = ProcessInfo.processInfo.environment["SENTRY_DSN"]
                ?? "https://examplePublicKey@o0.ingest.sentry.io/0"
            options.environment = ProcessInfo.processInfo.environment["SENTRY_ENVIRONMENT"]
            options.releaseName = Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String

            // Error monitoring (on by default — explicit for clarity)
            options.enableCrashHandler = true
            options.enableAppHangTrackingV2 = true
            options.enableWatchdogTerminationTracking = true
            options.attachScreenshot = true
            options.attachViewHierarchy = true
            options.sendDefaultPii = true

            // Tracing
            options.tracesSampleRate = 1.0          // lower to 0.2 in high-traffic production

            // Profiling (SDK 9.0.0+ API)
            options.configureProfiling = {
                $0.sessionSampleRate = 1.0
                $0.lifecycle = .trace
            }

            // Session Replay (disabled on iOS 26+ by default — safe to configure)
            options.sessionReplay.sessionSampleRate = 1.0
            options.sessionReplay.onErrorSampleRate = 1.0

            // Logging (SDK 9.0.0+ top-level; use options.experimental.enableLogs in 8.x)
            options.enableLogs = true
        }
    }

    var body: some Scene {
        WindowGroup { ContentView() }
    }
}
UIKit — AppDelegate:
swift
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 = ProcessInfo.processInfo.environment["SENTRY_DSN"]
                ?? "https://examplePublicKey@o0.ingest.sentry.io/0"
            options.environment = ProcessInfo.processInfo.environment["SENTRY_ENVIRONMENT"]
            options.releaseName = Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String

            options.enableCrashHandler = true
            options.enableAppHangTrackingV2 = true
            options.enableWatchdogTerminationTracking = true
            options.attachScreenshot = true
            options.attachViewHierarchy = true
            options.sendDefaultPii = true

            options.tracesSampleRate = 1.0

            options.configureProfiling = {
                $0.sessionSampleRate = 1.0
                $0.lifecycle = .trace
            }

            options.sessionReplay.sessionSampleRate = 1.0
            options.sessionReplay.onErrorSampleRate = 1.0

            // Logging (SDK 9.0.0+ top-level; use options.experimental.enableLogs in 8.x)
            options.enableLogs = true
        }
        return true
    }
}
⚠️ SDK initialization must occur on the main thread.

完整配置启用最多功能并使用合理默认值。请在应用启动时的其他代码之前添加。
SwiftUI — App入口:
swift
import SwiftUI
import Sentry

@main
struct MyApp: App {
    init() {
        SentrySDK.start { options in
            options.dsn = ProcessInfo.processInfo.environment["SENTRY_DSN"]
                ?? "https://examplePublicKey@o0.ingest.sentry.io/0"
            options.environment = ProcessInfo.processInfo.environment["SENTRY_ENVIRONMENT"]
            options.releaseName = Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String

            // 错误监控(默认启用 — 显式配置以明确)
            options.enableCrashHandler = true
            options.enableAppHangTrackingV2 = true
            options.enableWatchdogTerminationTracking = true
            options.attachScreenshot = true
            options.attachViewHierarchy = true
            options.sendDefaultPii = true

            // 追踪
            options.tracesSampleRate = 1.0          // 高流量生产环境可降低至0.2

            // 性能分析(SDK 9.0.0+ API)
            options.configureProfiling = {
                $0.sessionSampleRate = 1.0
                $0.lifecycle = .trace
            }

            // 会话重放(iOS 26+默认禁用 — 配置无风险)
            options.sessionReplay.sessionSampleRate = 1.0
            options.sessionReplay.onErrorSampleRate = 1.0

            // 日志(SDK 9.0.0+ 顶层配置;8.x版本请使用options.experimental.enableLogs)
            options.enableLogs = true
        }
    }

    var body: some Scene {
        WindowGroup { ContentView() }
    }
}
UIKit — AppDelegate:
swift
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 = ProcessInfo.processInfo.environment["SENTRY_DSN"]
                ?? "https://examplePublicKey@o0.ingest.sentry.io/0"
            options.environment = ProcessInfo.processInfo.environment["SENTRY_ENVIRONMENT"]
            options.releaseName = Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String

            options.enableCrashHandler = true
            options.enableAppHangTrackingV2 = true
            options.enableWatchdogTerminationTracking = true
            options.attachScreenshot = true
            options.attachViewHierarchy = true
            options.sendDefaultPii = true

            options.tracesSampleRate = 1.0

            options.configureProfiling = {
                $0.sessionSampleRate = 1.0
                $0.lifecycle = .trace
            }

            options.sessionReplay.sessionSampleRate = 1.0
            options.sessionReplay.onErrorSampleRate = 1.0

            // 日志(SDK 9.0.0+ 顶层配置;8.x版本请使用options.experimental.enableLogs)
            options.enableLogs = true
        }
        return true
    }
}
⚠️ SDK必须在主线程初始化。

For Each Agreed Feature

功能配置指导

Walk through features one at a time. Load the reference file for each, follow its steps, and verify before moving to the next:
FeatureReference fileLoad when...
Error Monitoring
${SKILL_ROOT}/references/error-monitoring.md
Always (baseline)
Tracing
${SKILL_ROOT}/references/tracing.md
App launch, network, UIViewController perf
Profiling
${SKILL_ROOT}/references/profiling.md
Production perf-sensitive apps
Session Replay
${SKILL_ROOT}/references/session-replay.md
User-facing iOS/tvOS apps
Logging
${SKILL_ROOT}/references/logging.md
Structured log capture needed
User Feedback
${SKILL_ROOT}/references/user-feedback.md
In-app bug reporting wanted
For each feature:
Read ${SKILL_ROOT}/references/<feature>.md
, follow steps exactly, verify it works.

逐个配置已选定的功能。请阅读对应参考文档,严格按照步骤操作并验证后再进行下一个功能:
功能参考文档加载时机
错误监控
${SKILL_ROOT}/references/error-monitoring.md
必选(基础功能)
追踪
${SKILL_ROOT}/references/tracing.md
应用启动、网络请求、UIViewController性能监控时
性能分析
${SKILL_ROOT}/references/profiling.md
生产环境性能敏感型应用
会话重放
${SKILL_ROOT}/references/session-replay.md
面向用户的iOS/tvOS应用
日志
${SKILL_ROOT}/references/logging.md
需要结构化日志捕获时
用户反馈
${SKILL_ROOT}/references/user-feedback.md
需要应用内报错反馈时
每个功能的配置流程:
阅读${SKILL_ROOT}/references/<feature>.md
,严格按照步骤操作,验证功能正常运行。

Configuration Reference

配置参考

Key
SentryOptions
Fields

关键
SentryOptions
字段

OptionTypeDefaultPurpose
dsn
String
""
SDK disabled if empty; reads
SENTRY_DSN
env var
environment
String
""
e.g.,
"production"
; reads
SENTRY_ENVIRONMENT
releaseName
String
""
e.g.,
"my-app@1.0.0"
; reads
SENTRY_RELEASE
debug
Bool
false
Verbose SDK output — disable in production
sendDefaultPii
Bool
false
Include IP, user info from active integrations
enableCrashHandler
Bool
true
Master switch for crash reporting
enableAppHangTrackingV2
Bool
true
(9.0+)
Differentiates fully/non-fully blocked hangs
appHangTimeoutInterval
Double
2.0
Seconds before classifying as hang
enableWatchdogTerminationTracking
Bool
true
Track watchdog kills (iOS, tvOS, Mac Catalyst)
attachScreenshot
Bool
false
Capture screenshot on error
attachViewHierarchy
Bool
false
Capture view hierarchy on error
tracesSampleRate
NSNumber?
nil
Transaction sample rate (
nil
= tracing disabled); Swift auto-boxes
Double
literals (e.g.
1.0
NSNumber
)
tracesSampler
Closure
nil
Dynamic per-transaction sampling (overrides rate)
enableAutoPerformanceTracing
Bool
true
Master switch for auto-instrumentation
tracePropagationTargets
[String]
[".*"]
Hosts/regex that receive distributed trace headers
enableCaptureFailedRequests
Bool
true
Auto-capture HTTP 5xx errors as events
enableNetworkBreadcrumbs
Bool
true
Breadcrumbs for outgoing HTTP requests
inAppInclude
[String]
[]
Module prefixes treated as "in-app" code
maxBreadcrumbs
Int
100
Max breadcrumbs per event
sampleRate
Float
1.0
Error event sample rate
beforeSend
Closure
nil
Hook to mutate/drop error events
onCrashedLastRun
Closure
nil
Called on next launch after a crash
选项类型默认值用途
dsn
String
""
为空时SDK禁用;优先读取
SENTRY_DSN
环境变量
environment
String
""
例如
"production"
;优先读取
SENTRY_ENVIRONMENT
环境变量
releaseName
String
""
例如
"my-app@1.0.0"
;优先读取
SENTRY_RELEASE
环境变量
debug
Bool
false
输出SDK详细日志 — 生产环境必须禁用
sendDefaultPii
Bool
false
包含IP、活跃集成中的用户信息
enableCrashHandler
Bool
true
崩溃报告总开关
enableAppHangTrackingV2
Bool
true
(9.0+)
区分完全阻塞和非完全阻塞的应用挂起
appHangTimeoutInterval
Double
2.0
判定为挂起的超时时间(秒)
enableWatchdogTerminationTracking
Bool
true
追踪看门狗终止事件(iOS、tvOS、Mac Catalyst)
attachScreenshot
Bool
false
错误发生时捕获截图
attachViewHierarchy
Bool
false
错误发生时捕获视图层级
tracesSampleRate
NSNumber?
nil
事务采样率(
nil
表示禁用追踪);Swift会自动将
Double
字面量装箱为
NSNumber
(例如
1.0
NSNumber
tracesSampler
Closure
nil
动态事务采样逻辑(优先级高于固定采样率)
enableAutoPerformanceTracing
Bool
true
自动检测性能总开关
tracePropagationTargets
[String]
[".*"]
接收分布式追踪头的主机/正则表达式
enableCaptureFailedRequests
Bool
true
自动将HTTP 5xx错误捕获为事件
enableNetworkBreadcrumbs
Bool
true
为 outgoing HTTP请求添加面包屑
inAppInclude
[String]
[]
被视为“应用内代码”的模块前缀
maxBreadcrumbs
Int
100
每个事件最多保留的面包屑数量
sampleRate
Float
1.0
错误事件采样率
beforeSend
Closure
nil
错误事件发送前的修改/丢弃钩子
onCrashedLastRun
Closure
nil
应用崩溃后重启时触发

Environment Variables

环境变量

VariableMaps toPurpose
SENTRY_DSN
dsn
Data Source Name
SENTRY_RELEASE
releaseName
App version (e.g.,
my-app@1.0.0
)
SENTRY_ENVIRONMENT
environment
Deployment environment
变量对应配置项用途
SENTRY_DSN
dsn
数据源名称
SENTRY_RELEASE
releaseName
应用版本(例如
my-app@1.0.0
SENTRY_ENVIRONMENT
environment
部署环境

Platform Feature Support Matrix

平台功能支持矩阵

FeatureiOStvOSmacOSwatchOSvisionOS
Crash Reporting
App Hangs V2
Watchdog Termination
App Start Tracing
UIViewController Tracing
SwiftUI Tracing
Network Tracking
Profiling
Session Replay
MetricKit✅ (15+)✅ (12+)

功能iOStvOSmacOSwatchOSvisionOS
崩溃报告
应用挂起V2
看门狗终止追踪
应用启动追踪
UIViewController追踪
SwiftUI追踪
网络追踪
性能分析
会话重放
MetricKit✅ (15+)✅ (12+)

Verification

验证

Test that Sentry is receiving events:
swift
// Trigger a test error event:
SentrySDK.capture(message: "Sentry Cocoa SDK test")

// Or test crash reporting (without debugger — crashes are intercepted by debugger):
// SentrySDK.crash()  // uncomment, run without debugger, relaunch to see crash report
Check the Sentry dashboard within a few seconds. If nothing appears:
  1. Set
    options.debug = true
    — prints SDK internals to Xcode console
  2. Verify the DSN is correct and the project exists
  3. Ensure initialization is on the main thread

测试Sentry是否能接收事件:
swift
// 触发测试错误事件:
SentrySDK.capture(message: "Sentry Cocoa SDK test")

// 或测试崩溃报告(需脱离调试器运行 — 调试器会拦截崩溃信号):
// SentrySDK.crash()  // 取消注释,脱离调试器运行,重启应用后查看崩溃报告
几秒内查看Sentry控制台。如果没有事件出现:
  1. 设置
    options.debug = true
    — 在Xcode控制台输出SDK内部日志
  2. 验证DSN格式正确且项目存在
  3. 确保SDK在主线程初始化

Production Settings

生产环境设置

Lower sample rates for production to control volume and cost:
swift
options.tracesSampleRate = 0.2          // 20% of transactions

options.configureProfiling = {
    $0.sessionSampleRate = 0.1          // 10% of sessions
    $0.lifecycle = .trace
}

options.sessionReplay.sessionSampleRate = 0.1   // 10% continuous
options.sessionReplay.onErrorSampleRate = 1.0   // 100% on error (keep high)

options.debug = false                   // never in production

降低采样率以控制事件数量和成本:
swift
options.tracesSampleRate = 0.2          // 仅采样20%的事务

options.configureProfiling = {
    $0.sessionSampleRate = 0.1          // 仅采样10%的会话
    $0.lifecycle = .trace
}

options.sessionReplay.sessionSampleRate = 0.1   // 持续采样10%的会话
options.sessionReplay.onErrorSampleRate = 1.0   // 错误发生时100%采样(建议保持高比例)

options.debug = false                   // 生产环境绝对禁用

Phase 4: Cross-Link

阶段4:跨链路配置

After completing Apple setup, check for a companion backend missing Sentry coverage:
bash
undefined
完成Apple平台配置后,检查是否有未配置Sentry的配套后端服务:
bash
undefined

Detect companion backend

检测配套后端服务

ls ../backend ../server ../api 2>/dev/null cat ../go.mod 2>/dev/null | head -5 cat ../requirements.txt ../Pipfile 2>/dev/null | head -5 cat ../Gemfile 2>/dev/null | head -5 cat ../package.json 2>/dev/null | grep -E '"name"|"dependencies"' | head -5

If a backend is found, configure `tracePropagationTargets` to enable distributed tracing end-to-end, and suggest the matching skill:

| Backend detected | Suggest skill | Trace header support |
|-----------------|--------------|---------------------|
| Go (`go.mod`) | `sentry-go-sdk` | ✅ automatic |
| Python (`requirements.txt`) | `sentry-python-sdk` | ✅ automatic |
| Ruby (`Gemfile`) | `sentry-ruby-sdk` | ✅ automatic |
| Node.js backend (`package.json`) | `sentry-node-sdk` (or `sentry-express-sdk`) | ✅ automatic |

---
ls ../backend ../server ../api 2>/dev/null cat ../go.mod 2>/dev/null | head -5 cat ../requirements.txt ../Pipfile 2>/dev/null | head -5 cat ../Gemfile 2>/dev/null | head -5 cat ../package.json 2>/dev/null | grep -E '"name"|"dependencies"' | head -5

如果检测到后端服务,配置`tracePropagationTargets`以实现端到端分布式追踪,并推荐对应的技能:

| 检测到的后端 | 推荐技能 | 追踪头支持 |
|-----------------|--------------|---------------------|
| Go (`go.mod`) | `sentry-go-sdk` | ✅ 自动支持 |
| Python (`requirements.txt`) | `sentry-python-sdk` | ✅ 自动支持 |
| Ruby (`Gemfile`) | `sentry-ruby-sdk` | ✅ 自动支持 |
| Node.js后端 (`package.json`) | `sentry-node-sdk`(或`sentry-express-sdk`) | ✅ 自动支持 |

---

Troubleshooting

故障排除

IssueSolution
Events not appearingSet
debug: true
, verify DSN format, ensure init is on main thread
Crashes not capturedRun without debugger attached — debugger intercepts signals
App hangs not reportedAuto-disabled when debugger attached; check
appHangTimeoutInterval
Session Replay not recordingCheck iOS version — disabled by default on iOS 26+ (Liquid Glass); verify
sessionSampleRate > 0
Tracing data missingConfirm
tracesSampleRate > 0
; check
enableAutoPerformanceTracing = true
Profiling data missingVerify
sessionSampleRate > 0
in
configureProfiling
; for
.trace
lifecycle, tracing must be enabled
rsync.samba
build error (CocoaPods)
Target Settings → "Enable User Script Sandbox" →
NO
Multiple SPM products selectedChoose only one of
Sentry
,
Sentry-Dynamic
,
SentrySwiftUI
,
Sentry-WithoutUIKitOrAppKit
inAppExclude
compile error
Removed in SDK 9.0.0 — use
inAppInclude
only
Watchdog termination not trackedRequires
enableCrashHandler = true
(it is by default)
Network breadcrumbs missingRequires
enableSwizzling = true
(it is by default)
profilesSampleRate
compile error
Removed in SDK 9.0.0 — use
configureProfiling
closure instead
问题解决方案
事件未出现设置
debug: true
,验证DSN格式,确保SDK在主线程初始化
崩溃未被捕获脱离调试器运行 — 调试器会拦截信号
应用挂起未上报调试器运行时自动禁用;检查
appHangTimeoutInterval
配置
会话重放未录制检查iOS版本 — iOS 26+默认禁用(Liquid Glass限制);验证
sessionSampleRate > 0
追踪数据缺失确认
tracesSampleRate > 0
;检查
enableAutoPerformanceTracing = true
性能分析数据缺失验证
configureProfiling
中的
sessionSampleRate > 0
.trace
生命周期下需启用追踪
CocoaPods构建出现
rsync.samba
错误
目标设置 → "Enable User Script Sandbox" → 设置为
NO
选择了多个SPM产品仅选择
Sentry
Sentry-Dynamic
SentrySwiftUI
Sentry-WithoutUIKitOrAppKit
中的一个
inAppExclude
编译错误
SDK 9.0.0已移除该选项 — 仅使用
inAppInclude
看门狗终止未被追踪需确保
enableCrashHandler = true
(默认已启用)
网络面包屑缺失需确保
enableSwizzling = true
(默认已启用)
profilesSampleRate
编译错误
SDK 9.0.0已移除该选项 — 使用
configureProfiling
闭包替代