@@ -891,6 +891,117 @@ func TestSegmentWith2LogGroupsFromConfig(t *testing.T) {
891
891
assert .Equal (t , cwl , segment .AWS .CWLogs )
892
892
}
893
893
894
+ func TestClientSpanWithAwsRemoteServiceName (t * testing.T ) {
895
+ spanName := "ABC.payment"
896
+ parentSpanID := newSegmentID ()
897
+ user := "testingT"
898
+ attributes := make (map [string ]interface {})
899
+ attributes [conventions .AttributeHTTPMethod ] = "POST"
900
+ attributes [conventions .AttributeHTTPScheme ] = "https"
901
+ attributes [conventions .AttributeHTTPHost ] = "payment.amazonaws.com"
902
+ attributes [conventions .AttributeHTTPTarget ] = "/"
903
+ attributes [conventions .AttributeRPCService ] = "ABC"
904
+ attributes [awsRemoteService ] = "PaymentService"
905
+
906
+ resource := constructDefaultResource ()
907
+ span := constructClientSpan (parentSpanID , spanName , 0 , "OK" , attributes )
908
+
909
+ segment , _ := MakeSegment (span , resource , nil , false , nil )
910
+ assert .Equal (t , "PaymentService" , * segment .Name )
911
+ assert .Equal (t , "subsegment" , * segment .Type )
912
+
913
+ jsonStr , err := MakeSegmentDocumentString (span , resource , nil , false , nil )
914
+
915
+ assert .NotNil (t , jsonStr )
916
+ assert .Nil (t , err )
917
+ assert .True (t , strings .Contains (jsonStr , "PaymentService" ))
918
+ assert .False (t , strings .Contains (jsonStr , user ))
919
+ assert .False (t , strings .Contains (jsonStr , "user" ))
920
+ }
921
+
922
+ func TestProducerSpanWithAwsRemoteServiceName (t * testing.T ) {
923
+ spanName := "ABC.payment"
924
+ parentSpanID := newSegmentID ()
925
+ user := "testingT"
926
+ attributes := make (map [string ]interface {})
927
+ attributes [conventions .AttributeHTTPMethod ] = "POST"
928
+ attributes [conventions .AttributeHTTPScheme ] = "https"
929
+ attributes [conventions .AttributeHTTPHost ] = "payment.amazonaws.com"
930
+ attributes [conventions .AttributeHTTPTarget ] = "/"
931
+ attributes [conventions .AttributeRPCService ] = "ABC"
932
+ attributes [awsRemoteService ] = "ProducerService"
933
+
934
+ resource := constructDefaultResource ()
935
+ span := constructProducerSpan (parentSpanID , spanName , 0 , "OK" , attributes )
936
+
937
+ segment , _ := MakeSegment (span , resource , nil , false , nil )
938
+ assert .Equal (t , "ProducerService" , * segment .Name )
939
+ assert .Equal (t , "subsegment" , * segment .Type )
940
+
941
+ jsonStr , err := MakeSegmentDocumentString (span , resource , nil , false , nil )
942
+
943
+ assert .NotNil (t , jsonStr )
944
+ assert .Nil (t , err )
945
+ assert .True (t , strings .Contains (jsonStr , "ProducerService" ))
946
+ assert .False (t , strings .Contains (jsonStr , user ))
947
+ assert .False (t , strings .Contains (jsonStr , "user" ))
948
+ }
949
+
950
+ func TestConsumerSpanWithAwsRemoteServiceName (t * testing.T ) {
951
+ spanName := "ABC.payment"
952
+ parentSpanID := newSegmentID ()
953
+ user := "testingT"
954
+ attributes := make (map [string ]interface {})
955
+ attributes [conventions .AttributeHTTPMethod ] = "POST"
956
+ attributes [conventions .AttributeHTTPScheme ] = "https"
957
+ attributes [conventions .AttributeHTTPHost ] = "payment.amazonaws.com"
958
+ attributes [conventions .AttributeHTTPTarget ] = "/"
959
+ attributes [conventions .AttributeRPCService ] = "ABC"
960
+ attributes [awsLocalService ] = "ConsumerService"
961
+
962
+ resource := constructDefaultResource ()
963
+ span := constructConsumerSpan (parentSpanID , spanName , 0 , "OK" , attributes )
964
+
965
+ segment , _ := MakeSegment (span , resource , nil , false , nil )
966
+ assert .Equal (t , "ConsumerService" , * segment .Name )
967
+
968
+ jsonStr , err := MakeSegmentDocumentString (span , resource , nil , false , nil )
969
+
970
+ assert .NotNil (t , jsonStr )
971
+ assert .Nil (t , err )
972
+ assert .True (t , strings .Contains (jsonStr , "ConsumerService" ))
973
+ assert .False (t , strings .Contains (jsonStr , user ))
974
+ assert .False (t , strings .Contains (jsonStr , "user" ))
975
+ }
976
+
977
+ func TestServerSpanWithAwsLocalServiceName (t * testing.T ) {
978
+ spanName := "ABC.payment"
979
+ parentSpanID := newSegmentID ()
980
+ user := "testingT"
981
+ attributes := make (map [string ]interface {})
982
+ attributes [conventions .AttributeHTTPMethod ] = "POST"
983
+ attributes [conventions .AttributeHTTPScheme ] = "https"
984
+ attributes [conventions .AttributeHTTPHost ] = "payment.amazonaws.com"
985
+ attributes [conventions .AttributeHTTPTarget ] = "/"
986
+ attributes [conventions .AttributeRPCService ] = "ABC"
987
+ attributes [awsLocalService ] = "PaymentLocalService"
988
+ attributes [awsRemoteService ] = "PaymentService"
989
+
990
+ resource := constructDefaultResource ()
991
+ span := constructServerSpan (parentSpanID , spanName , 0 , "OK" , attributes )
992
+
993
+ segment , _ := MakeSegment (span , resource , nil , false , nil )
994
+ assert .Equal (t , "PaymentLocalService" , * segment .Name )
995
+
996
+ jsonStr , err := MakeSegmentDocumentString (span , resource , nil , false , nil )
997
+
998
+ assert .NotNil (t , jsonStr )
999
+ assert .Nil (t , err )
1000
+ assert .True (t , strings .Contains (jsonStr , "PaymentLocalService" ))
1001
+ assert .False (t , strings .Contains (jsonStr , user ))
1002
+ assert .False (t , strings .Contains (jsonStr , "user" ))
1003
+ }
1004
+
894
1005
func constructClientSpan (parentSpanID pcommon.SpanID , name string , code ptrace.StatusCode , message string , attributes map [string ]interface {}) ptrace.Span {
895
1006
var (
896
1007
traceID = newTraceID ()
@@ -945,6 +1056,60 @@ func constructServerSpan(parentSpanID pcommon.SpanID, name string, code ptrace.S
945
1056
return span
946
1057
}
947
1058
1059
+ func constructConsumerSpan (parentSpanID pcommon.SpanID , name string , code ptrace.StatusCode , message string , attributes map [string ]interface {}) ptrace.Span {
1060
+ var (
1061
+ traceID = newTraceID ()
1062
+ spanID = newSegmentID ()
1063
+ endTime = time .Now ()
1064
+ startTime = endTime .Add (- 215 * time .Millisecond )
1065
+ spanAttributes = constructSpanAttributes (attributes )
1066
+ )
1067
+
1068
+ span := ptrace .NewSpan ()
1069
+ span .SetTraceID (traceID )
1070
+ span .SetSpanID (spanID )
1071
+ span .SetParentSpanID (parentSpanID )
1072
+ span .SetName (name )
1073
+ span .SetKind (ptrace .SpanKindConsumer )
1074
+ span .SetStartTimestamp (pcommon .NewTimestampFromTime (startTime ))
1075
+ span .SetEndTimestamp (pcommon .NewTimestampFromTime (endTime ))
1076
+
1077
+ status := ptrace .NewStatus ()
1078
+ status .SetCode (code )
1079
+ status .SetMessage (message )
1080
+ status .CopyTo (span .Status ())
1081
+
1082
+ spanAttributes .CopyTo (span .Attributes ())
1083
+ return span
1084
+ }
1085
+
1086
+ func constructProducerSpan (parentSpanID pcommon.SpanID , name string , code ptrace.StatusCode , message string , attributes map [string ]interface {}) ptrace.Span {
1087
+ var (
1088
+ traceID = newTraceID ()
1089
+ spanID = newSegmentID ()
1090
+ endTime = time .Now ()
1091
+ startTime = endTime .Add (- 215 * time .Millisecond )
1092
+ spanAttributes = constructSpanAttributes (attributes )
1093
+ )
1094
+
1095
+ span := ptrace .NewSpan ()
1096
+ span .SetTraceID (traceID )
1097
+ span .SetSpanID (spanID )
1098
+ span .SetParentSpanID (parentSpanID )
1099
+ span .SetName (name )
1100
+ span .SetKind (ptrace .SpanKindProducer )
1101
+ span .SetStartTimestamp (pcommon .NewTimestampFromTime (startTime ))
1102
+ span .SetEndTimestamp (pcommon .NewTimestampFromTime (endTime ))
1103
+
1104
+ status := ptrace .NewStatus ()
1105
+ status .SetCode (code )
1106
+ status .SetMessage (message )
1107
+ status .CopyTo (span .Status ())
1108
+
1109
+ spanAttributes .CopyTo (span .Attributes ())
1110
+ return span
1111
+ }
1112
+
948
1113
func constructSpanAttributes (attributes map [string ]interface {}) pcommon.Map {
949
1114
attrs := pcommon .NewMap ()
950
1115
for key , value := range attributes {
0 commit comments