@@ -39,6 +39,8 @@ public class HttpWebRequestActivitySourceTests : IDisposable
3939 private readonly string testServerHost ;
4040 private readonly int testServerPort ;
4141 private readonly string hostNameAndPort ;
42+ private readonly string netPeerName ;
43+ private readonly int netPeerPort ;
4244
4345 static HttpWebRequestActivitySourceTests ( )
4446 {
@@ -74,6 +76,8 @@ public HttpWebRequestActivitySourceTests()
7476 out this . testServerPort ) ;
7577
7678 this . hostNameAndPort = $ "{ this . testServerHost } :{ this . testServerPort } ";
79+ this . netPeerName = this . testServerHost ;
80+ this . netPeerPort = this . testServerPort ;
7781
7882 void ProcessServerRequest ( HttpListenerContext context )
7983 {
@@ -198,7 +202,7 @@ public async Task TestBasicReceiveAndResponseEvents(string method, string queryS
198202 // Check to make sure: The first record must be a request, the next record must be a response.
199203 Activity activity = AssertFirstEventWasStart ( eventRecords ) ;
200204
201- VerifyActivityStartTags ( this . hostNameAndPort , method , url , activity ) ;
205+ VerifyActivityStartTags ( this . netPeerName , this . netPeerPort , method , url , activity ) ;
202206
203207 Assert . True ( eventRecords . Records . TryDequeue ( out var stopEvent ) ) ;
204208 Assert . Equal ( "Stop" , stopEvent . Key ) ;
@@ -378,7 +382,7 @@ public async Task TestBasicReceiveAndResponseWebRequestEvents(string method, int
378382 // Check to make sure: The first record must be a request, the next record must be a response.
379383 Activity activity = AssertFirstEventWasStart ( eventRecords ) ;
380384
381- VerifyActivityStartTags ( this . hostNameAndPort , method , url , activity ) ;
385+ VerifyActivityStartTags ( this . netPeerName , this . netPeerPort , method , url , activity ) ;
382386
383387 Assert . True ( eventRecords . Records . TryDequeue ( out var stopEvent ) ) ;
384388 Assert . Equal ( "Stop" , stopEvent . Key ) ;
@@ -484,7 +488,7 @@ public async Task TestResponseWithoutContentEvents(string method)
484488 // Check to make sure: The first record must be a request, the next record must be a response.
485489 Activity activity = AssertFirstEventWasStart ( eventRecords ) ;
486490
487- VerifyActivityStartTags ( this . hostNameAndPort , method , url , activity ) ;
491+ VerifyActivityStartTags ( this . netPeerName , this . netPeerPort , method , url , activity ) ;
488492
489493 Assert . True ( eventRecords . Records . TryDequeue ( out var stopEvent ) ) ;
490494 Assert . Equal ( "Stop" , stopEvent . Key ) ;
@@ -523,9 +527,10 @@ public async Task TestRedirectedRequest(string method)
523527 [ InlineData ( "POST" ) ]
524528 public async Task TestRequestWithException ( string method )
525529 {
530+ string host = Guid . NewGuid ( ) . ToString ( ) + ".com" ;
526531 string url = method == "GET"
527- ? $ "http://{ Guid . NewGuid ( ) } .com "
528- : $ "http://{ Guid . NewGuid ( ) } .com ";
532+ ? $ "http://{ host } "
533+ : $ "http://{ host } ";
529534
530535 using var eventRecords = new ActivitySourceRecorder ( ) ;
531536
@@ -548,7 +553,7 @@ public async Task TestRequestWithException(string method)
548553
549554 // Check to make sure: The first record must be a request, the next record must be an exception.
550555 Activity activity = AssertFirstEventWasStart ( eventRecords ) ;
551- VerifyActivityStartTags ( null , method , url , activity ) ;
556+ VerifyActivityStartTags ( host , null , method , url , activity ) ;
552557
553558 Assert . True ( eventRecords . Records . TryDequeue ( out KeyValuePair < string , Activity > exceptionEvent ) ) ;
554559 Assert . Equal ( "Stop" , exceptionEvent . Key ) ;
@@ -587,7 +592,7 @@ public async Task TestCanceledRequest(string method)
587592 Assert . Equal ( 1 , eventRecords . Records . Count ( rec => rec . Key == "Stop" ) ) ;
588593
589594 Activity activity = AssertFirstEventWasStart ( eventRecords ) ;
590- VerifyActivityStartTags ( this . hostNameAndPort , method , url , activity ) ;
595+ VerifyActivityStartTags ( this . netPeerName , this . netPeerPort , method , url , activity ) ;
591596
592597 Assert . True ( eventRecords . Records . TryDequeue ( out KeyValuePair < string , Activity > exceptionEvent ) ) ;
593598 Assert . Equal ( "Stop" , exceptionEvent . Key ) ;
@@ -626,7 +631,7 @@ public async Task TestSecureTransportFailureRequest(string method)
626631 Assert . Equal ( 1 , eventRecords . Records . Count ( rec => rec . Key == "Stop" ) ) ;
627632
628633 Activity activity = AssertFirstEventWasStart ( eventRecords ) ;
629- VerifyActivityStartTags ( null , method , url , activity ) ;
634+ VerifyActivityStartTags ( "expired.badssl.com" , null , method , url , activity ) ;
630635
631636 Assert . True ( eventRecords . Records . TryDequeue ( out KeyValuePair < string , Activity > exceptionEvent ) ) ;
632637 Assert . Equal ( "Stop" , exceptionEvent . Key ) ;
@@ -668,7 +673,7 @@ public async Task TestSecureTransportRetryFailureRequest(string method)
668673 Assert . Equal ( 1 , eventRecords . Records . Count ( rec => rec . Key == "Stop" ) ) ;
669674
670675 Activity activity = AssertFirstEventWasStart ( eventRecords ) ;
671- VerifyActivityStartTags ( this . hostNameAndPort , method , url , activity ) ;
676+ VerifyActivityStartTags ( this . netPeerName , this . netPeerPort , method , url , activity ) ;
672677
673678 Assert . True ( eventRecords . Records . TryDequeue ( out KeyValuePair < string , Activity > exceptionEvent ) ) ;
674679 Assert . Equal ( "Stop" , exceptionEvent . Key ) ;
@@ -778,15 +783,17 @@ private static void VerifyHeaders(HttpWebRequest startRequest)
778783 Assert . Matches ( "^[0-9a-f]{2}-[0-9a-f]{32}-[0-9a-f]{16}-[0-9a-f]{2}$" , traceparent ) ;
779784 }
780785
781- private static void VerifyActivityStartTags ( string hostNameAndPort , string method , string url , Activity activity )
786+ private static void VerifyActivityStartTags ( string netPeerName , int ? netPeerPort , string method , string url , Activity activity )
782787 {
783788 Assert . NotNull ( activity . TagObjects ) ;
784789 Assert . Equal ( method , activity . GetTagValue ( SemanticConventions . AttributeHttpMethod ) ) ;
785- if ( hostNameAndPort != null )
790+ if ( netPeerPort != null )
786791 {
787- Assert . Equal ( hostNameAndPort , activity . GetTagValue ( SemanticConventions . AttributeHttpHost ) ) ;
792+ Assert . Equal ( netPeerPort , activity . GetTagValue ( SemanticConventions . AttributeNetPeerPort ) ) ;
788793 }
789794
795+ Assert . Equal ( netPeerName , activity . GetTagValue ( SemanticConventions . AttributeNetPeerName ) ) ;
796+
790797 Assert . Equal ( url , activity . GetTagValue ( SemanticConventions . AttributeHttpUrl ) ) ;
791798 }
792799
0 commit comments