22
22
23
23
public class YamlHelper {
24
24
25
- public static EmittedScope emittedScopeParser (String input ) {
26
- return new Yaml ().loadAs (input , EmittedScope .class );
27
- }
28
-
29
- public static EmittedMetrics emittedMetricsParser (String input ) {
30
- return new Yaml ().loadAs (input , EmittedMetrics .class );
31
- }
32
-
33
- public static EmittedSpans emittedSpansParser (String input ) {
34
- return new Yaml ().loadAs (input , EmittedSpans .class );
35
- }
36
-
37
25
public static void printInstrumentationList (
38
26
List <InstrumentationEntity > list , BufferedWriter writer ) {
39
27
Map <String , List <InstrumentationEntity >> groupedByGroup =
@@ -58,22 +46,7 @@ public static void printInstrumentationList(
58
46
entityMap .put ("srcPath" , entity .getSrcPath ());
59
47
60
48
if (entity .getScope () != null ) {
61
- Map <String , Object > scopeMap = new LinkedHashMap <>();
62
- scopeMap .put ("name" , entity .getScope ().getName ());
63
- scopeMap .put ("version" , entity .getScope ().getVersion ());
64
- scopeMap .put ("schemaUrl" , entity .getScope ().getSchemaUrl ());
65
-
66
- if (entity .getScope ().getAttributes () != null
67
- && !entity .getScope ().getAttributes ().isEmpty ()) {
68
-
69
- Map <String , Object > attributesMap = new LinkedHashMap <>();
70
- entity
71
- .getScope ()
72
- .getAttributes ()
73
- .forEach ((key , value ) -> attributesMap .put (String .valueOf (key ), value ));
74
- scopeMap .put ("attributes" , attributesMap );
75
- }
76
-
49
+ Map <String , Object > scopeMap = getScopeMap (entity );
77
50
entityMap .put ("scope" , scopeMap );
78
51
}
79
52
@@ -92,20 +65,7 @@ public static void printInstrumentationList(
92
65
entityMap .put ("metrics" , metricsList );
93
66
}
94
67
95
- Map <String , Object > spanDataMap = new LinkedHashMap <>();
96
- if (entity .getSpanKinds () != null && !entity .getSpanKinds ().isEmpty ()) {
97
- spanDataMap .put ("span_kinds" , entity .getSpanKinds ());
98
- }
99
- if (entity .getSpanAttributes () != null && !entity .getSpanAttributes ().isEmpty ()) {
100
- List <Map <String , Object >> attributesList = new ArrayList <>();
101
- for (EmittedSpans .EmittedSpanAttribute attribute : entity .getSpanAttributes ()) {
102
- Map <String , Object > attributeMap = new LinkedHashMap <>();
103
- attributeMap .put ("name" , attribute .getName ());
104
- attributeMap .put ("type" , attribute .getType ());
105
- attributesList .add (attributeMap );
106
- }
107
- spanDataMap .put ("attributes" , attributesList );
108
- }
68
+ Map <String , Object > spanDataMap = getSpanDataMap (entity );
109
69
if (!spanDataMap .isEmpty ()) {
110
70
entityMap .put ("span_data" , spanDataMap );
111
71
}
@@ -123,6 +83,42 @@ public static void printInstrumentationList(
123
83
yaml .dump (output , writer );
124
84
}
125
85
86
+ private static Map <String , Object > getSpanDataMap (InstrumentationEntity entity ) {
87
+ Map <String , Object > spanDataMap = new LinkedHashMap <>();
88
+ if (entity .getSpanKinds () != null && !entity .getSpanKinds ().isEmpty ()) {
89
+ spanDataMap .put ("span_kinds" , entity .getSpanKinds ());
90
+ }
91
+ if (entity .getSpanAttributes () != null && !entity .getSpanAttributes ().isEmpty ()) {
92
+ List <Map <String , Object >> attributesList = new ArrayList <>();
93
+ for (EmittedSpans .EmittedSpanAttribute attribute : entity .getSpanAttributes ()) {
94
+ Map <String , Object > attributeMap = new LinkedHashMap <>();
95
+ attributeMap .put ("name" , attribute .getName ());
96
+ attributeMap .put ("type" , attribute .getType ());
97
+ attributesList .add (attributeMap );
98
+ }
99
+ spanDataMap .put ("attributes" , attributesList );
100
+ }
101
+ return spanDataMap ;
102
+ }
103
+
104
+ private static Map <String , Object > getScopeMap (InstrumentationEntity entity ) {
105
+ Map <String , Object > scopeMap = new LinkedHashMap <>();
106
+ scopeMap .put ("name" , entity .getScope ().getName ());
107
+ scopeMap .put ("version" , entity .getScope ().getVersion ());
108
+ scopeMap .put ("schemaUrl" , entity .getScope ().getSchemaUrl ());
109
+
110
+ if (entity .getScope ().getAttributes () != null && !entity .getScope ().getAttributes ().isEmpty ()) {
111
+
112
+ Map <String , Object > attributesMap = new LinkedHashMap <>();
113
+ entity
114
+ .getScope ()
115
+ .getAttributes ()
116
+ .forEach ((key , value ) -> attributesMap .put (String .valueOf (key ), value ));
117
+ scopeMap .put ("attributes" , attributesMap );
118
+ }
119
+ return scopeMap ;
120
+ }
121
+
126
122
private static List <Map <String , Object >> getMetricsList (InstrumentationEntity entity ) {
127
123
List <Map <String , Object >> metricsList = new ArrayList <>();
128
124
for (EmittedMetrics .Metric metric : entity .getMetrics ()) {
@@ -149,5 +145,17 @@ public static InstrumentationMetaData metaDataParser(String input) {
149
145
return new Yaml ().loadAs (input , InstrumentationMetaData .class );
150
146
}
151
147
148
+ public static EmittedScope emittedScopeParser (String input ) {
149
+ return new Yaml ().loadAs (input , EmittedScope .class );
150
+ }
151
+
152
+ public static EmittedMetrics emittedMetricsParser (String input ) {
153
+ return new Yaml ().loadAs (input , EmittedMetrics .class );
154
+ }
155
+
156
+ public static EmittedSpans emittedSpansParser (String input ) {
157
+ return new Yaml ().loadAs (input , EmittedSpans .class );
158
+ }
159
+
152
160
private YamlHelper () {}
153
161
}
0 commit comments