Skip to content

Commit

Permalink
fix: add global metadata to ANR error reports
Browse files Browse the repository at this point in the history
  • Loading branch information
fractalwrench committed Jan 28, 2021
1 parent 773a06c commit f0a715d
Show file tree
Hide file tree
Showing 9 changed files with 27 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
* Check internal JNI calls for pending exceptions and no-op
[#1088](/~https://github.com/bugsnag/bugsnag-android/pull/1088)
[#1091](/~https://github.com/bugsnag/bugsnag-android/pull/1091)
* Add global metadata to ANR error reports
[#1095](/~https://github.com/bugsnag/bugsnag-android/pull/1095)

## 5.5.2 (2021-01-27)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -934,4 +934,8 @@ <T extends Plugin> T getPlugin(@NonNull Class<T> clz) {
Notifier getNotifier() {
return notifier;
}

MetadataState getMetadataState() {
return metadataState;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,8 @@ public boolean onError(@NonNull Event event) {
public static Event createEvent(@Nullable Throwable exc,
@NonNull Client client,
@NonNull SeverityReason severityReason) {
return new Event(exc, client.getConfig(), severityReason, client.logger);
Metadata metadata = client.getMetadataState().getMetadata();
return new Event(exc, client.getConfig(), severityReason, metadata, client.logger);
}

@NonNull
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ class AnrDetailsCollectorTest {
@Test
fun anrDetailsAltered() {
Mockito.`when`(client.config).thenReturn(BugsnagTestUtils.generateImmutableConfig())
Mockito.`when`(client.getMetadataState()).thenReturn(BugsnagTestUtils.generateMetadataState())
val event = NativeInterface.createEvent(
RuntimeException("whoops"),
client,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ static ImmutableConfig generateImmutableConfig() {
return convert(generateConfiguration());
}

static MetadataState generateMetadataState() {
return new MetadataState();
}

static ImmutableConfig convert(Configuration config) {
return ImmutableConfigKt.convertToImmutableConfig(config, null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ class EventDeserializerTest {

`when`(client.config).thenReturn(TestData.generateConfig())
`when`(client.getLogger()).thenReturn(object : Logger {})
`when`(client.getMetadataState()).thenReturn(TestHooks.generateMetadataState())
}

private fun breadcrumbMap() = hashMapOf(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,8 @@ class TestHooks {
static boolean getUnhandledOverridden(Event event) {
return event.impl.getUnhandledOverridden();
}

static MetadataState generateMetadataState() {
return new MetadataState();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.bugsnag.android.mazerunner.scenarios
import android.content.Context
import android.os.Handler
import android.os.Looper
import com.bugsnag.android.Bugsnag
import com.bugsnag.android.Configuration

/**
Expand All @@ -21,6 +22,11 @@ internal class AppNotRespondingScenario(

override fun startScenario() {
super.startScenario()
Bugsnag.addMetadata("custom", "global", "present in global metadata")
Bugsnag.addOnError { event ->
event.addMetadata("custom", "local", "present in local metadata")
true
}
val main = Handler(Looper.getMainLooper())
main.postDelayed(
Runnable {
Expand Down
4 changes: 4 additions & 0 deletions features/smoke_tests/unhandled.feature
Original file line number Diff line number Diff line change
Expand Up @@ -230,3 +230,7 @@ Scenario: ANR detection
And the event "threads.0.stacktrace.0.method" is not null
And the event "threads.0.stacktrace.0.file" is not null
And the event "threads.0.stacktrace.0.lineNumber" is not null

# Metadata validation
And the event "metaData.custom.global" equals "present in global metadata"
And the event "metaData.custom.local" equals "present in local metadata"

0 comments on commit f0a715d

Please sign in to comment.