@@ -20,11 +20,8 @@ import io.flutter.plugin.common.MethodChannel.MethodCallHandler
20
20
import io.flutter.plugin.common.MethodChannel.Result
21
21
import io.sentry.Breadcrumb
22
22
import io.sentry.DateUtils
23
- import io.sentry.Hint
24
23
import io.sentry.HubAdapter
25
24
import io.sentry.Sentry
26
- import io.sentry.SentryEvent
27
- import io.sentry.SentryOptions
28
25
import io.sentry.android.core.ActivityFramesTracker
29
26
import io.sentry.android.core.InternalSentrySdk
30
27
import io.sentry.android.core.LoadClass
@@ -35,10 +32,8 @@ import io.sentry.android.core.performance.TimeSpan
35
32
import io.sentry.android.replay.ReplayIntegration
36
33
import io.sentry.android.replay.ScreenshotRecorderConfig
37
34
import io.sentry.protocol.DebugImage
38
- import io.sentry.protocol.SdkVersion
39
35
import io.sentry.protocol.SentryId
40
36
import io.sentry.protocol.User
41
- import io.sentry.rrweb.RRWebOptionsEvent
42
37
import io.sentry.transport.CurrentDateProvider
43
38
import java.io.File
44
39
import java.lang.ref.WeakReference
@@ -79,11 +74,7 @@ class SentryFlutterPlugin :
79
74
channel = MethodChannel (flutterPluginBinding.binaryMessenger, " sentry_flutter" )
80
75
channel.setMethodCallHandler(this )
81
76
82
- sentryFlutter =
83
- SentryFlutter (
84
- androidSdk = ANDROID_SDK ,
85
- nativeSdk = NATIVE_SDK ,
86
- )
77
+ sentryFlutter = SentryFlutter ()
87
78
}
88
79
89
80
@Suppress(" CyclomaticComplexMethod" )
@@ -165,57 +156,45 @@ class SentryFlutterPlugin :
165
156
framesTracker = ActivityFramesTracker (LoadClass (), options)
166
157
}
167
158
168
- options.beforeSend = BeforeSendCallbackImpl (options.sdkVersion)
169
-
170
- // Replace the default ReplayIntegration with a Flutter-specific recorder.
171
- options.integrations.removeAll { it is ReplayIntegration }
172
- val cacheDirPath = options.cacheDirPath
173
- val replayOptions = options.sessionReplay
174
- val isReplayEnabled = replayOptions.isSessionReplayEnabled || replayOptions.isSessionReplayForErrorsEnabled
175
- if (cacheDirPath != null && isReplayEnabled) {
176
- replay =
177
- ReplayIntegration (
178
- context,
179
- dateProvider = CurrentDateProvider .getInstance(),
180
- recorderProvider = { SentryFlutterReplayRecorder (channel, replay) },
181
- recorderConfigProvider = {
182
- Log .i(
183
- " Sentry" ,
184
- " Replay configuration requested. Returning: %dx%d at %d FPS, %d BPS" .format(
185
- replayConfig.recordingWidth,
186
- replayConfig.recordingHeight,
187
- replayConfig.frameRate,
188
- replayConfig.bitRate,
189
- ),
190
- )
191
- replayConfig
192
- },
193
- replayCacheProvider = null ,
194
- )
195
- replay.breadcrumbConverter = SentryFlutterReplayBreadcrumbConverter ()
196
- options.addIntegration(replay)
197
- options.setReplayController(replay)
198
-
199
- options.beforeSendReplay =
200
- SentryOptions .BeforeSendReplayCallback { event, hint ->
201
- hint.replayRecording?.payload?.firstOrNull { it is RRWebOptionsEvent }?.let { optionsEvent ->
202
- val payload = (optionsEvent as RRWebOptionsEvent ).optionsPayload
203
-
204
- // Remove defaults set by the native SDK.
205
- payload.filterKeys { it.contains(" mask" ) }.forEach { (k, _) -> payload.remove(k) }
206
-
207
- // Now, set the Flutter-specific values.
208
- // TODO do this in a followup PR
209
- }
210
- event
211
- }
212
- } else {
213
- options.setReplayController(null )
214
- }
159
+ setupReplay(options)
215
160
}
216
161
result.success(" " )
217
162
}
218
163
164
+ private fun setupReplay (options : SentryAndroidOptions ) {
165
+ // Replace the default ReplayIntegration with a Flutter-specific recorder.
166
+ options.integrations.removeAll { it is ReplayIntegration }
167
+ val cacheDirPath = options.cacheDirPath
168
+ val replayOptions = options.sessionReplay
169
+ val isReplayEnabled = replayOptions.isSessionReplayEnabled || replayOptions.isSessionReplayForErrorsEnabled
170
+ if (cacheDirPath != null && isReplayEnabled) {
171
+ replay =
172
+ ReplayIntegration (
173
+ context,
174
+ dateProvider = CurrentDateProvider .getInstance(),
175
+ recorderProvider = { SentryFlutterReplayRecorder (channel, replay) },
176
+ recorderConfigProvider = {
177
+ Log .i(
178
+ " Sentry" ,
179
+ " Replay configuration requested. Returning: %dx%d at %d FPS, %d BPS" .format(
180
+ replayConfig.recordingWidth,
181
+ replayConfig.recordingHeight,
182
+ replayConfig.frameRate,
183
+ replayConfig.bitRate,
184
+ ),
185
+ )
186
+ replayConfig
187
+ },
188
+ replayCacheProvider = null ,
189
+ )
190
+ replay.breadcrumbConverter = SentryFlutterReplayBreadcrumbConverter ()
191
+ options.addIntegration(replay)
192
+ options.setReplayController(replay)
193
+ } else {
194
+ options.setReplayController(null )
195
+ }
196
+ }
197
+
219
198
private fun fetchNativeAppStart (result : Result ) {
220
199
if (! sentryFlutter.autoPerformanceTracingEnabled) {
221
200
result.success(null )
@@ -537,61 +516,9 @@ class SentryFlutterPlugin :
537
516
result.success(" " )
538
517
}
539
518
540
- private class BeforeSendCallbackImpl (
541
- private val sdkVersion : SdkVersion ? ,
542
- ) : SentryOptions.BeforeSendCallback {
543
- override fun execute (
544
- event : SentryEvent ,
545
- hint : Hint ,
546
- ): SentryEvent {
547
- setEventOriginTag(event)
548
- addPackages(event, sdkVersion)
549
- return event
550
- }
551
- }
552
-
553
519
companion object {
554
- private const val FLUTTER_SDK = " sentry.dart.flutter"
555
- private const val ANDROID_SDK = " sentry.java.android.flutter"
556
- private const val NATIVE_SDK = " sentry.native.android.flutter"
557
520
private const val NATIVE_CRASH_WAIT_TIME = 500L
558
521
559
- private fun setEventOriginTag (event : SentryEvent ) {
560
- event.sdk?.let {
561
- when (it.name) {
562
- FLUTTER_SDK -> setEventEnvironmentTag(event, " flutter" , " dart" )
563
- ANDROID_SDK -> setEventEnvironmentTag(event, environment = " java" )
564
- NATIVE_SDK -> setEventEnvironmentTag(event, environment = " native" )
565
- else -> return
566
- }
567
- }
568
- }
569
-
570
- private fun setEventEnvironmentTag (
571
- event : SentryEvent ,
572
- origin : String = "android",
573
- environment : String ,
574
- ) {
575
- event.setTag(" event.origin" , origin)
576
- event.setTag(" event.environment" , environment)
577
- }
578
-
579
- private fun addPackages (
580
- event : SentryEvent ,
581
- sdk : SdkVersion ? ,
582
- ) {
583
- event.sdk?.let {
584
- if (it.name == FLUTTER_SDK ) {
585
- sdk?.packageSet?.forEach { sentryPackage ->
586
- it.addPackage(sentryPackage.name, sentryPackage.version)
587
- }
588
- sdk?.integrationSet?.forEach { integration ->
589
- it.addIntegration(integration)
590
- }
591
- }
592
- }
593
- }
594
-
595
522
private fun crash () {
596
523
val exception = RuntimeException (" FlutterSentry Native Integration: Sample RuntimeException" )
597
524
val mainThread = Looper .getMainLooper().thread
0 commit comments