bugsnag / bugsnag-java Goto Github PK
View Code? Open in Web Editor NEWBugSnag error reporting for Java.
Home Page: https://www.bugsnag.com/platforms/java/
License: MIT License
BugSnag error reporting for Java.
Home Page: https://www.bugsnag.com/platforms/java/
License: MIT License
SyncHttpDelivery
is protected so I can't use it for BugSnag.setDelivery
.
https://github.com/bugsnag/bugsnag-java/blob/master/src/main/java/com/bugsnag/delivery/SyncHttpDelivery.java#L29
Can the constructor be made public, please? Thanks
Hi
I am facing bit difficult in integrating bugsnag to one of my application its java OpenXava web framwork i have tried to follow the Java (https://docs.bugsnag.com/platforms/java/other/) documentation, my application is running using tomcat , it doesn't contain pom.xml, i can include the bugsnag jar in my application, now after including how do i define the bugsnag key and steps to automatically capture the exceptions and record in bugnsag.
I am using bugsnag for multiple applications. Please help me out in integrating to this application to.
Thank you.
It would be extremely useful to have a Log4j appender that's configurable from log4j.xml
or log4j.properties
files.
Network error when posting to http://notify.bugsnag.com
public static void main(String[] args)
{
Client bugsnag = new Client("my-key");
LOG.info("HelloWorld start.");
workerA.start();
workerB.start();
bugsnag.notify(new RuntimeException("Non-fatal"));
int ss = 1998/0;
LOG.info("HelloWorld end." + ss);
}
There doesn't appear to be an API for deployment information. Specifically, I want to report the revision string to match up with the deployments that I'm sending via the Deploy Tracking API.
Observation
I'm setting bugsnag.setFilters("Authorization");
so that I can filter out a sensitive header.
When using cURL -u username:password, I noticed the 'authorization' header was still present in the BugSnag dashboard. HTTP headers are case insensitive and a server has no control over how a client will case the header names. I could filter both but that would be plain silly bugsnag.setFilters("authorization", "Authorization")
.
Expected Result
Update the Java SDK at the mentioned line below to compare the strings in a case insensitive way.
Side note: This same line below has an undocumented and undesired behaviour since it's written as if(key.contains(filter))
. If I filter on name
, it will filter as well name1
and username
. This is not desirable, especially since it's undocumented, but also because it forces developers to rename variables to avoid filter clashes..
Source of the Issue
My original problem is that I want the post body to be logged with each notification to Bugsnag. Since the Java library doesn't do this, I have to hack together a solution on my side.
It's an expensive task to take the request body my controller received and then serialize it back into a string and attach it to Bugsnag using addThreadMetaData
. If the exception rarely occurs, I would be wasting time on this expensive operation on all successful requests.
Describe the solution you'd like
I'd like addThreadMetaData
to take a callback (or a runnable lambda) instead of an Object, so that Bugsnag can evaluate it only if it needs to perform the notification to Bugsnag.
Describe alternatives you've considered
Although the method bugsnag.addCallback
gives access to the granular report, the callback is created when Bugsnag is initialized. The callback has no way to be aware of the controller state in Spring.
Additional context
My Spring controller decodes the post body into a specific object, for example
void postRequest(@RequestBody Payload payload) {}
I tried addThreadMetaData(..., payload)
but Bugsnag strips the contents. You're using an object mapper that filters for example things that aren't marked with your Expose
annotation.
An alternate solution to this thread: you could continue to use your existing object mapper for your own objects, but use a second new object mapper for the objects added via addThreadMetaData
so that you stop stripping out the data.
When all non daemon threads of any app finish, the JVM shuts down normally... After implementing Bugsnag JVM still runs. This behavior is not what I expect, especially for AWT/Swing apps.
`public class Test {
public static final void main(String[] args) {
Bugsnag instance = new Bugsnag("api key");
}
}`
JVM will never shut down...
3.6.1
If this cannot be fixed, please update your implementation guide to call System.exit(0) or bugsnag.close() somewhere in the code. Calling System.exit(0) is not common in AWT/Swing apps as user closes window and UI thread finishes normally.
This issue made our app update mechanism broken as JVM was running and old jar couldn't be overwritten with new one. Also it made our app unusable after broken update as we use FileLock to enable single instance of app and and lock was never released as JVM kept running. This has broken around 100 installations of our app before we realized what has happened and stopped update. Unfortunately we didn’t discover this bug during our testing, only after it was released to production.
The ExceptionHandler
forwards to the previously installed handler, but if there is none as is the default, you receive a NullPointerException
.
compile 'com.fasterxml.jackson.core:jackson-databind:2.8.9'
When I execute jar application in console I get this warning:
[Bugsnag] WARNING: Application terminated. 1 error(s) were not sent to Bugsnag
There's a way to set proxy configuration on .NET SDK. How to set proxy configuration in Java SDK?
This is how you set proxy configuration in OKHTTP.
==
int proxyPort = 8080;
String proxyHost = "proxyHost";
final String username = "username";
final String password = "password";
Authenticator proxyAuthenticator = new Authenticator() {
@OverRide public Request authenticate(Route route, Response response) throws IOException {
String credential = Credentials.basic(username, password);
return response.request().newBuilder()
.header("Proxy-Authorization", credential)
.build();
}
};
The request tab in bugsnag dashboard should have data in the params block
The params block is empty
Use Bugsnag for Java with Tomcat7 under the OpenJDK7.
Bugsnag 3.0.0
Being new to Java, we may be missing some required step to activate request params from a tomcat servlet.
Official Spring Boot support for WebFlux stacks
Describe the solution you'd like
Seems to only work out of the box with vanilla Spring Web, e.g. Exceptions thrown from controllers are not automatically sent to Bugsnag.
Describe alternatives you've considered
Implemented my own WebExceptionHandler to do this myself, but would be nice for it to work out of the box like it does for Spring Web
Additional context
getsentry/sentry-java#1529
The current dependency on version 2.9.1 is not very secure and brings in at least 20+ critical vulns.
Latest version stance can be found here
Current version of bugsnag deppends on jackson-databind with 2 vulnerabilities:
https://mvnrepository.com/artifact/com.bugsnag/bugsnag/3.6.4
Maybe it could be pumped?
The samples use a supported version of Spring Boot.
The sample uses Spring Boot 1.4.1.RELEASE that is EOLed for quite a while. 1.5 is going to be EOLed this August.
The SQLDelight IntelliJ Idea plugin uses Bugsnag. When opening the settings from IntelliJ, bug snag gets initialized via sqldelight which blocks the UI.
"AWT-EventQueue-0" prio=0 tid=0x0 nid=0x0 runnable
java.lang.Thread.State: RUNNABLE
(in native)
at [email protected]/java.net.Inet6AddressImpl.lookupAllHostAddr(Native Method)
at [email protected]/java.net.InetAddress$PlatformNameService.lookupAllHostAddr(InetAddress.java:929)
at [email protected]/java.net.InetAddress.getAddressesFromNameService(InetAddress.java:1519)
at [email protected]/java.net.InetAddress$NameServiceAddresses.get(InetAddress.java:848)
at [email protected]/java.net.InetAddress.getAllByName0(InetAddress.java:1509)
at [email protected]/java.net.InetAddress.getLocalHost(InetAddress.java:1641)
at com.bugsnag.callbacks.DeviceCallback.lookupHostname(DeviceCallback.java:44)
at com.bugsnag.callbacks.DeviceCallback.getHostnameValue(DeviceCallback.java:22)
at com.bugsnag.callbacks.DeviceCallback.initializeCache(DeviceCallback.java:52)
at com.bugsnag.Configuration.<init>(Configuration.java:58)
at com.bugsnag.Bugsnag.<init>(Bugsnag.java:92)
at app.cash.sqldelight.intellij.SqlDelightErrorHandler.<init>(SqlDelightErrorHandler.kt:32)
...
There's also a thread dump:
threadDumps-freeze-20220512-111722-AI-213.7172.25.2211.8563311-5sec.zip
I've reported it to both Android Studio as well as sqldeilght.
There also seem to be some suggested workarounds:
Currently in Report.java there the errors main text is pulled from.
public String getExceptionName() {
return throwable.getClass().getName();
}
This makes it hard to throw an error that isn't actually from a java throwable like a handled database error especially if you don't want to go through the hassle ( or in my case can't ) create MyException extends Exception style custom exception.
Another option might be to include a custom Throwable in the bugsnag API itself that overrode getClass() so getName() could return whatever we needed it to.
Thanks!
Cookies are filtered from request headers metadata, as Cookie
is included in the default filters.
Request
tab contains a headers
map with cookie
present.
We’re using bugsnag-spring
with Spring Boot 2.0.9 and Tomcat 9.0.30.
3.6.1
It looks like the issue is that the underlying servlet implementation stores header keys case-insensitively, so the default Cookie
filter does not match. When it comes to filtering, I think it would make sense to make all comparisons case-insensitive, so that a filter for "password"
matches "USER_PASSWORD"
, "adminPassword"
, etc.
Hi,
Im trying to use bugsnag-spring 3.4.4 with spring boot 2.1.0. Im using log4j2 and not logback. Logback is excluded and not on the classpath. It seems that bugsnag-java is dependent on logback. Im getting the following error when the application start:
caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'com.bugsnag.BugsnagSpringConfiguration': Invocation of init method failed; nested exception is java.lang.NoClassDefFoundError: ch/qos/logback/core/UnsynchronizedAppenderBase
We received a notification that Bugsnag will deprecate API v1 and asks to use v2 instead. When using the Java client, what needs to be done to keep the reporting up and running? Thanks!
When undeploying application, Plumbr reports the following PermGen memory leak:
Leaked classloader
org.apache.catalina.loader.WebappClassLoader
The leaking classloader is being held
in com.bugsnag.ExceptionHandler
in defaultUncaughtExceptionHandler of java.lang.Thread
in reference from native code (JNI global)
I create the bugsnag client via a static method in a final class. This is done during application startup.
I'm running Tomcat 7.0.64 with JVM 1.7.0_79-b15
Do you guys have a standard way of recording the hostname/IP of the machine raising an exception?
It looks like the Erlang client pokes it into the context (which conflicts a bit with the stated intent of context...)
In contrast, the go client stores it to host (tab) name (key).
There are a few reported and unfixed vulnerabilities:
CVE-2020-36518
CVE-2020-15250
Could you have a look at them?
https://mvnrepository.com/artifact/com.bugsnag/bugsnag/3.6.3
On the documentation page, there is a link pointing to "Additional Documentation" in the section "Support", but the URL https://github.com/bugsnag/bugsnag-java/tree/master/docs is dead
I just integrated Bugsnag into a Dropwizard application. In this application I have a mechanism in place to catch unhandled exceptions, log them, delegate to my own ErrorReporter
interface, and then return an appropriate JSON response (e.g., 500 ISE).
I integrated Bugsnag by creating a BugsnagErrorReporter
and suppressing the automatic uncaught exception handler. This is working great, but as my implementation calls bugsnag.notify()
it reports all exceptions as handled. I would like to be able to report these as unhandled exceptions since they're being caught by a JAX-RS ExceptionMapper
rather than in a catch block somewhere. There are other cases where I would want to report handled exceptions (i.e., places where I can gracefully recover but still want to know of a problem). This is similar in concept to how the Spring module is specifying a SeverityReasonType
of REASON_UNHANDLED_EXCEPTION_MIDDLEWARE
in its various handlers.
Looking at Report
, the getUnhandled()
method drives this setting in the JSON sent to Bugsnag and that method keys off of the HandledState
.
Alter the bugsnag.notify()
methods. There are a number of overloads and I am hesitant to disrupt this since it's the primary API a user would interact with.
Alter the Report
class to provide a way to flag the report as unhandled. e.g., report.flagAsUnhandled()
, report.flagAsUnhandledFromMiddleware()
, or etc. This would change the underlying HandledState
.
Place my BugsnagErrorReporter
in the com.bugsnag
package in my own code so that I can access package-private functionality. This would solve my immediate problem but would require me to use a non-public API that could change later and doesn't help anyone else who may want to report unhandled exceptions themselves.
I would be happy to create a PR that implements this, but I wanted to check with you first to see if this is something you agree with and/or if you have a preferred approach.
It outdated now.
We should send the hostname on java
Methods like keySet
and entrySet
filters out configured keys like get
does.
Data that should be filtered out is exposed in those methods.
Just call them to see that data is not filtered out.
3.1.4
This is a blocker for adoption by us because the version of jackson we use calls entrySet
to serialize data so all data is sent to bugsnag without filtering.
Add support for proxy settings similar to bugsnag-ruby.
Related to #31
HttpClient isn't configured to ever time out. I had some code calling client.notify
in a synchronized block and it got stuck in int status = conn.getResponseCode();
inside HttpClient.
Please see #25 for possible fix.
Just trying to notify using a regular api reference:
Client bugsnag = new Client("my-key");
bugsnag.notify(new RuntimeException("Non-fatal"));
com.bugsnag.http.BadResponseException: Got non-200 response code (411) from http://notify.bugsnag.com
Note: Yesterday it was working. Today I run my tests again but now this exception is thrown
When an unhandled exception occurs, the Spring framework iterates through a list of exception handlers looking for someone to consume the unhandled exception. This is the Java for loop in the Spring framework that is looking for 1 and only one exception handler to swallow the exception.
The existing BugSnag code explicitly sets BugsnagMvcExceptionHandler
as the first Exception Handler by setting Ordered.HIGHEST_PRECEDENCE
on line 22. The code on line 47-48 then explicitly lets some other exception handler try to consume the exceptions. This breaks the expectation that only 1 handler should be invoked.
It's more reasonable that the BugSnag library should run last in the chain and not first in the chain. Allowing other exception handlers to consume the exception first allows the application to consume or 'handle' the exception and swallow it before it reaches BugSnag.
For example, my Java application throws custom defined exceptions to perform URL redirects and display custom HTML error pages. I have a @ControllerAdvice class that then properly renders the content. However, the BugSnag library catches the exception, logs it to your API, and then finally my application code runs. Since I handled the exception, it should never have been logged by the library.
Another example, in my class with custom exception handling using @ControllerAdvice, for 1 particular exception, I explicitly invoke BugSnag to log an exception as handled. But then your code also logs it as unhandled in your own handler..
Create a spring boot project
Create a class to handle a custom exception and create a @ControllerAdvice annotated class to custom handle the exception.
Invoke the exception and watch BugSnag log it as unhandled as well as watch the @ControllerAdvice annotated class handle the exception.
I created this branch to solve the issue, but I couldn't understand the test that I broke. This example fix and the above referenced parts of the code explain well what the observed yet expected result should be.
https://github.com/bugsnag/bugsnag-java/compare/master...nkavian:lower-precedence?expand=1
Change the order on BugsnagMvcExceptionHandler from highest
to lowest
. This allows the application to handle exceptions. If an exception truly was not handled by any one else, then finally it should be logged to BugSnag as unhandled.
Using bugsnag.setIgnoreClasses()
is a workaround but it's undesirable as a long term solution. I have to maintain a list of 10+ classes to exclude here.
I am very new to Java development and trying to integrate bugsnag with an existing program we have running that requires to be built with Java 1.7.
I notice that v3 of bugsnag for java requires Java 1.8 as I get the dreaded Java unsupported major minor version 52.0
error, even though the release notes say it targets Java 1.6.
Can anyone help figure out how to compile bugsnag for Java 1.7?
Any help would be greatly appreciated.
Latest version 3.7 is not available for java 8
The 3.7 is build from docker env define by this Dockerfile for java 8 : dockerfiles/Dockerfile.java8-mazerunner
But the image used is openjdk:17-jdk-slim
At the moment you can only notify about a Throwable, it would be nice to support notifying with an arbitrary exception class, message and stack trace that you've obtained from something like coldfusion.
Threads in Java have names, knowing which thread a crash occurred on can help with debugging. We should capture the name of the crashing thread and send that with the creash report.
See:
[Thread.UncaughtExceptionHandler#uncaughtException](http://docs.oracle.com/javase/7/docs/api/java/lang/Thread.UncaughtExceptionHandler.html#uncaughtException%28java.lang.Thread, java.lang.Throwable%29)
Thread#getName
When throwing an exception from a Controller/RestController that is annotated with @ResponseStatus
with an HTTP status code in the 4xx range, the exception should be reported to Bugsnag with severity INFO.
Custom exceptions annotated with @ResponseStatus
are always reported with severity ERROR independent from the HTTP status that is set.
At the moment there is no code in ExceptionClassCallback
that would handle such exceptions.
@ResponseStatus
and an HTTP status in the 4xx rangebugsnag-spring 3.4.4
Since we typically use custom exceptions for client errors, a fix to this problem would greatly improve our user experience with Bugsnag. Thanks for looking into this!
With the upcoming release of spring 3.0, javax is dropped in favour of JakartaEE https://spring.io/blog/2022/10/20/spring-boot-3-0-0-rc1-available-now
Would be possible to have a major release version/separate branch of the library where this migration is done? I'll try to see if I can make the changes and test them locally.
Profiling my application that is using bugsnag client(mainly usingBugsnag.notify()
), bugsnag-async-deliver-%d thread seems creating many HandshakeCompletedNotify-Thread
.
As I read code, it seems calling HttpURLConnection.disconnect() in SyncHttpDelivery.java might be the cause.
https://bugs.openjdk.java.net/browse/JDK-8246039
A screenshot of a jfr profile of my app.
Is it able to reduce this new threads?
The same issue as here bugsnag/bugsnag-android#281 , but currently during use bugsnag-spring
java.util.ConcurrentModificationException at java.util.ArrayList$Itr.checkForComodification(ArrayList.java:909)
at java.util.ArrayList$Itr.next(ArrayList.java:859)
at com.bugsnag.Bugsnag.notify(Bugsnag.java:447)
at com.bugsnag.Bugsnag.notify(Bugsnag.java:407)
at com.bugsnag.Bugsnag.notify(Bugsnag.java:350)
Report error without stacktrace
There is no possibility of doing that
Stacktrace is required in Bugsnag client API
3.5.0
I understand that your integration is built for Java, but JVM has a lot of languages not all of them are treating exceptions as a default channel of errors. The problem appears when I'm using Scala libraries like Akka which some of the errors logged without a stack trace. I didn't see them in Bugsnag. Is there a chance to fix it?
Some users have been unable to comment on Github issues when an adblocker extension is enabled.
We recommend temporarily disabling the extension, or if that fails, contacting [email protected].
I'd like to use Bugsnag with custom reports that may include some objects in the tabs. It's pretty close with the current API, but the Serializer
is too restrictive:
this.mapper.setSerializationInclusion(Include.NON_EMPTY).setVisibilityChecker(this.mapper.getVisibilityChecker().with(Visibility.NONE));
Please provide a way to customize it, allowing us to use different ObjectMapper
. Some of us don't want Jackson annotations all over the code.
It would be even better if we could replace the serializer altogether and the dependency on Jackson was optional.
Do not throw NullPointerException
Sometime, SyncHttpDelivery throws NPE here.
Sorry, I don't know reproduce steps.
I guess we had network problem(me or bugsnag) when I met the problem.
The problem produced at Aug 9th, 14:43:46 only once.
3.2.0
I think the problem is caused by this code
connection
does not initialize If URL#openConnection
throws IOException
. However, this code tries connection.disconnect()
in finally
block.
We are not really a java app, but it is deployed on top of Java and can consume JARs when 3rd party tools come into play.
We use a jar loader within the app to consume libraries that helps with any sort of accidental conflicts version or otherwise. So having simple one jar loads is easier for us.
Admittedly i haven't don Java work in a long long time so my gradle skills are just reading blog posts.
I plopped this in the existing build.gradle file and ran it the custom task and got a .jar to my liking. I'd like to not have to do that each release, but I certainly can.
task customFatJar(type: Jar) {
manifest {
}
baseName = 'all-in-one-jar'
from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }
with jar
}
all-in-one-jar would obviously be something more like bugsnag-all-in-one-${version}.jar
Thanks!
Caused by: java.lang.NullPointerException
at com.bugsnag.Error.getExceptionName(Error.java:198)
at com.bugsnag.Error.shouldIgnore(Error.java:96)
at com.bugsnag.Client.notify(Client.java:115)
at com.bugsnag.Client.notify(Client.java:128)
at com.bugsnag.Client.notify(Client.java:136)
at com.huawei.bes.common.log.impl.BesLogImpl.debug(BesLogImpl.java:206)
at com.huawei.bes.common.log.impl.BesLogImpl.debug(BesLogImpl.java:178)
at com.huawei.bes.common.dfx.monitor.BESCustomEBusStatistic.initFilter(BESCustomEBusStatistic.java:86)
at com.huawei.bes.common.dfx.monitor.BESCustomEBusStatistic.init(BESCustomEBusStatistic.java:61)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeCustomInitMethod(AbstractAutowireCapableBeanFactory.java:1581)
We use BugsnagServletContainerInitializer
to initialise Bugsnag reporting in a Tomcat server. We have followed your advice and selected a version range [3.0,4.0)
in our Maven build. When you released version 3.7 of your java SDK, our builds broke, because the class has moved to another package.
Confirming with the semver specification, this change should entail a major version increment.
BugsnagServletContainerInitializer
somewhere in that project, and ensure that it compiles.[3.0,4.0)
as specified in your installation instructions.A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.