joshdholtz / Sentry-Android

[Deprecated] Use official "raven-java" library
https://github.com/getsentry/sentry-java
MIT License
180 stars 48 forks source link

how to add tag in unhandler exception. #67

Closed SwiftyWang closed 8 years ago

SwiftyWang commented 8 years ago

I have found the tag in capture Exception. But I cannot find this feature in unhandler exception sending. Can I add tags when app crash(unhandler Exception) use your library?

marcomorain commented 8 years ago

You can register an event capture listener to do this:

https://github.com/joshdholtz/Sentry-Android#set-a-listener-to-intercept-the-sentryeventbuilder-before-each-capture

// CALL THIS BEFORE CALLING Sentry.init
// Sets a listener to intercept the SentryEventBuilder before 
// each capture to set values that could change state
Sentry.setCaptureListener(new SentryEventCaptureListener() {

    @Override
    public SentryEventBuilder beforeCapture(SentryEventBuilder builder) {

        // Needs permission - <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
        ConnectivityManager connManager = (ConnectivityManager) getSystemService(CONNECTIVITY_SERVICE);
        NetworkInfo mWifi = connManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);

        // Sets extra key if wifi is connected
        try {
            builder.getExtra().put("wifi", String.valueOf(mWifi.isConnected()));
            builder.getTags().put("tag_1", "value_1");
        } catch (JSONException e) {}

        return builder;
    }

});
SwiftyWang commented 8 years ago

Very helpful!! Thank you very much!!!

joshdholtz commented 8 years ago

@marcomorain Thanks for answering this for me! 😊 You da 💣

marcomorain commented 8 years ago

💥