@@ -395,6 +395,7 @@ public void GetResourceWithTelemetrySDKAttributes()
395395 // Assert
396396 var attributes = resource . Attributes ;
397397 Assert . Equal ( 4 , attributes . Count ( ) ) ;
398+ ValidateDefaultAttributes ( attributes ) ;
398399 ValidateTelemetrySdkAttributes ( attributes ) ;
399400 }
400401
@@ -406,8 +407,9 @@ public void GetResourceWithDefaultAttributes_EmptyResource()
406407
407408 // Assert
408409 var attributes = resource . Attributes ;
409- Assert . Single ( attributes ) ;
410+ Assert . Equal ( 4 , attributes . Count ( ) ) ;
410411 ValidateDefaultAttributes ( attributes ) ;
412+ ValidateTelemetrySdkAttributes ( attributes ) ;
411413 }
412414
413415 [ Fact ]
@@ -418,9 +420,10 @@ public void GetResourceWithDefaultAttributes_ResourceWithAttrs()
418420
419421 // Assert
420422 var attributes = resource . Attributes ;
421- Assert . Equal ( 3 , attributes . Count ( ) ) ;
423+ Assert . Equal ( 6 , attributes . Count ( ) ) ;
422424 ValidateAttributes ( attributes , 0 , 1 ) ;
423425 ValidateDefaultAttributes ( attributes ) ;
426+ ValidateTelemetrySdkAttributes ( attributes ) ;
424427 }
425428
426429 [ Fact ]
@@ -432,11 +435,12 @@ public void GetResourceWithDefaultAttributes_WithResourceEnvVar()
432435
433436 // Assert
434437 var attributes = resource . Attributes ;
435- Assert . Equal ( 5 , attributes . Count ( ) ) ;
438+ Assert . Equal ( 8 , attributes . Count ( ) ) ;
436439 ValidateAttributes ( attributes , 0 , 1 ) ;
437440 ValidateDefaultAttributes ( attributes ) ;
438441 Assert . Contains ( new KeyValuePair < string , object > ( "EVKey1" , "EVVal1" ) , attributes ) ;
439442 Assert . Contains ( new KeyValuePair < string , object > ( "EVKey2" , "EVVal2" ) , attributes ) ;
443+ ValidateTelemetrySdkAttributes ( attributes ) ;
440444 }
441445
442446 [ Fact ]
@@ -448,9 +452,10 @@ public void EnvironmentVariableDetectors_DoNotDuplicateAttributes()
448452
449453 // Assert
450454 var attributes = resource . Attributes ;
451- Assert . Equal ( 3 , attributes . Count ( ) ) ;
455+ Assert . Equal ( 6 , attributes . Count ( ) ) ;
452456 Assert . Contains ( new KeyValuePair < string , object > ( "EVKey1" , "EVVal1" ) , attributes ) ;
453457 Assert . Contains ( new KeyValuePair < string , object > ( "EVKey2" , "EVVal2" ) , attributes ) ;
458+ ValidateTelemetrySdkAttributes ( attributes ) ;
454459 }
455460
456461 [ Fact ]
@@ -462,9 +467,10 @@ public void GetResource_WithServiceEnvVar()
462467
463468 // Assert
464469 var attributes = resource . Attributes ;
465- Assert . Equal ( 3 , attributes . Count ( ) ) ;
470+ Assert . Equal ( 6 , attributes . Count ( ) ) ;
466471 ValidateAttributes ( attributes , 0 , 1 ) ;
467472 Assert . Contains ( new KeyValuePair < string , object > ( "service.name" , "some-service" ) , attributes ) ;
473+ ValidateTelemetrySdkAttributes ( attributes ) ;
468474 }
469475
470476 [ Fact ]
@@ -477,9 +483,10 @@ public void GetResource_WithServiceNameSetWithTwoEnvVars()
477483
478484 // Assert
479485 var attributes = resource . Attributes ;
480- Assert . Equal ( 3 , attributes . Count ( ) ) ;
486+ Assert . Equal ( 6 , attributes . Count ( ) ) ;
481487 ValidateAttributes ( attributes , 0 , 1 ) ;
482488 Assert . Contains ( new KeyValuePair < string , object > ( "service.name" , "from-service-name" ) , attributes ) ;
489+ ValidateTelemetrySdkAttributes ( attributes ) ;
483490 }
484491
485492 [ Fact ]
@@ -492,9 +499,10 @@ public void GetResource_WithServiceNameSetWithTwoEnvVarsAndCode()
492499
493500 // Assert
494501 var attributes = resource . Attributes ;
495- Assert . Equal ( 4 , attributes . Count ( ) ) ;
502+ Assert . Equal ( 7 , attributes . Count ( ) ) ;
496503 ValidateAttributes ( attributes , 0 , 1 ) ;
497504 Assert . Contains ( new KeyValuePair < string , object > ( "service.name" , "from-code" ) , attributes ) ;
505+ ValidateTelemetrySdkAttributes ( attributes ) ;
498506 }
499507
500508 [ Fact ]
@@ -562,6 +570,21 @@ public void ResourceBuilder_AddDetectorInternal_Test()
562570 Assert . True ( validTestRun ) ;
563571 }
564572
573+ internal static void ValidateTelemetrySdkAttributes ( IEnumerable < KeyValuePair < string , object > > attributes )
574+ {
575+ Assert . Contains ( new KeyValuePair < string , object > ( "telemetry.sdk.name" , "opentelemetry" ) , attributes ) ;
576+ Assert . Contains ( new KeyValuePair < string , object > ( "telemetry.sdk.language" , "dotnet" ) , attributes ) ;
577+ var versionAttribute = attributes . Where ( pair => pair . Key . Equals ( "telemetry.sdk.version" ) ) ;
578+ Assert . Single ( versionAttribute ) ;
579+ }
580+
581+ internal static void ValidateDefaultAttributes ( IEnumerable < KeyValuePair < string , object > > attributes )
582+ {
583+ var serviceName = attributes . Where ( pair => pair . Key . Equals ( "service.name" ) ) ;
584+ Assert . Single ( serviceName ) ;
585+ Assert . Contains ( "unknown_service" , serviceName . FirstOrDefault ( ) . Value as string ) ;
586+ }
587+
565588 private static void ClearEnvVars ( )
566589 {
567590 Environment . SetEnvironmentVariable ( OtelEnvResourceDetector . EnvVarKey , null ) ;
@@ -594,21 +617,6 @@ private static void ValidateResource(Resource resource, int attributeCount)
594617 ValidateAttributes ( resource . Attributes ) ;
595618 }
596619
597- private static void ValidateTelemetrySdkAttributes ( IEnumerable < KeyValuePair < string , object > > attributes )
598- {
599- Assert . Contains ( new KeyValuePair < string , object > ( "telemetry.sdk.name" , "opentelemetry" ) , attributes ) ;
600- Assert . Contains ( new KeyValuePair < string , object > ( "telemetry.sdk.language" , "dotnet" ) , attributes ) ;
601- var versionAttribute = attributes . Where ( pair => pair . Key . Equals ( "telemetry.sdk.version" ) ) ;
602- Assert . Single ( versionAttribute ) ;
603- }
604-
605- private static void ValidateDefaultAttributes ( IEnumerable < KeyValuePair < string , object > > attributes )
606- {
607- var serviceName = attributes . Where ( pair => pair . Key . Equals ( "service.name" ) ) ;
608- Assert . Single ( serviceName ) ;
609- Assert . Contains ( "unknown_service" , serviceName . FirstOrDefault ( ) . Value as string ) ;
610- }
611-
612620 private static Dictionary < string , object > CreateAttributes ( int attributeCount , int startIndex = 0 )
613621 {
614622 var attributes = new Dictionary < string , object > ( ) ;
0 commit comments