@@ -16,7 +16,7 @@ use crate::proto::grpcio::trace::{
16
16
} ;
17
17
18
18
use crate :: transform:: common:: { to_nanos, Attributes } ;
19
- use opentelemetry:: sdk:: export:: trace:: SpanData ;
19
+ use opentelemetry:: sdk:: { export:: trace:: SpanData , self } ;
20
20
use opentelemetry:: trace:: { Link , SpanKind , StatusCode } ;
21
21
22
22
#[ cfg( all( feature = "grpc-sys" , not( feature = "tonic" ) ) ) ]
@@ -120,13 +120,21 @@ impl From<Link> for Span_Link {
120
120
}
121
121
}
122
122
123
+ fn resource_attributes ( resource : & sdk:: Resource ) -> Attributes {
124
+ resource
125
+ . iter ( )
126
+ . map ( |( k, v) | opentelemetry:: KeyValue :: new ( k. clone ( ) , v. clone ( ) ) )
127
+ . collect :: < Vec < _ > > ( )
128
+ . into ( )
129
+ }
130
+
123
131
impl From < SpanData > for ResourceSpans {
124
132
#[ cfg( feature = "tonic" ) ]
125
133
fn from ( source_span : SpanData ) -> Self {
126
134
let span_kind: span:: SpanKind = source_span. span_kind . into ( ) ;
127
135
ResourceSpans {
128
136
resource : Some ( Resource {
129
- attributes : Default :: default ( ) ,
137
+ attributes : resource_attributes ( & source_span . resource ) . 0 ,
130
138
dropped_attributes_count : 0 ,
131
139
} ) ,
132
140
instrumentation_library_spans : vec ! [ InstrumentationLibrarySpans {
@@ -183,15 +191,9 @@ impl From<SpanData> for ResourceSpans {
183
191
184
192
#[ cfg( all( feature = "grpc-sys" , not( feature = "tonic" ) ) ) ]
185
193
fn from ( source_span : SpanData ) -> Self {
186
- let resource_attributes: Attributes = source_span
187
- . resource
188
- . iter ( )
189
- . map ( |( k, v) | opentelemetry:: KeyValue :: new ( k. clone ( ) , v. clone ( ) ) )
190
- . collect :: < Vec < _ > > ( )
191
- . into ( ) ;
192
194
ResourceSpans {
193
195
resource : SingularPtrField :: from ( Some ( Resource {
194
- attributes : resource_attributes. 0 ,
196
+ attributes : resource_attributes ( & source_span . resource ) . 0 ,
195
197
dropped_attributes_count : 0 ,
196
198
..Default :: default ( )
197
199
} ) ) ,
0 commit comments