2323from opencensus .ext .azure .common .protocol import DataPoint
2424from opencensus .ext .azure .common .protocol import Envelope
2525from opencensus .ext .azure .common .protocol import MetricData
26+ from opencensus .ext .azure .metrics_exporter import standard_metrics
2627from opencensus .metrics import transport
2728from opencensus .metrics .export .metric_descriptor import MetricDescriptorType
28- from opencensus .stats import stats
29+ from opencensus .stats import stats as stats_module
2930from opencensus .trace import execution_context
3031
3132__all__ = ['MetricsExporter' , 'new_metrics_exporter' ]
@@ -54,18 +55,17 @@ def export_metrics(self, metrics):
5455 type_ = metric .descriptor .type
5556 if type_ != MetricDescriptorType .CUMULATIVE_DISTRIBUTION :
5657 md = metric .descriptor
57- # Each time series will be uniquely
58- # identified by it's label values
58+ # Each time series will be uniquely identified by its
59+ # label values
5960 for time_series in metric .time_series :
60- # Using stats, time_series should
61- # only have one point which contains
62- # the aggregated value
61+ # Using stats, time_series should only have one point
62+ # which contains the aggregated value
6363 data_point = self .create_data_points (
6464 time_series , md )[0 ]
6565 # The timestamp is when the metric was recorded
6666 time_stamp = time_series .points [0 ].timestamp
67- # Get the properties using label keys from metric
68- # and label values of the time series
67+ # Get the properties using label keys from metric and
68+ # label values of the time series
6969 properties = self .create_properties (time_series , md )
7070 envelopes .append (self .create_envelope (data_point ,
7171 time_stamp ,
@@ -90,9 +90,8 @@ def create_data_points(self, time_series, metric_descriptor):
9090
9191 def create_properties (self , time_series , metric_descriptor ):
9292 properties = {}
93- # We construct a properties map from the
94- # label keys and values
95- # We assume the ordering is already correct
93+ # We construct a properties map from the label keys and values. We
94+ # assume the ordering is already correct
9695 for i in range (len (metric_descriptor .label_keys )):
9796 if time_series .label_values [i ].value is None :
9897 value = "null"
@@ -117,11 +116,10 @@ def create_envelope(self, data_point, time_stamp, properties):
117116
118117 def _transmit_without_retry (self , envelopes ):
119118 # Contains logic from transport._transmit
120- # TODO: Remove this function from exporter and
121- # consolidate with transport._transmit to cover
122- # all exporter use cases.
123- # Uses cases pertain to properly handling failures
124- # and implementing a retry policy for this exporter
119+ # TODO: Remove this function from exporter and consolidate with
120+ # transport._transmit to cover all exporter use cases. Uses cases
121+ # pertain to properly handling failures and implementing a retry
122+ # policy for this exporter.
125123 # TODO: implement retry policy
126124 """
127125 Transmit the data envelopes to the ingestion service.
@@ -201,8 +199,8 @@ def _transmit_without_retry(self, envelopes):
201199 error ['message' ],
202200 envelopes [error ['index' ]],
203201 )
204- # show the envelopes that can be
205- # retried manually for visibility
202+ # show the envelopes that can be retried manually for
203+ # visibility
206204 if retryable_envelopes :
207205 logger .warning (
208206 'Error while processing data. Data dropped. ' +
@@ -241,9 +239,12 @@ def _transmit_without_retry(self, envelopes):
241239
242240
243241def new_metrics_exporter (** options ):
244- options = Options (** options )
245- exporter = MetricsExporter (options = options )
246- transport .get_exporter_thread (stats .stats ,
242+ options_ = Options (** options )
243+ exporter = MetricsExporter (options = options_ )
244+ producers = [stats_module .stats ]
245+ if options_ .enable_standard_metrics :
246+ producers .append (standard_metrics .producer )
247+ transport .get_exporter_thread (producers ,
247248 exporter ,
248- interval = options .export_interval )
249+ interval = options_ .export_interval )
249250 return exporter
0 commit comments