Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(sentry): clear name in device context #1207

Merged
merged 2 commits into from
Mar 16, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,11 @@
* Wrapper class for the Sentry error reporting framework.
*/
public class SentryErrorReporter {
// Limit the number of breadcrumbs to comply with Outline's data collection policy.
// 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.
// 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";

Expand All @@ -53,7 +55,8 @@ private SentryErrorReporter() {}

/**
* Handler that records logs with level INFO and above to Sentry.
* Exceptions are only logged locally to avoid sending sensitive data to the error reporting
* Exceptions are only logged locally to avoid sending sensitive data to the
* error reporting
* framework as part of stack traces.
*/
public final static Handler BREADCRUMB_LOG_HANDLER = new Handler() {
Expand Down Expand Up @@ -88,10 +91,11 @@ public void flush() {}

/**
* Initializes the error reporting framework with the given credentials.
* Configures an Android uncaught exception handler which sends events to Sentry.
* Configures an Android uncaught exception handler which sends events to
* Sentry.
*
* @param context Android application Context
* @param dsn Sentry API Key
* @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;
Expand Down Expand Up @@ -129,18 +133,23 @@ private static boolean isVpnServiceContext(Context context) {
* Sends previously recorded errors and messages to Sentry. Associate the report
* with the provided event id.
*
* @param eventId, unique identifier i.e. the event id for a error report in sentry-browser.
* @throws IllegalStateException when Sentry has not been initialized with an API key.
* @param eventId, unique identifier i.e. the event id for a error report in
* sentry-browser.
* @throws IllegalStateException when Sentry has not been initialized with an
* API key.
*/
public static void send(final String eventId) throws IllegalStateException {
if (!Sentry.isEnabled()) {
throw new IllegalStateException("Sentry not initialized");
}
recordVpnProcessLogs();
final String uuid = eventId != null ? eventId : UUID.randomUUID().toString();
// Associate this report with the event ID generated by sentry-browser for cross-referencing.
// If the ID is not present, use a random UUID to disambiguate the report message so it doesn't
// get clustered with other reports. Clustering retains the report data on the server side,
// Associate this report with the event ID generated by sentry-browser for
// cross-referencing.
// If the ID is not present, use a random UUID to disambiguate the report
// message so it doesn't
// get clustered with other reports. Clustering retains the report data on the
// server side,
// whereas inactivity results in its deletion after 90 days.
final SentryEvent event = new SentryEvent();
final Message message = new Message();
Expand Down Expand Up @@ -180,7 +189,8 @@ private static void addBreadcrumb(Breadcrumb breadcrumb) {
}
}

// Removes personally identifiably information and unnecessary metadata from a Sentry event.
// Removes personally identifiably information and unnecessary metadata from a
// Sentry event.
// Ensures that the Android device ID is not sent.
private static SentryEvent removeSentryEventPii(final SentryEvent event) {
final Contexts contexts = event.getContexts();
Expand All @@ -190,6 +200,7 @@ private static SentryEvent removeSentryEventPii(final SentryEvent event) {
device.setExternalFreeStorage(null);
device.setExternalStorageSize(null);
device.setId(null);
device.setName(null);
fortuna marked this conversation as resolved.
Show resolved Hide resolved
device.setOrientation(null);
device.setScreenDensity(null);
device.setScreenDpi(null);
Expand Down