Skip to content

Commit

Permalink
0.9.1 (#2)
Browse files Browse the repository at this point in the history
* Close BacktraceClient after unit test

* Filter out stack traces from 'org.apache.log4j' and  'org.apache.logging'

* Update library version to 0.9.1

* Update CHANGELOG.md

* Update README.md

* Update README.md

* Fix unit test
  • Loading branch information
BartoszLitwiniuk authored Apr 14, 2020
1 parent 1e2056e commit e56cb73
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 10 deletions.
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
# Backtrace Java Release Notes

## Version 0.9.1 - 14.04.2020
- Filter out stack traces from 'org.apache.log4j' and 'org.apache.logging'

## Version 0.9.0 - 23.03.2020
- First release.
- First release.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* Gradle
```
dependencies {
implementation 'com.github.backtrace-labs.backtrace-java:backtrace-java:0.9.0'
implementation 'com.github.backtrace-labs.backtrace-java:backtrace-java:0.9.1'
}
```

Expand All @@ -25,11 +25,11 @@ dependencies {
<dependency>
<groupId>com.github.backtrace-labs.backtrace-java</groupId>
<artifactId>backtrace-java</artifactId>
<version>0.9.0</version>
<version>0.9.1</version>
</dependency>
```

# Using Backtrace library <a name="using-backtrace"></a>
# Using Backtrace library <a name="using-backtrace"></a>
## Initialize a new BacktraceClient <a name="using-backtrace-initialization"></a>

First create a `BacktraceConfig` instance with your `Backtrace endpoint URL`. This endpoint URL will either be through a central https://submit.backtrace.io server on standard port 80/443, or directly to your Backtrace instance through a listener on port 6097/6098 (e.g. https://xxx.sp.backtrace.io:6098). Either integration will require a submission token to be included in the endpoint
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ plugins {
apply from: 'publish.gradle'

group = 'com.github.backtrace.io'
version = '0.9.0'
version = '0.9.1'

repositories {
jcenter()
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
VERSION_NAME=0.9.0
VERSION_NAME=0.9.1

GROUP=com.github.backtrace-labs.backtrace-java

Expand Down
14 changes: 12 additions & 2 deletions src/main/java/backtrace/io/data/report/BacktraceStackTrace.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,18 @@ private ArrayList<BacktraceStackFrame> gatherStacktraceInformation() {

ArrayList<BacktraceStackFrame> result = new ArrayList<>();
for (StackTraceElement frame : stackTraceElements) {
if ((frame == null) || (!frame.getClassName().isEmpty() && frame.getClassName().toLowerCase().startsWith(NAME)) ||
(frame.getClassName().toLowerCase().equals("java.lang.thread") && frame.getMethodName().equals("getStackTrace"))) {
if (
(frame == null) ||
(!frame.getClassName().isEmpty() && (
frame.getClassName().toLowerCase().startsWith(NAME) ||
frame.getClassName().toLowerCase().startsWith("org.apache.log4j") ||
frame.getClassName().toLowerCase().startsWith("org.apache.logging")))
||
(
frame.getClassName().toLowerCase().equals("java.lang.thread") &&
frame.getMethodName().equals("getStackTrace")
)
) {
continue;
}
result.add(new BacktraceStackFrame(frame));
Expand Down
8 changes: 7 additions & 1 deletion src/test/java/backtrace/io/CustomEventsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ public BacktraceResult onRequest(BacktraceData data) {
// THEN
try {
backtraceClient.await(1, TimeUnit.SECONDS);
backtraceClient.close();
} catch (Exception e) {
Assert.fail(e.getMessage());
}
Expand Down Expand Up @@ -99,6 +100,7 @@ public void onEvent(BacktraceResult backtraceResult) {
// THEN
try {
waiter.await(1, TimeUnit.SECONDS);
backtraceClient.close();
} catch (Exception e) {
Assert.fail(e.getMessage());
}
Expand Down Expand Up @@ -196,6 +198,7 @@ public BacktraceResult onRequest(BacktraceData data) {
// THEN
try{
boolean result = backtraceClient.await(2, TimeUnit.SECONDS);
backtraceClient.close();
Assert.assertFalse(result);
}
catch (Exception e){
Expand Down Expand Up @@ -225,6 +228,7 @@ public BacktraceResult onRequest(BacktraceData data) {
// THEN
try {
backtraceClient.await();
backtraceClient.close();
} catch (Exception e) {
Assert.fail(e.getMessage());
}
Expand Down Expand Up @@ -259,6 +263,7 @@ public BacktraceResult onRequest(BacktraceData data) {
// THEN
try {
backtraceClient.await();
backtraceClient.close();
} catch (Exception e) {
Assert.fail(e.getMessage());
}
Expand All @@ -269,7 +274,7 @@ public BacktraceResult onRequest(BacktraceData data) {
}

@Test
public void sendRequestWithAppVersionAndName() {
public void sendRequestWithAppVersionAndName() throws InterruptedException {
// GIVEN
BacktraceReport report = new BacktraceReport(message);
String appVersion = "release-1.0";
Expand All @@ -296,6 +301,7 @@ public BacktraceResult onRequest(BacktraceData data) {

try {
waiter.await(5, TimeUnit.SECONDS);
backtraceClient.close();
} catch (Exception exception) {
waiter.fail(exception);
}
Expand Down
36 changes: 35 additions & 1 deletion src/test/java/backtrace/io/StackTraceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,40 @@ public void removeIncorrectPathsFromNull() {
BacktraceStackTrace backtraceStackTrace = new BacktraceStackTrace(testException);

// THEN
Assert.assertEquals(backtraceStackTrace.getStackFrames().size(), 1);
Assert.assertEquals(1, backtraceStackTrace.getStackFrames().size());
}

@Test
public void removeApacheLog4jLogs() {
// GIVEN
final String declaringClass = "Demo";
Exception testException = new Exception();
StackTraceElement[] stackTraceElements = new StackTraceElement[2];
stackTraceElements[0] = new StackTraceElement("org.apache.log4j.AppenderSkeleton", "doAppend", "AppenderSkeleton.java", 1);
stackTraceElements[1] = new StackTraceElement("Demo", "test", "test", 1);
testException.setStackTrace(stackTraceElements);

// WHEN
BacktraceStackTrace backtraceStackTrace = new BacktraceStackTrace(testException);

// THEN
Assert.assertEquals(1, backtraceStackTrace.getStackFrames().size());
}

@Test
public void removeApacheLog4j2Logs() {
// GIVEN
final String declaringClass = "Demo";
Exception testException = new Exception();
StackTraceElement[] stackTraceElements = new StackTraceElement[2];
stackTraceElements[0] = new StackTraceElement("org.apache.logging.log4j.core.config.AppenderControl", "tryCallAppender", "AppenderControl.java", 1);
stackTraceElements[1] = new StackTraceElement("Demo", "test", "test", 1);
testException.setStackTrace(stackTraceElements);

// WHEN
BacktraceStackTrace backtraceStackTrace = new BacktraceStackTrace(testException);

// THEN
Assert.assertEquals(1, backtraceStackTrace.getStackFrames().size());
}
}

0 comments on commit e56cb73

Please sign in to comment.