Cognito KMM Template
  • Welcome
  • Getting Started
    • Quickstart: Getting Started
    • Prerequisites
    • Installation
    • Creating New App
  • Architecture
    • Overview
    • Modules
    • Data Flow
  • Feautures
    • Http Client
    • DataStore
    • Analytics
    • AdMob Integration
    • Crash Reporting
    • Built in Settings Page
  • Handle View States
    • StatelessSurface<T> Composable
    • Handle a screen with 3 states
  • Sequential Content with IndefiniteSurface
  • Handle multiple predefined states
  • Showing Paginated Data
  • Handling list data
Powered by GitBook
On this page
  1. Feautures

Crash Reporting

Integrating Sentry Crash Reporting in Your KMM Application

Overview:

This document outlines the steps involved in integrating Sentry crash reporting into your KMM application to track and diagnose errors.

Prerequisites:

  • A Sentry account is required.

  • The Sentry DSN (Data Source Name) obtained from your Sentry account.

  • Provide credentials in shared/src/commonMain/kotlin/configs/Credentials.kt file.

Integration:

  1. Initialization:

    • In your application class (e.g., AndroidApp in Android), initialize the Sentry SDK:

    Kotlin

    class AndroidApp : Application() {
        override fun onCreate() {
            super.onCreate()
            CrashAnalytics(this).init(Credentials.Sentry.dsn.get())
        }
    }
  2. Error Handling:

    • The library/src/commonMain/kotlin/data/responses/ErrMessage.kt enum class contains error handling logic. Ensure that it includes Sentry error reporting within appropriate error scenarios. For example:

fun Err.toMessage(): ErrMessage = when (this) {

    Err.GenericError -> {...}
    Err.NotExistsError -> {...}
    is Err.UserErr -> {...}
    is Err.ValidationErr -> {...}
    is Err.ParseErr -> {
    
       CrashAnalytics.capture(this.throwable)

       when (this) {...}

    }
    is Err.HttpErr<*> -> {

       CrashAnalytics.capture(this.throwable)

       when (this) {...}

    }
}

Additional Considerations:

  • Refer to the Sentry documentation for detailed information on configuration options, event customization, and advanced features.

  • Consider using Sentry's release management and source maps to correlate errors with specific code versions.

  • Customize the error handling logic in your application to capture relevant information and log it to Sentry.

Benefits of Sentry Integration:

  • Crash Tracking: Automatically capture and report crashes and errors.

  • Performance Monitoring: Track performance metrics and identify bottlenecks.

  • Issue Debugging: Use Sentry's tools to debug and resolve issues efficiently.

By integrating Sentry with your KMM application, you can gain valuable insights into your app's stability and performance, enabling you to improve its quality and user experience.

Note: The provided code snippet demonstrates how to capture and log exceptions in specific error types using CrashAnalytics.capture(this.throwable). You can customize this logic to capture additional information or handle different error types as needed.

PreviousAdMob IntegrationNextBuilt in Settings Page

Last updated 8 months ago