Skip to content

Commit

Permalink
Add custom tags to MicrometerCapability (#2305)
Browse files Browse the repository at this point in the history
* #1456 | Add custom tags to MicrometerCapability

* Update MicrometerCapability.java license year

---------

Co-authored-by: Marvin <[email protected]>
  • Loading branch information
BartekBanachowicz and velo authored Jan 25, 2024
1 parent 5dea9d1 commit 9507881
Showing 1 changed file with 23 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2012-2023 The Feign Authors
* Copyright 2012-2024 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
Expand All @@ -22,9 +22,14 @@
import io.micrometer.core.instrument.Clock;
import io.micrometer.core.instrument.MeterRegistry;
import io.micrometer.core.instrument.Metrics;
import io.micrometer.core.instrument.Tag;
import io.micrometer.core.instrument.simple.SimpleConfig;
import io.micrometer.core.instrument.simple.SimpleMeterRegistry;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

public class MicrometerCapability implements Capability {

private final MeterRegistry meterRegistry;
Expand All @@ -38,6 +43,17 @@ public MicrometerCapability(MeterRegistry meterRegistry) {
this.meterRegistry = meterRegistry;
}

public MicrometerCapability(MeterRegistry meterRegistry, List<Tag> tagsList) {
meterRegistry.config().commonTags(tagsList);
this.meterRegistry = meterRegistry;
}

public MicrometerCapability(MeterRegistry meterRegistry, Map<String, String> tagsMap) {
List<Tag> tagsList = mapTags(tagsMap);
meterRegistry.config().commonTags(tagsList);
this.meterRegistry = meterRegistry;
}

@Override
public Client enrich(Client client) {
return new MeteredClient(client, meterRegistry);
Expand All @@ -62,4 +78,10 @@ public Decoder enrich(Decoder decoder) {
public InvocationHandlerFactory enrich(InvocationHandlerFactory invocationHandlerFactory) {
return new MeteredInvocationHandleFactory(invocationHandlerFactory, meterRegistry);
}

private List<Tag> mapTags(Map<String, String> tags) {
return tags.keySet().stream()
.map(tagKey -> Tag.of(tagKey, tags.get(tagKey)))
.collect(Collectors.toList());
}
}

0 comments on commit 9507881

Please sign in to comment.