@@ -388,6 +388,152 @@ func TestElasticTransactionEnrich(t *testing.T) {
388388 }
389389}
390390
391+ // Tests root spans that represent a dependency and are mapped to a transaction.
392+ func TestRootSpanAsDependencyEnrich (t * testing.T ) {
393+ for _ , tc := range []struct {
394+ name string
395+ input ptrace.Span
396+ config config.Config
397+ enrichedAttrs map [string ]any
398+ expectedSpanLinks * ptrace.SpanLinkSlice
399+ }{
400+ {
401+ name : "outgoing_http_root_span" ,
402+ input : func () ptrace.Span {
403+ span := ptrace .NewSpan ()
404+ span .SetName ("rootClientSpan" )
405+ span .SetSpanID ([8 ]byte {1 })
406+ span .SetKind (ptrace .SpanKindClient )
407+ span .Attributes ().PutStr (semconv27 .AttributeHTTPRequestMethod , "GET" )
408+ span .Attributes ().PutStr (semconv27 .AttributeURLFull , "http://localhost:8080" )
409+ span .Attributes ().PutInt (semconv27 .AttributeHTTPResponseStatusCode , 200 )
410+ span .Attributes ().PutStr (semconv27 .AttributeNetworkProtocolVersion , "1.1" )
411+ return span
412+ }(),
413+ config : config .Enabled (),
414+ enrichedAttrs : map [string ]any {
415+ elasticattr .TimestampUs : int64 (0 ),
416+ elasticattr .TransactionName : "rootClientSpan" ,
417+ elasticattr .ProcessorEvent : "transaction" ,
418+ elasticattr .SpanType : "external" ,
419+ elasticattr .SpanSubtype : "http" ,
420+ elasticattr .SpanDestinationServiceResource : "localhost:8080" ,
421+ elasticattr .SpanName : "rootClientSpan" ,
422+ elasticattr .EventOutcome : "success" ,
423+ elasticattr .SuccessCount : int64 (1 ),
424+ elasticattr .ServiceTargetName : "localhost:8080" ,
425+ elasticattr .ServiceTargetType : "http" ,
426+ elasticattr .TransactionID : "0100000000000000" ,
427+ elasticattr .TransactionDurationUs : int64 (0 ),
428+ elasticattr .TransactionRepresentativeCount : float64 (1 ),
429+ elasticattr .TransactionResult : "HTTP 2xx" ,
430+ elasticattr .TransactionType : "external.http" ,
431+ elasticattr .TransactionSampled : true ,
432+ elasticattr .TransactionRoot : true ,
433+ elasticattr .SpanDurationUs : int64 (0 ),
434+ elasticattr .SpanRepresentativeCount : float64 (1 ),
435+ },
436+ },
437+ {
438+ name : "db_root_span" ,
439+ input : func () ptrace.Span {
440+ span := ptrace .NewSpan ()
441+ span .SetName ("rootClientSpan" )
442+ span .SetSpanID ([8 ]byte {1 })
443+ span .SetKind (ptrace .SpanKindClient )
444+ span .Attributes ().PutStr (semconv25 .AttributeDBSystem , "mssql" )
445+
446+ span .Attributes ().PutStr (semconv25 .AttributeDBName , "myDb" )
447+ span .Attributes ().PutStr (semconv25 .AttributeDBOperation , "SELECT" )
448+ span .Attributes ().PutStr (semconv25 .AttributeDBStatement , "SELECT * FROM wuser_table" )
449+ return span
450+ }(),
451+ config : config .Enabled (),
452+ enrichedAttrs : map [string ]any {
453+ elasticattr .TimestampUs : int64 (0 ),
454+ elasticattr .TransactionName : "rootClientSpan" ,
455+ elasticattr .ProcessorEvent : "transaction" ,
456+ elasticattr .SpanType : "db" ,
457+ elasticattr .SpanSubtype : "mssql" ,
458+ elasticattr .SpanDestinationServiceResource : "mssql" ,
459+ elasticattr .SpanName : "rootClientSpan" ,
460+ elasticattr .EventOutcome : "success" ,
461+ elasticattr .SuccessCount : int64 (1 ),
462+ elasticattr .ServiceTargetName : "myDb" ,
463+ elasticattr .ServiceTargetType : "mssql" ,
464+ elasticattr .TransactionID : "0100000000000000" ,
465+ elasticattr .TransactionDurationUs : int64 (0 ),
466+ elasticattr .TransactionRepresentativeCount : float64 (1 ),
467+ elasticattr .TransactionResult : "Success" ,
468+ elasticattr .TransactionType : "db.mssql" ,
469+ elasticattr .TransactionSampled : true ,
470+ elasticattr .TransactionRoot : true ,
471+ elasticattr .SpanDurationUs : int64 (0 ),
472+ elasticattr .SpanRepresentativeCount : float64 (1 ),
473+ },
474+ },
475+ {
476+ name : "producer_messaging_span" ,
477+ input : func () ptrace.Span {
478+ span := ptrace .NewSpan ()
479+ span .SetName ("rootClientSpan" )
480+ span .SetSpanID ([8 ]byte {1 })
481+ span .SetKind (ptrace .SpanKindProducer )
482+
483+ span .Attributes ().PutStr (semconv25 .AttributeServerAddress , "myServer" )
484+ span .Attributes ().PutStr (semconv25 .AttributeServerPort , "1234" )
485+ span .Attributes ().PutStr (semconv25 .AttributeMessagingSystem , "rabbitmq" )
486+ span .Attributes ().PutStr (semconv25 .AttributeMessagingDestinationName , "T" )
487+ span .Attributes ().PutStr (semconv25 .AttributeMessagingOperation , "publish" )
488+ span .Attributes ().PutStr (semconv25 .AttributeMessagingClientID , "a" )
489+ return span
490+ }(),
491+ config : config .Enabled (),
492+ enrichedAttrs : map [string ]any {
493+ elasticattr .TimestampUs : int64 (0 ),
494+ elasticattr .TransactionName : "rootClientSpan" ,
495+ elasticattr .ProcessorEvent : "transaction" ,
496+ elasticattr .SpanType : "messaging" ,
497+ elasticattr .SpanSubtype : "rabbitmq" ,
498+ elasticattr .SpanDestinationServiceResource : "rabbitmq/T" ,
499+ elasticattr .SpanName : "rootClientSpan" ,
500+ elasticattr .EventOutcome : "success" ,
501+ elasticattr .SuccessCount : int64 (1 ),
502+ elasticattr .ServiceTargetName : "T" ,
503+ elasticattr .ServiceTargetType : "rabbitmq" ,
504+ elasticattr .TransactionID : "0100000000000000" ,
505+ elasticattr .TransactionDurationUs : int64 (0 ),
506+ elasticattr .TransactionRepresentativeCount : float64 (1 ),
507+ elasticattr .TransactionResult : "Success" ,
508+ elasticattr .TransactionType : "messaging.rabbitmq" ,
509+ elasticattr .TransactionSampled : true ,
510+ elasticattr .TransactionRoot : true ,
511+ elasticattr .SpanDurationUs : int64 (0 ),
512+ elasticattr .SpanRepresentativeCount : float64 (1 ),
513+ },
514+ },
515+ } {
516+ t .Run (tc .name , func (t * testing.T ) {
517+ expectedSpan := ptrace .NewSpan ()
518+ tc .input .CopyTo (expectedSpan )
519+
520+ // Merge with the expected attributes and override the span links.
521+ for k , v := range tc .enrichedAttrs {
522+ expectedSpan .Attributes ().PutEmpty (k ).FromRaw (v )
523+ }
524+ // Override span links
525+ if tc .expectedSpanLinks != nil {
526+ tc .expectedSpanLinks .CopyTo (expectedSpan .Links ())
527+ } else {
528+ expectedSpan .Links ().RemoveIf (func (_ ptrace.SpanLink ) bool { return true })
529+ }
530+
531+ EnrichSpan (tc .input , tc .config )
532+ assert .NoError (t , ptracetest .CompareSpan (expectedSpan , tc .input ))
533+ })
534+ }
535+ }
536+
391537// Tests the enrichment logic for elastic's span definition.
392538func TestElasticSpanEnrich (t * testing.T ) {
393539 now := time .Unix (3600 , 0 )
0 commit comments