Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Sentry sdk to v2.0 #11302

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion WordPress/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ android {
// but we don't obfuscate the bytecode.
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard.cfg'
multiDexKeepProguard file('multidex-config.pro')
}

debug {
Expand Down Expand Up @@ -291,7 +292,7 @@ dependencies {
lintChecks 'org.wordpress:lint:1.0.1'

// Sentry
implementation 'io.sentry:sentry-android:1.7.16'
implementation 'io.sentry:sentry-android-core:2.0.0-rc04'
implementation 'org.slf4j:slf4j-nop:1.7.25'

// Debug
Expand Down
2 changes: 2 additions & 0 deletions WordPress/multidex-config.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-keep class io.sentry.android.core.SentryAndroidOptions
-keep class io.sentry.android.ndk.SentryNdk
3 changes: 3 additions & 0 deletions WordPress/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@
android:supportsRtl="true"
tools:ignore="UnusedAttribute">

<!-- Force manual initialization for Sentry to provide DSN programmatically-->
<meta-data android:name="io.sentry.auto-init" android:value="false" />

<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="@string/com_google_android_geo_api_key"/>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
package org.wordpress.android.util

import android.content.Context
import android.preference.PreferenceManager
import io.sentry.Sentry
import io.sentry.android.AndroidSentryClientFactory
import io.sentry.event.BreadcrumbBuilder
import io.sentry.android.core.SentryAndroid
import io.sentry.core.Breadcrumb
import io.sentry.core.Sentry
import io.sentry.core.SentryOptions.BeforeSendCallback
import org.wordpress.android.BuildConfig
import org.wordpress.android.R

class CrashLoggingUtils {
fun shouldEnableCrashLogging(context: android.content.Context): Boolean {
fun shouldEnableCrashLogging(context: Context): Boolean {
if (PackageUtils.isDebugBuild()) {
return false
}
Expand All @@ -18,9 +20,15 @@ class CrashLoggingUtils {
return !hasUserOptedOut
}

fun enableCrashLogging(context: android.content.Context) {
Sentry.init(BuildConfig.SENTRY_DSN, AndroidSentryClientFactory(context))
Sentry.getContext().addTag("version", BuildConfig.VERSION_NAME)
fun enableCrashLogging(context: Context) {
SentryAndroid.init(context.applicationContext) {
it.dsn = BuildConfig.SENTRY_DSN
it.beforeSend = BeforeSendCallback { event, hint ->
// Todo: Update event with additional info (extras)
return@BeforeSendCallback event
}
}
Sentry.setTag("version", BuildConfig.VERSION_NAME)
}

companion object {
Expand All @@ -33,7 +41,6 @@ class CrashLoggingUtils {
}

@JvmStatic fun stopCrashLogging() {
Sentry.clearContext()
Sentry.close()
}

Expand All @@ -42,13 +49,11 @@ class CrashLoggingUtils {
return
}

Sentry.getContext().recordBreadcrumb(
BreadcrumbBuilder().setMessage(message).build()
)
Sentry.addBreadcrumb(Breadcrumb(message))
}

@JvmStatic fun log(exception: Throwable) {
Sentry.capture(exception)
Sentry.captureException(exception)
}

@JvmStatic fun logException(tr: Throwable, tag: AppLog.T) {
Expand Down