|
1 | 1 | package org.simple.clinic |
2 | 2 |
|
3 | 3 | import android.app.Application |
4 | | -import android.content.Context |
5 | 4 | import androidx.test.platform.app.InstrumentationRegistry |
6 | | -import com.datadog.android.Datadog |
7 | | -import com.datadog.android.core.configuration.Configuration |
8 | | -import com.datadog.android.core.configuration.Credentials |
9 | | -import com.datadog.android.core.configuration.UploadFrequency |
10 | | -import com.datadog.android.privacy.TrackingConsent |
11 | | -import com.datadog.android.rum.GlobalRum |
12 | | -import com.datadog.android.rum.RumMonitor |
13 | | -import com.datadog.android.rum.tracking.ViewTrackingStrategy |
14 | | -import com.datadog.android.tracing.AndroidTracer |
15 | 5 | import com.tspoon.traceur.Traceur |
16 | | -import io.opentracing.util.GlobalTracer |
| 6 | +import io.sentry.SentryLevel |
| 7 | +import io.sentry.SentryOptions |
| 8 | +import io.sentry.android.core.SentryAndroid |
17 | 9 | import org.simple.clinic.TestClinicApp.Companion.appComponent |
18 | 10 | import org.simple.clinic.benchmark.BackupBenchmarkDatabase |
19 | 11 | import org.simple.clinic.di.DaggerTestAppComponent |
@@ -100,9 +92,8 @@ class TestClinicApp : Application() { |
100 | 92 | dataSync.syncTheWorld() |
101 | 93 | backupBenchmarkDatabase.backup() |
102 | 94 |
|
103 | | - setupDatadog( |
104 | | - clientToken = instrumentationArgs.getString("dd_client_token")!!, |
105 | | - applicationId = instrumentationArgs.getString("dd_application_id")!! |
| 95 | + setupSentry( |
| 96 | + dsn = instrumentationArgs.getString("sentry_dsn")!!, |
106 | 97 | ) |
107 | 98 | } |
108 | 99 | } |
@@ -155,39 +146,20 @@ class TestClinicApp : Application() { |
155 | 146 | .build() |
156 | 147 | } |
157 | 148 |
|
158 | | - private fun setupDatadog( |
159 | | - clientToken: String, |
160 | | - applicationId: String |
161 | | - ) { |
162 | | - val datadogConfig = Configuration |
163 | | - .Builder( |
164 | | - logsEnabled = true, |
165 | | - tracesEnabled = true, |
166 | | - crashReportsEnabled = false, |
167 | | - rumEnabled = false |
168 | | - ) |
169 | | - .useViewTrackingStrategy(NoopViewTrackingStrategy()) |
170 | | - .setUploadFrequency(UploadFrequency.FREQUENT) |
171 | | - .build() |
172 | | - val credentials = Credentials( |
173 | | - clientToken = clientToken, |
174 | | - envName = "test", |
175 | | - variant = BuildConfig.FLAVOR, |
176 | | - rumApplicationId = applicationId, |
177 | | - serviceName = "simple-android-perf-regression" |
178 | | - ) |
179 | | - Datadog.initialize(this, credentials, datadogConfig, TrackingConsent.GRANTED) |
180 | | - GlobalRum.registerIfAbsent(RumMonitor.Builder().build()) |
181 | | - GlobalTracer.registerIfAbsent(AndroidTracer.Builder().setPartialFlushThreshold(5).build()) |
182 | | - } |
183 | | - |
184 | | - private class NoopViewTrackingStrategy : ViewTrackingStrategy { |
185 | | - override fun register(context: Context) { |
186 | | - // No need to track views in tests |
187 | | - } |
188 | | - |
189 | | - override fun unregister(context: Context?) { |
190 | | - // No need to track views in tests |
| 149 | + private fun setupSentry(dsn: String) { |
| 150 | + SentryAndroid.init(this) { options -> |
| 151 | + options.dsn = dsn |
| 152 | + options.environment = "test" |
| 153 | + options.sampleRate = 0.0 |
| 154 | + options.tracesSampleRate = 1.0 |
| 155 | + |
| 156 | + options.beforeSend = SentryOptions.BeforeSendCallback { event, _ -> |
| 157 | + if (event.level != SentryLevel.DEBUG) { |
| 158 | + event |
| 159 | + } else { |
| 160 | + null |
| 161 | + } |
| 162 | + } |
191 | 163 | } |
192 | 164 | } |
193 | 165 | } |
0 commit comments