Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backtrace for java exceptions. #661

Closed
igortwago opened this issue Feb 6, 2017 · 5 comments
Closed

Backtrace for java exceptions. #661

igortwago opened this issue Feb 6, 2017 · 5 comments
Labels

Comments

@igortwago
Copy link

I am a java developer, and I am using airbrake in a java project.
I don't understand why, but airbrake transforms java stack frames into the format, which is not very useful for java developers.
For example I have stack frames

["java.lang.RuntimeException"," 	at TestException.method(TestException.java:19)"," 	at TestException.main(TestException.java:25)]"

In a console or a log file it would look like

Exception in thread "main" java.lang.RuntimeException
	at TestException.method(TestException.java:19)
	at TestException.main(TestException.java:25)

When I have an exception like this one, I can copy it to a java IDE stack trace console and access any code line from this stack trace.

But in airbrake backtrace looks like

java.lang.RuntimeException:-1 in java.lang.RuntimeException
TestException.java:19 in 	at TestException.method
TestException.java:25 in 	at TestException.main

Java IDEs don't support this format.

@kyrylo
Copy link
Contributor

kyrylo commented Feb 6, 2017

Sorry, I'm not quite following. Are you using the airbrake gem (this repo) with JRuby or are you using our Java Notifier (https://github.com/airbrake/airbrake-java)?

@igortwago
Copy link
Author

igortwago commented Feb 7, 2017

I am using java notifier

		<dependency>
			<groupId>io.airbrake</groupId>
			<artifactId>airbrake-java</artifactId>
			<version>2.2.8</version>
		</dependency>
		try {
			method();
		}
		catch(Throwable t) {
		    
			Map<String, Object> errorMessages = new HashMap<>();
			
			
	        AirbrakeNotice notice = new AirbrakeNotice("key",
	                "twago-dev", "dev",
	                "errorMessage", "errorClass", new Backtrace(
	                        Lists.newArrayList("java.lang.RuntimeException"," 	at TestException.method(TestException.java:19)"," 	at TestException.main(TestException.java:25)")),
	                Collections.<String, Object> emptyMap(),
	                Collections.<String, Object> emptyMap(), errorMessages,
	                Collections.<String> emptyList(), true, "errorUrl", "component");

	        
		    AirbrakeNotifier notifier = new AirbrakeNotifier("http://api.airbrake.io/notifier_api/v2/notices");
		    notifier.notify(notice);
		    
		}		
	}

The idea is when I send backtrace with this values

java.lang.RuntimeException
 	at TestException.method(TestException.java:19)
 	at TestException.main(TestException.java:25)

airbrake shows backtrace in this way

java.lang.RuntimeException:-1 in java.lang.RuntimeException
TestException.java:19 in 	at TestException.method
TestException.java:25 in 	at TestException.main

@kyrylo kyrylo added the Question label Feb 7, 2017
@kyrylo
Copy link
Contributor

kyrylo commented Feb 7, 2017

I see. This repository is for our Ruby notifier. Would you mind posting this issue to https://github.com/airbrake/airbrake-java ? I can do that myself, if you prefer.

@kyrylo kyrylo closed this as completed Feb 7, 2017
@igortwago
Copy link
Author

Ok, you are right, the problem is in Java Notifier

	public BacktraceLine(String line) {
		String classAndMethodName = line.replaceAll("\\(.*", "").replaceAll("^at ", "");

		int periodSepIndex = classAndMethodName.lastIndexOf(".");
		if (periodSepIndex > 0) {
			className = classAndMethodName.substring(0, classAndMethodName.lastIndexOf("."));
		} else {
			className = classAndMethodName;
		}
		fileName = fileName(line);
		lineNumber = lineNumber(line);
		methodName = methodName(classAndMethodName);
	}

@igortwago
Copy link
Author

On the second thought, I think the problem is on how airbrake represents stack trace.
Java Notifier sends backtrace in this format

		<backtrace>
			<line method="java.lang.RuntimeException this is an error" file="java.lang.RuntimeException this is an error"
				number="-1" />
			<line method="	at TestAirbrake.method" file="TestAirbrake.java"
				number="19" />
			<line method="	at TestAirbrake.main" file="TestAirbrake.java"
				number="25" />
		</backtrace>

and airbrake represents this information in the same format, instead of reformatting it to the java style.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants