@@ -93,13 +93,16 @@ class CloudMonitoringMetricsExporter(MetricExporter):
9393 must be used when there exist two (or more) exporters that may
9494 export to the same metric name within WRITE_INTERVAL seconds of
9595 each other.
96+ prefix: the prefix of the metric. It is "workload.googleapis.com" by
97+ default if not specified.
9698 """
9799
98100 def __init__ (
99101 self ,
100102 project_id : Optional [str ] = None ,
101103 client : Optional [MetricServiceClient ] = None ,
102104 add_unique_identifier : bool = False ,
105+ prefix : Optional [str ] = "workload.googleapis.com" ,
103106 ):
104107 # Default preferred_temporality is all CUMULATIVE so need to customize
105108 super ().__init__ ()
@@ -129,6 +132,7 @@ def __init__(
129132 self ._exporter_start_time_seconds ,
130133 self ._exporter_start_time_nanos ,
131134 ) = divmod (time_ns (), NANOS_PER_SECOND )
135+ self ._prefix = prefix
132136
133137 def _batch_write (self , series : List [TimeSeries ]) -> None :
134138 """Cloud Monitoring allows writing up to 200 time series at once
@@ -159,7 +163,7 @@ def _get_metric_descriptor(
159163 :param record:
160164 :return:
161165 """
162- descriptor_type = f"workload.googleapis.com /{ metric .name } "
166+ descriptor_type = f"{ self . _prefix } /{ metric .name } "
163167 if descriptor_type in self ._metric_descriptors :
164168 return self ._metric_descriptors [descriptor_type ]
165169
0 commit comments