1
- use std:: { any:: Any , borrow:: Cow , fmt , hash:: Hash , marker, sync:: Arc } ;
1
+ use std:: { any:: Any , borrow:: Cow , collections :: HashSet , hash:: Hash , marker, sync:: Arc } ;
2
2
3
3
use opentelemetry_api:: {
4
4
metrics:: {
5
5
AsyncInstrument , MetricsError , Result , SyncCounter , SyncHistogram , SyncUpDownCounter , Unit ,
6
6
} ,
7
- KeyValue ,
7
+ Key , KeyValue ,
8
8
} ;
9
9
10
10
use crate :: {
@@ -158,7 +158,7 @@ impl Instrument {
158
158
/// let view = new_view(criteria, mask);
159
159
/// # drop(view);
160
160
/// ```
161
- #[ derive( Default ) ]
161
+ #[ derive( Default , Debug ) ]
162
162
#[ non_exhaustive]
163
163
pub struct Stream {
164
164
/// The human-readable identifier of the stream.
@@ -169,12 +169,14 @@ pub struct Stream {
169
169
pub unit : Unit ,
170
170
/// Aggregation the stream uses for an instrument.
171
171
pub aggregation : Option < Aggregation > ,
172
- /// applied to all attributes recorded for an instrument.
173
- pub attribute_filter : Option < Filter > ,
172
+ /// An allow-list of attribute keys that will be preserved for the stream.
173
+ ///
174
+ /// Any attribute recorded for the stream with a key not in this set will be
175
+ /// dropped. If the set is empty, all attributes will be dropped, if `None` all
176
+ /// attributes will be kept.
177
+ pub allowed_attribute_keys : Option < Arc < HashSet < Key > > > ,
174
178
}
175
179
176
- type Filter = Arc < dyn Fn ( & KeyValue ) -> bool + Send + Sync > ;
177
-
178
180
impl Stream {
179
181
/// Create a new stream with empty values.
180
182
pub fn new ( ) -> Self {
@@ -205,25 +207,14 @@ impl Stream {
205
207
self
206
208
}
207
209
208
- /// Set the stream attribute filter.
209
- pub fn attribute_filter (
210
- mut self ,
211
- filter : impl Fn ( & KeyValue ) -> bool + Send + Sync + ' static ,
212
- ) -> Self {
213
- self . attribute_filter = Some ( Arc :: new ( filter) ) ;
214
- self
215
- }
216
- }
210
+ /// Set the stream allowed attribute keys.
211
+ ///
212
+ /// Any attribute recorded for the stream with a key not in this set will be
213
+ /// dropped. If this set is empty all attributes will be dropped.
214
+ pub fn allowed_attribute_keys ( mut self , attribute_keys : impl IntoIterator < Item = Key > ) -> Self {
215
+ self . allowed_attribute_keys = Some ( Arc :: new ( attribute_keys. into_iter ( ) . collect ( ) ) ) ;
217
216
218
- impl fmt:: Debug for Stream {
219
- fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
220
- f. debug_struct ( "Stream" )
221
- . field ( "name" , & self . name )
222
- . field ( "description" , & self . description )
223
- . field ( "unit" , & self . unit )
224
- . field ( "aggregation" , & self . aggregation )
225
- . field ( "attribute_filter" , & self . attribute_filter . is_some ( ) )
226
- . finish ( )
217
+ self
227
218
}
228
219
}
229
220
0 commit comments