• Stars
    star
    180
  • Rank 213,042 (Top 5 %)
  • Language
    Java
  • License
    MIT License
  • Created over 11 years ago
  • Updated 5 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

[Deprecated] Use official "raven-java" library

[Deprecated] Sentry-Android - Sentry Client for Android

⚠️ Please use official raven-java library - https://github.com/getsentry/sentry-java

It does what every Sentry client needs to do

Below is an example of how to register Sentry-Android to handle uncaught exceptions

<!-- REQUIRED to send captures to Sentry -->
<uses-permission android:name="android.permission.INTERNET" />

<!-- OPTIONAL but makes Sentry-Android smarter -->
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
import com.joshdholtz.sentry.Sentry;

public class MainActivity extends Activity {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        // Sentry will look for uncaught exceptions from previous runs and send them
        Sentry.init(this, "YOUR-SENTRY-DSN");
    }
}

Features

Sentry-Android has two features that make it easy to use.

First, Sentry-Android will, by default, install an uncaught exception handler that will catch and report any uncaught exceptions (crashes) in your app. You only need to add a single line of code to set up Sentry-Android.

Second, since Sentry-Android is written specifically for Android, we can automatically associate device and OS information to error-reports. The table below shows an example of what the data will look like in Sentry.

DEVICE
Familygoogle
Modelbullhead (Nexus 5X)
Architectureaarch64
Orientationportrait
screen_resolution1794x1080
OPERATING SYSTEM
NameAndroid
Version7.0 (24)
Kernel Version3.10.73-g76d746e
PACKAGE
namecom.example.package
version_code210
version_name2.1

Crash Report Behavior

Sentry-Android will attempt to send all crash reports when the app starts back up. If something fails to upload, Sentry-Android will attempt to send again on next start. If you would like to manually attempt to send crash reports, please use the following call in your app 😊 Sentry.sendAllCachedCapturedEvents()

Updates

Version Changes
1.6.2 Now able to set the environment of the app #123
1.6.1 Fix bug in release version setting - the built-in package version was overriding the user-specified one. #120
1.6.0 Increase breadcrumb limit to 100 to match other Sentry clients, allow runtime configuration. #117.
Removed org.apache HTTP library 116.
1.5.4 Ensure that breadcrumbs are added to all exceptions. #115.
1.5.3 Fix thread-safety bug when serializing breadcrumbs. #110 (thanks to fab1an).
1.5.2 Send stack-frames to Sentry in the correct order. #95.
Use the versionName, rather than versionCode, as the default value for the release field of events (thanks to FelixBondarenko).
1.5.1 Revert accidental API removal of captureException(Throwable, SentryEventLevel).
1.5.0 Add Breadcrumb support #70.
Add release tracking by default #78.
Add the ability to attach a stack-trace to any event #81.
Use a fixed-size thread-pool for sending events #80.
Make it easier to add a message when capturing an exception #77.
Added helper methods for addExtra and addTag #74.
(thanks to marcomorain)
1.4.4 Sends up device, app, and OS context by default (thanks to marcomorain)
1.4.3 Fixes for a Google Play warning and added option to not use crash reporting (thanks to ZeroStride)
1.4.1 Fixes for a potential memory leak and a crash (thanks to Syhids and woostrowski)
1.4.0 Fixes issues when using self-hosted Sentry server
1.2.1 Sends up data to Sentry as UTF-8
1.2.0 Added support for Android version 23 and made library avaiable to install via gradle
1.1.4 Added support for verify_ssl on DSN (thanks Kras4ooo)
1.1.3 Exceptions appear super mega awesome in Sentry now (thanks doapp-jeremiah)
1.1.2 Bug fixed - Setting a captureListener was required to send a report (thanks mathzol)
1.1.1 Uncaught exception handler now calls SentryEventCaptureListener
1.1.0 Saves requests that were captured offline or failed and tries to resend them when it can
1.0.0 Removed dependency to Protocol; allows capture of message from background thread
0.1.0 Initial release

How To Get Started

Gradle

Available in jCenter

compile 'com.joshdholtz.sentry:sentry-android:1.6.0'

Manual

JAR can be downloaded here

This Is How We Do It

Permissions in manifest

The AndroidManifest.xml requires the permission android.permission.INTERNET and would like the permission android.permission.ACCESS_NETWORK_STATE even though optional.

<!-- REQUIRED to send captures to Sentry -->
<uses-permission android:name="android.permission.INTERNET" />

<!-- OPTIONAL but makes Sentry-Android smarter -->
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

Capture a message

Sentry.captureMessage("Something significant may have happened");

Capture a caught exception

try {
	JSONObject obj = new JSONObject();
} catch (JSONException e) {
	Sentry.captureException(e);
}

Capture custom event

Sentry.captureEvent(new Sentry.SentryEventBuilder()
	.setMessage("Being awesome")
	.setCulprit("Josh Holtz")
	.setTimestamp(System.currentTimeMillis())
);

Capture Breadcrumbs

You can record breadcrumbs to track what happened in your application leading up to an error.

There are 3 ways to log a breadcrumb.

// Record that a user sent a HTTP POST to example.com and it was successful.
Sentry.addHttpBreadcrumb("http://example.com", "POST", 200);

// Record the fact that user clicked a button to go from the main menu to the
// settings menu.
Sentry.addNavigationBreadcrumb("user.click", "main menu", "settings");

// Record a general,  application specific event
Sentry.addBreadcrumb("user.state_change", "logged in");

Release Tracking

The SDK will automatically tag events with a release. The release is set to the app's versionName by default. You can override the release easily by using the setRelease(String release) function from inside a SentryEventCaptureListener.

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
        return builder
            .addExtra("wifi", String.valueOf(mWifi.isConnected()))
            .addTag("tag_1", "value_1");
    }
});

Contact

Email: [email protected]
Twitter: @joshdholtz

License

Sentry-Android is available under the MIT license.

More Repositories

1

DeckUI

Swift DSL for writing slide decks in Xcode
Swift
602
star
2

jsonapi-ios

A library for loading data from a JSON API datasource.
Objective-C
182
star
3

jenkins-slack-command

Start a build in Jenkins using a Slack Command
Ruby
55
star
4

wassup

Easily scriptable terminal dashboard
Ruby
39
star
5

crunchygif

EZPZ VIDEO TO GIF CREATOR
Swift
34
star
6

fastlane-plugin-github_action

A plugin for setting up fastlane on GitHub Actions
Ruby
33
star
7

CropImageView

Super easy component for Android to crop an image
Java
33
star
8

connectkit-examples

21
star
9

NSDate-MinimalTimeAgo

NSDate category for very minimal style time ago
Objective-C
17
star
10

exportation

CLI tool of easy exporting/encrypting, and decrypting/importing of certificates and private keys
Ruby
17
star
11

ios-promises

[Deprecated] [Super no longer maintained] Objective-C implementation of jQuery-ish promises
Objective-C
17
star
12

LayoutOfRelativity

iOS relative layout rules
Objective-C
9
star
13

Notables-Swift

Protocol extensions for common NSNotifications for the lazy (me)
Swift
9
star
14

fastlane-plugin-queue

Queues for fastlane - with web interface 😱
Ruby
9
star
15

dotenv_to_ci

The laziest way to transfer environment variables from a .env file to a CI provider 👋
Ruby
8
star
16

ionic-configurator

Configure Ionic (Cordova) config.xml files for individual environments using Mustache templating
JavaScript
8
star
17

swift-webframeworks-docker

Docker containers used for spinning up different Swift web frameworks
Swift
8
star
18

dotfiles

Vim Script
7
star
19

fastlane-plugin-rename_android_package

Ruby
7
star
20

wassup-swift

Wassup is a flexible and customizable dashboard for showing GitHub data.
Swift
7
star
21

ios-swift-test

Swift
7
star
22

chrome-circle-pr

Send a parameterized build to your CircleCI project from the push of a button while viewing your Pull Request on Github
JavaScript
7
star
23

fastlane-plugin-android_keystore

Generate an Android keystore file
Ruby
6
star
24

CircleShadowImageView

iOS UIImageView subclass for making a circle image with a shadow
Objective-C
6
star
25

ecto-lazy-float

Ecto.LazyFloat - An Ecto.Float that accepts binary and integers
Elixir
6
star
26

jenkins-ironmq

Start a Jenkins job from an IronMQ message
Ruby
5
star
27

Protocol-Android

Java
5
star
28

JHSidebar

Objective-C
5
star
29

JHTableViewPullRefresh

Objective-C
3
star
30

RestCat

A RESTful library for iOS
Objective-C
3
star
31

hubby

Ruby
3
star
32

wassup-swift-releases

3
star
33

grandpa-kennys-fishing-adventure-early-access

3
star
34

raven-rust

Rust
2
star
35

circleci-orbs

CircleCI Orbs that make my life easier 😊
2
star
36

html-pager

HTML Pager
Ruby
2
star
37

fastlane-plugin-revenuecat

A fastlane plugin for interacting with the RevenueCat Developer API
Ruby
2
star
38

PicPick

Java
2
star
39

Trajectory

Android routing library
Java
2
star
40

shift

Application backend
JavaScript
2
star
41

liveedutv-obs-overlay

A LiveEdu.tv overlay for use in OBS (or other streaming application)
HTML
2
star
42

fastlane-plugin-install_android

Ruby
2
star
43

homeboy

JavaScript
1
star
44

joshdholtz

Ruby
1
star
45

slack-receipt-bot

Elixir
1
star
46

SlideyMenuGuy

Objective-C
1
star
47

NProgressIsh-iOS

NProgress like style progress bar for iOS
Objective-C
1
star
48

fastlane-plugin-bomb_emoji

💣 all the emojis in the fastlane output
Ruby
1
star
49

raycast-revenuecat

TypeScript
1
star
50

climbon-api

Swift
1
star
51

cupcakegram-ios

Swift
1
star
52

Protocol

Protocol
Objective-C
1
star
53

Protocol-iOS

Objective-C
1
star
54

JHAccordion

Objective-C
1
star
55

NavBarSwipeTitle

Objective-C
1
star
56

old_harmonic

A Swift library for loading JSON objects and arrays into Swift objects
Swift
1
star
57

yeah-buddy

JavaScript
1
star
58

ionic-configurator-example

CSS
1
star
59

star-wars-a-new-app

Swift
1
star
60

fastlane-plugin-testfairy

Upload an IPA to TestFairy
Ruby
1
star
61

Rekt-Swift

Functional approach to altering CGRect
Swift
1
star
62

Mockery-iOS

iOS Web Framework?? Not sure what to call this yet
Objective-C
1
star
63

KSCrash-Locking-Up-In-Swift-Example

KSCrash locks up in Swift but not in Objective-C (both example included)
C
1
star
64

storekit-config-file-demo

Demo app on how to use StoreKit Config File with RevenueCat and StoreKit 2
Swift
1
star
65

JustTransloadit-iOS

A simple to use Transloadit library
Objective-C
1
star
66

test-repo-for-fastlane-plugin-github_action

Ruby
1
star
67

CLGeocoder-DoubleLookup

CLGeocoder+DoubleLookup - Give address components, get more address components back (like zip code)
Objective-C
1
star
68

altconf-fastlane-best-practices

AltConf Lab Session Slides - fastlane Best Practices
CSS
1
star