Skip to content

Commit

Permalink
Merge pull request #906 from bugsnag/v5rn-client-notify-tweak
Browse files Browse the repository at this point in the history
Respect pre-populated fields on Event when notifying
  • Loading branch information
fractalwrench authored Jul 17, 2020
2 parents 3a31b88 + 5694e98 commit 79a2b6a
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 22 deletions.
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

0 comments on commit 79a2b6a

Please sign in to comment.