Skip to content

Commit

Permalink
Android: sample VPN process error reports (#1017)
Browse files Browse the repository at this point in the history
  • Loading branch information
alalamav committed May 4, 2021
1 parent 2f92363 commit 09d7867
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@
public class SentryErrorReporter {
// Limit the number of breadcrumbs to comply with Outline's data collection policy.
private static final int MAX_BREADCRUMBS = 100;
// Reduce the number of VPN service process Sentry error reports by setting a sampling rate.
private static final double VPN_PROCESS_ERROR_REPORTING_SAMPLE_RATE = 0.75;
private static final String CATEGORY_VPN_PROCESS = "vpn";

// Disallow instantiation in favor of a purely static class.
Expand Down Expand Up @@ -92,9 +94,11 @@ public void flush() {}
* @param dsn Sentry API Key
*/
public static void init(Context context, final String dsn) {
double sampleRate = isVpnServiceContext(context) ? VPN_PROCESS_ERROR_REPORTING_SAMPLE_RATE : 1;
SentryAndroid.init(context, options -> {
options.setDsn(dsn);
options.setMaxBreadcrumbs(MAX_BREADCRUMBS);
options.setSampleRate(sampleRate);
options.setBeforeSend(((event, hint) -> {
try {
return removeSentryEventPii(event);
Expand All @@ -112,6 +116,15 @@ public static void init(Context context, final String dsn) {
}
}

private static boolean isVpnServiceContext(Context context) {
try {
return context.getClass().getName().contains("vpn");
} catch (Exception e) {
Log.w(SentryErrorReporter.class.getName(), "Failed to determine running context");
}
return false;
}

/**
* Sends previously recorded errors and messages to Sentry. Associate the report
* with the provided event id.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,7 @@ private void storeActiveTunnel(final TunnelConfig config, boolean isUdpSupported

private void initErrorReporting(final String apiKey) {
try {
SentryErrorReporter.init(getApplicationContext(), apiKey);
SentryErrorReporter.init(this, apiKey);
} catch (Exception e) {
LOG.log(Level.SEVERE, "Failed to initialize Sentry", e);
}
Expand Down

0 comments on commit 09d7867

Please sign in to comment.