Skip to content

Commit f817b5f

Browse files
committed
feat: init automatic capture of navigation telemetry events
1 parent 9d560e0 commit f817b5f

2 files changed

Lines changed: 37 additions & 0 deletions

File tree

rollbar-android/src/main/java/com/rollbar/android/Rollbar.java

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import static com.rollbar.android.util.Constants.ROLLBAR_NAMESPACE;
44

5+
import android.app.Application;
56
import android.content.Context;
67
import android.content.pm.ApplicationInfo;
78
import android.content.pm.PackageManager;
@@ -19,6 +20,7 @@
1920
import com.rollbar.api.payload.data.TelemetryType;
2021
import com.rollbar.api.payload.data.body.RollbarThread;
2122
import com.rollbar.notifier.config.ConfigProvider;
23+
import com.rollbar.notifier.telemetry.TelemetryEventTracker;
2224
import com.rollbar.notifier.uncaughtexception.RollbarUncaughtExceptionHandler;
2325
import com.rollbar.android.provider.NotifierProvider;
2426
import com.rollbar.android.provider.PersonProvider;
@@ -233,6 +235,7 @@ public static Rollbar init(
233235
suspendWhenNetworkIsUnavailable);
234236
if (androidConfiguration != null) {
235237
initAnrDetector(context, androidConfiguration);
238+
initAutomaticCaptureOfNavigationTelemetryEvents(context, androidConfiguration);
236239
}
237240
}
238241

@@ -273,6 +276,7 @@ public static Rollbar init(Context context, ConfigProvider provider) {
273276
notifier = new Rollbar(context, null, null, true, false, provider);
274277
AndroidConfiguration androidConfiguration = makeDefaultAndroidConfiguration();
275278
initAnrDetector(context, androidConfiguration);
279+
initAutomaticCaptureOfNavigationTelemetryEvents(context, androidConfiguration);
276280
}
277281
return notifier;
278282
}
@@ -1173,6 +1177,31 @@ public void run() {
11731177
});
11741178
}
11751179

1180+
private static void initAutomaticCaptureOfNavigationTelemetryEvents(
1181+
Context context,
1182+
AndroidConfiguration androidConfiguration
1183+
) {
1184+
if (!androidConfiguration.mustCaptureNavigationEvents()) {
1185+
return;
1186+
}
1187+
1188+
com.rollbar.notifier.Rollbar rollbarNotifier = notifier.rollbar;
1189+
if (rollbarNotifier == null) {
1190+
return;
1191+
}
1192+
1193+
TelemetryEventTracker telemetryEventTracker = rollbarNotifier.getTelemetryEventTracker();
1194+
if (telemetryEventTracker == null) {
1195+
return;
1196+
}
1197+
1198+
Context appContext = context.getApplicationContext();
1199+
if (appContext instanceof Application) {
1200+
Application application = (Application) appContext;
1201+
application.registerActivityLifecycleCallbacks(new TelemetryNavigationCallbacks(telemetryEventTracker));
1202+
}
1203+
}
1204+
11761205
private String loadAccessTokenFromManifest(Context context) throws NameNotFoundException {
11771206
Context appContext = context.getApplicationContext();
11781207
ApplicationInfo ai = appContext.getPackageManager().getApplicationInfo(appContext.getPackageName(), PackageManager.GET_META_DATA);

rollbar-java/src/main/java/com/rollbar/notifier/RollbarBase.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,14 @@ public void recordNetworkEventFor(Level level, String method, String url, String
103103
telemetryEventTracker.recordNetworkEventFor(level, getSource(), method, url, statusCode);
104104
}
105105

106+
/**
107+
* Gives the current TelemetryEventTracker
108+
* @return the {@link TelemetryEventTracker}
109+
*/
110+
public TelemetryEventTracker getTelemetryEventTracker() {
111+
return telemetryEventTracker;
112+
}
113+
106114
/**
107115
* Replace the configuration of this instance directly.
108116
*

0 commit comments

Comments
 (0)