1
1
/*
2
- * Copyright 2012-2023 The Feign Authors
2
+ * Copyright 2012-2024 The Feign Authors
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
5
5
* in compliance with the License. You may obtain a copy of the License at
22
22
import io .micrometer .core .instrument .Clock ;
23
23
import io .micrometer .core .instrument .MeterRegistry ;
24
24
import io .micrometer .core .instrument .Metrics ;
25
+ import io .micrometer .core .instrument .Tag ;
25
26
import io .micrometer .core .instrument .simple .SimpleConfig ;
26
27
import io .micrometer .core .instrument .simple .SimpleMeterRegistry ;
27
28
29
+ import java .util .List ;
30
+ import java .util .Map ;
31
+ import java .util .stream .Collectors ;
32
+
28
33
public class MicrometerCapability implements Capability {
29
34
30
35
private final MeterRegistry meterRegistry ;
@@ -38,6 +43,17 @@ public MicrometerCapability(MeterRegistry meterRegistry) {
38
43
this .meterRegistry = meterRegistry ;
39
44
}
40
45
46
+ public MicrometerCapability (MeterRegistry meterRegistry , List <Tag > tagsList ) {
47
+ meterRegistry .config ().commonTags (tagsList );
48
+ this .meterRegistry = meterRegistry ;
49
+ }
50
+
51
+ public MicrometerCapability (MeterRegistry meterRegistry , Map <String , String > tagsMap ) {
52
+ List <Tag > tagsList = mapTags (tagsMap );
53
+ meterRegistry .config ().commonTags (tagsList );
54
+ this .meterRegistry = meterRegistry ;
55
+ }
56
+
41
57
@ Override
42
58
public Client enrich (Client client ) {
43
59
return new MeteredClient (client , meterRegistry );
@@ -62,4 +78,10 @@ public Decoder enrich(Decoder decoder) {
62
78
public InvocationHandlerFactory enrich (InvocationHandlerFactory invocationHandlerFactory ) {
63
79
return new MeteredInvocationHandleFactory (invocationHandlerFactory , meterRegistry );
64
80
}
81
+
82
+ private List <Tag > mapTags (Map <String , String > tags ) {
83
+ return tags .keySet ().stream ()
84
+ .map (tagKey -> Tag .of (tagKey , tags .get (tagKey )))
85
+ .collect (Collectors .toList ());
86
+ }
65
87
}
0 commit comments