-
Notifications
You must be signed in to change notification settings - Fork 870
Add initial Sentry setup for crashes and perf tracking #7141
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
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
e315bc2
Add initial Sentry setup for crashes and perf tracking
amitkma 769cae9
Merge branch 'develop' into feature/amit/sentry-integration
amitkma 6c007bd
Fix failing analytics tests
amitkma eaaf0d6
Reformat code to fix style issue
amitkma 030f4d8
Close sentry when user signs out
2460752
Add initial unit tests for Sentry
9a9f8ac
Merge branch 'develop' into feature/amit/sentry-integration
5fa7c5f
Remove unused import
cb2af6b
Exclude amitkma from signoff requirements for PRs
d118bdf
Merge branch 'develop' into feature/amit/sentry-integration
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| Add basic integration of Sentry to capture errors and crashes if user has given consent. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -68,25 +68,29 @@ object Config { | |
| * The analytics configuration to use for the Debug build type. | ||
| * Can be disabled by providing Analytics.Disabled | ||
| */ | ||
| val DEBUG_ANALYTICS_CONFIG = Analytics.PostHog( | ||
| val DEBUG_ANALYTICS_CONFIG = Analytics.Enabled( | ||
| postHogHost = "https://posthog.element.dev", | ||
| postHogApiKey = "phc_VtA1L35nw3aeAtHIx1ayrGdzGkss7k1xINeXcoIQzXN", | ||
| policyLink = "https://element.io/cookie-policy", | ||
| sentryDSN = "https://[email protected]/49", | ||
| sentryEnvironment = "DEBUG" | ||
| ) | ||
|
|
||
| /** | ||
| * The analytics configuration to use for the Release build type. | ||
| * Can be disabled by providing Analytics.Disabled | ||
| */ | ||
| val RELEASE_ANALYTICS_CONFIG = Analytics.PostHog( | ||
| val RELEASE_ANALYTICS_CONFIG = Analytics.Enabled( | ||
| postHogHost = "https://posthog.hss.element.io", | ||
| postHogApiKey = "phc_Jzsm6DTm6V2705zeU5dcNvQDlonOR68XvX2sh1sEOHO", | ||
| policyLink = "https://element.io/cookie-policy", | ||
| sentryDSN = "https://[email protected]/49", | ||
| sentryEnvironment = "RELEASE" | ||
| ) | ||
|
|
||
| /** | ||
| * The analytics configuration to use for the Nightly build type. | ||
| * Can be disabled by providing Analytics.Disabled | ||
| */ | ||
| val NIGHTLY_ANALYTICS_CONFIG = RELEASE_ANALYTICS_CONFIG | ||
| val NIGHTLY_ANALYTICS_CONFIG = RELEASE_ANALYTICS_CONFIG.copy(sentryEnvironment = "NIGHTLY") | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
vector/src/main/java/im/vector/app/features/analytics/impl/SentryFactory.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| /* | ||
| * Copyright (c) 2022 New Vector Ltd | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package im.vector.app.features.analytics.impl | ||
|
|
||
| import android.content.Context | ||
| import im.vector.app.features.analytics.AnalyticsConfig | ||
| import im.vector.app.features.analytics.log.analyticsTag | ||
| import io.sentry.Sentry | ||
| import io.sentry.SentryOptions | ||
| import io.sentry.android.core.SentryAndroid | ||
| import timber.log.Timber | ||
| import javax.inject.Inject | ||
|
|
||
| class SentryFactory @Inject constructor( | ||
| private val context: Context, | ||
| private val analyticsConfig: AnalyticsConfig, | ||
| ) { | ||
|
|
||
| fun initSentry() { | ||
| Timber.tag(analyticsTag.value).d("Initializing Sentry") | ||
| if (Sentry.isEnabled()) return | ||
| SentryAndroid.init(context) { options -> | ||
| options.dsn = analyticsConfig.sentryDSN | ||
| options.beforeSend = SentryOptions.BeforeSendCallback { event, _ -> event } | ||
| options.tracesSampleRate = 1.0 | ||
| options.isEnableUserInteractionTracing = true | ||
| options.environment = analyticsConfig.sentryEnvironment | ||
| options.diagnosticLevel | ||
| } | ||
| } | ||
|
|
||
| fun stopSentry() { | ||
| Timber.tag(analyticsTag.value).d("Stopping Sentry") | ||
| Sentry.close() | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
vector/src/test/java/im/vector/app/test/fakes/FakeSentryFactory.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| /* | ||
| * Copyright (c) 2022 New Vector Ltd | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package im.vector.app.test.fakes | ||
|
|
||
| import im.vector.app.features.analytics.impl.SentryFactory | ||
| import io.mockk.every | ||
| import io.mockk.mockk | ||
| import io.mockk.verify | ||
|
|
||
| class FakeSentryFactory { | ||
| private var isSentryEnabled = false | ||
|
|
||
| val instance = mockk<SentryFactory>().also { | ||
| every { it.initSentry() } answers { | ||
| isSentryEnabled = true | ||
| } | ||
|
|
||
| every { it.stopSentry() } answers { | ||
| isSentryEnabled = false | ||
| } | ||
| } | ||
|
|
||
| fun verifySentryInit() { | ||
| verify { instance.initSentry() } | ||
| } | ||
|
|
||
| fun verifySentryClose() { | ||
| verify { instance.stopSentry() } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.