@@ -677,27 +677,37 @@ func TestMessagingTransaction(t *testing.T) {
677
677
}
678
678
679
679
func TestMessagingSpan (t * testing.T ) {
680
- event := transformSpanWithAttributes (t , map [string ]interface {}{
681
- "messaging.system" : "kafka" ,
682
- "messaging.destination" : "myTopic" ,
683
- "net.peer.ip" : "10.20.30.40" ,
684
- "net.peer.port" : 123 ,
685
- }, func (s ptrace.Span ) {
686
- s .SetKind (ptrace .SpanKindProducer )
687
- })
688
- assert .Equal (t , "messaging" , event .Span .Type )
689
- assert .Equal (t , "kafka" , event .Span .Subtype )
690
- assert .Equal (t , "send" , event .Span .Action )
691
- assert .Empty (t , event .Labels )
692
- assert .Equal (t , & modelpb.Destination {
693
- Address : "10.20.30.40" ,
694
- Port : 123 ,
695
- }, event .Destination )
696
- assert .Empty (t , cmp .Diff (& modelpb.DestinationService {
697
- Type : "messaging" ,
698
- Name : "kafka" ,
699
- Resource : "kafka/myTopic" ,
700
- }, event .Span .DestinationService , protocmp .Transform ()))
680
+ for _ , attr := range []map [string ]any {
681
+ {
682
+ "messaging.system" : "kafka" ,
683
+ "messaging.destination" : "myTopic" ,
684
+ "net.peer.ip" : "10.20.30.40" ,
685
+ "net.peer.port" : 123 ,
686
+ },
687
+ {
688
+ "messaging.system" : "kafka" ,
689
+ "messaging.destination.name" : "myTopic" ,
690
+ "net.peer.ip" : "10.20.30.40" ,
691
+ "net.peer.port" : 123 ,
692
+ },
693
+ } {
694
+ event := transformSpanWithAttributes (t , attr , func (s ptrace.Span ) {
695
+ s .SetKind (ptrace .SpanKindProducer )
696
+ })
697
+ assert .Equal (t , "messaging" , event .Span .Type )
698
+ assert .Equal (t , "kafka" , event .Span .Subtype )
699
+ assert .Equal (t , "send" , event .Span .Action )
700
+ assert .Empty (t , event .Labels )
701
+ assert .Equal (t , & modelpb.Destination {
702
+ Address : "10.20.30.40" ,
703
+ Port : 123 ,
704
+ }, event .Destination )
705
+ assert .Empty (t , cmp .Diff (& modelpb.DestinationService {
706
+ Type : "messaging" ,
707
+ Name : "kafka" ,
708
+ Resource : "kafka/myTopic" ,
709
+ }, event .Span .DestinationService , protocmp .Transform ()))
710
+ }
701
711
}
702
712
703
713
func TestMessagingSpan_DestinationResource (t * testing.T ) {
@@ -708,40 +718,66 @@ func TestMessagingSpan_DestinationResource(t *testing.T) {
708
718
assert .Empty (t , cmp .Diff (expectedDestinationService , event .Span .DestinationService , protocmp .Transform ()))
709
719
}
710
720
721
+ setAttr := func (t * testing.T , baseAttr map [string ]any , key string , val any ) map [string ]any {
722
+ t .Helper ()
723
+ newAttr := make (map [string ]any )
724
+ // Copy from the original map to the target map
725
+ for key , value := range baseAttr {
726
+ newAttr [key ] = value
727
+ }
728
+ newAttr [key ] = val
729
+ return newAttr
730
+ }
731
+
711
732
t .Run ("system_destination_peerservice_peeraddress" , func (t * testing.T ) {
712
- test (t , & modelpb.Destination {
713
- Address : "127.0.0.1" ,
714
- }, & modelpb.DestinationService {
715
- Type : "messaging" ,
716
- Name : "testsvc" ,
717
- Resource : "127.0.0.1/testtopic" ,
718
- }, map [string ]interface {}{
719
- "messaging.system" : "kafka" ,
720
- "messaging.destination" : "testtopic" ,
721
- "peer.service" : "testsvc" ,
722
- "peer.address" : "127.0.0.1" ,
723
- })
733
+ baseAttr := map [string ]any {
734
+ "messaging.system" : "kafka" ,
735
+ "peer.service" : "testsvc" ,
736
+ "peer.address" : "127.0.0.1" ,
737
+ }
738
+ for _ , attr := range []map [string ]any {
739
+ setAttr (t , baseAttr , "messaging.destination" , "testtopic" ),
740
+ setAttr (t , baseAttr , "messaging.destination.name" , "testtopic" ),
741
+ } {
742
+ test (t , & modelpb.Destination {
743
+ Address : "127.0.0.1" ,
744
+ }, & modelpb.DestinationService {
745
+ Type : "messaging" ,
746
+ Name : "testsvc" ,
747
+ Resource : "127.0.0.1/testtopic" ,
748
+ }, attr )
749
+ }
724
750
})
725
751
t .Run ("system_destination_peerservice" , func (t * testing.T ) {
726
- test (t , nil , & modelpb.DestinationService {
727
- Type : "messaging" ,
728
- Name : "testsvc" ,
729
- Resource : "testsvc/testtopic" ,
730
- }, map [string ]interface {}{
731
- "messaging.system" : "kafka" ,
732
- "messaging.destination" : "testtopic" ,
733
- "peer.service" : "testsvc" ,
734
- })
752
+ baseAttr := map [string ]any {
753
+ "messaging.system" : "kafka" ,
754
+ "peer.service" : "testsvc" ,
755
+ }
756
+ for _ , attr := range []map [string ]any {
757
+ setAttr (t , baseAttr , "messaging.destination" , "testtopic" ),
758
+ setAttr (t , baseAttr , "messaging.destination.name" , "testtopic" ),
759
+ } {
760
+ test (t , nil , & modelpb.DestinationService {
761
+ Type : "messaging" ,
762
+ Name : "testsvc" ,
763
+ Resource : "testsvc/testtopic" ,
764
+ }, attr )
765
+ }
735
766
})
736
767
t .Run ("system_destination" , func (t * testing.T ) {
737
- test (t , nil , & modelpb.DestinationService {
738
- Type : "messaging" ,
739
- Name : "kafka" ,
740
- Resource : "kafka/testtopic" ,
741
- }, map [string ]interface {}{
742
- "messaging.system" : "kafka" ,
743
- "messaging.destination" : "testtopic" ,
744
- })
768
+ baseAttr := map [string ]any {
769
+ "messaging.system" : "kafka" ,
770
+ }
771
+ for _ , attr := range []map [string ]any {
772
+ setAttr (t , baseAttr , "messaging.destination" , "testtopic" ),
773
+ setAttr (t , baseAttr , "messaging.destination.name" , "testtopic" ),
774
+ } {
775
+ test (t , nil , & modelpb.DestinationService {
776
+ Type : "messaging" ,
777
+ Name : "kafka" ,
778
+ Resource : "kafka/testtopic" ,
779
+ }, attr )
780
+ }
745
781
})
746
782
}
747
783
@@ -776,6 +812,9 @@ func TestTransactionTypePriorities(t *testing.T) {
776
812
777
813
attribs ["messaging.destination" ] = "foobar"
778
814
assert .Equal (t , "messaging" , transactionWithAttribs (attribs ).Transaction .Type )
815
+ delete (attribs , "messaging.destination" )
816
+ attribs ["messaging.destination.name" ] = "foobar"
817
+ assert .Equal (t , "messaging" , transactionWithAttribs (attribs ).Transaction .Type )
779
818
}
780
819
781
820
func TestSpanTypePriorities (t * testing.T ) {
@@ -797,6 +836,10 @@ func TestSpanTypePriorities(t *testing.T) {
797
836
attribs ["messaging.destination" ] = "foobar"
798
837
assert .Equal (t , "messaging" , spanWithAttribs (attribs ).Span .Type )
799
838
839
+ delete (attribs , "messaging.destination" )
840
+ attribs ["messaging.destination.name" ] = "foobar"
841
+ assert .Equal (t , "messaging" , spanWithAttribs (attribs ).Span .Type )
842
+
800
843
attribs ["db.statement" ] = "SELECT * FROM FOO"
801
844
assert .Equal (t , "db" , spanWithAttribs (attribs ).Span .Type )
802
845
}
@@ -1655,6 +1698,17 @@ func TestServiceTarget(t *testing.T) {
1655
1698
event := transformSpanWithAttributes (t , input )
1656
1699
assert .Empty (t , cmp .Diff (expected , event .Service .Target , protocmp .Transform ()))
1657
1700
}
1701
+
1702
+ setAttr := func (t * testing.T , baseAttr map [string ]any , key string , val any ) map [string ]any {
1703
+ t .Helper ()
1704
+ newAttr := make (map [string ]any )
1705
+ // Copy from the original map to the target map
1706
+ for key , value := range baseAttr {
1707
+ newAttr [key ] = value
1708
+ }
1709
+ newAttr [key ] = val
1710
+ return newAttr
1711
+ }
1658
1712
t .Run ("db_spans_with_peerservice_system" , func (t * testing.T ) {
1659
1713
test (t , & modelpb.ServiceTarget {
1660
1714
Type : "postgresql" ,
@@ -1762,35 +1816,48 @@ func TestServiceTarget(t *testing.T) {
1762
1816
})
1763
1817
1764
1818
t .Run ("messaging_spans_with_peerservice_system_destination" , func (t * testing.T ) {
1765
- test (t , & modelpb.ServiceTarget {
1766
- Name : "myTopic" ,
1767
- Type : "kafka" ,
1768
- }, map [string ]interface {}{
1769
- "peer.service" : "testsvc" ,
1770
- "messaging.system" : "kafka" ,
1771
- "messaging.destination" : "myTopic" ,
1772
- })
1819
+ baseAttr := map [string ]any {
1820
+ "peer.service" : "testsvc" ,
1821
+ "messaging.system" : "kafka" ,
1822
+ }
1823
+ for _ , attr := range []map [string ]any {
1824
+ setAttr (t , baseAttr , "messaging.destination" , "myTopic" ),
1825
+ setAttr (t , baseAttr , "messaging.destination.name" , "myTopic" ),
1826
+ } {
1827
+ test (t , & modelpb.ServiceTarget {
1828
+ Name : "myTopic" ,
1829
+ Type : "kafka" ,
1830
+ }, attr )
1831
+ }
1773
1832
})
1774
1833
1775
1834
t .Run ("messaging_spans_with_peerservice_system_destination_tempdestination" , func (t * testing.T ) {
1776
- test (t , & modelpb.ServiceTarget {
1777
- Name : "testsvc" ,
1778
- Type : "kafka" ,
1779
- }, map [string ]interface {}{
1835
+ baseAttr := map [string ]any {
1780
1836
"peer.service" : "testsvc" ,
1781
1837
"messaging.temp_destination" : true ,
1782
1838
"messaging.system" : "kafka" ,
1783
- "messaging.destination" : "myTopic" ,
1784
- })
1839
+ }
1840
+ for _ , attr := range []map [string ]any {
1841
+ setAttr (t , baseAttr , "messaging.destination" , "myTopic" ),
1842
+ setAttr (t , baseAttr , "messaging.destination.name" , "myTopic" ),
1843
+ } {
1844
+ test (t , & modelpb.ServiceTarget {
1845
+ Name : "testsvc" ,
1846
+ Type : "kafka" ,
1847
+ }, attr )
1848
+ }
1785
1849
})
1786
1850
1787
1851
t .Run ("messaging_spans_with_destination" , func (t * testing.T ) {
1788
- test (t , & modelpb.ServiceTarget {
1789
- Name : "myTopic" ,
1790
- Type : "messaging" ,
1791
- }, map [string ]interface {}{
1792
- "messaging.destination" : "myTopic" ,
1793
- })
1852
+ for _ , attr := range []map [string ]any {
1853
+ {"messaging.destination" : "myTopic" },
1854
+ {"messaging.destination.name" : "myTopic" },
1855
+ } {
1856
+ test (t , & modelpb.ServiceTarget {
1857
+ Name : "myTopic" ,
1858
+ Type : "messaging" ,
1859
+ }, attr )
1860
+ }
1794
1861
})
1795
1862
}
1796
1863
0 commit comments