-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
set root cause as the exception_name in micrometer tags #1883
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
c989a17
set root cause as the exception_name in micrometer tags
chao-chang-paypay c57a599
set root cause as the exception_name in other metrics system
chao-chang-paypay 9841388
Merge branch 'master' into master
chao-chang-paypay 85066f2
set root cause as the exception_name in other metrics system
chao-chang-paypay 6244dc3
Update ExceptionUtilsTest.java
chao-chang-paypay 0a67e8a
Merge branch 'master' of github.com:chao-chang-paypay/feign
chao-chang-paypay 4fcc79e
reformat
chao-chang-paypay d92d77b
reformat
chao-chang-paypay 23cb5ed
add root_cause_name instead of changing exception_name
chao-chang-paypay 73a1cc8
Merge branch 'master' into master
velo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* | ||
* Copyright 2012-2022 The Feign Authors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except | ||
* in compliance with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software distributed under the License | ||
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express | ||
* or implied. See the License for the specific language governing permissions and limitations under | ||
* the License. | ||
*/ | ||
package feign.utils; | ||
|
||
import java.util.HashSet; | ||
import java.util.Set; | ||
|
||
public class ExceptionUtils { | ||
/** | ||
* Introspects the {@link Throwable} to obtain the root cause. | ||
* | ||
* <p> | ||
* This method walks through the exception chain to the last element, "root" of the tree, using | ||
* {@link Throwable#getCause()}, and returns that exception. | ||
* | ||
* @param throwable the throwable to get the root cause for, may be null | ||
* @return the root cause of the {@link Throwable}, {@code null} if null throwable input | ||
*/ | ||
public static Throwable getRootCause(Throwable throwable) { | ||
if (throwable == null) { | ||
return null; | ||
} | ||
Throwable rootCause = throwable; | ||
// this is to avoid infinite loops for recursive cases | ||
final Set<Throwable> seenThrowables = new HashSet<>(); | ||
seenThrowables.add(rootCause); | ||
while ((rootCause.getCause() != null && !seenThrowables.contains(rootCause.getCause()))) { | ||
seenThrowables.add(rootCause.getCause()); | ||
rootCause = rootCause.getCause(); | ||
} | ||
return rootCause; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/* | ||
* Copyright 2012-2022 The Feign Authors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except | ||
* in compliance with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software distributed under the License | ||
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express | ||
* or implied. See the License for the specific language governing permissions and limitations under | ||
* the License. | ||
*/ | ||
package feign.utils; | ||
|
||
import org.junit.Test; | ||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
public class ExceptionUtilsTest { | ||
@Test | ||
public void rootCauseOfNullIsNull() { | ||
Throwable e = null; | ||
Throwable rootCause = ExceptionUtils.getRootCause(e); | ||
assertThat(rootCause).isNull(); | ||
} | ||
|
||
@Test | ||
public void rootCauseIsSelf() { | ||
Throwable e = new Exception(); | ||
Throwable rootCause = ExceptionUtils.getRootCause(e); | ||
assertThat(rootCause).isSameAs(e); | ||
} | ||
|
||
@Test | ||
public void rootCauseIsDifferent() { | ||
Throwable rootCause = new Exception(); | ||
Throwable e = new Exception(rootCause); | ||
Throwable actualRootCause = ExceptionUtils.getRootCause(e); | ||
assertThat(actualRootCause).isSameAs(rootCause); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
getCause
can return null, in that case would cause NPEThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As long as e is not null, getRootCause won’t return null as we can see here
https://github.com/OpenFeign/feign/pull/1883/files#diff-3bfdf878b3ea38d5268a9d72389c1f54ebabf1d76ad9a308e1eed93d95ed0048R38
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ow, awesome, great!