1616 *
1717 */
1818use opentelemetry_proto:: tonic:: collector:: trace:: v1:: ExportTraceServiceRequest ;
19+ use opentelemetry_proto:: tonic:: common:: v1:: KeyValue ;
1920use opentelemetry_proto:: tonic:: trace:: v1:: ScopeSpans ;
2021use opentelemetry_proto:: tonic:: trace:: v1:: Span ;
2122use opentelemetry_proto:: tonic:: trace:: v1:: Status ;
@@ -24,6 +25,8 @@ use opentelemetry_proto::tonic::trace::v1::span::Event;
2425use opentelemetry_proto:: tonic:: trace:: v1:: span:: Link ;
2526use serde_json:: { Map , Value } ;
2627
28+ use crate :: otel:: otel_utils:: flatten_attributes;
29+
2730use super :: otel_utils:: convert_epoch_nano_to_timestamp;
2831use super :: otel_utils:: insert_attributes;
2932
@@ -197,7 +200,7 @@ fn flatten_events(events: &[Event], span_start_time_unix_nano: u64) -> Vec<Map<S
197200 ) ,
198201 ) ;
199202
200- insert_attributes ( & mut event_json, & event. attributes ) ;
203+ insert_events_attributes ( & mut event_json, & event. attributes ) ;
201204 event_json. insert (
202205 "event_dropped_attributes_count" . to_string ( ) ,
203206 Value :: Number ( event. dropped_attributes_count . into ( ) ) ,
@@ -224,7 +227,7 @@ fn flatten_links(links: &[Link]) -> Vec<Map<String, Value>> {
224227 Value :: String ( hex:: encode ( & link. trace_id ) ) ,
225228 ) ;
226229
227- insert_attributes ( & mut link_json, & link. attributes ) ;
230+ insert_links_attributes ( & mut link_json, & link. attributes ) ;
228231 link_json. insert (
229232 "link_dropped_attributes_count" . to_string ( ) ,
230233 Value :: Number ( link. dropped_attributes_count . into ( ) ) ,
@@ -397,6 +400,20 @@ fn flatten_span_record(span_record: &Span) -> Vec<Map<String, Value>> {
397400 span_records_json
398401}
399402
403+ pub fn insert_events_attributes ( map : & mut Map < String , Value > , attributes : & [ KeyValue ] ) {
404+ let attributes_json = flatten_attributes ( attributes) ;
405+ for ( key, value) in attributes_json {
406+ map. insert ( format ! ( "event_{}" , key) , value) ;
407+ }
408+ }
409+
410+ pub fn insert_links_attributes ( map : & mut Map < String , Value > , attributes : & [ KeyValue ] ) {
411+ let attributes_json = flatten_attributes ( attributes) ;
412+ for ( key, value) in attributes_json {
413+ map. insert ( format ! ( "link_{}" , key) , value) ;
414+ }
415+ }
416+
400417#[ cfg( test) ]
401418mod tests {
402419 use super :: * ;
0 commit comments