Benoit Marty
1 year ago
committed by
GitHub
28 changed files with 280 additions and 27 deletions
@ -0,0 +1,48 @@
@@ -0,0 +1,48 @@
|
||||
/* |
||||
* Copyright (c) 2023 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 io.element.android.services.analytics.noop |
||||
|
||||
import com.squareup.anvil.annotations.ContributesBinding |
||||
import im.vector.app.features.analytics.itf.VectorAnalyticsEvent |
||||
import im.vector.app.features.analytics.itf.VectorAnalyticsScreen |
||||
import im.vector.app.features.analytics.plan.UserProperties |
||||
import io.element.android.libraries.di.AppScope |
||||
import io.element.android.libraries.di.SingleIn |
||||
import io.element.android.services.analytics.api.AnalyticsService |
||||
import io.element.android.services.analyticsproviders.api.AnalyticsProvider |
||||
import kotlinx.coroutines.flow.Flow |
||||
import kotlinx.coroutines.flow.flowOf |
||||
import javax.inject.Inject |
||||
|
||||
@SingleIn(AppScope::class) |
||||
@ContributesBinding(AppScope::class) |
||||
class NoopAnalyticsService @Inject constructor( |
||||
) : AnalyticsService { |
||||
override fun getAvailableAnalyticsProviders(): Set<AnalyticsProvider> = emptySet() |
||||
override fun getUserConsent(): Flow<Boolean> = flowOf(false) |
||||
override suspend fun setUserConsent(userConsent: Boolean) = Unit |
||||
override fun didAskUserConsent(): Flow<Boolean> = flowOf(true) |
||||
override suspend fun setDidAskUserConsent() = Unit |
||||
override fun getAnalyticsId(): Flow<String> = flowOf("") |
||||
override suspend fun setAnalyticsId(analyticsId: String) = Unit |
||||
override suspend fun onSignOut() = Unit |
||||
override suspend fun reset() = Unit |
||||
override fun capture(event: VectorAnalyticsEvent) = Unit |
||||
override fun screen(screen: VectorAnalyticsScreen) = Unit |
||||
override fun updateUserProperties(userProperties: UserProperties) = Unit |
||||
override fun trackError(throwable: Throwable) = Unit |
||||
} |
@ -0,0 +1,35 @@
@@ -0,0 +1,35 @@
|
||||
/* |
||||
* Copyright (c) 2023 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. |
||||
*/ |
||||
plugins { |
||||
id("io.element.android-library") |
||||
alias(libs.plugins.anvil) |
||||
} |
||||
|
||||
android { |
||||
namespace = "io.element.android.services.analyticsproviders.sentry" |
||||
} |
||||
|
||||
anvil { |
||||
generateDaggerFactories.set(true) |
||||
} |
||||
|
||||
dependencies { |
||||
implementation(libs.dagger) |
||||
implementation(libs.sentry) |
||||
implementation(projects.libraries.core) |
||||
implementation(projects.libraries.di) |
||||
implementation(projects.services.analyticsproviders.api) |
||||
} |
@ -0,0 +1,26 @@
@@ -0,0 +1,26 @@
|
||||
<?xml version="1.0" encoding="utf-8"?><!-- |
||||
~ Copyright (c) 2023 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. |
||||
--> |
||||
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"> |
||||
|
||||
<application> |
||||
<!-- Sentry auto-initialization disabled --> |
||||
<meta-data |
||||
android:name="io.sentry.auto-init" |
||||
android:value="false" /> |
||||
</application> |
||||
|
||||
</manifest> |
@ -0,0 +1,79 @@
@@ -0,0 +1,79 @@
|
||||
/* |
||||
* Copyright (c) 2023 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 io.element.android.services.analyticsproviders.sentry |
||||
|
||||
import android.content.Context |
||||
import com.squareup.anvil.annotations.ContributesMultibinding |
||||
import im.vector.app.features.analytics.itf.VectorAnalyticsEvent |
||||
import im.vector.app.features.analytics.itf.VectorAnalyticsScreen |
||||
import im.vector.app.features.analytics.plan.UserProperties |
||||
import io.element.android.libraries.core.meta.BuildMeta |
||||
import io.element.android.libraries.core.meta.BuildType |
||||
import io.element.android.libraries.di.AppScope |
||||
import io.element.android.libraries.di.ApplicationContext |
||||
import io.element.android.services.analyticsproviders.api.AnalyticsProvider |
||||
import io.element.android.services.analyticsproviders.sentry.log.analyticsTag |
||||
import io.sentry.Sentry |
||||
import io.sentry.SentryOptions |
||||
import io.sentry.android.core.SentryAndroid |
||||
import timber.log.Timber |
||||
import javax.inject.Inject |
||||
|
||||
@ContributesMultibinding(AppScope::class) |
||||
class SentryAnalyticsProvider @Inject constructor( |
||||
@ApplicationContext private val context: Context, |
||||
private val buildMeta: BuildMeta, |
||||
) : AnalyticsProvider { |
||||
override val name = SentryConfig.name |
||||
|
||||
override fun init() { |
||||
Timber.tag(analyticsTag.value).d("Initializing Sentry") |
||||
if (Sentry.isEnabled()) return |
||||
SentryAndroid.init(context) { options -> |
||||
options.dsn = SentryConfig.dns |
||||
options.beforeSend = SentryOptions.BeforeSendCallback { event, _ -> event } |
||||
options.tracesSampleRate = 1.0 |
||||
options.isEnableUserInteractionTracing = true |
||||
options.environment = buildMeta.buildType.toSentryEnv() |
||||
options.diagnosticLevel |
||||
} |
||||
} |
||||
|
||||
override fun stop() { |
||||
Timber.tag(analyticsTag.value).d("Stopping Sentry") |
||||
Sentry.close() |
||||
} |
||||
|
||||
override fun capture(event: VectorAnalyticsEvent) { |
||||
} |
||||
|
||||
override fun screen(screen: VectorAnalyticsScreen) { |
||||
} |
||||
|
||||
override fun updateUserProperties(userProperties: UserProperties) { |
||||
} |
||||
|
||||
override fun trackError(throwable: Throwable) { |
||||
Sentry.captureException(throwable) |
||||
} |
||||
} |
||||
|
||||
private fun BuildType.toSentryEnv() = when (this) { |
||||
BuildType.RELEASE -> SentryConfig.envRelease |
||||
BuildType.NIGHTLY, |
||||
BuildType.DEBUG -> SentryConfig.envDebug |
||||
} |
@ -0,0 +1,24 @@
@@ -0,0 +1,24 @@
|
||||
/* |
||||
* Copyright (c) 2023 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 io.element.android.services.analyticsproviders.sentry |
||||
|
||||
object SentryConfig { |
||||
const val name = "Sentry" |
||||
const val dns = "https://32f7ff6a6e724f90838b7654042b2e81@sentry.tools.element.io/59" |
||||
const val envDebug = "DEBUG" |
||||
const val envRelease = "RELEASE" |
||||
} |
@ -0,0 +1,21 @@
@@ -0,0 +1,21 @@
|
||||
/* |
||||
* Copyright (c) 2023 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 io.element.android.services.analyticsproviders.sentry.log |
||||
|
||||
import io.element.android.libraries.core.log.logger.LoggerTag |
||||
|
||||
internal val analyticsTag = LoggerTag("Sentry") |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading…
Reference in new issue