Skip to content

Commit fe011ff

Browse files
romtsnclaude
andcommitted
chore(samples): Add Mapbox MapsActivity to exercise SurfaceView replay capture
Scaffolds a simple Mapbox-backed MapsActivity in the sample app so the new experimental captureSurfaceViews option can be exercised end-to-end. Mapbox 11.x renders into a SurfaceView by default, which previously appeared as a transparent hole in Session Replay recordings (GH-4862). Also flips the sample's replay strategy to pixelCopy and relaxes default masking so maps and text are visible in the replay, and switches MyApplication to manual SentryAndroid.init so we can set the new captureSurfaceViews option programmatically. The Mapbox SDK requires MAPBOX_DOWNLOADS_TOKEN in ~/.gradle/gradle.properties and a public access token wired into the app (R.string.mapbox_access_token or MapboxOptions.accessToken). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 29da076 commit fe011ff

7 files changed

Lines changed: 78 additions & 16 deletions

File tree

sentry-samples/sentry-samples-android/build.gradle.kts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,8 @@ dependencies {
129129
implementation(projects.sentryOkhttp)
130130
implementation(projects.sentrySpotlight)
131131

132+
implementation("com.mapbox.maps:android:11.16.2")
133+
132134
// how to exclude androidx if release health feature is disabled
133135
// implementation(projects.sentryAndroid) {
134136
// exclude(group = "androidx.lifecycle", module = "lifecycle-process")

sentry-samples/sentry-samples-android/src/main/AndroidManifest.xml

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,10 @@
8888
android:name=".TriggerHttpRequestActivity"
8989
android:exported="false" />
9090

91+
<activity
92+
android:name=".MapsActivity"
93+
android:exported="false" />
94+
9195
<!-- NOTE: Replace the test DSN below with YOUR OWN DSN to see the events from this app in your Sentry project/dashboard-->
9296
<meta-data
9397
android:name="io.sentry.dsn"
@@ -116,7 +120,9 @@
116120
<!-- <meta-data android:name="io.sentry.anr.enable" android:value="false" />-->
117121

118122
<!-- how to disable the auto-init-->
119-
<!-- <meta-data android:name="io.sentry.auto-init" android:value="false" />-->
123+
<meta-data
124+
android:name="io.sentry.auto-init"
125+
android:value="false" />
120126

121127
<!-- how to disable the NDK-->
122128
<!-- <meta-data android:name="io.sentry.ndk.enable" android:value="false" />-->
@@ -227,13 +233,16 @@
227233

228234
<meta-data
229235
android:name="io.sentry.session-replay.screenshot-strategy"
230-
android:value="canvas" />
236+
android:value="pixelCopy" />
231237
<meta-data
232238
android:name="io.sentry.session-replay.session-sample-rate"
233239
android:value="1" />
234240
<meta-data
235241
android:name="io.sentry.session-replay.mask-all-text"
236-
android:value="true" />
242+
android:value="false" />
243+
<meta-data
244+
android:name="io.sentry.session-replay.mask-all-images"
245+
android:value="false" />
237246

238247
<!-- Testing Network Details -->
239248
<!-- Catpure network details for all urls -->

sentry-samples/sentry-samples-android/src/main/java/io/sentry/samples/android/MainActivity.kt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -709,6 +709,16 @@ fun IntegrationsScreen() {
709709
}
710710
}
711711
}
712+
item {
713+
SentryTraced("open_maps_activity") {
714+
OutlinedButton(
715+
onClick = { activity.startActivity(Intent(activity, MapsActivity::class.java)) },
716+
modifier = Modifier,
717+
) {
718+
Text("Open Maps Activity", maxLines = 2, overflow = TextOverflow.Ellipsis)
719+
}
720+
}
721+
}
712722
item {
713723
SentryTraced("throw_in_coroutine") {
714724
OutlinedButton(onClick = { CoroutinesUtil.throwInCoroutine() }, modifier = Modifier) {
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package io.sentry.samples.android
2+
3+
import android.os.Bundle
4+
import androidx.appcompat.app.AppCompatActivity
5+
import com.mapbox.geojson.Point
6+
import com.mapbox.maps.CameraOptions
7+
import com.mapbox.maps.MapView
8+
import com.mapbox.maps.Style
9+
10+
/**
11+
* Hosts a full-screen Mapbox [MapView] to test Session Replay's SurfaceView capture path. By
12+
* default Mapbox 11.x renders into a [android.view.SurfaceView], so this screen will be all black
13+
* in replays without `SentryReplayOptions.isCaptureSurfaceViews = true`.
14+
*
15+
* Requires `MAPBOX_DOWNLOADS_TOKEN` in `~/.gradle/gradle.properties` to resolve the SDK and a
16+
* public access token wired into `R.string.mapbox_access_token` (or set via
17+
* `MapboxOptions.accessToken`).
18+
*/
19+
class MapsActivity : AppCompatActivity() {
20+
21+
private lateinit var mapView: MapView
22+
23+
override fun onCreate(savedInstanceState: Bundle?) {
24+
super.onCreate(savedInstanceState)
25+
mapView = MapView(this)
26+
setContentView(mapView)
27+
28+
mapView.mapboxMap.setCamera(
29+
CameraOptions.Builder().center(Point.fromLngLat(-0.1276, 51.5072)).zoom(10.0).build()
30+
)
31+
mapView.mapboxMap.loadStyle(Style.STANDARD)
32+
}
33+
}

sentry-samples/sentry-samples-android/src/main/java/io/sentry/samples/android/MyApplication.java

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import android.app.Application;
44
import android.os.StrictMode;
55
import io.sentry.Sentry;
6+
import io.sentry.android.core.SentryAndroid;
67

78
/** Apps. main Application. */
89
public class MyApplication extends Application {
@@ -13,19 +14,15 @@ public void onCreate() {
1314
strictMode();
1415
super.onCreate();
1516

16-
// Example how to initialize the SDK manually which allows access to SentryOptions callbacks.
17-
// Make sure you disable the auto init via manifest meta-data: io.sentry.auto-init=false
18-
// SentryAndroid.init(
19-
// this,
20-
// options -> {
21-
// /*
22-
// use options, for example, to add a beforeSend callback:
23-
//
24-
// options.setBeforeSend((event, hint) -> {
25-
// process event
26-
// });
27-
// */
28-
// });
17+
// Auto-init is disabled in the manifest so we can tweak SentryOptions here. All other options
18+
// still come from the manifest meta-data (DSN, sample rates, replay config, etc.).
19+
SentryAndroid.init(
20+
this,
21+
options -> {
22+
// Experimental: capture SurfaceView content (e.g. Mapbox, Unity, video players) so they
23+
// don't appear as transparent holes in Session Replay recordings.
24+
options.getSessionReplay().setCaptureSurfaceViews(true);
25+
});
2926
}
3027

3128
private void strictMode() {

sentry-samples/sentry-samples-android/src/main/res/values/strings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,4 +56,5 @@ Nulla interdum gravida augue, vel fringilla lorem bibendum vel. In hac habitasse
5656
<string name="open_camera_activity">Open Camera Activity</string>
5757
<string name="open_http_request_activity">Open Trigger HTTP Request Activity</string>
5858
<string name="trigger_okhttp_request">Trigger OkHttp Request</string>
59+
<string name="open_maps_activity">Open Maps Activity</string>
5960
</resources>

settings.gradle.kts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,16 @@ dependencyResolutionManagement {
1212
google()
1313
mavenCentral()
1414
mavenLocal()
15+
// Mapbox Maven repository — used by the sample's MapsActivity. Requires
16+
// MAPBOX_DOWNLOADS_TOKEN in ~/.gradle/gradle.properties.
17+
maven {
18+
url = uri("https://api.mapbox.com/downloads/v2/releases/maven")
19+
credentials {
20+
username = "mapbox"
21+
password = providers.gradleProperty("MAPBOX_DOWNLOADS_TOKEN").getOrElse("")
22+
}
23+
authentication { create<org.gradle.authentication.http.BasicAuthentication>("basic") }
24+
}
1525
}
1626
}
1727

0 commit comments

Comments
 (0)