1
1
use crate :: { OtelData , PreSampledTracer } ;
2
2
use once_cell:: unsync;
3
3
use opentelemetry:: {
4
- trace:: { self as otel, noop, OrderMap , TraceContextExt } ,
4
+ trace:: { self as otel, noop, TraceContextExt } ,
5
5
Context as OtelContext , Key , KeyValue , StringValue , Value ,
6
6
} ;
7
7
use std:: any:: TypeId ;
@@ -290,21 +290,21 @@ impl<'a, 'b> field::Visit for SpanEventVisitor<'a, 'b> {
290
290
if self . sem_conv_config . error_records_to_exceptions {
291
291
if let Some ( span) = & mut self . span_builder {
292
292
if let Some ( attrs) = span. attributes . as_mut ( ) {
293
- attrs. insert (
294
- Key :: new ( FIELD_EXCEPTION_MESSAGE ) ,
293
+ attrs. push ( KeyValue :: new (
294
+ FIELD_EXCEPTION_MESSAGE ,
295
295
Value :: String ( error_msg. clone ( ) . into ( ) ) ,
296
- ) ;
296
+ ) ) ;
297
297
298
298
// NOTE: This is actually not the stacktrace of the exception. This is
299
299
// the "source chain". It represents the heirarchy of errors from the
300
300
// app level to the lowest level such as IO. It does not represent all
301
301
// of the callsites in the code that led to the error happening.
302
302
// `std::error::Error::backtrace` is a nightly-only API and cannot be
303
303
// used here until the feature is stabilized.
304
- attrs. insert (
305
- Key :: new ( FIELD_EXCEPTION_STACKTRACE ) ,
304
+ attrs. push ( KeyValue :: new (
305
+ FIELD_EXCEPTION_STACKTRACE ,
306
306
Value :: Array ( chain. clone ( ) . into ( ) ) ,
307
- ) ;
307
+ ) ) ;
308
308
}
309
309
}
310
310
}
@@ -362,7 +362,7 @@ impl<'a> SpanAttributeVisitor<'a> {
362
362
fn record ( & mut self , attribute : KeyValue ) {
363
363
debug_assert ! ( self . span_builder. attributes. is_some( ) ) ;
364
364
if let Some ( v) = self . span_builder . attributes . as_mut ( ) {
365
- v. insert ( attribute. key , attribute. value ) ;
365
+ v. push ( KeyValue :: new ( attribute. key , attribute. value ) ) ;
366
366
}
367
367
}
368
368
}
@@ -859,34 +859,34 @@ where
859
859
builder. trace_id = Some ( self . tracer . new_trace_id ( ) ) ;
860
860
}
861
861
862
- let builder_attrs = builder. attributes . get_or_insert ( OrderMap :: with_capacity (
862
+ let builder_attrs = builder. attributes . get_or_insert ( Vec :: with_capacity (
863
863
attrs. fields ( ) . len ( ) + self . extra_span_attrs ( ) ,
864
864
) ) ;
865
865
866
866
if self . location {
867
867
let meta = attrs. metadata ( ) ;
868
868
869
869
if let Some ( filename) = meta. file ( ) {
870
- builder_attrs. insert ( "code.filepath" . into ( ) , filename. into ( ) ) ;
870
+ builder_attrs. push ( KeyValue :: new ( "code.filepath" , filename) ) ;
871
871
}
872
872
873
873
if let Some ( module) = meta. module_path ( ) {
874
- builder_attrs. insert ( "code.namespace" . into ( ) , module. into ( ) ) ;
874
+ builder_attrs. push ( KeyValue :: new ( "code.namespace" , module) ) ;
875
875
}
876
876
877
877
if let Some ( line) = meta. line ( ) {
878
- builder_attrs. insert ( "code.lineno" . into ( ) , ( line as i64 ) . into ( ) ) ;
878
+ builder_attrs. push ( KeyValue :: new ( "code.lineno" , line as i64 ) ) ;
879
879
}
880
880
}
881
881
882
882
if self . with_threads {
883
- THREAD_ID . with ( |id| builder_attrs. insert ( "thread.id" . into ( ) , ( * * id as i64 ) . into ( ) ) ) ;
883
+ THREAD_ID . with ( |id| builder_attrs. push ( KeyValue :: new ( "thread.id" , * * id as i64 ) ) ) ;
884
884
if let Some ( name) = std:: thread:: current ( ) . name ( ) {
885
885
// TODO(eliza): it's a bummer that we have to allocate here, but
886
886
// we can't easily get the string as a `static`. it would be
887
887
// nice if `opentelemetry` could also take `Arc<str>`s as
888
888
// `String` values...
889
- builder_attrs. insert ( "thread.name" . into ( ) , name. to_owned ( ) . into ( ) ) ;
889
+ builder_attrs. push ( KeyValue :: new ( "thread.name" , name. to_string ( ) ) ) ;
890
890
}
891
891
}
892
892
@@ -1090,9 +1090,9 @@ where
1090
1090
1091
1091
let attributes = builder
1092
1092
. attributes
1093
- . get_or_insert_with ( || OrderMap :: with_capacity ( 2 ) ) ;
1094
- attributes. insert ( busy_ns, timings. busy . into ( ) ) ;
1095
- attributes. insert ( idle_ns, timings. idle . into ( ) ) ;
1093
+ . get_or_insert_with ( || Vec :: with_capacity ( 2 ) ) ;
1094
+ attributes. push ( KeyValue :: new ( busy_ns, timings. busy ) ) ;
1095
+ attributes. push ( KeyValue :: new ( idle_ns, timings. idle ) ) ;
1096
1096
}
1097
1097
}
1098
1098
@@ -1168,7 +1168,7 @@ mod tests {
1168
1168
where
1169
1169
T : Into < Cow < ' static , str > > ,
1170
1170
{
1171
- noop:: NoopSpan :: new ( )
1171
+ noop:: NoopSpan :: DEFAULT
1172
1172
}
1173
1173
fn span_builder < T > ( & self , name : T ) -> otel:: SpanBuilder
1174
1174
where
@@ -1185,7 +1185,7 @@ mod tests {
1185
1185
builder,
1186
1186
parent_cx : parent_cx. clone ( ) ,
1187
1187
} ) ;
1188
- noop:: NoopSpan :: new ( )
1188
+ noop:: NoopSpan :: DEFAULT
1189
1189
}
1190
1190
}
1191
1191
@@ -1369,7 +1369,7 @@ mod tests {
1369
1369
let attributes = tracer. with_data ( |data| data. builder . attributes . as_ref ( ) . unwrap ( ) . clone ( ) ) ;
1370
1370
let keys = attributes
1371
1371
. iter ( )
1372
- . map ( |( key , _ ) | key. as_str ( ) )
1372
+ . map ( |kv| kv . key . as_str ( ) )
1373
1373
. collect :: < Vec < & str > > ( ) ;
1374
1374
assert ! ( keys. contains( & "idle_ns" ) ) ;
1375
1375
assert ! ( keys. contains( & "busy_ns" ) ) ;
@@ -1405,7 +1405,7 @@ mod tests {
1405
1405
1406
1406
let key_values = attributes
1407
1407
. into_iter ( )
1408
- . map ( |( key , value ) | ( key. as_str ( ) . to_owned ( ) , value) )
1408
+ . map ( |kv | ( kv . key . as_str ( ) . to_owned ( ) , kv . value ) )
1409
1409
. collect :: < HashMap < _ , _ > > ( ) ;
1410
1410
1411
1411
assert_eq ! ( key_values[ "error" ] . as_str( ) , "user error" ) ;
@@ -1467,7 +1467,7 @@ mod tests {
1467
1467
1468
1468
let key_values = attributes
1469
1469
. into_iter ( )
1470
- . map ( |( key , value ) | ( key. as_str ( ) . to_owned ( ) , value) )
1470
+ . map ( |kv | ( kv . key . as_str ( ) . to_owned ( ) , kv . value ) )
1471
1471
. collect :: < HashMap < _ , _ > > ( ) ;
1472
1472
1473
1473
assert_eq ! ( key_values[ "error" ] . as_str( ) , "user error" ) ;
@@ -1508,7 +1508,7 @@ mod tests {
1508
1508
let attributes = tracer. with_data ( |data| data. builder . attributes . as_ref ( ) . unwrap ( ) . clone ( ) ) ;
1509
1509
let keys = attributes
1510
1510
. iter ( )
1511
- . map ( |( key , _ ) | key. as_str ( ) )
1511
+ . map ( |kv| kv . key . as_str ( ) )
1512
1512
. collect :: < Vec < & str > > ( ) ;
1513
1513
assert ! ( keys. contains( & "code.filepath" ) ) ;
1514
1514
assert ! ( keys. contains( & "code.namespace" ) ) ;
@@ -1528,7 +1528,7 @@ mod tests {
1528
1528
let attributes = tracer. with_data ( |data| data. builder . attributes . as_ref ( ) . unwrap ( ) . clone ( ) ) ;
1529
1529
let keys = attributes
1530
1530
. iter ( )
1531
- . map ( |( key , _ ) | key. as_str ( ) )
1531
+ . map ( |kv| kv . key . as_str ( ) )
1532
1532
. collect :: < Vec < & str > > ( ) ;
1533
1533
assert ! ( !keys. contains( & "code.filepath" ) ) ;
1534
1534
assert ! ( !keys. contains( & "code.namespace" ) ) ;
@@ -1554,7 +1554,7 @@ mod tests {
1554
1554
let attributes = tracer
1555
1555
. with_data ( |data| data. builder . attributes . as_ref ( ) . unwrap ( ) . clone ( ) )
1556
1556
. drain ( ..)
1557
- . map ( |( key , value ) | ( key. as_str ( ) . to_string ( ) , value) )
1557
+ . map ( |kv | ( kv . key . as_str ( ) . to_string ( ) , kv . value ) )
1558
1558
. collect :: < HashMap < _ , _ > > ( ) ;
1559
1559
assert_eq ! ( attributes. get( "thread.name" ) , expected_name. as_ref( ) ) ;
1560
1560
assert_eq ! ( attributes. get( "thread.id" ) , Some ( & expected_id) ) ;
@@ -1573,7 +1573,7 @@ mod tests {
1573
1573
let attributes = tracer. with_data ( |data| data. builder . attributes . as_ref ( ) . unwrap ( ) . clone ( ) ) ;
1574
1574
let keys = attributes
1575
1575
. iter ( )
1576
- . map ( |( key , _ ) | key. as_str ( ) )
1576
+ . map ( |kv| kv . key . as_str ( ) )
1577
1577
. collect :: < Vec < & str > > ( ) ;
1578
1578
assert ! ( !keys. contains( & "thread.name" ) ) ;
1579
1579
assert ! ( !keys. contains( & "thread.id" ) ) ;
@@ -1611,7 +1611,7 @@ mod tests {
1611
1611
1612
1612
let key_values = attributes
1613
1613
. into_iter ( )
1614
- . map ( |( key , value ) | ( key. as_str ( ) . to_owned ( ) , value) )
1614
+ . map ( |kv | ( kv . key . as_str ( ) . to_owned ( ) , kv . value ) )
1615
1615
. collect :: < HashMap < _ , _ > > ( ) ;
1616
1616
1617
1617
assert_eq ! ( key_values[ FIELD_EXCEPTION_MESSAGE ] . as_str( ) , "user error" ) ;
@@ -1663,7 +1663,7 @@ mod tests {
1663
1663
1664
1664
let key_values = attributes
1665
1665
. into_iter ( )
1666
- . map ( |( key , value ) | ( key. as_str ( ) . to_owned ( ) , value) )
1666
+ . map ( |kv | ( kv . key . as_str ( ) . to_owned ( ) , kv . value ) )
1667
1667
. collect :: < HashMap < _ , _ > > ( ) ;
1668
1668
1669
1669
assert_eq ! ( key_values[ FIELD_EXCEPTION_MESSAGE ] . as_str( ) , "user error" ) ;
0 commit comments