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

Track number of exception that happen while decoding payload #1288

Merged
merged 1 commit into from
Oct 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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