1111
1212namespace AWS . Distro . OpenTelemetry . AutoInstrumentation . Tests ;
1313
14- // testSpanNamePropagationBySpanKind in java is included in TestAttributesPropagationBySpanKind Tests
14+ /// <summary>
15+ /// testSpanNamePropagationBySpanKind in java is included in TestAttributesPropagationBySpanKind Tests
16+ /// </summary>
17+ [ System . Diagnostics . CodeAnalysis . SuppressMessage ( "StyleCop.CSharp.DocumentationRules" , "SA1600:Elements should be documented" , Justification = "Tests" ) ]
18+ #pragma warning disable CS8604 // Possible null reference argument.
1519public class AttributePropagatingSpanProcessorTest
1620{
1721 private Func < Activity , string > spanNameExtractor = AwsSpanProcessingUtil . GetIngressOperation ;
1822 private Resource resource = Resource . Empty ;
1923 private string spanNameKey = "spanName" ;
2024 private string testKey1 = "key1" ;
2125 private string testKey2 = "key2" ;
22- private Tracer tracer ;
2326 private ActivitySource activitySource = new ActivitySource ( "test" ) ;
2427 private AttributePropagatingSpanProcessor attributePropagatingSpanProcessor ;
2528
@@ -41,8 +44,8 @@ public void TestAttributesPropagationBySpanKindWithAppOnly()
4144 {
4245 foreach ( ActivityKind activityKind in Enum . GetValues ( typeof ( ActivityKind ) ) )
4346 {
44- Activity spanWithAppOnly = this . activitySource . StartActivity ( "parent" , activityKind ) ;
45- spanWithAppOnly . SetTag ( this . testKey1 , "testValue1" ) ;
47+ Activity ? spanWithAppOnly = this . activitySource . StartActivity ( "parent" , activityKind ) ;
48+ spanWithAppOnly ? . SetTag ( this . testKey1 , "testValue1" ) ;
4649 this . attributePropagatingSpanProcessor . OnStart ( spanWithAppOnly ) ;
4750 if ( activityKind == ActivityKind . Server )
4851 {
@@ -66,8 +69,8 @@ public void TestAttributesPropagationBySpanKindWithOpOnly()
6669 {
6770 foreach ( ActivityKind activityKind in Enum . GetValues ( typeof ( ActivityKind ) ) )
6871 {
69- Activity spanWithOpOnly = this . activitySource . StartActivity ( "parent" , activityKind ) ;
70- spanWithOpOnly . SetTag ( this . testKey2 , "testValue2" ) ;
72+ Activity ? spanWithOpOnly = this . activitySource . StartActivity ( "parent" , activityKind ) ;
73+ spanWithOpOnly ? . SetTag ( this . testKey2 , "testValue2" ) ;
7174 this . attributePropagatingSpanProcessor . OnStart ( spanWithOpOnly ) ;
7275 if ( activityKind == ActivityKind . Server )
7376 {
@@ -91,9 +94,9 @@ public void TestAttributesPropagationBySpanKindWithAppAndOp()
9194 {
9295 foreach ( ActivityKind activityKind in Enum . GetValues ( typeof ( ActivityKind ) ) )
9396 {
94- Activity spanWithAppAndOp = this . activitySource . StartActivity ( "parent" , activityKind ) ;
95- spanWithAppAndOp . SetTag ( this . testKey1 , "testValue1" ) ;
96- spanWithAppAndOp . SetTag ( this . testKey2 , "testValue2" ) ;
97+ Activity ? spanWithAppAndOp = this . activitySource . StartActivity ( "parent" , activityKind ) ;
98+ spanWithAppAndOp ? . SetTag ( this . testKey1 , "testValue1" ) ;
99+ spanWithAppAndOp ? . SetTag ( this . testKey2 , "testValue2" ) ;
97100 this . attributePropagatingSpanProcessor . OnStart ( spanWithAppAndOp ) ;
98101 if ( activityKind == ActivityKind . Server )
99102 {
@@ -115,18 +118,18 @@ public void TestAttributesPropagationBySpanKindWithAppAndOp()
115118 [ Fact ]
116119 public void TestAttributesPropagationWithInternalKinds ( )
117120 {
118- Activity grandParentActivity = this . activitySource . StartActivity ( "grandparent" , ActivityKind . Internal ) ;
119- grandParentActivity . SetTag ( this . testKey1 , "testValue1" ) ;
121+ Activity ? grandParentActivity = this . activitySource . StartActivity ( "grandparent" , ActivityKind . Internal ) ;
122+ grandParentActivity ? . SetTag ( this . testKey1 , "testValue1" ) ;
120123 this . attributePropagatingSpanProcessor . OnStart ( grandParentActivity ) ;
121124
122- Activity parentActivity = this . activitySource . StartActivity ( "parent" , ActivityKind . Internal ) ;
123- parentActivity . SetTag ( this . testKey2 , "testValue2" ) ;
125+ Activity ? parentActivity = this . activitySource . StartActivity ( "parent" , ActivityKind . Internal ) ;
126+ parentActivity ? . SetTag ( this . testKey2 , "testValue2" ) ;
124127 this . attributePropagatingSpanProcessor . OnStart ( parentActivity ) ;
125128
126- Activity childActivity = this . activitySource . StartActivity ( "grandparent" , ActivityKind . Client ) ;
129+ Activity ? childActivity = this . activitySource . StartActivity ( "grandparent" , ActivityKind . Client ) ;
127130 this . attributePropagatingSpanProcessor . OnStart ( childActivity ) ;
128131
129- Activity grandChildActivity = this . activitySource . StartActivity ( "grandparent" , ActivityKind . Internal ) ;
132+ Activity ? grandChildActivity = this . activitySource . StartActivity ( "grandparent" , ActivityKind . Internal ) ;
130133 this . attributePropagatingSpanProcessor . OnStart ( grandChildActivity ) ;
131134
132135 Assert . Equal ( "testValue1" , grandParentActivity . GetTagItem ( this . testKey1 ) ) ;
@@ -145,15 +148,14 @@ public void TestAttributesPropagationWithInternalKinds()
145148 [ Fact ]
146149 public void TestOverrideAttributes ( )
147150 {
148- Activity parentActivity = this . activitySource . StartActivity ( "parent" , ActivityKind . Server ) ;
149- parentActivity . SetTag ( this . testKey1 , "testValue1" ) ;
150- parentActivity . SetTag ( this . testKey2 , "testValue2" ) ;
151+ Activity ? parentActivity = this . activitySource . StartActivity ( "parent" , ActivityKind . Server ) ;
152+ parentActivity ? . SetTag ( this . testKey1 , "testValue1" ) ;
153+ parentActivity ? . SetTag ( this . testKey2 , "testValue2" ) ;
151154
152- Activity transmitActivity1 = this . CreateNestedSpan ( parentActivity , 2 ) ;
155+ this . CreateNestedSpan ( parentActivity , 2 ) ;
153156
154- Activity childActivity = this . activitySource . StartActivity ( "child:1" ) ;
155-
156- childActivity . SetTag ( this . testKey2 , "testValue3" ) ;
157+ Activity ? childActivity = this . activitySource . StartActivity ( "child:1" ) ;
158+ childActivity ? . SetTag ( this . testKey2 , "testValue3" ) ;
157159
158160 Activity transmitActivity2 = this . CreateNestedSpan ( childActivity , 2 ) ;
159161
@@ -163,20 +165,20 @@ public void TestOverrideAttributes()
163165 [ Fact ]
164166 public void TestSpanNamePropagationWithRemoteParentSpan ( )
165167 {
166- Activity parent = this . activitySource . StartActivity ( "parent" ) ;
167- Activity activity = this . activitySource . StartActivity ( "parent" , ActivityKind . Server ) ;
168- PropertyInfo propertyInfo = typeof ( Activity ) . GetProperty ( "HasRemoteParent" , BindingFlags . Instance | BindingFlags . NonPublic | BindingFlags . Public ) ;
169- MethodInfo setterMethodInfo = propertyInfo . GetSetMethod ( true ) ;
170- setterMethodInfo . Invoke ( activity , new object [ ] { true } ) ;
168+ this . activitySource . StartActivity ( "parent" ) ;
169+ Activity ? activity = this . activitySource . StartActivity ( "parent" , ActivityKind . Server ) ;
170+ PropertyInfo ? propertyInfo = typeof ( Activity ) . GetProperty ( "HasRemoteParent" , BindingFlags . Instance | BindingFlags . NonPublic | BindingFlags . Public ) ;
171+ MethodInfo ? setterMethodInfo = propertyInfo ? . GetSetMethod ( true ) ;
172+ setterMethodInfo ? . Invoke ( activity , new object [ ] { true } ) ;
171173 this . ValidateSpanAttributesInheritance ( activity , "parent" , null , null ) ;
172174 }
173175
174176 [ Fact ]
175177 public void TestAwsSdkDescendantSpan ( )
176178 {
177- Activity awsSdkActivity = this . activitySource . StartActivity ( "parent" , ActivityKind . Client ) ;
178- awsSdkActivity . SetTag ( TraceSemanticConventions . AttributeRpcSystem , "aws-api" ) ;
179- Assert . Null ( awsSdkActivity . GetTagItem ( AwsAttributeKeys . AttributeAWSSdkDescendant ) ) ;
179+ Activity ? awsSdkActivity = this . activitySource . StartActivity ( "parent" , ActivityKind . Client ) ;
180+ awsSdkActivity ? . SetTag ( TraceSemanticConventions . AttributeRpcSystem , "aws-api" ) ;
181+ Assert . Null ( awsSdkActivity ? . GetTagItem ( AwsAttributeKeys . AttributeAWSSdkDescendant ) ) ;
180182
181183 Activity childActivity = this . CreateNestedSpan ( awsSdkActivity , 1 ) ;
182184 Assert . NotNull ( childActivity . GetTagItem ( AwsAttributeKeys . AttributeAWSSdkDescendant ) ) ;
@@ -186,34 +188,34 @@ public void TestAwsSdkDescendantSpan()
186188 [ Fact ]
187189 public void TestConsumerParentSpanKindAttributePropagation ( )
188190 {
189- Activity grandParentActivity = this . activitySource . StartActivity ( "grandparent" , ActivityKind . Consumer ) ;
190- Activity parentActivity = this . activitySource . StartActivity ( "parent" , ActivityKind . Internal ) ;
191- Activity childActivity = this . activitySource . StartActivity ( "child" , ActivityKind . Consumer ) ;
192- childActivity . SetTag (
191+ this . activitySource . StartActivity ( "grandparent" , ActivityKind . Consumer ) ;
192+ Activity ? parentActivity = this . activitySource . StartActivity ( "parent" , ActivityKind . Internal ) ;
193+ Activity ? childActivity = this . activitySource . StartActivity ( "child" , ActivityKind . Consumer ) ;
194+ childActivity ? . SetTag (
193195 TraceSemanticConventions . AttributeMessagingOperation ,
194196 TraceSemanticConventions . MessagingOperationValues . Process ) ;
195197
196- Assert . Null ( parentActivity . GetTagItem ( AwsAttributeKeys . AttributeAWSConsumerParentSpanKind ) ) ;
197- Assert . Null ( childActivity . GetTagItem ( AwsAttributeKeys . AttributeAWSConsumerParentSpanKind ) ) ;
198+ Assert . Null ( parentActivity ? . GetTagItem ( AwsAttributeKeys . AttributeAWSConsumerParentSpanKind ) ) ;
199+ Assert . Null ( childActivity ? . GetTagItem ( AwsAttributeKeys . AttributeAWSConsumerParentSpanKind ) ) ;
198200 }
199201
200202 [ Fact ]
201203 public void TestNoConsumerParentSpanKindAttributeWithConsumerProcess ( )
202204 {
203- Activity parentActivity = this . activitySource . StartActivity ( "parent" , ActivityKind . Server ) ;
204- Activity childActivity = this . activitySource . StartActivity ( "child" , ActivityKind . Consumer ) ;
205- childActivity . SetTag (
205+ this . activitySource . StartActivity ( "parent" , ActivityKind . Server ) ;
206+ Activity ? childActivity = this . activitySource . StartActivity ( "child" , ActivityKind . Consumer ) ;
207+ childActivity ? . SetTag (
206208 TraceSemanticConventions . AttributeMessagingOperation ,
207209 TraceSemanticConventions . MessagingOperationValues . Process ) ;
208- Assert . Null ( childActivity . GetTagItem ( AwsAttributeKeys . AttributeAWSConsumerParentSpanKind ) ) ;
210+ Assert . Null ( childActivity ? . GetTagItem ( AwsAttributeKeys . AttributeAWSConsumerParentSpanKind ) ) ;
209211 }
210212
211213 [ Fact ]
212214 public void TestConsumerParentSpanKindAttributeWithConsumerParent ( )
213215 {
214- Activity parentActivity = this . activitySource . StartActivity ( "parent" , ActivityKind . Consumer ) ;
216+ Activity ? parentActivity = this . activitySource . StartActivity ( "parent" , ActivityKind . Consumer ) ;
217+ Activity ? childActivity = this . activitySource . StartActivity ( "child" , ActivityKind . Consumer ) ;
215218 this . attributePropagatingSpanProcessor . OnStart ( parentActivity ) ;
216- Activity childActivity = this . activitySource . StartActivity ( "child" , ActivityKind . Consumer ) ;
217219 this . attributePropagatingSpanProcessor . OnStart ( childActivity ) ;
218220 childActivity . SetTag (
219221 TraceSemanticConventions . AttributeMessagingOperation ,
@@ -228,7 +230,7 @@ private Activity CreateNestedSpan(Activity parentSpan, int depth)
228230 return parentSpan ;
229231 }
230232
231- Activity childSpan = this . activitySource . StartActivity ( "child:" + depth ) ;
233+ Activity ? childSpan = this . activitySource . StartActivity ( "child:" + depth ) ;
232234 this . attributePropagatingSpanProcessor . OnStart ( childSpan ) ;
233235
234236 try
0 commit comments