@@ -192,7 +192,10 @@ pub mod tonic {
192
192
. into_iter ( )
193
193
. map ( |( instrumentation, span_records) | ScopeSpans {
194
194
scope : Some ( ( instrumentation, None ) . into ( ) ) ,
195
- schema_url : resource. schema_url . clone ( ) . unwrap_or_default ( ) ,
195
+ schema_url : instrumentation
196
+ . schema_url ( )
197
+ . map ( ToOwned :: to_owned)
198
+ . unwrap_or_default ( ) ,
196
199
spans : span_records
197
200
. into_iter ( )
198
201
. map ( |span_data| span_data. clone ( ) . into ( ) )
@@ -470,4 +473,51 @@ mod tests {
470
473
span_data3. span_context. trace_id( ) . to_bytes( ) . to_vec( )
471
474
) ;
472
475
}
476
+
477
+ #[ test]
478
+ fn test_scope_spans_uses_instrumentation_schema_url_not_resource ( ) {
479
+ let resource = Resource :: builder_empty ( )
480
+ . with_schema_url ( vec ! [ ] , "http://resource-schema" )
481
+ . build ( ) ;
482
+
483
+ let instrumentation_scope = InstrumentationScope :: builder ( "test-lib" )
484
+ . with_schema_url ( "http://instrumentation-schema" )
485
+ . build ( ) ;
486
+
487
+ let span_data = SpanData {
488
+ span_context : SpanContext :: new (
489
+ TraceId :: from ( 123 ) ,
490
+ SpanId :: from ( 456 ) ,
491
+ TraceFlags :: default ( ) ,
492
+ false ,
493
+ TraceState :: default ( ) ,
494
+ ) ,
495
+ parent_span_id : SpanId :: from ( 0 ) ,
496
+ parent_span_is_remote : false ,
497
+ span_kind : SpanKind :: Internal ,
498
+ name : Cow :: Borrowed ( "test_span" ) ,
499
+ start_time : now ( ) ,
500
+ end_time : now ( ) + Duration :: from_secs ( 1 ) ,
501
+ attributes : vec ! [ ] ,
502
+ dropped_attributes_count : 0 ,
503
+ events : SpanEvents :: default ( ) ,
504
+ links : SpanLinks :: default ( ) ,
505
+ status : Status :: Unset ,
506
+ instrumentation_scope,
507
+ } ;
508
+
509
+ let resource: ResourceAttributesWithSchema = ( & resource) . into ( ) ;
510
+ let grouped_spans = crate :: transform:: trace:: tonic:: group_spans_by_resource_and_scope (
511
+ vec ! [ span_data] ,
512
+ & resource,
513
+ ) ;
514
+
515
+ assert_eq ! ( grouped_spans. len( ) , 1 ) ;
516
+ let resource_spans = & grouped_spans[ 0 ] ;
517
+ assert_eq ! ( resource_spans. schema_url, "http://resource-schema" ) ;
518
+
519
+ let scope_spans = & resource_spans. scope_spans ;
520
+ assert_eq ! ( scope_spans. len( ) , 1 ) ;
521
+ assert_eq ! ( scope_spans[ 0 ] . schema_url, "http://instrumentation-schema" ) ;
522
+ }
473
523
}
0 commit comments