33
44using System . Collections . Concurrent ;
55using System . Diagnostics ;
6+ using System . Globalization ;
67using System . Net ;
78#if NETFRAMEWORK
89using System . Net . Http ;
@@ -358,7 +359,8 @@ public void IntegrationTest(
358359 var serviceName = ( string ) exporter . ParentProvider . GetDefaultResource ( ) . Attributes
359360 . Where ( pair => pair . Key == ResourceSemanticConventions . AttributeServiceName ) . FirstOrDefault ( ) . Value ;
360361 var resourceTags = string . Empty ;
361- var activity = CreateTestActivity ( isRootSpan : isRootSpan , status : status ) ;
362+ var dateTime = DateTime . UtcNow ;
363+ var activity = CreateTestActivity ( isRootSpan : isRootSpan , status : status , dateTime : dateTime ) ;
362364 if ( useTestResource )
363365 {
364366 serviceName = "MyService" ;
@@ -422,7 +424,35 @@ public void IntegrationTest(
422424 }
423425
424426 Assert . Equal (
425- $@"[{{""traceId"":""{traceId}"",""name"":""Name"",{parentId}""id"":""{ZipkinActivityConversionExtensions.EncodeSpanId(context.SpanId)}"",""kind"":""CLIENT"",""timestamp"":{timestamp},""duration"":60000000,""localEndpoint"":{{""serviceName"":""{serviceName}""{ipInformation}}},""remoteEndpoint"":{{""serviceName"":""http://localhost:44312/""}},""annotations"":[{{""timestamp"":{eventTimestamp},""value"":""Event1""}},{{""timestamp"":{eventTimestamp},""value"":""Event2""}}],""tags"":{{{resourceTags}""stringKey"":""value"",""longKey"":""1"",""longKey2"":""1"",""doubleKey"":""1"",""doubleKey2"":""1"",""longArrayKey"":""[1,2]"",""boolKey"":""true"",""boolArrayKey"":""[true,false]"",""http.host"":""http://localhost:44312/"",{statusTag}{errorTag}""otel.scope.name"":""CreateTestActivity"",""otel.library.name"":""CreateTestActivity"",""peer.service"":""http://localhost:44312/""}}}}]" ,
427+ $@"[{{""traceId"":""{traceId}"","
428+ + @"""name"":""Name"","
429+ + parentId
430+ + $@ """id"":""{ ZipkinActivityConversionExtensions . EncodeSpanId ( context . SpanId ) } "","
431+ + @"""kind"":""CLIENT"","
432+ + $@ """timestamp"":{ timestamp } ,"
433+ + @"""duration"":60000000,"
434+ + $@ """localEndpoint"":{{""serviceName"":""{ serviceName } ""{ ipInformation } }},"
435+ + @"""remoteEndpoint"":{""serviceName"":""http://localhost:44312/""},"
436+ + $@ """annotations"":[{{""timestamp"":{ eventTimestamp } ,""value"":""Event1""}},{{""timestamp"":{ eventTimestamp } ,""value"":""Event2""}}],"
437+ + @"""tags"":{"
438+ + resourceTags
439+ + $@ """stringKey"":""value"","
440+ + @"""longKey"":""1"","
441+ + @"""longKey2"":""1"","
442+ + @"""doubleKey"":""1"","
443+ + @"""doubleKey2"":""1"","
444+ + @"""longArrayKey"":""[1,2]"","
445+ + @"""boolKey"":""true"","
446+ + @"""boolArrayKey"":""[true,false]"","
447+ + @"""http.host"":""http://localhost:44312/"","
448+ + $@ """dateTimeKey"":""{ Convert . ToString ( dateTime , CultureInfo . InvariantCulture ) } "","
449+ + $@ """dateTimeArrayKey"":""[\u0022{ Convert . ToString ( dateTime , CultureInfo . InvariantCulture ) } \u0022]"","
450+ + statusTag
451+ + errorTag
452+ + @"""otel.scope.name"":""CreateTestActivity"","
453+ + @"""otel.library.name"":""CreateTestActivity"","
454+ + @"""peer.service"":""http://localhost:44312/"""
455+ + "}}]" ,
426456 Responses [ requestId ] ) ;
427457 }
428458
@@ -434,13 +464,16 @@ internal static Activity CreateTestActivity(
434464 bool addLinks = true,
435465 Resource resource = null ,
436466 ActivityKind kind = ActivityKind. Client,
437- Status ? status = null )
467+ Status ? status = null ,
468+ DateTime? dateTime = null )
438469 {
439470 var startTimestamp = DateTime. UtcNow;
440471 var endTimestamp = startTimestamp . AddSeconds ( 60 ) ;
441472 var eventTimestamp = DateTime . UtcNow ;
442473 var traceId = ActivityTraceId . CreateFromString ( "e8ea7e9ac72de94e91fabc613f9686b2 ". AsSpan ( ) ) ;
443474
475+ dateTime ??= DateTime . UtcNow ;
476+
444477 var parentSpanId = isRootSpan ? default : ActivitySpanId . CreateFromBytes ( new byte [ ] { 12 , 23 , 34 , 45 , 56 , 67 , 78 , 89 } ) ;
445478
446479 var attributes = new Dictionary < string , object >
@@ -454,6 +487,8 @@ internal static Activity CreateTestActivity(
454487 { "boolKey", true } ,
455488 { "boolArrayKey", new bool [ ] { true , false } } ,
456489 { "http.host" , "http://localhost:44312/" } , // simulating instrumentation tag adding http.host
490+ { "dateTimeKey" , dateTime . Value } ,
491+ { "dateTimeArrayKey" , new DateTime [ ] { dateTime . Value } } ,
457492 } ;
458493 if ( additionalAttributes != null )
459494 {
0 commit comments