@@ -336,7 +336,6 @@ fn flatten_span_record(span_record: &Span) -> Vec<Map<String, Value>> {
336
336
span_records_json
337
337
}
338
338
339
-
340
339
#[ cfg( test) ]
341
340
mod tests {
342
341
use super :: * ;
@@ -360,13 +359,21 @@ mod tests {
360
359
KeyValue {
361
360
key: "service.name" . to_string( ) ,
362
361
value: Some ( AnyValue {
363
- value: Some ( opentelemetry_proto:: tonic:: common:: v1:: any_value:: Value :: StringValue ( "test-service" . to_string( ) ) ) ,
362
+ value: Some (
363
+ opentelemetry_proto:: tonic:: common:: v1:: any_value:: Value :: StringValue (
364
+ "test-service" . to_string( ) ,
365
+ ) ,
366
+ ) ,
364
367
} ) ,
365
368
} ,
366
369
KeyValue {
367
370
key: "http.method" . to_string( ) ,
368
371
value: Some ( AnyValue {
369
- value: Some ( opentelemetry_proto:: tonic:: common:: v1:: any_value:: Value :: StringValue ( "GET" . to_string( ) ) ) ,
372
+ value: Some (
373
+ opentelemetry_proto:: tonic:: common:: v1:: any_value:: Value :: StringValue (
374
+ "GET" . to_string( ) ,
375
+ ) ,
376
+ ) ,
370
377
} ) ,
371
378
} ,
372
379
]
@@ -398,7 +405,8 @@ mod tests {
398
405
assert_eq ! (
399
406
result. get( "span_status_description" ) . unwrap( ) ,
400
407
& Value :: String ( expected_description. to_string( ) ) ,
401
- "Status description should match expected value for code {}" , code
408
+ "Status description should match expected value for code {}" ,
409
+ code
402
410
) ;
403
411
assert_eq ! (
404
412
result. get( "span_status_message" ) . unwrap( ) ,
@@ -432,7 +440,8 @@ mod tests {
432
440
assert_eq ! (
433
441
result. get( "span_kind_description" ) . unwrap( ) ,
434
442
& Value :: String ( expected_description. to_string( ) ) ,
435
- "Span kind description should match expected value for kind {}" , kind
443
+ "Span kind description should match expected value for kind {}" ,
444
+ kind
436
445
) ;
437
446
}
438
447
}
@@ -459,7 +468,8 @@ mod tests {
459
468
assert_eq ! (
460
469
result. get( "span_flags_description" ) . unwrap( ) ,
461
470
& Value :: String ( expected_description. to_string( ) ) ,
462
- "Span flags description should match expected value for flags {}" , flags
471
+ "Span flags description should match expected value for flags {}" ,
472
+ flags
463
473
) ;
464
474
}
465
475
}
@@ -488,7 +498,10 @@ mod tests {
488
498
489
499
// Check first event
490
500
let first_event = & result[ 0 ] ;
491
- assert ! ( first_event. contains_key( "event_time_unix_nano" ) , "Should contain timestamp" ) ;
501
+ assert ! (
502
+ first_event. contains_key( "event_time_unix_nano" ) ,
503
+ "Should contain timestamp"
504
+ ) ;
492
505
assert_eq ! (
493
506
first_event. get( "event_name" ) . unwrap( ) ,
494
507
& Value :: String ( "request.start" . to_string( ) ) ,
@@ -499,7 +512,10 @@ mod tests {
499
512
& Value :: Number ( 2 . into( ) ) ,
500
513
"Dropped attributes count should be preserved"
501
514
) ;
502
- assert ! ( first_event. contains_key( "service.name" ) , "Should contain flattened attributes" ) ;
515
+ assert ! (
516
+ first_event. contains_key( "service.name" ) ,
517
+ "Should contain flattened attributes"
518
+ ) ;
503
519
504
520
// Check second event
505
521
let second_event = & result[ 1 ] ;
@@ -518,16 +534,14 @@ mod tests {
518
534
#[ test]
519
535
fn test_flatten_links_structure ( ) {
520
536
// Test that links are properly flattened with all expected fields
521
- let links = vec ! [
522
- Link {
523
- trace_id: sample_trace_id( ) ,
524
- span_id: sample_span_id( ) ,
525
- trace_state: "state1" . to_string( ) ,
526
- attributes: sample_attributes( ) ,
527
- dropped_attributes_count: 1 ,
528
- flags: 0 ,
529
- } ,
530
- ] ;
537
+ let links = vec ! [ Link {
538
+ trace_id: sample_trace_id( ) ,
539
+ span_id: sample_span_id( ) ,
540
+ trace_state: "state1" . to_string( ) ,
541
+ attributes: sample_attributes( ) ,
542
+ dropped_attributes_count: 1 ,
543
+ flags: 0 ,
544
+ } ] ;
531
545
532
546
let result = flatten_links ( & links) ;
533
547
@@ -549,7 +563,10 @@ mod tests {
549
563
& Value :: Number ( 1 . into( ) ) ,
550
564
"Dropped attributes count should be preserved"
551
565
) ;
552
- assert ! ( link. contains_key( "service.name" ) , "Should contain flattened attributes" ) ;
566
+ assert ! (
567
+ link. contains_key( "service.name" ) ,
568
+ "Should contain flattened attributes"
569
+ ) ;
553
570
}
554
571
555
572
#[ test]
@@ -611,12 +628,30 @@ mod tests {
611
628
& Value :: String ( "SPAN_KIND_SERVER" . to_string( ) ) ,
612
629
"All records should contain span kind description"
613
630
) ;
614
- assert ! ( record. contains_key( "span_trace_id" ) , "Should contain trace ID" ) ;
615
- assert ! ( record. contains_key( "span_span_id" ) , "Should contain span ID" ) ;
616
- assert ! ( record. contains_key( "span_start_time_unix_nano" ) , "Should contain start time" ) ;
617
- assert ! ( record. contains_key( "span_end_time_unix_nano" ) , "Should contain end time" ) ;
618
- assert ! ( record. contains_key( "service.name" ) , "Should contain span attributes" ) ;
619
- assert ! ( record. contains_key( "span_status_code" ) , "Should contain status" ) ;
631
+ assert ! (
632
+ record. contains_key( "span_trace_id" ) ,
633
+ "Should contain trace ID"
634
+ ) ;
635
+ assert ! (
636
+ record. contains_key( "span_span_id" ) ,
637
+ "Should contain span ID"
638
+ ) ;
639
+ assert ! (
640
+ record. contains_key( "span_start_time_unix_nano" ) ,
641
+ "Should contain start time"
642
+ ) ;
643
+ assert ! (
644
+ record. contains_key( "span_end_time_unix_nano" ) ,
645
+ "Should contain end time"
646
+ ) ;
647
+ assert ! (
648
+ record. contains_key( "service.name" ) ,
649
+ "Should contain span attributes"
650
+ ) ;
651
+ assert ! (
652
+ record. contains_key( "span_status_code" ) ,
653
+ "Should contain status"
654
+ ) ;
620
655
}
621
656
622
657
// One record should be an event, one should be a link
@@ -650,17 +685,30 @@ mod tests {
650
685
651
686
let result = flatten_span_record ( & span) ;
652
687
653
- assert_eq ! ( result. len( ) , 1 , "Should have exactly one record for span without events/links" ) ;
688
+ assert_eq ! (
689
+ result. len( ) ,
690
+ 1 ,
691
+ "Should have exactly one record for span without events/links"
692
+ ) ;
654
693
655
694
let record = & result[ 0 ] ;
656
695
assert_eq ! (
657
696
record. get( "span_name" ) . unwrap( ) ,
658
697
& Value :: String ( "simple-span" . to_string( ) ) ,
659
698
"Should contain span name"
660
699
) ;
661
- assert ! ( !record. contains_key( "event_name" ) , "Should not contain event fields" ) ;
662
- assert ! ( !record. contains_key( "link_trace_id" ) , "Should not contain link fields" ) ;
663
- assert ! ( !record. contains_key( "span_status_code" ) , "Should not contain status when none provided" ) ;
700
+ assert ! (
701
+ !record. contains_key( "event_name" ) ,
702
+ "Should not contain event fields"
703
+ ) ;
704
+ assert ! (
705
+ !record. contains_key( "link_trace_id" ) ,
706
+ "Should not contain link fields"
707
+ ) ;
708
+ assert ! (
709
+ !record. contains_key( "span_status_code" ) ,
710
+ "Should not contain status when none provided"
711
+ ) ;
664
712
}
665
713
666
714
#[ test]
@@ -705,10 +753,16 @@ mod tests {
705
753
assert_eq ! ( hex_span_id, "12345678" , "Span ID should be lowercase hex" ) ;
706
754
}
707
755
if let Some ( Value :: String ( hex_parent_span_id) ) = record. get ( "span_parent_span_id" ) {
708
- assert_eq ! ( hex_parent_span_id, "87654321" , "Parent span ID should be lowercase hex" ) ;
756
+ assert_eq ! (
757
+ hex_parent_span_id, "87654321" ,
758
+ "Parent span ID should be lowercase hex"
759
+ ) ;
709
760
}
710
761
if let Some ( Value :: String ( link_trace_id) ) = record. get ( "link_trace_id" ) {
711
- assert_eq ! ( link_trace_id, "ffabcdef" , "Link trace ID should be lowercase hex" ) ;
762
+ assert_eq ! (
763
+ link_trace_id, "ffabcdef" ,
764
+ "Link trace ID should be lowercase hex"
765
+ ) ;
712
766
}
713
767
}
714
768
}
@@ -823,15 +877,36 @@ mod tests {
823
877
fn test_known_field_list_completeness ( ) {
824
878
// Test that the OTEL_TRACES_KNOWN_FIELD_LIST contains all expected fields
825
879
let expected_fields = [
826
- "scope_name" , "scope_version" , "scope_schema_url" , "scope_dropped_attributes_count" ,
827
- "resource_schema_url" , "resource_dropped_attributes_count" ,
828
- "span_trace_id" , "span_span_id" , "span_name" , "span_parent_span_id" , "name" ,
829
- "span_kind" , "span_kind_description" , "span_start_time_unix_nano" , "span_end_time_unix_nano" ,
830
- "event_name" , "event_time_unix_nano" , "event_dropped_attributes_count" ,
831
- "link_span_id" , "link_trace_id" , "link_dropped_attributes_count" ,
832
- "span_dropped_events_count" , "span_dropped_links_count" , "span_dropped_attributes_count" ,
833
- "span_trace_state" , "span_flags" , "span_flags_description" ,
834
- "span_status_code" , "span_status_description" , "span_status_message" ,
880
+ "scope_name" ,
881
+ "scope_version" ,
882
+ "scope_schema_url" ,
883
+ "scope_dropped_attributes_count" ,
884
+ "resource_schema_url" ,
885
+ "resource_dropped_attributes_count" ,
886
+ "span_trace_id" ,
887
+ "span_span_id" ,
888
+ "span_name" ,
889
+ "span_parent_span_id" ,
890
+ "name" ,
891
+ "span_kind" ,
892
+ "span_kind_description" ,
893
+ "span_start_time_unix_nano" ,
894
+ "span_end_time_unix_nano" ,
895
+ "event_name" ,
896
+ "event_time_unix_nano" ,
897
+ "event_dropped_attributes_count" ,
898
+ "link_span_id" ,
899
+ "link_trace_id" ,
900
+ "link_dropped_attributes_count" ,
901
+ "span_dropped_events_count" ,
902
+ "span_dropped_links_count" ,
903
+ "span_dropped_attributes_count" ,
904
+ "span_trace_state" ,
905
+ "span_flags" ,
906
+ "span_flags_description" ,
907
+ "span_status_code" ,
908
+ "span_status_description" ,
909
+ "span_status_message" ,
835
910
] ;
836
911
837
912
assert_eq ! (
0 commit comments