Community程式設計與開發github.com

getsentry/sentry-android-sdk

在 Android 專案中完整設定 Sentry SDK。當要求「為 Android 新增 Sentry」、「安裝 sentry-android」、「在 Android 中設定 Sentry」或配置錯誤監控、追蹤、效能分析、工作階段重播或紀錄時使用。支援 Kotlin 和 Java 程式碼庫。

sentry-android-sdk 是什麼?

此技能「getsentry/sentry-android-sdk」為 Android 開發者提供完整的 Sentry SDK 整合方案,涵蓋錯誤監控、效能追蹤、資料庫剖析、工作階段重播及進階紀錄功能。它支援 Kotlin 和 Java 兩種程式語言,並能自動偵測專案類型(如 Jetpack Compose、傳統 XML 介面)來提供最合適的設定步驟。透過修改 build.gradle.kts (或 build.gradle) 檔案與 Application 類別,技能會注入必要的 Sentry 相依性與初始化程式碼,並可選擇性配置效能取樣率、工作階段重播選項,以及整合 Android Gradle 外掛以自動上傳原始碼對應檔案。此技能特別適合在開發者明確要求為 Android 專案加入 Sentry SDK 時使用,能大幅減少手動查找與設定步驟。

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

Installed? Explore more 程式設計與開發 skills: steipete/bluebubbles, steipete/eightctl, steipete/blucli · View all 6 →

在你喜歡的 AI 中提問

開啟一個已預先載入此 Agent Skill 的新對話。

說明文件

sentry-android-sdk 是做什麼的?

完整的 Sentry SDK 設定,適用於 Android 開發。當被要求「在 Android 中加入 Sentry」、「安裝 sentry-android」、「在 Android 中設定 Sentry」,或需要配置錯誤監控、追蹤、效能分析、工作階段重播或紀錄功能時使用。支援 Kotlin 和 Java 程式碼庫。

支援的功能

  • 錯誤監控(Error Monitoring)
  • 效能追蹤(Performance Tracing)
  • 資料庫剖析(Database Profiling)
  • 工作階段重播(Session Replay)
  • 紀錄(Logging)

使用方式

1. 在專案的根層級 build.gradle.kts (或 build.gradle) 中加入 Sentry 外掛

// build.gradle.kts (專案層級)
plugins {
    id("io.sentry.android.gradle") version "4.12.0" apply false
}

或使用 Groovy:

// build.gradle (專案層級)
buildscript {
    dependencies {
        classpath 'io.sentry:sentry-android-gradle-plugin:4.12.0'
    }
}

2. 在應用程式模組的 build.gradle.kts (或 build.gradle) 中套用外掛並加入相依性

// build.gradle.kts (app 模組層級)
plugins {
    id("com.android.application")
    id("io.sentry.android.gradle")
}

dependencies {
    implementation("io.sentry:sentry-android:7.16.0")
}

或使用 Groovy:

// build.gradle (app 模組層級)
plugins {
    id 'com.android.application'
    id 'io.sentry.android.gradle'
}

dependencies {
    implementation 'io.sentry:sentry-android:7.16.0'
}

3. 初始化 Sentry

在您的 AndroidManifest.xml 中加入中繼資料(Metadata):

<application>
    <meta-data
        android:name="io.sentry.dsn"
        android:value="https://[email protected]/0" />
</application>

或者透過程式碼初始化:

import io.sentry.Sentry
import io.sentry.android.core.SentryAndroid

class MyApplication : Application() {
    override fun onCreate() {
        super.onCreate()
        
        SentryAndroid.init(this) { options ->
            options.dsn = "https://[email protected]/0"
            options.tracesSampleRate = 1.0
            options.profilesSampleRate = 1.0
        }
    }
}

4. 配置效能追蹤與工作階段重播(選擇性)

SentryAndroid.init(this) { options ->
    options.dsn = "https://[email protected]/0"
    options.tracesSampleRate = 1.0
    options.profilesSampleRate = 1.0
    
    // 啟用工作階段重播
    options.experimental.sessionReplay.sessionSampleRate = 1.0
    options.experimental.sessionReplay.onErrorSampleRate = 1.0
}

進階設定

自動上傳原始碼對應檔案(ProGuard / R8)

若已套用 io.sentry.android.gradle 外掛,建置時會自動上傳對應的對映檔案。您也可以在 build.gradle.kts 中進一步自訂:

sentry {
    autoUploadProguardMapping.set(true)
    includeProguardMapping.set(true)
    uploadNativeSymbols.set(true)
}

紀錄整合

若要同時啟用紀錄功能,可以加入 sentry-android-logcat:

dependencies {
    implementation("io.sentry:sentry-android-logcat:7.16.0")
}

注意事項

  • 請務必將 DSN 換成您 Sentry 專案中實際的 DSN 金鑰。
  • 如果需要更詳細的設定選項,請參考 Sentry Android SDK 官方文件。
  • 若是使用 Jetpack Compose 專案,可額外加入 sentry-android-compose 相依性以取得更緊密的整合。

Individual skills in this repo

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

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-cocoa-sdk

Full Sentry SDK setup for Apple platforms (iOS, macOS, tvOS, watchOS, visionOS). Use when asked to "add Sentry to iOS", "add Sentry to Swift", "install sentry-cocoa", or configure error monitoring, tracing, profiling, session replay, logging, or metrics for Apple applications. Supports SwiftUI and UIKit.

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.

相關技能