Skip to content

Commit

Permalink
Merge pull request #65 from TheRealAgentK/master
Browse files Browse the repository at this point in the history
4.0.1
  • Loading branch information
TheRealAgentK committed Jun 30, 2019
2 parents 037ad08 + 284d815 commit 8ba3d3a
Show file tree
Hide file tree
Showing 15 changed files with 143 additions and 56 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
## Changelog

- v4.0.1:
- Fixes for an issue with breadcrumb processing (#64) and improved general parsing of the stack trace
- Fixes inability to use CrashReporingOnBeforeSend interface due to wrong visibility (#63)
- Safeguard against slightly obscure "out of files" scenario that can cause File.listFiles() to return null (#62)
- General improvements to the sample app:
- Refactoring of sample app into its own namespace
- Samples for breadcrumb handling
- Samples for intercepting the crash reporting data

- v4.0.0:
- Minor internal changes to memory handling
- Linting cleanup
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ Supports Android 4.1+ (API 16+).

## IMPORTANT

### 17 Juni 2019
### 30 Juni 2019

Raygun4Android 4.0 is considered stable.
Raygun4Android 4.0.x is currently considered to be the stable line of the provider.

Raygun4Android is currently actively being worked on towards a release of version 4.1.

With the release of 4.0.0-beta2, the 4.0.0 development branch has been merged into master and is now the mainstream development line.
With the release of 4.0.0-beta2, the 4.0.0 development branch had been merged into master and is now the mainstream development line.

If you want the older stable version 3.0.6 please check out the change set labelled with v3.0.6 and go from there.

Expand Down Expand Up @@ -41,7 +41,7 @@ Then add the following to your **module's** build.gradle:
```gradle
dependencies {
...
implementation 'com.raygun:raygun4android:4.0.0'
implementation 'com.raygun:raygun4android:4.0.1'
}
```

Expand Down
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ android {
}
compileSdkVersion 28
defaultConfig {
applicationId "com.raygun.raygun4android.sample"
applicationId "com.raygun.raygun4androidsample"
minSdkVersion 16
targetSdkVersion 28
versionCode = Long.valueOf(VERSION_CODE)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.raygun.raygun4android.sample
package com.raygun.raygun4androidsample.sample

import android.support.test.InstrumentationRegistry
import android.support.test.runner.AndroidJUnit4
Expand All @@ -19,6 +19,6 @@ class ExampleInstrumentedTest {
fun useAppContext() {
// Context of the app under test.
val appContext = InstrumentationRegistry.getTargetContext()
assertEquals("com.raygun.raygun4android.sample", appContext.packageName)
assertEquals("com.raygun.raygun4androidsample.sample", appContext.packageName)
}
}
2 changes: 1 addition & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.raygun.raygun4android.sample">
package="com.raygun.raygun4androidsample.sample">

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.raygun.raygun4android.sample
package com.raygun.raygun4androidsample.sample

import android.app.Application
import android.support.v7.app.AppCompatActivity
Expand All @@ -22,9 +22,12 @@ class MainActivity : AppCompatActivity() {
RaygunClient.init(applicationContext as Application)
RaygunClient.enableCrashReporting()
RaygunClient.enableRUM(this)
RaygunClient.shouldProcessBreadcrumbLocation(true)

RaygunClient.setCustomData(initialCustomData)

RaygunClient.setOnBeforeSend(SampleOnBeforeSend())

val buttonSend = findViewById<Button>(R.id.button_send)
val buttonCrash = findViewById<Button>(R.id.button_crash)
val buttonHandleException = findViewById<Button>(R.id.button_handleException)
Expand Down Expand Up @@ -71,6 +74,7 @@ class MainActivity : AppCompatActivity() {
user.firstName = "User C"
user.email = "[email protected]"
RaygunClient.setUser(user)
RaygunClient.recordBreadcrumb("I'm now user C")
}

buttonSetUserB.setOnClickListener{
Expand All @@ -79,6 +83,7 @@ class MainActivity : AppCompatActivity() {
user.firstName = "User D"
user.email = "[email protected]"
RaygunClient.setUser(user)
RaygunClient.recordBreadcrumb("I'm now user D")
}

buttonSecondActivity.setOnClickListener {
Expand All @@ -88,5 +93,8 @@ class MainActivity : AppCompatActivity() {

textViewAppVersion.text = "App ${BuildConfig.VERSION_NAME} (${BuildConfig.VERSION_CODE} ${BuildConfig.BUILD_TYPE})"
textViewProviderVersion.text = "Provider ${com.raygun.raygun4android.BuildConfig.VERSION_NAME} (${com.raygun.raygun4android.BuildConfig.VERSION_CODE} ${BuildConfig.BUILD_TYPE})"

RaygunClient.recordBreadcrumb("I'm here in Main Activity")

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.raygun.raygun4androidsample.sample

import android.util.Log
import com.raygun.raygun4android.CrashReportingOnBeforeSend
import com.raygun.raygun4android.messages.crashreporting.RaygunMessage

internal class SampleOnBeforeSend : CrashReportingOnBeforeSend {
override fun onBeforeSend(message: RaygunMessage): RaygunMessage {
Log.i("Raygun4Android-Sample", "In SampleOnBeforeSend - About to post to Raygun, returning the payload as is...")
return message
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.raygun.raygun4android.sample
package com.raygun.raygun4androidsample.sample

import android.content.Context
import android.content.Intent
Expand All @@ -8,7 +8,10 @@ import android.util.Log
import android.widget.Button
import android.widget.TextView
import com.raygun.raygun4android.RaygunClient
import com.raygun.raygun4android.messages.crashreporting.RaygunBreadcrumbLevel
import com.raygun.raygun4android.messages.crashreporting.RaygunBreadcrumbMessage
import com.raygun.raygun4android.messages.shared.RaygunUserInfo
import java.util.*

class SecondActivity : AppCompatActivity() {

Expand Down Expand Up @@ -75,6 +78,22 @@ class SecondActivity : AppCompatActivity() {

textViewAppVersion.text = "App ${BuildConfig.VERSION_NAME} (${BuildConfig.VERSION_CODE} ${BuildConfig.BUILD_TYPE})"
textViewProviderVersion.text = "Provider ${com.raygun.raygun4android.BuildConfig.VERSION_NAME} (${com.raygun.raygun4android.BuildConfig.VERSION_CODE} ${BuildConfig.BUILD_TYPE})"

RaygunClient.clearBreadcrumbs()

val customData = WeakHashMap<String,Any>()
customData["someKey"] = "someValue"
customData["someotherkey"] = "someothervalue"

val breadcrumbMessage = RaygunBreadcrumbMessage.Builder("I'm here in SecondActivity")
.level(RaygunBreadcrumbLevel.ERROR)
.category("Launch")
.lineNumber(78)
.methodName("onCreate")
.customData(customData)
.build()

RaygunClient.recordBreadcrumb(breadcrumbMessage)
}

companion object {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.raygun.raygun4android.sample
package com.raygun.raygun4androidsample.sample

import org.junit.Test

Expand Down
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ org.gradle.jvmargs=-Xmx1536m
# 5.3.3-beta2-SNAPSHOT
#
# Adding -SNAPSHOT to VERSION_NAME triggers publishing to a snapshot server at Maven Central.
VERSION_NAME=4.0.0
VERSION_NAME=4.0.1

# Use a numeric value for VERSION_CODE
#
Expand All @@ -40,7 +40,7 @@ VERSION_NAME=4.0.0
# 4.0.0-alpha1 -> 40000031
# 5.2.3 -> 50203000
# 5.3.3-beta2 -> 50303072
VERSION_CODE=40000099
VERSION_CODE=40001099

GROUP=com.raygun

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public class CrashReporting {
private static CrashReportingOnBeforeSend onBeforeSend;
private static List tags;
private static Map customData;
private static List<RaygunBreadcrumbMessage> breadcrumbs;
private static List<RaygunBreadcrumbMessage> breadcrumbs = new ArrayList<>();
private static boolean shouldProcessBreadcrumbLocation = false;

static RaygunUncaughtExceptionHandler getExceptionHandler() {
Expand Down Expand Up @@ -62,22 +62,44 @@ static void recordBreadcrumb(String message) {
}

static void recordBreadcrumb(RaygunBreadcrumbMessage breadcrumb) {
breadcrumbs.add(processBreadcrumbLocation(breadcrumb, shouldProcessBreadcrumbLocation(),3));
breadcrumbs.add(processBreadcrumbLocation(breadcrumb, shouldProcessBreadcrumbLocation()));
}

private static RaygunBreadcrumbMessage processBreadcrumbLocation(RaygunBreadcrumbMessage breadcrumb, boolean shouldProcessBreadcrumbLocation, int stackFrame) {
static void clearBreadcrumbs() {
breadcrumbs.clear();
}

private static RaygunBreadcrumbMessage processBreadcrumbLocation(RaygunBreadcrumbMessage breadcrumb, boolean shouldProcessBreadcrumbLocation) {

if(shouldProcessBreadcrumbLocation && breadcrumb.getClassName() == null) {
StackTraceElement frame = Thread.currentThread().getStackTrace()[stackFrame];

return new RaygunBreadcrumbMessage.Builder(breadcrumb.getMessage())
.category(breadcrumb.getCategory())
.customData(breadcrumb.getCustomData())
.level(breadcrumb.getLevel())
.className(frame.getClassName())
.methodName(frame.getMethodName())
.lineNumber(frame.getLineNumber())
.build();

StackTraceElement[] trace = Thread.currentThread().getStackTrace();
StackTraceElement frame = null;

if (trace != null && trace.length > 0) {
for (int i = 0; i < trace.length-1; i++) {
StackTraceElement thisFrame =trace[i];
StackTraceElement nextFrame = trace[i+1];

if (thisFrame.getClassName().contains("com.raygun.raygun4android.") && !nextFrame.getClassName().contains("com.raygun.raygun4android.")) {
frame = nextFrame;
break;
}
}
}

if (frame != null) {
return new RaygunBreadcrumbMessage.Builder(breadcrumb.getMessage())
.category(breadcrumb.getCategory())
.customData(breadcrumb.getCustomData())
.level(breadcrumb.getLevel())
.className(frame.getClassName())
.methodName(frame.getMethodName())
.lineNumber(frame.getLineNumber())
.build();
}


}

return breadcrumb;
Expand Down Expand Up @@ -163,31 +185,36 @@ static void attachExceptionHandler() {
static void postCachedMessages() {
if (RaygunNetworkUtils.hasInternetConnection(RaygunClient.getApplicationContext())) {
File[] fileList = RaygunClient.getApplicationContext().getCacheDir().listFiles(new RaygunFileFilter());
for (File f : fileList) {
try {
if (RaygunFileUtils.getExtension(f.getName()).equalsIgnoreCase(RaygunSettings.DEFAULT_FILE_EXTENSION)) {
ObjectInputStream ois = null;
try {
ois = new ObjectInputStream(new FileInputStream(f));
SerializedMessage serializedMessage = (SerializedMessage) ois.readObject();
enqueueWorkForCrashReportingService(RaygunClient.getApiKey(), serializedMessage.message);
if (!f.delete()) {
RaygunLogger.w("Couldn't delete cached report (" + f.getName() + ")");
}
} finally {
if (ois != null) {
ois.close();
if (fileList != null) {
for (File f : fileList) {
try {
if (RaygunFileUtils.getExtension(f.getName()).equalsIgnoreCase(RaygunSettings.DEFAULT_FILE_EXTENSION)) {
ObjectInputStream ois = null;
try {
ois = new ObjectInputStream(new FileInputStream(f));
SerializedMessage serializedMessage = (SerializedMessage) ois.readObject();
enqueueWorkForCrashReportingService(RaygunClient.getApiKey(), serializedMessage.message);
if (!f.delete()) {
RaygunLogger.w("Couldn't delete cached report (" + f.getName() + ")");
}
} finally {
if (ois != null) {
ois.close();
}
}
}
} catch (FileNotFoundException e) {
RaygunLogger.e("Error loading cached message from filesystem - " + e.getMessage());
} catch (IOException e) {
RaygunLogger.e("Error reading cached message from filesystem - " + e.getMessage());
} catch (ClassNotFoundException e) {
RaygunLogger.e("Error in handling cached message from filesystem - " + e.getMessage());
}
} catch (FileNotFoundException e) {
RaygunLogger.e("Error loading cached message from filesystem - " + e.getMessage());
} catch (IOException e) {
RaygunLogger.e("Error reading cached message from filesystem - " + e.getMessage());
} catch (ClassNotFoundException e) {
RaygunLogger.e("Error in cached message from filesystem - " + e.getMessage());
}
} else {
RaygunLogger.e("Error in handling cached message from filesystem - could not get a list of files from cache dir");
}

}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

import com.raygun.raygun4android.messages.crashreporting.RaygunMessage;

interface CrashReportingOnBeforeSend {
public interface CrashReportingOnBeforeSend {
RaygunMessage onBeforeSend(RaygunMessage message);
}
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,14 @@ public static void recordBreadcrumb(RaygunBreadcrumbMessage breadcrumb) {
CrashReporting.recordBreadcrumb(breadcrumb);
}

/**
* Clears breadcrumbs
*
*/
public static void clearBreadcrumbs() {
CrashReporting.clearBreadcrumbs();
}

/**
* Enables the processing of the full location of breadcrumb messages. This defaults to false and please
* be aware that setting this to true could seriously degrade the performance of your application.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
public class RaygunBreadcrumbMessage {
private String message;
private String category;
private int level = RaygunBreadcrumbLevel.INFO.ordinal();
private int level;
private String type = "Manual";
private Map<String, Object> customData = new WeakHashMap<String, Object>();
private Map<String, Object> customData;
private Long timestamp = System.currentTimeMillis();
private String className;
private String methodName;
Expand All @@ -17,8 +17,8 @@ public class RaygunBreadcrumbMessage {
public static class Builder {
private String message;
private String category;
private int level;
private Map<String, Object> customData;
private int level = RaygunBreadcrumbLevel.INFO.ordinal();
private Map<String, Object> customData = new WeakHashMap<>();
private String className;
private String methodName;
private Integer lineNumber;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,18 @@ public static String getExtension(String filename) {
public static void clearCachedReports(Context context) {
synchronized(RaygunFileUtils.class) {
final File[] fileList = context.getCacheDir().listFiles(new RaygunFileFilter());

for (File f : fileList) {
if (RaygunFileUtils.getExtension(f.getName()).equalsIgnoreCase(RaygunSettings.DEFAULT_FILE_EXTENSION)) {
if (!f.delete()) {
RaygunLogger.w("Couldn't delete cached report (" + f.getName() + ")");
if (fileList != null) {
for (File f : fileList) {
if (RaygunFileUtils.getExtension(f.getName()).equalsIgnoreCase(RaygunSettings.DEFAULT_FILE_EXTENSION)) {
if (!f.delete()) {
RaygunLogger.w("Couldn't delete cached report (" + f.getName() + ")");
}
}
}
} else {
RaygunLogger.e("Error in handling cached message from filesystem - could not get a list of files from cache dir");
}

}
}
}

0 comments on commit 8ba3d3a

Please sign in to comment.