@@ -7,7 +7,7 @@ use opentelemetry_sdk::metrics::{
7
7
} ;
8
8
use std:: sync:: { Arc , Mutex } ;
9
9
10
- use crate :: { Collector , PrometheusExporter } ;
10
+ use crate :: { Collector , PrometheusExporter , ResourceSelector } ;
11
11
12
12
/// [PrometheusExporter] configuration options
13
13
#[ derive( Default ) ]
@@ -19,6 +19,7 @@ pub struct ExporterBuilder {
19
19
namespace : Option < String > ,
20
20
disable_scope_info : bool ,
21
21
reader : ManualReaderBuilder ,
22
+ resource_selector : ResourceSelector ,
22
23
}
23
24
24
25
impl fmt:: Debug for ExporterBuilder {
@@ -114,6 +115,19 @@ impl ExporterBuilder {
114
115
self
115
116
}
116
117
118
+ /// Configures whether to export resource as attributes with every metric.
119
+ ///
120
+ /// Note that this is orthogonal to the `target_info` metric, which can be disabled using `without_target_info`.
121
+ ///
122
+ /// If you called `without_target_info` and `with_resource_selector` with `ResourceSelector::None`, resource will not be exported at all.
123
+ pub fn with_resource_selector (
124
+ mut self ,
125
+ resource_selector : impl Into < ResourceSelector > ,
126
+ ) -> Self {
127
+ self . resource_selector = resource_selector. into ( ) ;
128
+ self
129
+ }
130
+
117
131
/// Registers an external [MetricProducer] with this reader.
118
132
///
119
133
/// The producer is used as a source of aggregated metric data which is
@@ -136,6 +150,8 @@ impl ExporterBuilder {
136
150
create_target_info_once : OnceCell :: new ( ) ,
137
151
namespace : self . namespace ,
138
152
inner : Mutex :: new ( Default :: default ( ) ) ,
153
+ resource_selector : self . resource_selector ,
154
+ resource_labels_once : OnceCell :: new ( ) ,
139
155
} ;
140
156
141
157
let registry = self . registry . unwrap_or_default ( ) ;
0 commit comments