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

Respect pre-populated fields on Event when notifying #906

Merged
merged 1 commit into from
Jul 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 25 additions & 21 deletions bugsnag-android-core/src/main/java/com/bugsnag/android/Client.java
Original file line number Diff line number Diff line change
Expand Up @@ -613,7 +613,7 @@ public void notify(@NonNull Throwable exc, @Nullable OnErrorCallback onError) {
HandledState handledState = HandledState.newInstance(REASON_HANDLED_EXCEPTION);
Metadata metadata = metadataState.getMetadata();
Event event = new Event(exc, immutableConfig, handledState, metadata, logger);
notifyInternal(event, onError);
populateAndNotifyAndroidEvent(event, onError);
} else {
logNull("notify");
}
Expand All @@ -631,28 +631,11 @@ void notifyUnhandledException(@NonNull Throwable exc, Metadata metadata,
= HandledState.newInstance(severityReason, Severity.ERROR, attributeValue);
Metadata data = Metadata.Companion.merge(metadataState.getMetadata(), metadata);
Event event = new Event(exc, immutableConfig, handledState, data, logger);
notifyInternal(event, null);
populateAndNotifyAndroidEvent(event, null);
}

void notifyInternal(@NonNull Event event,
@Nullable OnErrorCallback onError) {
// Don't notify if this event class should be ignored
if (event.shouldDiscardClass()) {
return;
}

if (!immutableConfig.shouldNotifyForReleaseStage()) {
return;
}

// get session for event
Session currentSession = sessionTracker.getCurrentSession();

if (currentSession != null
&& (immutableConfig.getAutoTrackSessions() || !currentSession.isAutoCaptured())) {
event.setSession(currentSession);
}

void populateAndNotifyAndroidEvent(@NonNull Event event,
@Nullable OnErrorCallback onError) {
// Capture the state of the app and device and attach diagnostics to the event
event.setDevice(deviceDataCollector.generateDeviceWithState(new Date().getTime()));
event.addMetadata("device", deviceDataCollector.getDeviceMetadata());
Expand All @@ -674,6 +657,27 @@ void notifyInternal(@NonNull Event event,
String context = contextState.getContext();
event.setContext(context != null ? context : appDataCollector.getActiveScreenClass());
}
notifyInternal(event, onError);
}

void notifyInternal(@NonNull Event event,
@Nullable OnErrorCallback onError) {
// Don't notify if this event class should be ignored
if (event.shouldDiscardClass()) {
return;
}

if (!immutableConfig.shouldNotifyForReleaseStage()) {
return;
}

// get session for event
Session currentSession = sessionTracker.getCurrentSession();

if (currentSession != null
&& (immutableConfig.getAutoTrackSessions() || !currentSession.isAutoCaptured())) {
event.setSession(currentSession);
}

// Run on error tasks, don't notify if any return false
if (!callbackState.runOnErrorTasks(event, logger)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ internal class AnrDetailsCollector {
}
} else {
addErrorStateInfo(event, anrDetails)
client.notifyInternal(event, null)
client.populateAndNotifyAndroidEvent(event, null)
}
}
})
Expand Down