@@ -17,6 +17,20 @@ public ConsoleMetricExporter(ConsoleExporterOptions options)
17
17
18
18
public override ExportResult Export ( in Batch < Metric > batch )
19
19
{
20
+ // Print Resource information once at the beginning of the batch
21
+ var resource = this . ParentProvider . GetResource ( ) ;
22
+ if ( resource != Resource . Empty )
23
+ {
24
+ this . WriteLine ( "Resource associated with Metrics:" ) ;
25
+ foreach ( var resourceAttribute in resource . Attributes )
26
+ {
27
+ if ( this . TagWriter . TryTransformTag ( resourceAttribute . Key , resourceAttribute . Value , out var result ) )
28
+ {
29
+ this . WriteLine ( $ "\t { result . Key } : { result . Value } ") ;
30
+ }
31
+ }
32
+ }
33
+
20
34
foreach ( var metric in batch )
21
35
{
22
36
var msg = new StringBuilder ( Environment . NewLine ) ;
@@ -25,7 +39,7 @@ public override ExportResult Export(in Batch<Metric> batch)
25
39
#else
26
40
msg . Append ( $ "Metric Name: { metric . Name } ") ;
27
41
#endif
28
- if ( string . IsNullOrEmpty ( metric . Description ) )
42
+ if ( ! string . IsNullOrEmpty ( metric . Description ) )
29
43
{
30
44
#if NET
31
45
msg . Append ( CultureInfo . InvariantCulture , $ ", Description: { metric . Description } ") ;
@@ -34,7 +48,7 @@ public override ExportResult Export(in Batch<Metric> batch)
34
48
#endif
35
49
}
36
50
37
- if ( string . IsNullOrEmpty ( metric . Unit ) )
51
+ if ( ! string . IsNullOrEmpty ( metric . Unit ) )
38
52
{
39
53
#if NET
40
54
msg . Append ( CultureInfo . InvariantCulture , $ ", Unit: { metric . Unit } ") ;
@@ -43,8 +57,34 @@ public override ExportResult Export(in Batch<Metric> batch)
43
57
#endif
44
58
}
45
59
60
+ #if NET
61
+ msg . Append ( CultureInfo . InvariantCulture , $ ", Metric Type: { metric . MetricType } ") ;
62
+ #else
63
+ msg . Append ( $ ", Metric Type: { metric . MetricType } ") ;
64
+ #endif
65
+
46
66
this . WriteLine ( msg . ToString ( ) ) ;
47
67
68
+ // Print Instrumentation scope (Meter) information once per metric
69
+ this . WriteLine ( "Instrumentation scope (Meter):" ) ;
70
+ this . WriteLine ( $ "\t Name: { metric . MeterName } ") ;
71
+ if ( ! string . IsNullOrEmpty ( metric . MeterVersion ) )
72
+ {
73
+ this . WriteLine ( $ "\t Version: { metric . MeterVersion } ") ;
74
+ }
75
+
76
+ if ( metric . MeterTags ? . Any ( ) == true )
77
+ {
78
+ this . WriteLine ( "\t Tags:" ) ;
79
+ foreach ( var meterTag in metric . MeterTags )
80
+ {
81
+ if ( this . TagWriter . TryTransformTag ( meterTag , out var result ) )
82
+ {
83
+ this . WriteLine ( $ "\t \t { result . Key } : { result . Value } ") ;
84
+ }
85
+ }
86
+ }
87
+
48
88
foreach ( ref readonly var metricPoint in metric . GetMetricPoints ( ) )
49
89
{
50
90
string valueDisplay = string . Empty ;
@@ -226,12 +266,6 @@ public override ExportResult Export(in Batch<Metric> batch)
226
266
msg . Append ( ' ' ) ;
227
267
}
228
268
229
- msg . AppendLine ( ) ;
230
- #if NET
231
- msg . AppendLine ( CultureInfo . InvariantCulture , $ "Metric Type: { metric . MetricType } ") ;
232
- #else
233
- msg . Append ( $ "Metric Type: { metric . MetricType } ") ;
234
- #endif
235
269
msg . AppendLine ( ) ;
236
270
#if NET
237
271
msg . Append ( CultureInfo . InvariantCulture , $ "Value: { valueDisplay } ") ;
@@ -247,38 +281,6 @@ public override ExportResult Export(in Batch<Metric> batch)
247
281
}
248
282
249
283
this . WriteLine ( msg . ToString ( ) ) ;
250
-
251
- this . WriteLine ( "Instrumentation scope (Meter):" ) ;
252
- this . WriteLine ( $ "\t Name: { metric . MeterName } ") ;
253
- if ( ! string . IsNullOrEmpty ( metric . MeterVersion ) )
254
- {
255
- this . WriteLine ( $ "\t Version: { metric . MeterVersion } ") ;
256
- }
257
-
258
- if ( metric . MeterTags ? . Any ( ) == true )
259
- {
260
- this . WriteLine ( "\t Tags:" ) ;
261
- foreach ( var meterTag in metric . MeterTags )
262
- {
263
- if ( this . TagWriter . TryTransformTag ( meterTag , out var result ) )
264
- {
265
- this . WriteLine ( $ "\t \t { result . Key } : { result . Value } ") ;
266
- }
267
- }
268
- }
269
-
270
- var resource = this . ParentProvider . GetResource ( ) ;
271
- if ( resource != Resource . Empty )
272
- {
273
- this . WriteLine ( "Resource associated with Metric:" ) ;
274
- foreach ( var resourceAttribute in resource . Attributes )
275
- {
276
- if ( this . TagWriter . TryTransformTag ( resourceAttribute . Key , resourceAttribute . Value , out var result ) )
277
- {
278
- this . WriteLine ( $ "\t { result . Key } : { result . Value } ") ;
279
- }
280
- }
281
- }
282
284
}
283
285
}
284
286
0 commit comments