@@ -10,70 +10,29 @@ namespace OpenTelemetry.Exporter;
1010
1111public class ConsoleMetricExporter : ConsoleExporter < Metric >
1212{
13- private Resource ? resource ;
14-
1513 public ConsoleMetricExporter ( ConsoleExporterOptions options )
1614 : base ( options )
1715 {
1816 }
1917
2018 public override ExportResult Export ( in Batch < Metric > batch )
2119 {
22- if ( this . resource == null )
23- {
24- this . resource = this . ParentProvider . GetResource ( ) ;
25- if ( this . resource != Resource . Empty )
26- {
27- this . WriteLine ( "Resource associated with Metric:" ) ;
28- foreach ( var resourceAttribute in this . resource . Attributes )
29- {
30- if ( this . TagWriter . TryTransformTag ( resourceAttribute . Key , resourceAttribute . Value , out var result ) )
31- {
32- this . WriteLine ( $ " { result . Key } : { result . Value } ") ;
33- }
34- }
35- }
36- }
37-
3820 foreach ( var metric in batch )
3921 {
4022 var msg = new StringBuilder ( $ "\n ") ;
4123 msg . Append ( $ "Metric Name: { metric . Name } ") ;
4224 if ( metric . Description != string . Empty )
4325 {
44- msg . Append ( ", " ) ;
45- msg . Append ( metric . Description ) ;
26+ msg . Append ( $ ", Description: { metric . Description } ") ;
4627 }
4728
4829 if ( metric . Unit != string . Empty )
4930 {
5031 msg . Append ( $ ", Unit: { metric . Unit } ") ;
5132 }
5233
53- if ( ! string . IsNullOrEmpty ( metric . MeterName ) )
54- {
55- msg . Append ( $ ", Meter: { metric . MeterName } ") ;
56-
57- if ( ! string . IsNullOrEmpty ( metric . MeterVersion ) )
58- {
59- msg . Append ( $ "/{ metric . MeterVersion } ") ;
60- }
61- }
62-
6334 this . WriteLine ( msg . ToString ( ) ) ;
6435
65- if ( metric . MeterTags != null )
66- {
67- foreach ( var meterTag in metric . MeterTags )
68- {
69- this . WriteLine ( "\t Meter Tags:" ) ;
70- if ( this . TagWriter . TryTransformTag ( meterTag , out var result ) )
71- {
72- this . WriteLine ( $ "\t \t { result . Key } : { result . Value } ") ;
73- }
74- }
75- }
76-
7736 foreach ( ref readonly var metricPoint in metric . GetMetricPoints ( ) )
7837 {
7938 string valueDisplay = string . Empty ;
@@ -220,7 +179,7 @@ public override ExportResult Export(in Batch<Metric> batch)
220179 {
221180 if ( ! appendedTagString )
222181 {
223- exemplarString . Append ( " Filtered Tags : " ) ;
182+ exemplarString . Append ( " Filtered Tags: " ) ;
224183 appendedTagString = true ;
225184 }
226185
@@ -257,6 +216,38 @@ public override ExportResult Export(in Batch<Metric> batch)
257216 }
258217
259218 this . WriteLine ( msg . ToString ( ) ) ;
219+
220+ this . WriteLine ( "Instrumentation scope (Meter):" ) ;
221+ this . WriteLine ( $ "\t Name: { metric . MeterName } ") ;
222+ if ( ! string . IsNullOrEmpty ( metric . MeterVersion ) )
223+ {
224+ this . WriteLine ( $ "\t Version: { metric . MeterVersion } ") ;
225+ }
226+
227+ if ( metric . MeterTags ? . Any ( ) == true )
228+ {
229+ this . WriteLine ( "\t Tags:" ) ;
230+ foreach ( var meterTag in metric . MeterTags )
231+ {
232+ if ( this . TagWriter . TryTransformTag ( meterTag , out var result ) )
233+ {
234+ this . WriteLine ( $ "\t \t { result . Key } : { result . Value } ") ;
235+ }
236+ }
237+ }
238+
239+ var resource = this . ParentProvider . GetResource ( ) ;
240+ if ( resource != Resource . Empty )
241+ {
242+ this . WriteLine ( "Resource associated with Metric:" ) ;
243+ foreach ( var resourceAttribute in resource . Attributes )
244+ {
245+ if ( this . TagWriter . TryTransformTag ( resourceAttribute . Key , resourceAttribute . Value , out var result ) )
246+ {
247+ this . WriteLine ( $ "\t { result . Key } : { result . Value } ") ;
248+ }
249+ }
250+ }
260251 }
261252 }
262253
0 commit comments