open-telemetry / opentelemetry-dotnet

The OpenTelemetry .NET Client
https://opentelemetry.io
Apache License 2.0
3.18k stars 753 forks source link

[Propagators] Nullable annotations #5767

Closed Kielek closed 1 month ago

Kielek commented 2 months ago

Towards #3958

Changes

[Propagators] Nullable

Merge requirement checklist

Kielek commented 2 months ago

Potential diff for contrib repo:

diff --git a/src/OpenTelemetry.Extensions.AWS/.publicApi/PublicAPI.Unshipped.txt b/src/OpenTelemetry.Extensions.AWS/.publicApi/PublicAPI.Unshipped.txt
index a7a1588b..cc69db22 100644
--- a/src/OpenTelemetry.Extensions.AWS/.publicApi/PublicAPI.Unshipped.txt
+++ b/src/OpenTelemetry.Extensions.AWS/.publicApi/PublicAPI.Unshipped.txt
@@ -2,7 +2,7 @@ OpenTelemetry.Extensions.AWS.AWSXRayIdGenerator
 OpenTelemetry.Extensions.AWS.Trace.AWSXRayPropagator
 OpenTelemetry.Extensions.AWS.Trace.AWSXRayPropagator.AWSXRayPropagator() -> void
 OpenTelemetry.Trace.TracerProviderBuilderExtensions
-override OpenTelemetry.Extensions.AWS.Trace.AWSXRayPropagator.Extract<T>(OpenTelemetry.Context.Propagation.PropagationContext context, T carrier, System.Func<T, string!, System.Collections.Generic.IEnumerable<string!>!>! getter) -> OpenTelemetry.Context.Propagation.PropagationContext
+override OpenTelemetry.Extensions.AWS.Trace.AWSXRayPropagator.Extract<T>(OpenTelemetry.Context.Propagation.PropagationContext context, T carrier, System.Func<T, string!, System.Collections.Generic.IEnumerable<string!>?>! getter) -> OpenTelemetry.Context.Propagation.PropagationContext
 override OpenTelemetry.Extensions.AWS.Trace.AWSXRayPropagator.Fields.get -> System.Collections.Generic.ISet<string!>!
 override OpenTelemetry.Extensions.AWS.Trace.AWSXRayPropagator.Inject<T>(OpenTelemetry.Context.Propagation.PropagationContext context, T carrier, System.Action<T, string!, string!>! setter) -> void
 static OpenTelemetry.Trace.TracerProviderBuilderExtensions.AddXRayTraceId(this OpenTelemetry.Trace.TracerProviderBuilder! builder) -> OpenTelemetry.Trace.TracerProviderBuilder!
diff --git a/src/OpenTelemetry.Extensions.AWS/Trace/AWSXRayPropagator.cs b/src/OpenTelemetry.Extensions.AWS/Trace/AWSXRayPropagator.cs
index 569bae53..4e8d5ac8 100644
--- a/src/OpenTelemetry.Extensions.AWS/Trace/AWSXRayPropagator.cs
+++ b/src/OpenTelemetry.Extensions.AWS/Trace/AWSXRayPropagator.cs
@@ -38,7 +38,7 @@ public class AWSXRayPropagator : TextMapPropagator
     public override ISet<string> Fields => new HashSet<string>() { AWSXRayTraceHeaderKey };

     /// <inheritdoc/>
-    public override PropagationContext Extract<T>(PropagationContext context, T carrier, Func<T, string, IEnumerable<string>> getter)
+    public override PropagationContext Extract<T>(PropagationContext context, T carrier, Func<T, string, IEnumerable<string>?> getter)
     {
         if (context.ActivityContext.IsValid())
         {
diff --git a/test/OpenTelemetry.Instrumentation.AspNet.TelemetryHttpModule.Tests/ActivityHelperTest.cs b/test/OpenTelemetry.Instrumentation.AspNet.TelemetryHttpModule.Tests/ActivityHelperTest.cs
index 0e7bacce..d5dabf7c 100644
--- a/test/OpenTelemetry.Instrumentation.AspNet.TelemetryHttpModule.Tests/ActivityHelperTest.cs
+++ b/test/OpenTelemetry.Instrumentation.AspNet.TelemetryHttpModule.Tests/ActivityHelperTest.cs
@@ -555,7 +555,7 @@ public class ActivityHelperTest : IDisposable
     {
         public override ISet<string>? Fields => null;

-        public override PropagationContext Extract<T>(PropagationContext context, T carrier, Func<T, string, IEnumerable<string>> getter)
+        public override PropagationContext Extract<T>(PropagationContext context, T carrier, Func<T, string, IEnumerable<string>?> getter)
         {
             return default;
         }
diff --git a/test/OpenTelemetry.Instrumentation.AspNetCore.Tests/BasicTests.cs b/test/OpenTelemetry.Instrumentation.AspNetCore.Tests/BasicTests.cs
index 03cc1600..4eeed567 100644
--- a/test/OpenTelemetry.Instrumentation.AspNetCore.Tests/BasicTests.cs
+++ b/test/OpenTelemetry.Instrumentation.AspNetCore.Tests/BasicTests.cs
@@ -1202,7 +1202,7 @@ public sealed class BasicTests

         public override ISet<string> Fields => throw new NotImplementedException();

-        public override PropagationContext Extract<T>(PropagationContext context, T carrier, Func<T, string, IEnumerable<string>> getter)
+        public override PropagationContext Extract<T>(PropagationContext context, T carrier, Func<T, string, IEnumerable<string>?> getter)
         {
             return new PropagationContext(this.activityContext, this.baggage);
         }
diff --git a/test/OpenTelemetry.Instrumentation.GrpcCore.Tests/GrpcCoreClientInterceptorTests.cs b/test/OpenTelemetry.Instrumentation.GrpcCore.Tests/GrpcCoreClientInterceptorTests.cs
index 150f20a3..57db6c4d 100644
--- a/test/OpenTelemetry.Instrumentation.GrpcCore.Tests/GrpcCoreClientInterceptorTests.cs
+++ b/test/OpenTelemetry.Instrumentation.GrpcCore.Tests/GrpcCoreClientInterceptorTests.cs
@@ -389,9 +389,11 @@ public class GrpcCoreClientInterceptorTests
         {
             propagatorCalled++;
             capturedPropagationContext = propagation;
-            capturedCarrier = (Metadata)carrier;
+            capturedCarrier = (Metadata?)carrier;

             // Make sure the original metadata make it through
+
+            Assert.NotNull(capturedCarrier);
             if (additionalMetadata != null)
             {
                 Assert.Equal(capturedCarrier, additionalMetadata);
diff --git a/test/Shared/CustomTextMapPropagator.cs b/test/Shared/CustomTextMapPropagator.cs
index 8d3404e8..fc869441 100644
--- a/test/Shared/CustomTextMapPropagator.cs
+++ b/test/Shared/CustomTextMapPropagator.cs
@@ -24,7 +24,7 @@ internal sealed class CustomTextMapPropagator : TextMapPropagator
 #pragma warning restore SA1010 // Opening square brackets should be spaced correctly
 #pragma warning restore SA1201 // Elements should appear in the correct order

-    public override PropagationContext Extract<T>(PropagationContext context, T carrier, Func<T, string, IEnumerable<string>> getter)
+    public override PropagationContext Extract<T>(PropagationContext context, T carrier, Func<T, string, IEnumerable<string>?> getter)
     {
         if (this.TraceId != default && this.SpanId != default)
         {
diff --git a/test/Shared/TestTextMapPropagator.cs b/test/Shared/TestTextMapPropagator.cs
index ba58606a..5c2c36da 100644
--- a/test/Shared/TestTextMapPropagator.cs
+++ b/test/Shared/TestTextMapPropagator.cs
@@ -9,13 +9,13 @@ namespace OpenTelemetry.Tests;

 internal class TestTextMapPropagator : TextMapPropagator
 {
-    public Action<PropagationContext, object, Action<object, string, string>>? OnInject { get; set; }
+    public Action<PropagationContext, object?, Action<object, string, string>>? OnInject { get; set; }

     public Action? Extracted { get; set; }

     public override ISet<string> Fields => throw new NotImplementedException();

-    public override PropagationContext Extract<T>(PropagationContext context, T carrier, Func<T, string, IEnumerable<string>> getter)
+    public override PropagationContext Extract<T>(PropagationContext context, T carrier, Func<T, string, IEnumerable<string>?> getter)
     {
         this.Extracted?.Invoke();
         return context;
@@ -23,10 +23,9 @@ internal class TestTextMapPropagator : TextMapPropagator

     public override void Inject<T>(PropagationContext context, T carrier, Action<T, string, string> setter)
     {
-        var newAction = new Action<T, string, string>((c, k, v) => setter(c, k, v));
         this.OnInject?.Invoke(
             context,
             carrier,
-            new Action<object, string, string>((c, k, v) => setter((T)c, k, v)));
+            (c, k, v) => setter((T)c, k, v));
     }
 }
codecov[bot] commented 2 months ago

Codecov Report

Attention: Patch coverage is 81.81818% with 4 lines in your changes missing coverage. Please review.

Project coverage is 86.21%. Comparing base (6250307) to head (8bb5e43). Report is 299 commits behind head on main.

Files with missing lines Patch % Lines
src/OpenTelemetry.Api/Trace/SpanContext.cs 0.00% 3 Missing :warning:
...etry.Api/Context/Propagation/PropagationContext.cs 0.00% 1 Missing :warning:
Additional details and impacted files [![Impacted file tree graph](https://app.codecov.io/gh/open-telemetry/opentelemetry-dotnet/pull/5767/graphs/tree.svg?width=650&height=150&src=pr&token=vscyfvPfy5&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=open-telemetry)](https://app.codecov.io/gh/open-telemetry/opentelemetry-dotnet/pull/5767?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=open-telemetry) ```diff @@ Coverage Diff @@ ## main #5767 +/- ## ========================================== + Coverage 83.38% 86.21% +2.82% ========================================== Files 297 256 -41 Lines 12531 11147 -1384 ========================================== - Hits 10449 9610 -839 + Misses 2082 1537 -545 ``` | [Flag](https://app.codecov.io/gh/open-telemetry/opentelemetry-dotnet/pull/5767/flags?src=pr&el=flags&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=open-telemetry) | Coverage Δ | | |---|---|---| | [unittests](https://app.codecov.io/gh/open-telemetry/opentelemetry-dotnet/pull/5767/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=open-telemetry) | `?` | | | [unittests-Project-Experimental](https://app.codecov.io/gh/open-telemetry/opentelemetry-dotnet/pull/5767/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=open-telemetry) | `86.20% <81.81%> (?)` | | | [unittests-Project-Stable](https://app.codecov.io/gh/open-telemetry/opentelemetry-dotnet/pull/5767/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=open-telemetry) | `86.14% <81.81%> (?)` | | Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=open-telemetry#carryforward-flags-in-the-pull-request-comment) to find out more. | [Files with missing lines](https://app.codecov.io/gh/open-telemetry/opentelemetry-dotnet/pull/5767?dropdown=coverage&src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=open-telemetry) | Coverage Δ | | |---|---|---| | [...nTelemetry.Api/Context/Propagation/B3Propagator.cs](https://app.codecov.io/gh/open-telemetry/opentelemetry-dotnet/pull/5767?src=pr&el=tree&filepath=src%2FOpenTelemetry.Api%2FContext%2FPropagation%2FB3Propagator.cs&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=open-telemetry#diff-c3JjL09wZW5UZWxlbWV0cnkuQXBpL0NvbnRleHQvUHJvcGFnYXRpb24vQjNQcm9wYWdhdG9yLmNz) | `86.02% <100.00%> (+0.15%)` | :arrow_up: | | [...metry.Api/Context/Propagation/BaggagePropagator.cs](https://app.codecov.io/gh/open-telemetry/opentelemetry-dotnet/pull/5767?src=pr&el=tree&filepath=src%2FOpenTelemetry.Api%2FContext%2FPropagation%2FBaggagePropagator.cs&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=open-telemetry#diff-c3JjL09wZW5UZWxlbWV0cnkuQXBpL0NvbnRleHQvUHJvcGFnYXRpb24vQmFnZ2FnZVByb3BhZ2F0b3IuY3M=) | `85.00% <100.00%> (-0.49%)` | :arrow_down: | | [.../Context/Propagation/CompositeTextMapPropagator.cs](https://app.codecov.io/gh/open-telemetry/opentelemetry-dotnet/pull/5767?src=pr&el=tree&filepath=src%2FOpenTelemetry.Api%2FContext%2FPropagation%2FCompositeTextMapPropagator.cs&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=open-telemetry#diff-c3JjL09wZW5UZWxlbWV0cnkuQXBpL0NvbnRleHQvUHJvcGFnYXRpb24vQ29tcG9zaXRlVGV4dE1hcFByb3BhZ2F0b3IuY3M=) | `100.00% <100.00%> (+16.66%)` | :arrow_up: | | [...y.Api/Context/Propagation/NoopTextMapPropagator.cs](https://app.codecov.io/gh/open-telemetry/opentelemetry-dotnet/pull/5767?src=pr&el=tree&filepath=src%2FOpenTelemetry.Api%2FContext%2FPropagation%2FNoopTextMapPropagator.cs&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=open-telemetry#diff-c3JjL09wZW5UZWxlbWV0cnkuQXBpL0NvbnRleHQvUHJvcGFnYXRpb24vTm9vcFRleHRNYXBQcm9wYWdhdG9yLmNz) | `33.33% <100.00%> (+33.33%)` | :arrow_up: | | [...enTelemetry.Api/Context/Propagation/Propagators.cs](https://app.codecov.io/gh/open-telemetry/opentelemetry-dotnet/pull/5767?src=pr&el=tree&filepath=src%2FOpenTelemetry.Api%2FContext%2FPropagation%2FPropagators.cs&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=open-telemetry#diff-c3JjL09wZW5UZWxlbWV0cnkuQXBpL0NvbnRleHQvUHJvcGFnYXRpb24vUHJvcGFnYXRvcnMuY3M=) | `100.00% <ø> (ø)` | | | [....Api/Context/Propagation/TraceContextPropagator.cs](https://app.codecov.io/gh/open-telemetry/opentelemetry-dotnet/pull/5767?src=pr&el=tree&filepath=src%2FOpenTelemetry.Api%2FContext%2FPropagation%2FTraceContextPropagator.cs&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=open-telemetry#diff-c3JjL09wZW5UZWxlbWV0cnkuQXBpL0NvbnRleHQvUHJvcGFnYXRpb24vVHJhY2VDb250ZXh0UHJvcGFnYXRvci5jcw==) | `90.82% <100.00%> (+1.35%)` | :arrow_up: | | [...etry.Api/Context/Propagation/TraceStateUtilsNew.cs](https://app.codecov.io/gh/open-telemetry/opentelemetry-dotnet/pull/5767?src=pr&el=tree&filepath=src%2FOpenTelemetry.Api%2FContext%2FPropagation%2FTraceStateUtilsNew.cs&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=open-telemetry#diff-c3JjL09wZW5UZWxlbWV0cnkuQXBpL0NvbnRleHQvUHJvcGFnYXRpb24vVHJhY2VTdGF0ZVV0aWxzTmV3LmNz) | `83.00% <100.00%> (ø)` | | | [...enTelemetry.Extensions.Propagators/B3Propagator.cs](https://app.codecov.io/gh/open-telemetry/opentelemetry-dotnet/pull/5767?src=pr&el=tree&filepath=src%2FOpenTelemetry.Extensions.Propagators%2FB3Propagator.cs&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=open-telemetry#diff-c3JjL09wZW5UZWxlbWV0cnkuRXh0ZW5zaW9ucy5Qcm9wYWdhdG9ycy9CM1Byb3BhZ2F0b3IuY3M=) | `86.02% <100.00%> (+0.15%)` | :arrow_up: | | [...lemetry.Extensions.Propagators/JaegerPropagator.cs](https://app.codecov.io/gh/open-telemetry/opentelemetry-dotnet/pull/5767?src=pr&el=tree&filepath=src%2FOpenTelemetry.Extensions.Propagators%2FJaegerPropagator.cs&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=open-telemetry#diff-c3JjL09wZW5UZWxlbWV0cnkuRXh0ZW5zaW9ucy5Qcm9wYWdhdG9ycy9KYWVnZXJQcm9wYWdhdG9yLmNz) | `95.38% <100.00%> (ø)` | | | [...etry.Api/Context/Propagation/PropagationContext.cs](https://app.codecov.io/gh/open-telemetry/opentelemetry-dotnet/pull/5767?src=pr&el=tree&filepath=src%2FOpenTelemetry.Api%2FContext%2FPropagation%2FPropagationContext.cs&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=open-telemetry#diff-c3JjL09wZW5UZWxlbWV0cnkuQXBpL0NvbnRleHQvUHJvcGFnYXRpb24vUHJvcGFnYXRpb25Db250ZXh0LmNz) | `64.28% <0.00%> (ø)` | | | ... and [1 more](https://app.codecov.io/gh/open-telemetry/opentelemetry-dotnet/pull/5767?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=open-telemetry) | | ... and [211 files with indirect coverage changes](https://app.codecov.io/gh/open-telemetry/opentelemetry-dotnet/pull/5767/indirect-changes?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=open-telemetry)
github-actions[bot] commented 1 month ago

This PR was marked stale due to lack of activity and will be closed in 7 days. Commenting or Pushing will instruct the bot to automatically remove the label. This bot runs once per day.

github-actions[bot] commented 1 month ago

This PR was marked stale due to lack of activity and will be closed in 7 days. Commenting or pushing will instruct the bot to automatically remove the label. This bot runs once per day.