Community编程与开发github.com

getsentry/sentry-cocoa-sdk

在 Apple 平台(iOS、macOS、tvOS、watchOS、visionOS)上完整配置 Sentry SDK。适用于“为 iOS 添加 Sentry”、“为 Swift 添加 Sentry”、“安装 sentry-cocoa”或为 Apple 应用配置错误监控、追踪、性能分析、会话回放、日志记录或指标等场景。支持 SwiftUI 和 UIKit。

sentry-cocoa-sdk 是什么?

此技能为用户提供在 Apple 平台(iOS、macOS、tvOS、watchOS、visionOS)上完整配置 Sentry SDK 的标准化流程。它适用于 Cursor、Claude Code 等 AI 代理工具,当开发者提出“添加 Sentry 到 iOS”、“安装 sentry-cocoa”或“配置错误监控”等需求时,该技能会自动执行相关设置。技能的核心价值在于自动化安装初始化、配置 DSN、启用性能追踪、会话回放、日志和指标等高级功能,并确保与 SwiftUI 和 UIKit 的兼容性。通过遵循 SKILL.md 中的步骤,AI 代理能高效完成原本需要手动查阅文档的复杂集成任务,大幅减少配置错误和重复劳动。

兼容平台~Claude Code~Codex CLI~Cursor
Part ofMobile
npx skills add https://github.com/getsentry/sentry-for-ai/tree/main/skills/sentry-cocoa-sdk

Installed? Explore more 编程与开发 skills: steipete/bluebubbles, steipete/eightctl, steipete/blucli · View all 6 →

在你喜欢的 AI 中提问

打开一个已预加载此 Agent Skill 的新对话。

文档

sentry-cocoa-sdk 是做什么的?

在 Apple 平台(iOS、macOS、tvOS、watchOS、visionOS)上完整配置 Sentry SDK。适用于“为 iOS 添加 Sentry”、“为 Swift 添加 Sentry”、“安装 sentry-cocoa”或为 Apple 应用配置错误监控、追踪、性能分析、会话回放、日志记录或指标等场景。支持 SwiftUI 和 UIKit。

使用说明

前置条件

通过 CocoaPods 安装

在你的 Podfile 中添加:

pod 'Sentry', '~> 8.0'

然后运行:

pod install

通过 Swift Package Manager 安装

在 Xcode 中选择 File > Add Packages...,搜索 https://github.com/getsentry/sentry-cocoa,并选择最新版本。

基本初始化

在 AppDelegate.swift 或 SwiftUI 应用的入口文件中添加以下代码:

import Sentry

// 尽早初始化
SentrySDK.start { options in
    options.dsn = "https://[email protected]/0"
    options.debug = true // 开发阶段可启用调试日志
}

SwiftUI 集成

对于 SwiftUI 应用,可以在 @main 结构体中进行初始化:

import SwiftUI
import Sentry

@main
struct MyApp: App {
    init() {
        SentrySDK.start { options in
            options.dsn = "https://[email protected]/0"
            options.tracesSampleRate = 1.0 // 性能追踪采样率
            options.profilesSampleRate = 1.0 // 性能分析采样率
        }
    }

    var body: some Scene {
        WindowGroup {
            ContentView()
        }
    }
}

UIKit 集成

对于 UIKit 应用,在 AppDelegate 的 application(_:didFinishLaunchingWithOptions:) 中初始化:

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 = "https://[email protected]/0"
            options.tracesSampleRate = 0.5
        }
        return true
    }
}

启用高级功能

性能追踪

options.tracesSampleRate = 1.0 // 设为 0 到 1 之间的浮点数

性能分析

options.profilesSampleRate = 1.0 // 需要同时启用性能追踪

会话回放

options.experimental.sessionReplay = SentryReplayOptions(sessionSampleRate: 1.0, errorSampleRate: 1.0)

日志记录

SentrySDK.capture(message: "自定义日志消息")

常见问题

  • DSN 在哪里获取? 登录 sentry.io 或你的自托管 Sentry 实例,在项目设置中找到 DSN。
  • 如何验证安装成功? 初始化时设置 options.debug = true,然后在代码中手动触发一个错误:SentrySDK.capture(error: NSError(domain: "test", code: 1))。
  • 支持哪些 Apple 平台? iOS、macOS、tvOS、watchOS、visionOS。

更多资源

Individual skills in this repo

This repo contains 20 individual skills — each has its own dedicated page.

getsentry/sentry-android-sdk

Full Sentry SDK setup for Android. Use when asked to "add Sentry to Android", "install sentry-android", "setup Sentry in Android", or configure error monitoring, tracing, profiling, session replay, or logging for Android applications. Supports Kotlin and Java codebases.

getsentry/sentry-browser-sdk

Full Sentry SDK setup for browser JavaScript. Use when asked to "add Sentry to a website", "install @sentry/browser", or configure error monitoring, tracing, session replay, or logging for vanilla JavaScript, jQuery, static sites, or WordPress.

getsentry/sentry-cloudflare-sdk

Full Sentry SDK setup for Cloudflare Workers and Pages. Use when asked to "add Sentry to Cloudflare Workers", "install @sentry/cloudflare", or configure error monitoring, tracing, logging, crons, or AI monitoring for Cloudflare Workers, Pages, Durable Objects, Queues, Workflows, or Hono on Cloudflare.

getsentry/sentry-code-review

Analyze and resolve Sentry comments on GitHub Pull Requests. Use this when asked to review or fix issues identified by Sentry in PR comments. Can review specific PRs by number or automatically find recent PRs with Sentry feedback.

getsentry/sentry-create-alert

Create Sentry alerts using the workflow engine API. Use when asked to create alerts, set up notifications, configure issue priority alerts, or build workflow automations. Supports email, Slack, PagerDuty, Discord, and other notification actions.

getsentry/sentry-dotnet-sdk

Full Sentry SDK setup for .NET. Use when asked to "add Sentry to .NET", "install Sentry for C#", or configure error monitoring, tracing, profiling, logging, or crons for ASP.NET Core, MAUI, WPF, WinForms, Blazor, Azure Functions, or any other .NET application.

getsentry/sentry-elixir-sdk

Full Sentry SDK setup for Elixir. Use when asked to "add Sentry to Elixir", "install sentry for Elixir", or configure error monitoring, tracing, logging, or crons for Elixir, Phoenix, or Plug applications. Supports Phoenix, Plug, LiveView, Oban, and Quantum.

getsentry/sentry-feature-setup

Configure specific Sentry features beyond basic SDK setup. Use when asked to monitor AI/LLM calls, set up OpenTelemetry pipelines, create alerts and notifications, or enable span streaming.

getsentry/sentry-fix-issues

Find and fix issues from Sentry using MCP. Use when asked to fix Sentry errors, debug production issues, investigate exceptions, or resolve bugs reported in Sentry. Methodically analyzes stack traces, breadcrumbs, traces, and context to identify root causes.

getsentry/sentry-flutter-sdk

Full Sentry SDK setup for Flutter and Dart. Use when asked to "add Sentry to Flutter", "install sentry_flutter", "setup Sentry in Dart", or configure error monitoring, tracing, profiling, session replay, or logging for Flutter applications. Supports Android, iOS, macOS, Linux, Windows, and Web.

getsentry/sentry-go-sdk

Full Sentry SDK setup for Go. Use when asked to "add Sentry to Go", "install sentry-go", "setup Sentry in Go", or configure error monitoring, tracing, logging, metrics, or crons for Go applications. Supports net/http, Gin, Echo, Fiber, FastHTTP, Iris, Negroni, and gRPC.

getsentry/sentry-nestjs-sdk

Full Sentry SDK setup for NestJS. Use when asked to "add Sentry to NestJS", "install @sentry/nestjs", "setup Sentry in NestJS", or configure error monitoring, tracing, profiling, logging, metrics, crons, or AI monitoring for NestJS applications. Supports Express and Fastify adapters, GraphQL, microservices, WebSockets, and background jobs.

getsentry/sentry-nextjs-sdk

Full Sentry SDK setup for Next.js. Use when asked to "add Sentry to Next.js", "install @sentry/nextjs", or configure error monitoring, tracing, session replay, logging, profiling, AI monitoring, or crons for Next.js applications. Supports Next.js 13+ with App Router and Pages Router.

getsentry/sentry-node-sdk

Full Sentry SDK setup for Node.js, Bun, and Deno. Use when asked to "add Sentry to Node.js", "add Sentry to Bun", "add Sentry to Deno", "install @sentry/node", "@sentry/bun", or "@sentry/deno", or configure error monitoring, tracing, logging, profiling, metrics, crons, or AI monitoring for server-side JavaScript/TypeScript runtimes.

getsentry/sentry-otel-exporter-setup

Configure the OpenTelemetry Collector with Sentry Exporter for multi-project routing and automatic project creation. Use when setting up OTel with Sentry, configuring collector pipelines for traces and logs, or routing telemetry from multiple services to Sentry projects.

getsentry/sentry-php-sdk

Full Sentry SDK setup for PHP. Use when asked to "add Sentry to PHP", "install sentry/sentry", "setup Sentry in PHP", or configure error monitoring, tracing, profiling, logging, metrics, or crons for PHP applications. Supports plain PHP, Laravel, and Symfony.

getsentry/sentry-pr-code-review

Review a project's PRs to check for issues detected in code review by Seer Bug Prediction. Use when asked to review or fix issues identified by Sentry in PR comments, or to find recent PRs with Sentry feedback.

getsentry/sentry-python-sdk

Full Sentry SDK setup for Python. Use when asked to "add Sentry to Python", "install sentry-sdk", "setup Sentry in Python", or configure error monitoring, tracing, profiling, logging, metrics, crons, or AI monitoring for Python applications. Supports Django, Flask, FastAPI, Celery, Starlette, AIOHTTP, Tornado, and more.

getsentry/sentry-react-native-sdk

Full Sentry SDK setup for React Native and Expo. Use when asked to "add Sentry to React Native", "install @sentry/react-native", "setup Sentry in Expo", or configure error monitoring, tracing, profiling, session replay, or logging for React Native applications. Supports Expo managed, Expo bare, and vanilla React Native.

getsentry/sentry-react-sdk

Full Sentry SDK setup for React. Use when asked to "add Sentry to React", "install @sentry/react", or configure error monitoring, tracing, session replay, profiling, or logging for React applications. Supports React 16+, React Router v5-v7 non-framework mode, TanStack Router, Redux, Vite, and webpack.

相关技能