Skip to content

Commit

Permalink
Track number of exception that happen while decoding payload (#1288)
Browse files Browse the repository at this point in the history
  • Loading branch information
velo committed Oct 27, 2020
1 parent a1f49bc commit 336f2ce
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,18 @@ public Object decode(Response response, Type type)
metricSuppliers.timers())
.time()) {
decoded = decoder.decode(response, type);
} catch (IOException | RuntimeException e) {
metricRegistry.meter(
metricName.metricName(template.methodMetadata(), template.feignTarget(), "error_count")
.tagged("exception_name", e.getClass().getSimpleName()),
metricSuppliers.meters()).mark();
throw e;
} catch (Exception e) {
metricRegistry.meter(
metricName.metricName(template.methodMetadata(), template.feignTarget(), "error_count")
.tagged("exception_name", e.getClass().getSimpleName()),
metricSuppliers.meters()).mark();
throw new IOException(e);
}

if (body != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import feign.MethodMetadata;
import feign.Target;
import io.micrometer.core.instrument.Tag;
import io.micrometer.core.instrument.config.NamingConvention;
import io.micrometer.core.instrument.Tags;

public final class FeignMetricName {

Expand All @@ -43,17 +43,17 @@ public String name() {
return meteredComponent.getName();
}

public List<Tag> tag(MethodMetadata methodMetadata, Target<?> target, Tag... tags) {
public Tags tag(MethodMetadata methodMetadata, Target<?> target, Tag... tags) {
return tag(methodMetadata.targetType(), methodMetadata.method(), target.url(), tags);
}

public List<Tag> tag(Class<?> targetType, Method method, String url, Tag... extraTags) {
public Tags tag(Class<?> targetType, Method method, String url, Tag... extraTags) {
List<Tag> tags = new ArrayList<>();
tags.add(Tag.of("client", targetType.getName()));
tags.add(Tag.of("method", method.getName()));
tags.add(Tag.of("host", extractHost(url)));
tags.addAll(Arrays.asList(extraTags));
return tags;
return Tags.of(tags);
}

private String extractHost(final String targetUrl) {
Expand Down
11 changes: 11 additions & 0 deletions micrometer/src/main/java/feign/micrometer/MeteredDecoder.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import feign.codec.DecodeException;
import feign.codec.Decoder;
import io.micrometer.core.instrument.MeterRegistry;
import io.micrometer.core.instrument.Tag;

/**
* Warp feign {@link Decoder} with metrics.
Expand Down Expand Up @@ -56,8 +57,18 @@ public Object decode(Response response, Type type)
metricName.tag(template.methodMetadata(), template.feignTarget()))
.recordCallable(() -> decoder.decode(meteredResponse, type));
} catch (IOException | RuntimeException e) {
meterRegistry.counter(
metricName.name("error_count"),
metricName.tag(template.methodMetadata(), template.feignTarget())
.and(Tag.of("exception_name", e.getClass().getSimpleName())))
.count();
throw e;
} catch (Exception e) {
meterRegistry.counter(
metricName.name("error_count"),
metricName.tag(template.methodMetadata(), template.feignTarget())
.and(Tag.of("exception_name", e.getClass().getSimpleName())))
.count();
throw new IOException(e);
}

Expand Down

0 comments on commit 336f2ce

Please sign in to comment.