Skip to content

Commit 868b710

Browse files
authored
Fixed warnings that come up during build (#156)
1 parent 82a2e1c commit 868b710

12 files changed

+438
-464
lines changed

src/AWS.Distro.OpenTelemetry.AutoInstrumentation/AWS.Distro.OpenTelemetry.AutoInstrumentation.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
<PackageReference Include="OpenTelemetry.Extensions.AWS" Version="1.3.0-beta.1" />
2727
<PackageReference Include="OpenTelemetry.Extensions.Propagators" Version="1.9.0" />
2828
<PackageReference Include="OpenTelemetry.Instrumentation.AspNetCore" Version="1.9.0" />
29-
<PackageReference Include="OpenTelemetry.Instrumentation.AspNet" Version="1.9.0-beta.1" />
29+
<PackageReference Include="OpenTelemetry.Instrumentation.AspNet" Version="1.9.0-beta.1" Condition="'$(TargetFramework)' == 'net462'" />
3030
<PackageReference Include="OpenTelemetry.Instrumentation.AWSLambda" Version="1.3.0-beta.1" Condition="'$(TargetFramework)' != 'net462'" />
3131
<PackageReference Include="OpenTelemetry.Instrumentation.Http" Version="1.9.0" />
3232
<PackageReference Include="OpenTelemetry.ResourceDetectors.AWS" Version="1.4.0-beta.1" />

src/AWS.Distro.OpenTelemetry.AutoInstrumentation/AssemblyInfo.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,6 @@
44
using System.Runtime.CompilerServices;
55

66
[assembly: InternalsVisibleTo("AWS.Distro.OpenTelemetry.AutoInstrumentation.Tests, PublicKey=00240000048000009400000006020000002400005253413100040000010001008d2066d801b36facea88de93502124d2697889d1251da824ac38fcb95689c2f21fed97e968cffa5b8fbb1d8bd66c6e9054f2dc0246298535fe8d6e012abe467c10c4a1c18c77f46da66a8fb4cda9712a0cdddca800c75eca847fc91fc6e4d76d64dd3c82bf7615f13cf20b34e650d9d1564e7db267c31c8ecb287dcf8931e68e")]
7+
78
// public key copied from https://github.com/castleproject/Core/blob/91ab2bcef135c441690b24506d7152527467ba9e/src/Castle.Core/Core/Internal/InternalsVisible.cs#L31
89
[assembly: InternalsVisibleTo("DynamicProxyGenAssembly2,PublicKey=0024000004800000940000000602000000240000525341310004000001000100c547cac37abd99c8db225ef2f6c8a3602f3b3606cc9891605d02baa56104f4cfc0734aa39b93bf7852f7d9266654753cc297e7d2edfe0bac1cdcf9f717241550e0a7b191195b7667bb4f64bcb8e2121380fd1d9d46ad2d92d2d15605093924cceaf74c4861eff62abf69b9291ed0a340e113be11e6a7d3113e92484cf7045cc7")]

src/AWS.Distro.OpenTelemetry.AutoInstrumentation/GlobalSuppressions.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,8 @@
2424
[assembly: SuppressMessage("StyleCop.CSharp.SpacingRules", "SA1011:Closing square brackets should be spaced correctly", Justification = "Reviewed", Scope = "member", Target = "~M:OtlpUdpExporter.Export(OpenTelemetry.Batch{System.Diagnostics.Activity}@)~OpenTelemetry.ExportResult")]
2525
[assembly: SuppressMessage("StyleCop.CSharp.SpacingRules", "SA1011:Closing square brackets should be spaced correctly", Justification = "Reviewed", Scope = "member", Target = "~M:OtlpUdpExporter.SerializeSpans(OpenTelemetry.Batch{System.Diagnostics.Activity})~System.Byte[]")]
2626
[assembly: SuppressMessage("StyleCop.CSharp.MaintainabilityRules", "SA1402:File may only contain a single type", Justification = "Reviewed", Scope = "type", Target = "~T:StatusCodeConverter")]
27+
[assembly: SuppressMessage("StyleCop.CSharp.NamingRules", "SA1307:Accessible fields should begin with upper-case letter", Justification = "Reviewed", Scope = "member", Target = "~F:AWS.Distro.OpenTelemetry.AutoInstrumentation.Version.version")]
28+
[assembly: SuppressMessage("StyleCop.CSharp.MaintainabilityRules", "SA1400:Access modifier should be declared", Justification = "Reviewed", Scope = "type", Target = "~T:AWS.Distro.OpenTelemetry.AutoInstrumentation.Version")]
29+
[assembly: SuppressMessage("StyleCop.CSharp.MaintainabilityRules", "SA1401:Fields should be private", Justification = "Reviewed", Scope = "member", Target = "~F:AWS.Distro.OpenTelemetry.AutoInstrumentation.Version.version")]
2730

2831
// TODO, review these suppressions.
Lines changed: 45 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,18 @@
1111

1212
namespace 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.
1519
public 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

Comments
 (0)