Skip to content

Commit

Permalink
add root_cause_name instead of changing exception_name
Browse files Browse the repository at this point in the history
  • Loading branch information
chao-chang-paypay committed Dec 16, 2022
1 parent d92d77b commit 23cb5ed
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ protected void recordFailure(RequestTemplate template, FeignException e) {
MetricRegistry.name(
httpResponseCode(template),
"exception_name",
e.getClass().getSimpleName(),
"root_cause_name",
ExceptionUtils.getRootCause(e).getClass().getSimpleName(),
"status_group",
e.status() / 100 + "xx",
Expand All @@ -82,6 +84,8 @@ protected void recordFailure(RequestTemplate template, Exception e) {
MetricRegistry.name(
httpResponseCode(template),
"exception_name",
e.getClass().getSimpleName(),
"root_cause_name",
ExceptionUtils.getRootCause(e).getClass().getSimpleName(),
"uri",
template.methodMetadata().template().path()),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,9 @@ protected void recordFailure(RequestTemplate template, FeignException e) {
metricRegistry
.counter(
httpResponseCode(template)
.tagged("exception_name", ExceptionUtils.getRootCause(e).getClass().getSimpleName())
.tagged("exception_name", e.getClass().getSimpleName())
.tagged("root_cause_name",
ExceptionUtils.getRootCause(e).getClass().getSimpleName())
.tagged("http_status", String.valueOf(e.status()))
.tagged("status_group", e.status() / 100 + "xx")
.tagged("uri", template.methodMetadata().template().path()))
Expand All @@ -71,7 +73,9 @@ protected void recordFailure(RequestTemplate template, Exception e) {
metricRegistry
.counter(
httpResponseCode(template)
.tagged("exception_name", ExceptionUtils.getRootCause(e).getClass().getSimpleName())
.tagged("exception_name", e.getClass().getSimpleName())
.tagged("root_cause_name",
ExceptionUtils.getRootCause(e).getClass().getSimpleName())
.tagged("uri", template.methodMetadata().template().path()))
.inc();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,16 @@ public Object decode(Response response, Type type)
} catch (IOException | RuntimeException e) {
metricRegistry.meter(
metricName.metricName(template.methodMetadata(), template.feignTarget(), "error_count")
.tagged("exception_name", ExceptionUtils.getRootCause(e).getClass().getSimpleName())
.tagged("exception_name", e.getClass().getSimpleName())
.tagged("root_cause_name", ExceptionUtils.getRootCause(e).getClass().getSimpleName())
.tagged("uri", template.methodMetadata().template().path()),
metricSuppliers.meters()).mark();
throw e;
} catch (Exception e) {
metricRegistry.meter(
metricName.metricName(template.methodMetadata(), template.feignTarget(), "error_count")
.tagged("exception_name", ExceptionUtils.getRootCause(e).getClass().getSimpleName())
.tagged("exception_name", e.getClass().getSimpleName())
.tagged("root_cause_name", ExceptionUtils.getRootCause(e).getClass().getSimpleName())
.tagged("uri", template.methodMetadata().template().path()),
metricSuppliers.meters()).mark();
throw new IOException(e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
*/
package feign.metrics5;


import feign.utils.ExceptionUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -87,7 +86,8 @@ public InvocationHandler create(Target target, Map<Method, MethodHandler> dispat
metricRegistry
.meter(metricName.metricName(clientClass, method, target.url())
.resolve("exception")
.tagged("exception_name",
.tagged("exception_name", e.getClass().getSimpleName())
.tagged("root_cause_name",
ExceptionUtils.getRootCause(e).getClass().getSimpleName()),
metricSuppliers.meters())
.mark();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@ public Tags tag(Class<?> targetType, Method method, String url, Throwable e, Tag
tags.add(Tag.of("method", method.getName()));
tags.add(Tag.of("host", extractHost(url)));
if (e != null) {
tags.add(Tag.of("exception_name", ExceptionUtils.getRootCause(e).getClass().getSimpleName()));
tags.add(Tag.of("exception_name", e.getClass().getSimpleName()));
tags.add(
Tag.of("root_cause_name", ExceptionUtils.getRootCause(e).getClass().getSimpleName()));
}
tags.addAll(Arrays.asList(extraTags));
return Tags.of(tags);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,8 @@ protected Counter createExceptionCounter(Response response, Type type, Exception
final RequestTemplate template = response.request().requestTemplate();
final Tags allTags = metricTagResolver.tag(template.methodMetadata(), template.feignTarget(),
Tag.of("uri", template.methodMetadata().template().path()),
Tag.of("exception_name", ExceptionUtils.getRootCause(e).getClass().getSimpleName()))
Tag.of("exception_name", e.getClass().getSimpleName()),
Tag.of("root_cause_name", ExceptionUtils.getRootCause(e).getClass().getSimpleName()))
.and(extraTags);
return meterRegistry.counter(metricName.name("error_count"), allTags);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,8 @@ public void shouldMetricCollectionWithCustomException() {
assertThat(thrown.getMessage(), equalTo("Test error"));

assertThat(
getMetric("exception", "exception_name", "RuntimeException", "method", "get"),
getMetric("exception", "exception_name", "RuntimeException", "method", "get",
"root_cause_name", "RuntimeException"),
notNullValue());
}

Expand Down

0 comments on commit 23cb5ed

Please sign in to comment.