@@ -101,22 +101,16 @@ impl<'a> AttributeLike for SpanAttribute<'a> {
101101 }
102102}
103103
104- /// Span properties extracted from a v04 `Span<T>`, with attributes pre-collected.
105- ///
106- /// Pre-collection is required because [`SpanProperties::attributes`] must return
107- /// `impl Iterator<Item = &Self::Attribute>` — items need to exist in memory to be referenced.
108- pub struct V04SpanProperties < ' a > {
109- name : & ' a str ,
110- service : & ' a str ,
111- resource : & ' a str ,
104+ /// Span properties borrowing from a v04 `Span<T>`.
105+ pub struct V04SpanProperties < ' a , T : TraceData > {
106+ span : & ' a Span < T > ,
112107 env : Option < & ' a str > ,
113108 status_code : Option < u32 > ,
114- attributes : Vec < SpanAttribute < ' a > > ,
115109}
116110
117- impl < ' a > V04SpanProperties < ' a > {
111+ impl < ' a , T : TraceData > V04SpanProperties < ' a , T > {
118112 /// Builds span properties by borrowing from `span` for lifetime `'a`.
119- pub fn from_span < T : TraceData > ( span : & ' a Span < T > ) -> Self {
113+ pub fn from_span ( span : & ' a Span < T > ) -> Self {
120114 let env = span. meta . get ( "env" ) . map ( |v| v. borrow ( ) ) ;
121115
122116 let status_code = span
@@ -132,58 +126,52 @@ impl<'a> V04SpanProperties<'a> {
132126 . and_then ( |s| s. borrow ( ) . parse ( ) . ok ( ) )
133127 } ) ;
134128
135- let attributes = span
136- . meta
137- . iter ( )
138- . map ( |( k, v) | SpanAttribute {
139- key : k. borrow ( ) ,
140- value : SpanAttributeValue :: Meta ( v. borrow ( ) ) ,
141- } )
142- . chain ( span. metrics . iter ( ) . map ( |( k, v) | SpanAttribute {
143- key : k. borrow ( ) ,
144- value : SpanAttributeValue :: Metric ( * v) ,
145- } ) )
146- . collect ( ) ;
147-
148129 V04SpanProperties {
149- name : span. name . borrow ( ) ,
150- service : span. service . borrow ( ) ,
151- resource : span. resource . borrow ( ) ,
130+ span,
152131 env,
153132 status_code,
154- attributes,
155133 }
156134 }
157135}
158136
159- impl < ' a > SpanProperties for V04SpanProperties < ' a > {
160- type Attribute = SpanAttribute < ' a > ;
137+ impl < ' a , T : TraceData > SpanProperties for V04SpanProperties < ' a , T > {
138+ type Attribute < ' b >
139+ = SpanAttribute < ' b >
140+ where
141+ Self : ' b ;
161142
162143 fn operation_name ( & self ) -> Cow < ' _ , str > {
163- Cow :: Borrowed ( self . name )
144+ Cow :: Borrowed ( self . span . name . borrow ( ) )
164145 }
165146
166147 fn service ( & self ) -> Cow < ' _ , str > {
167- Cow :: Borrowed ( self . service )
148+ Cow :: Borrowed ( self . span . service . borrow ( ) )
168149 }
169150
170151 fn env ( & self ) -> Cow < ' _ , str > {
171152 self . env . map_or ( Cow :: Borrowed ( "" ) , Cow :: Borrowed )
172153 }
173154
174155 fn resource ( & self ) -> Cow < ' _ , str > {
175- Cow :: Borrowed ( self . resource )
156+ Cow :: Borrowed ( self . span . resource . borrow ( ) )
176157 }
177158
178159 fn status_code ( & self ) -> Option < u32 > {
179160 self . status_code
180161 }
181162
182- fn attributes < ' b > ( & ' b self ) -> impl Iterator < Item = & ' b Self :: Attribute >
183- where
184- Self : ' b ,
185- {
186- self . attributes . iter ( )
163+ fn attributes ( & self ) -> impl Iterator < Item = SpanAttribute < ' _ > > + ' _ {
164+ self . span
165+ . meta
166+ . iter ( )
167+ . map ( |( k, v) | SpanAttribute {
168+ key : k. borrow ( ) ,
169+ value : SpanAttributeValue :: Meta ( v. borrow ( ) ) ,
170+ } )
171+ . chain ( self . span . metrics . iter ( ) . map ( |( k, v) | SpanAttribute {
172+ key : k. borrow ( ) ,
173+ value : SpanAttributeValue :: Metric ( * v) ,
174+ } ) )
187175 }
188176
189177 fn get_alternate_key < ' b > ( & self , _key : & ' b str ) -> Option < Cow < ' b , str > > {
@@ -204,7 +192,7 @@ pub struct V04SamplingData<'a, T: TraceData> {
204192impl < ' a , T : TraceData > SamplingData for V04SamplingData < ' a , T > {
205193 type TraceId = u128 ;
206194 type Properties < ' b >
207- = V04SpanProperties < ' b >
195+ = V04SpanProperties < ' b , T >
208196 where
209197 Self : ' b ;
210198
@@ -218,7 +206,7 @@ impl<'a, T: TraceData> SamplingData for V04SamplingData<'a, T> {
218206
219207 fn with_span_properties < S , R , F > ( & self , s : & S , f : F ) -> R
220208 where
221- F : for < ' b > Fn ( & S , & V04SpanProperties < ' b > ) -> R ,
209+ F : for < ' b > Fn ( & S , & V04SpanProperties < ' b , T > ) -> R ,
222210 {
223211 let props = V04SpanProperties :: from_span ( self . span ) ;
224212 f ( s, & props)
0 commit comments