3
3
4
4
using System . Collections . Concurrent ;
5
5
using System . Diagnostics ;
6
+ using System . Globalization ;
6
7
using System . Net ;
7
8
#if NETFRAMEWORK
8
9
using System . Net . Http ;
@@ -358,7 +359,8 @@ public void IntegrationTest(
358
359
var serviceName = ( string ) exporter . ParentProvider . GetDefaultResource ( ) . Attributes
359
360
. Where ( pair => pair . Key == ResourceSemanticConventions . AttributeServiceName ) . FirstOrDefault ( ) . Value ;
360
361
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 ) ;
362
364
if ( useTestResource )
363
365
{
364
366
serviceName = "MyService" ;
@@ -422,7 +424,35 @@ public void IntegrationTest(
422
424
}
423
425
424
426
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
+ + "}}]" ,
426
456
Responses [ requestId ] ) ;
427
457
}
428
458
@@ -434,13 +464,16 @@ internal static Activity CreateTestActivity(
434
464
bool addLinks = true,
435
465
Resource resource = null ,
436
466
ActivityKind kind = ActivityKind. Client,
437
- Status ? status = null )
467
+ Status ? status = null ,
468
+ DateTime? dateTime = null )
438
469
{
439
470
var startTimestamp = DateTime. UtcNow;
440
471
var endTimestamp = startTimestamp . AddSeconds ( 60 ) ;
441
472
var eventTimestamp = DateTime . UtcNow ;
442
473
var traceId = ActivityTraceId . CreateFromString ( "e8ea7e9ac72de94e91fabc613f9686b2 ". AsSpan ( ) ) ;
443
474
475
+ dateTime ??= DateTime . UtcNow ;
476
+
444
477
var parentSpanId = isRootSpan ? default : ActivitySpanId . CreateFromBytes ( new byte [ ] { 12 , 23 , 34 , 45 , 56 , 67 , 78 , 89 } ) ;
445
478
446
479
var attributes = new Dictionary < string , object >
@@ -454,6 +487,8 @@ internal static Activity CreateTestActivity(
454
487
{ "boolKey", true } ,
455
488
{ "boolArrayKey", new bool [ ] { true , false } } ,
456
489
{ "http.host" , "http://localhost:44312/" } , // simulating instrumentation tag adding http.host
490
+ { "dateTimeKey" , dateTime . Value } ,
491
+ { "dateTimeArrayKey" , new DateTime [ ] { dateTime . Value } } ,
457
492
} ;
458
493
if ( additionalAttributes != null )
459
494
{
0 commit comments