diff --git a/Directory.Build.props b/Directory.Build.props
index a0a856b99..20abcafb9 100644
--- a/Directory.Build.props
+++ b/Directory.Build.props
@@ -4,6 +4,6 @@
false
false
- 10.0
+ 11.0
diff --git a/src/OpenTelemetry.AutoInstrumentation/.publicApi/net462/PublicAPI.Shipped.txt b/src/OpenTelemetry.AutoInstrumentation/.publicApi/net462/PublicAPI.Shipped.txt
index e69de29bb..7dc5c5811 100644
--- a/src/OpenTelemetry.AutoInstrumentation/.publicApi/net462/PublicAPI.Shipped.txt
+++ b/src/OpenTelemetry.AutoInstrumentation/.publicApi/net462/PublicAPI.Shipped.txt
@@ -0,0 +1 @@
+#nullable enable
diff --git a/src/OpenTelemetry.AutoInstrumentation/.publicApi/net462/PublicAPI.Unshipped.txt b/src/OpenTelemetry.AutoInstrumentation/.publicApi/net462/PublicAPI.Unshipped.txt
index 3301fb056..3b7010f05 100644
--- a/src/OpenTelemetry.AutoInstrumentation/.publicApi/net462/PublicAPI.Unshipped.txt
+++ b/src/OpenTelemetry.AutoInstrumentation/.publicApi/net462/PublicAPI.Unshipped.txt
@@ -6,13 +6,12 @@ OpenTelemetry.AutoInstrumentation.CallTarget.CallTargetReturn.CallTargetRetur
OpenTelemetry.AutoInstrumentation.CallTarget.CallTargetReturn.CallTargetReturn(T returnValue) -> void
OpenTelemetry.AutoInstrumentation.CallTarget.CallTargetReturn.GetReturnValue() -> T
OpenTelemetry.AutoInstrumentation.CallTarget.CallTargetState
-OpenTelemetry.AutoInstrumentation.CallTarget.CallTargetState.Activity.get -> System.Diagnostics.Activity
+OpenTelemetry.AutoInstrumentation.CallTarget.CallTargetState.Activity.get -> System.Diagnostics.Activity?
OpenTelemetry.AutoInstrumentation.CallTarget.CallTargetState.CallTargetState() -> void
-OpenTelemetry.AutoInstrumentation.CallTarget.CallTargetState.CallTargetState(System.Diagnostics.Activity activity) -> void
-OpenTelemetry.AutoInstrumentation.CallTarget.CallTargetState.CallTargetState(System.Diagnostics.Activity activity, object state) -> void
-OpenTelemetry.AutoInstrumentation.CallTarget.CallTargetState.CallTargetState(System.Diagnostics.Activity activity, object state, System.DateTimeOffset? startTime) -> void
-OpenTelemetry.AutoInstrumentation.CallTarget.CallTargetState.StartTime.get -> System.DateTimeOffset?
-OpenTelemetry.AutoInstrumentation.CallTarget.CallTargetState.State.get -> object
+OpenTelemetry.AutoInstrumentation.CallTarget.CallTargetState.CallTargetState(System.Diagnostics.Activity! activity) -> void
+OpenTelemetry.AutoInstrumentation.CallTarget.CallTargetState.CallTargetState(System.Diagnostics.Activity! activity, object! state, System.DateTimeOffset? startTime) -> void
+OpenTelemetry.AutoInstrumentation.CallTarget.CallTargetState.CallTargetState(System.Diagnostics.Activity? activity, object! state) -> void
+OpenTelemetry.AutoInstrumentation.CallTarget.CallTargetState.State.get -> object?
OpenTelemetry.AutoInstrumentation.Instrumentations.GraphQL.ExecuteAsyncIntegration
OpenTelemetry.AutoInstrumentation.Instrumentations.Logger.LoggingBuilderIntegration
OpenTelemetry.AutoInstrumentation.Instrumentations.MongoDB.MongoClientIntegration
@@ -20,8 +19,8 @@ OpenTelemetry.AutoInstrumentation.Instrumentations.MySqlData.MySqlConnectionStri
OpenTelemetry.AutoInstrumentation.Instrumentations.StackExchangeRedis.StackExchangeRedisIntegration
OpenTelemetry.AutoInstrumentation.Instrumentations.StackExchangeRedis.StackExchangeRedisIntegrationAsync
OpenTelemetry.AutoInstrumentation.Instrumentations.Validations.StrongNamedValidation
-override OpenTelemetry.AutoInstrumentation.CallTarget.CallTargetReturn.ToString() -> string
-override OpenTelemetry.AutoInstrumentation.CallTarget.CallTargetState.ToString() -> string
+override OpenTelemetry.AutoInstrumentation.CallTarget.CallTargetReturn.ToString() -> string!
+override OpenTelemetry.AutoInstrumentation.CallTarget.CallTargetState.ToString() -> string!
static OpenTelemetry.AutoInstrumentation.CallTarget.CallTargetInvoker.BeginMethod(TTarget instance, TArg1 arg1, TArg2 arg2, TArg3 arg3, TArg4 arg4, TArg5 arg5, TArg6 arg6, TArg7 arg7, TArg8 arg8) -> OpenTelemetry.AutoInstrumentation.CallTarget.CallTargetState
static OpenTelemetry.AutoInstrumentation.CallTarget.CallTargetInvoker.BeginMethod(TTarget instance, TArg1 arg1, TArg2 arg2, TArg3 arg3, TArg4 arg4, TArg5 arg5, TArg6 arg6, TArg7 arg7) -> OpenTelemetry.AutoInstrumentation.CallTarget.CallTargetState
static OpenTelemetry.AutoInstrumentation.CallTarget.CallTargetInvoker.BeginMethod(TTarget instance, TArg1 arg1, TArg2 arg2, TArg3 arg3, TArg4 arg4, TArg5 arg5, TArg6 arg6) -> OpenTelemetry.AutoInstrumentation.CallTarget.CallTargetState
@@ -31,11 +30,11 @@ static OpenTelemetry.AutoInstrumentation.CallTarget.CallTargetInvoker.BeginMetho
static OpenTelemetry.AutoInstrumentation.CallTarget.CallTargetInvoker.BeginMethod(TTarget instance, TArg1 arg1, TArg2 arg2) -> OpenTelemetry.AutoInstrumentation.CallTarget.CallTargetState
static OpenTelemetry.AutoInstrumentation.CallTarget.CallTargetInvoker.BeginMethod(TTarget instance, TArg1 arg1) -> OpenTelemetry.AutoInstrumentation.CallTarget.CallTargetState
static OpenTelemetry.AutoInstrumentation.CallTarget.CallTargetInvoker.BeginMethod(TTarget instance) -> OpenTelemetry.AutoInstrumentation.CallTarget.CallTargetState
-static OpenTelemetry.AutoInstrumentation.CallTarget.CallTargetInvoker.BeginMethod(TTarget instance, object[] arguments) -> OpenTelemetry.AutoInstrumentation.CallTarget.CallTargetState
-static OpenTelemetry.AutoInstrumentation.CallTarget.CallTargetInvoker.EndMethod(TTarget instance, TReturn returnValue, System.Exception exception, OpenTelemetry.AutoInstrumentation.CallTarget.CallTargetState state) -> OpenTelemetry.AutoInstrumentation.CallTarget.CallTargetReturn
-static OpenTelemetry.AutoInstrumentation.CallTarget.CallTargetInvoker.EndMethod(TTarget instance, System.Exception exception, OpenTelemetry.AutoInstrumentation.CallTarget.CallTargetState state) -> OpenTelemetry.AutoInstrumentation.CallTarget.CallTargetReturn
-static OpenTelemetry.AutoInstrumentation.CallTarget.CallTargetInvoker.GetDefaultValue() -> T
-static OpenTelemetry.AutoInstrumentation.CallTarget.CallTargetInvoker.LogException(System.Exception exception) -> void
+static OpenTelemetry.AutoInstrumentation.CallTarget.CallTargetInvoker.BeginMethod(TTarget instance, object![]! arguments) -> OpenTelemetry.AutoInstrumentation.CallTarget.CallTargetState
+static OpenTelemetry.AutoInstrumentation.CallTarget.CallTargetInvoker.EndMethod(TTarget instance, TReturn returnValue, System.Exception! exception, OpenTelemetry.AutoInstrumentation.CallTarget.CallTargetState state) -> OpenTelemetry.AutoInstrumentation.CallTarget.CallTargetReturn
+static OpenTelemetry.AutoInstrumentation.CallTarget.CallTargetInvoker.EndMethod(TTarget instance, System.Exception! exception, OpenTelemetry.AutoInstrumentation.CallTarget.CallTargetState state) -> OpenTelemetry.AutoInstrumentation.CallTarget.CallTargetReturn
+static OpenTelemetry.AutoInstrumentation.CallTarget.CallTargetInvoker.GetDefaultValue() -> T?
+static OpenTelemetry.AutoInstrumentation.CallTarget.CallTargetInvoker.LogException(System.Exception! exception) -> void
static OpenTelemetry.AutoInstrumentation.CallTarget.CallTargetReturn.GetDefault() -> OpenTelemetry.AutoInstrumentation.CallTarget.CallTargetReturn
static OpenTelemetry.AutoInstrumentation.CallTarget.CallTargetReturn.GetDefault() -> OpenTelemetry.AutoInstrumentation.CallTarget.CallTargetReturn
static OpenTelemetry.AutoInstrumentation.CallTarget.CallTargetState.GetDefault() -> OpenTelemetry.AutoInstrumentation.CallTarget.CallTargetState
\ No newline at end of file
diff --git a/src/OpenTelemetry.AutoInstrumentation/.publicApi/net6.0/PublicAPI.Shipped.txt b/src/OpenTelemetry.AutoInstrumentation/.publicApi/net6.0/PublicAPI.Shipped.txt
index e69de29bb..7dc5c5811 100644
--- a/src/OpenTelemetry.AutoInstrumentation/.publicApi/net6.0/PublicAPI.Shipped.txt
+++ b/src/OpenTelemetry.AutoInstrumentation/.publicApi/net6.0/PublicAPI.Shipped.txt
@@ -0,0 +1 @@
+#nullable enable
diff --git a/src/OpenTelemetry.AutoInstrumentation/.publicApi/net6.0/PublicAPI.Unshipped.txt b/src/OpenTelemetry.AutoInstrumentation/.publicApi/net6.0/PublicAPI.Unshipped.txt
index 3301fb056..3b7010f05 100644
--- a/src/OpenTelemetry.AutoInstrumentation/.publicApi/net6.0/PublicAPI.Unshipped.txt
+++ b/src/OpenTelemetry.AutoInstrumentation/.publicApi/net6.0/PublicAPI.Unshipped.txt
@@ -6,13 +6,12 @@ OpenTelemetry.AutoInstrumentation.CallTarget.CallTargetReturn.CallTargetRetur
OpenTelemetry.AutoInstrumentation.CallTarget.CallTargetReturn.CallTargetReturn(T returnValue) -> void
OpenTelemetry.AutoInstrumentation.CallTarget.CallTargetReturn.GetReturnValue() -> T
OpenTelemetry.AutoInstrumentation.CallTarget.CallTargetState
-OpenTelemetry.AutoInstrumentation.CallTarget.CallTargetState.Activity.get -> System.Diagnostics.Activity
+OpenTelemetry.AutoInstrumentation.CallTarget.CallTargetState.Activity.get -> System.Diagnostics.Activity?
OpenTelemetry.AutoInstrumentation.CallTarget.CallTargetState.CallTargetState() -> void
-OpenTelemetry.AutoInstrumentation.CallTarget.CallTargetState.CallTargetState(System.Diagnostics.Activity activity) -> void
-OpenTelemetry.AutoInstrumentation.CallTarget.CallTargetState.CallTargetState(System.Diagnostics.Activity activity, object state) -> void
-OpenTelemetry.AutoInstrumentation.CallTarget.CallTargetState.CallTargetState(System.Diagnostics.Activity activity, object state, System.DateTimeOffset? startTime) -> void
-OpenTelemetry.AutoInstrumentation.CallTarget.CallTargetState.StartTime.get -> System.DateTimeOffset?
-OpenTelemetry.AutoInstrumentation.CallTarget.CallTargetState.State.get -> object
+OpenTelemetry.AutoInstrumentation.CallTarget.CallTargetState.CallTargetState(System.Diagnostics.Activity! activity) -> void
+OpenTelemetry.AutoInstrumentation.CallTarget.CallTargetState.CallTargetState(System.Diagnostics.Activity! activity, object! state, System.DateTimeOffset? startTime) -> void
+OpenTelemetry.AutoInstrumentation.CallTarget.CallTargetState.CallTargetState(System.Diagnostics.Activity? activity, object! state) -> void
+OpenTelemetry.AutoInstrumentation.CallTarget.CallTargetState.State.get -> object?
OpenTelemetry.AutoInstrumentation.Instrumentations.GraphQL.ExecuteAsyncIntegration
OpenTelemetry.AutoInstrumentation.Instrumentations.Logger.LoggingBuilderIntegration
OpenTelemetry.AutoInstrumentation.Instrumentations.MongoDB.MongoClientIntegration
@@ -20,8 +19,8 @@ OpenTelemetry.AutoInstrumentation.Instrumentations.MySqlData.MySqlConnectionStri
OpenTelemetry.AutoInstrumentation.Instrumentations.StackExchangeRedis.StackExchangeRedisIntegration
OpenTelemetry.AutoInstrumentation.Instrumentations.StackExchangeRedis.StackExchangeRedisIntegrationAsync
OpenTelemetry.AutoInstrumentation.Instrumentations.Validations.StrongNamedValidation
-override OpenTelemetry.AutoInstrumentation.CallTarget.CallTargetReturn.ToString() -> string
-override OpenTelemetry.AutoInstrumentation.CallTarget.CallTargetState.ToString() -> string
+override OpenTelemetry.AutoInstrumentation.CallTarget.CallTargetReturn.ToString() -> string!
+override OpenTelemetry.AutoInstrumentation.CallTarget.CallTargetState.ToString() -> string!
static OpenTelemetry.AutoInstrumentation.CallTarget.CallTargetInvoker.BeginMethod(TTarget instance, TArg1 arg1, TArg2 arg2, TArg3 arg3, TArg4 arg4, TArg5 arg5, TArg6 arg6, TArg7 arg7, TArg8 arg8) -> OpenTelemetry.AutoInstrumentation.CallTarget.CallTargetState
static OpenTelemetry.AutoInstrumentation.CallTarget.CallTargetInvoker.BeginMethod(TTarget instance, TArg1 arg1, TArg2 arg2, TArg3 arg3, TArg4 arg4, TArg5 arg5, TArg6 arg6, TArg7 arg7) -> OpenTelemetry.AutoInstrumentation.CallTarget.CallTargetState
static OpenTelemetry.AutoInstrumentation.CallTarget.CallTargetInvoker.BeginMethod(TTarget instance, TArg1 arg1, TArg2 arg2, TArg3 arg3, TArg4 arg4, TArg5 arg5, TArg6 arg6) -> OpenTelemetry.AutoInstrumentation.CallTarget.CallTargetState
@@ -31,11 +30,11 @@ static OpenTelemetry.AutoInstrumentation.CallTarget.CallTargetInvoker.BeginMetho
static OpenTelemetry.AutoInstrumentation.CallTarget.CallTargetInvoker.BeginMethod(TTarget instance, TArg1 arg1, TArg2 arg2) -> OpenTelemetry.AutoInstrumentation.CallTarget.CallTargetState
static OpenTelemetry.AutoInstrumentation.CallTarget.CallTargetInvoker.BeginMethod(TTarget instance, TArg1 arg1) -> OpenTelemetry.AutoInstrumentation.CallTarget.CallTargetState
static OpenTelemetry.AutoInstrumentation.CallTarget.CallTargetInvoker.BeginMethod(TTarget instance) -> OpenTelemetry.AutoInstrumentation.CallTarget.CallTargetState
-static OpenTelemetry.AutoInstrumentation.CallTarget.CallTargetInvoker.BeginMethod(TTarget instance, object[] arguments) -> OpenTelemetry.AutoInstrumentation.CallTarget.CallTargetState
-static OpenTelemetry.AutoInstrumentation.CallTarget.CallTargetInvoker.EndMethod(TTarget instance, TReturn returnValue, System.Exception exception, OpenTelemetry.AutoInstrumentation.CallTarget.CallTargetState state) -> OpenTelemetry.AutoInstrumentation.CallTarget.CallTargetReturn
-static OpenTelemetry.AutoInstrumentation.CallTarget.CallTargetInvoker.EndMethod(TTarget instance, System.Exception exception, OpenTelemetry.AutoInstrumentation.CallTarget.CallTargetState state) -> OpenTelemetry.AutoInstrumentation.CallTarget.CallTargetReturn
-static OpenTelemetry.AutoInstrumentation.CallTarget.CallTargetInvoker.GetDefaultValue() -> T
-static OpenTelemetry.AutoInstrumentation.CallTarget.CallTargetInvoker.LogException(System.Exception exception) -> void
+static OpenTelemetry.AutoInstrumentation.CallTarget.CallTargetInvoker.BeginMethod(TTarget instance, object![]! arguments) -> OpenTelemetry.AutoInstrumentation.CallTarget.CallTargetState
+static OpenTelemetry.AutoInstrumentation.CallTarget.CallTargetInvoker.EndMethod(TTarget instance, TReturn returnValue, System.Exception! exception, OpenTelemetry.AutoInstrumentation.CallTarget.CallTargetState state) -> OpenTelemetry.AutoInstrumentation.CallTarget.CallTargetReturn
+static OpenTelemetry.AutoInstrumentation.CallTarget.CallTargetInvoker.EndMethod(TTarget instance, System.Exception! exception, OpenTelemetry.AutoInstrumentation.CallTarget.CallTargetState state) -> OpenTelemetry.AutoInstrumentation.CallTarget.CallTargetReturn
+static OpenTelemetry.AutoInstrumentation.CallTarget.CallTargetInvoker.GetDefaultValue() -> T?
+static OpenTelemetry.AutoInstrumentation.CallTarget.CallTargetInvoker.LogException(System.Exception! exception) -> void
static OpenTelemetry.AutoInstrumentation.CallTarget.CallTargetReturn.GetDefault() -> OpenTelemetry.AutoInstrumentation.CallTarget.CallTargetReturn
static OpenTelemetry.AutoInstrumentation.CallTarget.CallTargetReturn.GetDefault() -> OpenTelemetry.AutoInstrumentation.CallTarget.CallTargetReturn
static OpenTelemetry.AutoInstrumentation.CallTarget.CallTargetState.GetDefault() -> OpenTelemetry.AutoInstrumentation.CallTarget.CallTargetState
\ No newline at end of file
diff --git a/src/OpenTelemetry.AutoInstrumentation/CallTarget/CallTargetInvoker.cs b/src/OpenTelemetry.AutoInstrumentation/CallTarget/CallTargetInvoker.cs
index 4d7f1b808..10bf0c9ff 100644
--- a/src/OpenTelemetry.AutoInstrumentation/CallTarget/CallTargetInvoker.cs
+++ b/src/OpenTelemetry.AutoInstrumentation/CallTarget/CallTargetInvoker.cs
@@ -313,14 +313,14 @@ public static class CallTargetInvoker
/// CallTarget state
/// CallTarget return structure
[MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static CallTargetReturn EndMethod(TTarget instance, TReturn returnValue, Exception exception, CallTargetState state)
+ public static CallTargetReturn EndMethod(TTarget instance, TReturn returnValue, Exception exception, CallTargetState state)
{
if (IntegrationOptions.IsIntegrationEnabled)
{
return EndMethodHandler.Invoke(instance, returnValue, exception, state);
}
- return new CallTargetReturn(returnValue);
+ return new CallTargetReturn(returnValue);
}
///
@@ -341,5 +341,5 @@ public static class CallTargetInvoker
/// Type to get the default value
/// Default value of T
[MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static T GetDefaultValue() => default;
+ public static T? GetDefaultValue() => default;
}
diff --git a/src/OpenTelemetry.AutoInstrumentation/CallTarget/CallTargetState.cs b/src/OpenTelemetry.AutoInstrumentation/CallTarget/CallTargetState.cs
index cf2711328..21ca33b37 100644
--- a/src/OpenTelemetry.AutoInstrumentation/CallTarget/CallTargetState.cs
+++ b/src/OpenTelemetry.AutoInstrumentation/CallTarget/CallTargetState.cs
@@ -25,10 +25,9 @@ namespace OpenTelemetry.AutoInstrumentation.CallTarget;
///
public readonly struct CallTargetState
{
- private readonly Activity _previousActivity;
- private readonly Activity _activity;
- private readonly object _state;
- private readonly DateTimeOffset? _startTime;
+ private readonly Activity? _previousActivity;
+ private readonly Activity? _activity;
+ private readonly object? _state;
///
/// Initializes a new instance of the struct.
@@ -39,7 +38,6 @@ public readonly struct CallTargetState
_previousActivity = null;
_activity = activity;
_state = null;
- _startTime = null;
}
///
@@ -47,12 +45,11 @@ public readonly struct CallTargetState
///
/// Activity instance
/// Object state instance
- public CallTargetState(Activity activity, object state)
+ public CallTargetState(Activity? activity, object state)
{
_previousActivity = null;
_activity = activity;
_state = state;
- _startTime = null;
}
///
@@ -66,33 +63,26 @@ public readonly struct CallTargetState
_previousActivity = null;
_activity = activity;
_state = state;
- _startTime = startTime;
}
- internal CallTargetState(Activity previousActivity, CallTargetState state)
+ internal CallTargetState(Activity? previousActivity, CallTargetState state)
{
_previousActivity = previousActivity;
_activity = state._activity;
_state = state._state;
- _startTime = state._startTime;
}
///
/// Gets the CallTarget BeginMethod activity
///
- public Activity Activity => _activity;
+ public Activity? Activity => _activity;
///
/// Gets the CallTarget BeginMethod state
///
- public object State => _state;
+ public object? State => _state;
- ///
- /// Gets the CallTarget state StartTime
- ///
- public DateTimeOffset? StartTime => _startTime;
-
- internal Activity PreviousActivity => _previousActivity;
+ internal Activity? PreviousActivity => _previousActivity;
///
/// Gets the default call target state (used by the native side to initialize the locals)
diff --git a/src/OpenTelemetry.AutoInstrumentation/CallTarget/Handlers/BeginMethodHandler.cs b/src/OpenTelemetry.AutoInstrumentation/CallTarget/Handlers/BeginMethodHandler.cs
index 2039664d9..2ae035ceb 100644
--- a/src/OpenTelemetry.AutoInstrumentation/CallTarget/Handlers/BeginMethodHandler.cs
+++ b/src/OpenTelemetry.AutoInstrumentation/CallTarget/Handlers/BeginMethodHandler.cs
@@ -31,7 +31,7 @@ internal static class BeginMethodHandler
{
try
{
- DynamicMethod dynMethod = IntegrationMapper.CreateBeginMethodDelegate(typeof(TIntegration), typeof(TTarget), Array.Empty());
+ DynamicMethod? dynMethod = IntegrationMapper.CreateBeginMethodDelegate(typeof(TIntegration), typeof(TTarget), Array.Empty());
if (dynMethod != null)
{
_invokeDelegate = (InvokeDelegate)dynMethod.CreateDelegate(typeof(InvokeDelegate));
diff --git a/src/OpenTelemetry.AutoInstrumentation/CallTarget/Handlers/BeginMethodHandler`1.cs b/src/OpenTelemetry.AutoInstrumentation/CallTarget/Handlers/BeginMethodHandler`1.cs
index 3dc32b5a8..6fe82e8ad 100644
--- a/src/OpenTelemetry.AutoInstrumentation/CallTarget/Handlers/BeginMethodHandler`1.cs
+++ b/src/OpenTelemetry.AutoInstrumentation/CallTarget/Handlers/BeginMethodHandler`1.cs
@@ -31,7 +31,7 @@ internal static class BeginMethodHandler
{
try
{
- DynamicMethod dynMethod = IntegrationMapper.CreateBeginMethodDelegate(typeof(TIntegration), typeof(TTarget), new[] { typeof(TArg1) });
+ DynamicMethod? dynMethod = IntegrationMapper.CreateBeginMethodDelegate(typeof(TIntegration), typeof(TTarget), new[] { typeof(TArg1) });
if (dynMethod != null)
{
_invokeDelegate = (InvokeDelegate)dynMethod.CreateDelegate(typeof(InvokeDelegate));
diff --git a/src/OpenTelemetry.AutoInstrumentation/CallTarget/Handlers/BeginMethodHandler`2.cs b/src/OpenTelemetry.AutoInstrumentation/CallTarget/Handlers/BeginMethodHandler`2.cs
index 42f35ecd1..5d462aae2 100644
--- a/src/OpenTelemetry.AutoInstrumentation/CallTarget/Handlers/BeginMethodHandler`2.cs
+++ b/src/OpenTelemetry.AutoInstrumentation/CallTarget/Handlers/BeginMethodHandler`2.cs
@@ -31,7 +31,7 @@ internal static class BeginMethodHandler
{
try
{
- DynamicMethod dynMethod = IntegrationMapper.CreateBeginMethodDelegate(typeof(TIntegration), typeof(TTarget), new[] { typeof(TArg1), typeof(TArg2) });
+ DynamicMethod? dynMethod = IntegrationMapper.CreateBeginMethodDelegate(typeof(TIntegration), typeof(TTarget), new[] { typeof(TArg1), typeof(TArg2) });
if (dynMethod != null)
{
_invokeDelegate = (InvokeDelegate)dynMethod.CreateDelegate(typeof(InvokeDelegate));
diff --git a/src/OpenTelemetry.AutoInstrumentation/CallTarget/Handlers/BeginMethodHandler`3.cs b/src/OpenTelemetry.AutoInstrumentation/CallTarget/Handlers/BeginMethodHandler`3.cs
index 66bb95d98..c790d7186 100644
--- a/src/OpenTelemetry.AutoInstrumentation/CallTarget/Handlers/BeginMethodHandler`3.cs
+++ b/src/OpenTelemetry.AutoInstrumentation/CallTarget/Handlers/BeginMethodHandler`3.cs
@@ -31,7 +31,7 @@ internal static class BeginMethodHandler
{
- public virtual TReturn SetContinuation(TTarget instance, TReturn returnValue, Exception exception, CallTargetState state)
+ public virtual TReturn? SetContinuation(TTarget instance, TReturn? returnValue, Exception? exception, CallTargetState state)
{
return returnValue;
}
@@ -37,12 +37,12 @@ internal class ContinuationGenerator
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
- protected static TTo FromTReturn(TReturn returnValue)
+ protected static TTo FromTReturn(TReturn? returnValue)
{
#if NET6_0_OR_GREATER
- return Unsafe.As(ref returnValue);
+ return Unsafe.As(ref returnValue);
#else
- return ContinuationsHelper.Convert(returnValue);
+ return ContinuationsHelper.Convert(returnValue);
#endif
}
}
diff --git a/src/OpenTelemetry.AutoInstrumentation/CallTarget/Handlers/Continuations/ContinuationsHelper.cs b/src/OpenTelemetry.AutoInstrumentation/CallTarget/Handlers/Continuations/ContinuationsHelper.cs
index 2d0b4cc41..4a76f3fd5 100644
--- a/src/OpenTelemetry.AutoInstrumentation/CallTarget/Handlers/Continuations/ContinuationsHelper.cs
+++ b/src/OpenTelemetry.AutoInstrumentation/CallTarget/Handlers/Continuations/ContinuationsHelper.cs
@@ -25,7 +25,7 @@ internal static class ContinuationsHelper
[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal static Type GetResultType(Type parentType)
{
- Type currentType = parentType;
+ Type? currentType = parentType;
while (currentType != null)
{
Type[] typeArguments = currentType.GenericTypeArguments ?? Type.EmptyTypes;
diff --git a/src/OpenTelemetry.AutoInstrumentation/CallTarget/Handlers/Continuations/TaskContinuationGenerator.cs b/src/OpenTelemetry.AutoInstrumentation/CallTarget/Handlers/Continuations/TaskContinuationGenerator.cs
index 967527407..ceb8ed156 100644
--- a/src/OpenTelemetry.AutoInstrumentation/CallTarget/Handlers/Continuations/TaskContinuationGenerator.cs
+++ b/src/OpenTelemetry.AutoInstrumentation/CallTarget/Handlers/Continuations/TaskContinuationGenerator.cs
@@ -22,7 +22,7 @@ namespace OpenTelemetry.AutoInstrumentation.CallTarget.Handlers.Continuations;
internal class TaskContinuationGenerator : ContinuationGenerator
{
- private static readonly Func _continuation;
+ private static readonly Func? _continuation;
private static readonly bool _preserveContext;
static TaskContinuationGenerator()
@@ -30,12 +30,12 @@ internal class TaskContinuationGenerator : Conti
var result = IntegrationMapper.CreateAsyncEndMethodDelegate(typeof(TIntegration), typeof(TTarget), typeof(object));
if (result.Method != null)
{
- _continuation = (Func)result.Method.CreateDelegate(typeof(Func));
+ _continuation = (Func)result.Method.CreateDelegate(typeof(Func));
_preserveContext = result.PreserveContext;
}
}
- public override TReturn SetContinuation(TTarget instance, TReturn returnValue, Exception exception, CallTargetState state)
+ public override TReturn? SetContinuation(TTarget instance, TReturn? returnValue, Exception? exception, CallTargetState state)
{
if (_continuation == null)
{
@@ -65,11 +65,11 @@ internal class TaskContinuationGenerator : Conti
await new NoThrowAwaiter(previousTask, _preserveContext);
}
- Exception exception = null;
+ Exception? exception = null;
if (previousTask.Status == TaskStatus.Faulted)
{
- exception = previousTask.Exception.GetBaseException();
+ exception = previousTask.Exception!.GetBaseException();
}
else if (previousTask.Status == TaskStatus.Canceled)
{
@@ -89,7 +89,7 @@ internal class TaskContinuationGenerator : Conti
// *
// Calls the CallTarget integration continuation, exceptions here should never bubble up to the application
// *
- _continuation(target, null, exception, state);
+ _continuation!(target, null, exception, state);
}
catch (Exception ex)
{
diff --git a/src/OpenTelemetry.AutoInstrumentation/CallTarget/Handlers/Continuations/TaskContinuationGenerator`1.cs b/src/OpenTelemetry.AutoInstrumentation/CallTarget/Handlers/Continuations/TaskContinuationGenerator`1.cs
index aeb0b165d..ab4329262 100644
--- a/src/OpenTelemetry.AutoInstrumentation/CallTarget/Handlers/Continuations/TaskContinuationGenerator`1.cs
+++ b/src/OpenTelemetry.AutoInstrumentation/CallTarget/Handlers/Continuations/TaskContinuationGenerator`1.cs
@@ -24,7 +24,7 @@ namespace OpenTelemetry.AutoInstrumentation.CallTarget.Handlers.Continuations;
internal class TaskContinuationGenerator : ContinuationGenerator
{
- private static readonly Func _continuation;
+ private static readonly Func? _continuation;
private static readonly bool _preserveContext;
static TaskContinuationGenerator()
@@ -32,12 +32,12 @@ internal class TaskContinuationGenerator)result.Method.CreateDelegate(typeof(Func));
+ _continuation = (Func)result.Method.CreateDelegate(typeof(Func));
_preserveContext = result.PreserveContext;
}
}
- public override TReturn SetContinuation(TTarget instance, TReturn returnValue, Exception exception, CallTargetState state)
+ public override TReturn? SetContinuation(TTarget instance, TReturn? returnValue, Exception? exception, CallTargetState state)
{
if (_continuation == null)
{
@@ -60,16 +60,16 @@ internal class TaskContinuationGenerator ContinuationAction(Task previousTask, TTarget target, CallTargetState state)
+ private static async Task ContinuationAction(Task previousTask, TTarget target, CallTargetState state)
{
if (!previousTask.IsCompleted)
{
await new NoThrowAwaiter(previousTask, _preserveContext);
}
- TResult taskResult = default;
- Exception exception = null;
- TResult continuationResult = default;
+ TResult? taskResult = default;
+ Exception? exception = null;
+ TResult? continuationResult = default;
if (previousTask.Status == TaskStatus.RanToCompletion)
{
@@ -77,7 +77,7 @@ internal class TaskContinuationGenerator : ContinuationGenerator
{
- private static readonly Func _continuation;
+ private static readonly Func? _continuation;
private static readonly bool _preserveContext;
static ValueTaskContinuationGenerator()
@@ -29,12 +29,12 @@ internal class ValueTaskContinuationGenerator :
var result = IntegrationMapper.CreateAsyncEndMethodDelegate(typeof(TIntegration), typeof(TTarget), typeof(object));
if (result.Method != null)
{
- _continuation = (Func)result.Method.CreateDelegate(typeof(Func));
+ _continuation = (Func)result.Method.CreateDelegate(typeof(Func));
_preserveContext = result.PreserveContext;
}
}
- public override TReturn SetContinuation(TTarget instance, TReturn returnValue, Exception exception, CallTargetState state)
+ public override TReturn? SetContinuation(TTarget instance, TReturn? returnValue, Exception? exception, CallTargetState state)
{
if (_continuation is null)
{
@@ -64,7 +64,7 @@ internal class ValueTaskContinuationGenerator :
// *
// Calls the CallTarget integration continuation, exceptions here should never bubble up to the application
// *
- _continuation(instance, default, ex, state);
+ _continuation!(instance, default, ex, state);
}
catch (Exception contEx)
{
@@ -79,7 +79,7 @@ internal class ValueTaskContinuationGenerator :
// *
// Calls the CallTarget integration continuation, exceptions here should never bubble up to the application
// *
- _continuation(instance, default, default, state);
+ _continuation!(instance, default, default, state);
}
catch (Exception contEx)
{
diff --git a/src/OpenTelemetry.AutoInstrumentation/CallTarget/Handlers/Continuations/ValueTaskContinuationGenerator`1.cs b/src/OpenTelemetry.AutoInstrumentation/CallTarget/Handlers/Continuations/ValueTaskContinuationGenerator`1.cs
index ab62b601e..8ff5e7614 100644
--- a/src/OpenTelemetry.AutoInstrumentation/CallTarget/Handlers/Continuations/ValueTaskContinuationGenerator`1.cs
+++ b/src/OpenTelemetry.AutoInstrumentation/CallTarget/Handlers/Continuations/ValueTaskContinuationGenerator`1.cs
@@ -23,7 +23,7 @@ namespace OpenTelemetry.AutoInstrumentation.CallTarget.Handlers.Continuations;
#if NET6_0_OR_GREATER
internal class ValueTaskContinuationGenerator : ContinuationGenerator
{
- private static readonly Func _continuation;
+ private static readonly Func? _continuation;
private static readonly bool _preserveContext;
static ValueTaskContinuationGenerator()
@@ -31,12 +31,12 @@ internal class ValueTaskContinuationGenerator)result.Method.CreateDelegate(typeof(Func));
+ _continuation = (Func)result.Method.CreateDelegate(typeof(Func));
_preserveContext = result.PreserveContext;
}
}
- public override TReturn SetContinuation(TTarget instance, TReturn returnValue, Exception exception, CallTargetState state)
+ public override TReturn? SetContinuation(TTarget instance, TReturn? returnValue, Exception? exception, CallTargetState state)
{
if (_continuation is null)
{
@@ -52,9 +52,9 @@ internal class ValueTaskContinuationGenerator previousValueTask = FromTReturn>(returnValue);
return ToTReturn(InnerSetValueTaskContinuation(instance, previousValueTask, state));
- static async ValueTask InnerSetValueTaskContinuation(TTarget instance, ValueTask previousValueTask, CallTargetState state)
+ static async ValueTask InnerSetValueTaskContinuation(TTarget instance, ValueTask previousValueTask, CallTargetState state)
{
- TResult result = default;
+ TResult? result = default;
try
{
result = await previousValueTask.ConfigureAwait(_preserveContext);
@@ -66,7 +66,7 @@ internal class ValueTaskContinuationGenerator
{
try
{
- DynamicMethod dynMethod = IntegrationMapper.CreateEndMethodDelegate(typeof(TIntegration), typeof(TTarget));
+ DynamicMethod? dynMethod = IntegrationMapper.CreateEndMethodDelegate(typeof(TIntegration), typeof(TTarget));
if (dynMethod != null)
{
_invokeDelegate = (InvokeDelegate)dynMethod.CreateDelegate(typeof(InvokeDelegate));
diff --git a/src/OpenTelemetry.AutoInstrumentation/CallTarget/Handlers/EndMethodHandler`1.cs b/src/OpenTelemetry.AutoInstrumentation/CallTarget/Handlers/EndMethodHandler`1.cs
index e71ea5ad4..097fb7aac 100644
--- a/src/OpenTelemetry.AutoInstrumentation/CallTarget/Handlers/EndMethodHandler`1.cs
+++ b/src/OpenTelemetry.AutoInstrumentation/CallTarget/Handlers/EndMethodHandler`1.cs
@@ -27,15 +27,15 @@ namespace OpenTelemetry.AutoInstrumentation.CallTarget.Handlers;
internal static class EndMethodHandler
{
- private static readonly InvokeDelegate _invokeDelegate = null;
- private static readonly ContinuationGenerator _continuationGenerator = null;
+ private static readonly InvokeDelegate? _invokeDelegate;
+ private static readonly ContinuationGenerator? _continuationGenerator;
static EndMethodHandler()
{
Type returnType = typeof(TReturn);
try
{
- DynamicMethod dynMethod = IntegrationMapper.CreateEndMethodDelegate(typeof(TIntegration), typeof(TTarget), returnType);
+ DynamicMethod? dynMethod = IntegrationMapper.CreateEndMethodDelegate(typeof(TIntegration), typeof(TTarget), returnType);
if (dynMethod != null)
{
_invokeDelegate = (InvokeDelegate)dynMethod.CreateDelegate(typeof(InvokeDelegate));
@@ -52,13 +52,13 @@ internal static class EndMethodHandler
if (typeof(Task).IsAssignableFrom(returnType))
{
// The type is a Task<>
- _continuationGenerator = (ContinuationGenerator)Activator.CreateInstance(typeof(TaskContinuationGenerator<,,,>).MakeGenericType(typeof(TIntegration), typeof(TTarget), returnType, ContinuationsHelper.GetResultType(returnType)));
+ _continuationGenerator = (ContinuationGenerator?)Activator.CreateInstance(typeof(TaskContinuationGenerator<,,,>).MakeGenericType(typeof(TIntegration), typeof(TTarget), returnType, ContinuationsHelper.GetResultType(returnType)));
}
#if NET6_0_OR_GREATER
else if (genericReturnType == typeof(ValueTask<>))
{
// The type is a ValueTask<>
- _continuationGenerator = (ContinuationGenerator)Activator.CreateInstance(typeof(ValueTaskContinuationGenerator<,,,>).MakeGenericType(typeof(TIntegration), typeof(TTarget), returnType, ContinuationsHelper.GetResultType(returnType)));
+ _continuationGenerator = (ContinuationGenerator?)Activator.CreateInstance(typeof(ValueTaskContinuationGenerator<,,,>).MakeGenericType(typeof(TIntegration), typeof(TTarget), returnType, ContinuationsHelper.GetResultType(returnType)));
}
#endif
}
@@ -79,10 +79,10 @@ internal static class EndMethodHandler
}
}
- internal delegate CallTargetReturn InvokeDelegate(TTarget instance, TReturn returnValue, Exception exception, CallTargetState state);
+ internal delegate CallTargetReturn InvokeDelegate(TTarget instance, TReturn? returnValue, Exception exception, CallTargetState state);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
- internal static CallTargetReturn Invoke(TTarget instance, TReturn returnValue, Exception exception, CallTargetState state)
+ internal static CallTargetReturn Invoke(TTarget instance, TReturn? returnValue, Exception exception, CallTargetState state)
{
if (_continuationGenerator != null)
{
@@ -95,10 +95,10 @@ internal static class EndMethodHandler
if (_invokeDelegate != null)
{
- CallTargetReturn returnWrap = _invokeDelegate(instance, returnValue, exception, state);
+ CallTargetReturn returnWrap = _invokeDelegate(instance, returnValue, exception, state);
returnValue = returnWrap.GetReturnValue();
}
- return new CallTargetReturn(returnValue);
+ return new CallTargetReturn(returnValue);
}
}
diff --git a/src/OpenTelemetry.AutoInstrumentation/CallTarget/Handlers/IntegrationMapper.cs b/src/OpenTelemetry.AutoInstrumentation/CallTarget/Handlers/IntegrationMapper.cs
index 2163b09a7..9a34cd9c5 100644
--- a/src/OpenTelemetry.AutoInstrumentation/CallTarget/Handlers/IntegrationMapper.cs
+++ b/src/OpenTelemetry.AutoInstrumentation/CallTarget/Handlers/IntegrationMapper.cs
@@ -32,10 +32,10 @@ internal class IntegrationMapper
private const string EndAsyncMethodName = "OnAsyncMethodEnd";
private static readonly ILogger Log = OtelLogging.GetLogger();
- private static readonly MethodInfo UnwrapReturnValueMethodInfo = typeof(IntegrationMapper).GetMethod(nameof(IntegrationMapper.UnwrapReturnValue), BindingFlags.NonPublic | BindingFlags.Static);
- private static readonly MethodInfo ConvertTypeMethodInfo = typeof(IntegrationMapper).GetMethod(nameof(IntegrationMapper.ConvertType), BindingFlags.NonPublic | BindingFlags.Static);
+ private static readonly MethodInfo UnwrapReturnValueMethodInfo = typeof(IntegrationMapper).GetMethod(nameof(IntegrationMapper.UnwrapReturnValue), BindingFlags.NonPublic | BindingFlags.Static)!;
+ private static readonly MethodInfo ConvertTypeMethodInfo = typeof(IntegrationMapper).GetMethod(nameof(IntegrationMapper.ConvertType), BindingFlags.NonPublic | BindingFlags.Static)!;
- internal static DynamicMethod CreateBeginMethodDelegate(Type integrationType, Type targetType, Type[] argumentsTypes)
+ internal static DynamicMethod? CreateBeginMethodDelegate(Type integrationType, Type targetType, Type[] argumentsTypes)
{
/*
* OnMethodBegin signatures with 1 or more parameters with 1 or more generics:
@@ -51,7 +51,7 @@ internal class IntegrationMapper
*/
Log.Debug($"Creating BeginMethod Dynamic Method for '{integrationType.FullName}' integration. [Target={targetType.FullName}]");
- MethodInfo onMethodBeginMethodInfo = integrationType.GetMethod(BeginMethodName, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
+ MethodInfo? onMethodBeginMethodInfo = integrationType.GetMethod(BeginMethodName, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
if (onMethodBeginMethodInfo is null)
{
return null;
@@ -86,13 +86,13 @@ internal class IntegrationMapper
bool mustLoadInstance = onMethodBeginParameters.Length != argumentsTypes.Length;
Type instanceGenericType = genericArgumentsTypes[0];
- Type instanceGenericConstraint = instanceGenericType.GetGenericParameterConstraints().FirstOrDefault();
- Type instanceProxyType = null;
+ Type? instanceGenericConstraint = instanceGenericType.GetGenericParameterConstraints().FirstOrDefault();
+ Type? instanceProxyType = null;
if (instanceGenericConstraint != null)
{
var result = DuckType.GetOrCreateProxyType(instanceGenericConstraint, targetType);
instanceProxyType = result.ProxyType;
- callGenericTypes.Add(instanceProxyType);
+ callGenericTypes.Add(instanceProxyType!);
}
else
{
@@ -100,7 +100,7 @@ internal class IntegrationMapper
}
DynamicMethod callMethod = new DynamicMethod(
- $"{onMethodBeginMethodInfo.DeclaringType.Name}.{onMethodBeginMethodInfo.Name}",
+ $"{onMethodBeginMethodInfo.DeclaringType?.Name}.{onMethodBeginMethodInfo.Name}",
typeof(CallTargetState),
new Type[] { targetType }.Concat(argumentsTypes),
onMethodBeginMethodInfo.Module,
@@ -115,7 +115,7 @@ internal class IntegrationMapper
if (instanceGenericConstraint != null)
{
- WriteCreateNewProxyInstance(ilWriter, instanceProxyType, targetType);
+ WriteCreateNewProxyInstance(ilWriter, instanceProxyType!, targetType);
}
}
@@ -124,8 +124,8 @@ internal class IntegrationMapper
{
Type sourceParameterType = argumentsTypes[mustLoadInstance ? i - 1 : i];
Type targetParameterType = onMethodBeginParameters[i].ParameterType;
- Type targetParameterTypeConstraint = null;
- Type parameterProxyType = null;
+ Type? targetParameterTypeConstraint = null;
+ Type? parameterProxyType = null;
if (targetParameterType.IsGenericParameter)
{
@@ -139,7 +139,7 @@ internal class IntegrationMapper
{
var result = DuckType.GetOrCreateProxyType(targetParameterTypeConstraint, sourceParameterType);
parameterProxyType = result.ProxyType;
- callGenericTypes.Add(parameterProxyType);
+ callGenericTypes.Add(parameterProxyType!);
}
}
else if (!targetParameterType.IsAssignableFrom(sourceParameterType) && (!(sourceParameterType.IsEnum && targetParameterType.IsEnum)))
@@ -179,7 +179,7 @@ internal class IntegrationMapper
*/
Log.Debug($"Creating SlowBeginMethod Dynamic Method for '{integrationType.FullName}' integration. [Target={targetType.FullName}]");
- MethodInfo onMethodBeginMethodInfo = integrationType.GetMethod(BeginMethodName, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
+ MethodInfo? onMethodBeginMethodInfo = integrationType.GetMethod(BeginMethodName, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
if (onMethodBeginMethodInfo is null)
{
throw new NullReferenceException($"Couldn't find the method: {BeginMethodName} in type: {integrationType.FullName}");
@@ -202,13 +202,13 @@ internal class IntegrationMapper
bool mustLoadInstance = onMethodBeginParameters[0].ParameterType.IsGenericParameter && onMethodBeginParameters[0].ParameterType.GenericParameterPosition == 0;
Type instanceGenericType = genericArgumentsTypes[0];
- Type instanceGenericConstraint = instanceGenericType.GetGenericParameterConstraints().FirstOrDefault();
- Type instanceProxyType = null;
+ Type? instanceGenericConstraint = instanceGenericType.GetGenericParameterConstraints().FirstOrDefault();
+ Type? instanceProxyType = null;
if (instanceGenericConstraint != null)
{
var result = DuckType.GetOrCreateProxyType(instanceGenericConstraint, targetType);
instanceProxyType = result.ProxyType;
- callGenericTypes.Add(instanceProxyType);
+ callGenericTypes.Add(instanceProxyType!);
}
else
{
@@ -216,7 +216,7 @@ internal class IntegrationMapper
}
DynamicMethod callMethod = new DynamicMethod(
- $"{onMethodBeginMethodInfo.DeclaringType.Name}.{onMethodBeginMethodInfo.Name}",
+ $"{onMethodBeginMethodInfo.DeclaringType?.Name}.{onMethodBeginMethodInfo.Name}",
typeof(CallTargetState),
new Type[] { targetType, typeof(object[]) },
onMethodBeginMethodInfo.Module,
@@ -231,7 +231,7 @@ internal class IntegrationMapper
if (instanceGenericConstraint != null)
{
- WriteCreateNewProxyInstance(ilWriter, instanceProxyType, targetType);
+ WriteCreateNewProxyInstance(ilWriter, instanceProxyType!, targetType);
}
}
@@ -239,7 +239,7 @@ internal class IntegrationMapper
for (var i = mustLoadInstance ? 1 : 0; i < onMethodBeginParameters.Length; i++)
{
Type targetParameterType = onMethodBeginParameters[i].ParameterType;
- Type targetParameterTypeConstraint = null;
+ Type? targetParameterTypeConstraint = null;
if (targetParameterType.IsGenericParameter)
{
@@ -280,7 +280,7 @@ internal class IntegrationMapper
return callMethod;
}
- internal static DynamicMethod CreateEndMethodDelegate(Type integrationType, Type targetType)
+ internal static DynamicMethod? CreateEndMethodDelegate(Type integrationType, Type targetType)
{
/*
* OnMethodEnd signatures with 2 or 3 parameters with 1 generics:
@@ -290,7 +290,7 @@ internal class IntegrationMapper
*/
Log.Debug($"Creating EndMethod Dynamic Method for '{integrationType.FullName}' integration. [Target={targetType.FullName}]");
- MethodInfo onMethodEndMethodInfo = integrationType.GetMethod(EndMethodName, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
+ MethodInfo? onMethodEndMethodInfo = integrationType.GetMethod(EndMethodName, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
if (onMethodEndMethodInfo is null)
{
return null;
@@ -331,13 +331,13 @@ internal class IntegrationMapper
bool mustLoadInstance = onMethodEndParameters.Length == 3;
Type instanceGenericType = genericArgumentsTypes[0];
- Type instanceGenericConstraint = instanceGenericType.GetGenericParameterConstraints().FirstOrDefault();
- Type instanceProxyType = null;
+ Type? instanceGenericConstraint = instanceGenericType.GetGenericParameterConstraints().FirstOrDefault();
+ Type? instanceProxyType = null;
if (instanceGenericConstraint != null)
{
var result = DuckType.GetOrCreateProxyType(instanceGenericConstraint, targetType);
instanceProxyType = result.ProxyType;
- callGenericTypes.Add(instanceProxyType);
+ callGenericTypes.Add(instanceProxyType!);
}
else
{
@@ -345,7 +345,7 @@ internal class IntegrationMapper
}
DynamicMethod callMethod = new DynamicMethod(
- $"{onMethodEndMethodInfo.DeclaringType.Name}.{onMethodEndMethodInfo.Name}",
+ $"{onMethodEndMethodInfo.DeclaringType?.Name}.{onMethodEndMethodInfo.Name}",
typeof(CallTargetReturn),
new Type[] { targetType, typeof(Exception), typeof(CallTargetState) },
onMethodEndMethodInfo.Module,
@@ -360,7 +360,7 @@ internal class IntegrationMapper
if (instanceGenericConstraint != null)
{
- WriteCreateNewProxyInstance(ilWriter, instanceProxyType, targetType);
+ WriteCreateNewProxyInstance(ilWriter, instanceProxyType!, targetType);
}
}
@@ -380,7 +380,7 @@ internal class IntegrationMapper
return callMethod;
}
- internal static DynamicMethod CreateEndMethodDelegate(Type integrationType, Type targetType, Type returnType)
+ internal static DynamicMethod? CreateEndMethodDelegate(Type integrationType, Type targetType, Type returnType)
{
/*
* OnMethodEnd signatures with 3 or 4 parameters with 1 or 2 generics:
@@ -391,7 +391,7 @@ internal class IntegrationMapper
*/
Log.Debug($"Creating EndMethod Dynamic Method for '{integrationType.FullName}' integration. [Target={targetType.FullName}, ReturnType={returnType.FullName}]");
- MethodInfo onMethodEndMethodInfo = integrationType.GetMethod(EndMethodName, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
+ MethodInfo? onMethodEndMethodInfo = integrationType.GetMethod(EndMethodName, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
if (onMethodEndMethodInfo is null)
{
return null;
@@ -432,13 +432,13 @@ internal class IntegrationMapper
bool mustLoadInstance = onMethodEndParameters.Length == 4;
Type instanceGenericType = genericArgumentsTypes[0];
- Type instanceGenericConstraint = instanceGenericType.GetGenericParameterConstraints().FirstOrDefault();
- Type instanceProxyType = null;
+ Type? instanceGenericConstraint = instanceGenericType.GetGenericParameterConstraints().FirstOrDefault();
+ Type? instanceProxyType = null;
if (instanceGenericConstraint != null)
{
var result = DuckType.GetOrCreateProxyType(instanceGenericConstraint, targetType);
instanceProxyType = result.ProxyType;
- callGenericTypes.Add(instanceProxyType);
+ callGenericTypes.Add(instanceProxyType!);
}
else
{
@@ -447,9 +447,9 @@ internal class IntegrationMapper
int returnParameterIndex = onMethodEndParameters.Length == 4 ? 1 : 0;
bool isAGenericReturnValue = onMethodEndParameters[returnParameterIndex].ParameterType.IsGenericParameter;
- Type returnValueGenericType = null;
- Type returnValueGenericConstraint = null;
- Type returnValueProxyType = null;
+ Type? returnValueGenericType = null;
+ Type? returnValueGenericConstraint = null;
+ Type? returnValueProxyType = null;
if (isAGenericReturnValue)
{
returnValueGenericType = genericArgumentsTypes[1];
@@ -458,7 +458,7 @@ internal class IntegrationMapper
{
var result = DuckType.GetOrCreateProxyType(returnValueGenericConstraint, returnType);
returnValueProxyType = result.ProxyType;
- callGenericTypes.Add(returnValueProxyType);
+ callGenericTypes.Add(returnValueProxyType!);
}
else
{
@@ -471,7 +471,7 @@ internal class IntegrationMapper
}
DynamicMethod callMethod = new DynamicMethod(
- $"{onMethodEndMethodInfo.DeclaringType.Name}.{onMethodEndMethodInfo.Name}.{targetType.Name}.{returnType.Name}",
+ $"{onMethodEndMethodInfo.DeclaringType?.Name}.{onMethodEndMethodInfo.Name}.{targetType.Name}.{returnType.Name}",
typeof(CallTargetReturn<>).MakeGenericType(returnType),
new Type[] { targetType, returnType, typeof(Exception), typeof(CallTargetState) },
onMethodEndMethodInfo.Module,
@@ -486,7 +486,7 @@ internal class IntegrationMapper
if (instanceGenericConstraint != null)
{
- WriteCreateNewProxyInstance(ilWriter, instanceProxyType, targetType);
+ WriteCreateNewProxyInstance(ilWriter, instanceProxyType!, targetType);
}
}
@@ -534,7 +534,7 @@ internal class IntegrationMapper
*/
Log.Debug($"Creating AsyncEndMethod Dynamic Method for '{integrationType.FullName}' integration. [Target={targetType.FullName}, ReturnType={returnType.FullName}]");
- MethodInfo onAsyncMethodEndMethodInfo = integrationType.GetMethod(EndAsyncMethodName, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
+ MethodInfo? onAsyncMethodEndMethodInfo = integrationType.GetMethod(EndAsyncMethodName, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
if (onAsyncMethodEndMethodInfo is null)
{
Log.Warning($"Couldn't find the method: {EndAsyncMethodName} in type: {integrationType.FullName}");
@@ -578,13 +578,13 @@ internal class IntegrationMapper
bool mustLoadInstance = onAsyncMethodEndParameters.Length == 4;
Type instanceGenericType = genericArgumentsTypes[0];
- Type instanceGenericConstraint = instanceGenericType.GetGenericParameterConstraints().FirstOrDefault();
- Type instanceProxyType = null;
+ Type? instanceGenericConstraint = instanceGenericType.GetGenericParameterConstraints().FirstOrDefault();
+ Type? instanceProxyType = null;
if (instanceGenericConstraint != null)
{
var result = DuckType.GetOrCreateProxyType(instanceGenericConstraint, targetType);
instanceProxyType = result.ProxyType;
- callGenericTypes.Add(instanceProxyType);
+ callGenericTypes.Add(instanceProxyType!);
}
else
{
@@ -593,9 +593,9 @@ internal class IntegrationMapper
int returnParameterIndex = onAsyncMethodEndParameters.Length == 4 ? 1 : 0;
bool isAGenericReturnValue = onAsyncMethodEndParameters[returnParameterIndex].ParameterType.IsGenericParameter;
- Type returnValueGenericType = null;
- Type returnValueGenericConstraint = null;
- Type returnValueProxyType = null;
+ Type? returnValueGenericType = null;
+ Type? returnValueGenericConstraint = null;
+ Type? returnValueProxyType = null;
if (isAGenericReturnValue)
{
returnValueGenericType = genericArgumentsTypes[1];
@@ -604,7 +604,7 @@ internal class IntegrationMapper
{
var result = DuckType.GetOrCreateProxyType(returnValueGenericConstraint, returnType);
returnValueProxyType = result.ProxyType;
- callGenericTypes.Add(returnValueProxyType);
+ callGenericTypes.Add(returnValueProxyType!);
}
else
{
@@ -617,7 +617,7 @@ internal class IntegrationMapper
}
DynamicMethod callMethod = new DynamicMethod(
- $"{onAsyncMethodEndMethodInfo.DeclaringType.Name}.{onAsyncMethodEndMethodInfo.Name}.{targetType.Name}.{returnType.Name}",
+ $"{onAsyncMethodEndMethodInfo.DeclaringType?.Name}.{onAsyncMethodEndMethodInfo.Name}.{targetType.Name}.{returnType.Name}",
returnType,
new Type[] { targetType, returnType, typeof(Exception), typeof(CallTargetState) },
onAsyncMethodEndMethodInfo.Module,
@@ -632,7 +632,7 @@ internal class IntegrationMapper
if (instanceGenericConstraint != null)
{
- WriteCreateNewProxyInstance(ilWriter, instanceProxyType, targetType);
+ WriteCreateNewProxyInstance(ilWriter, instanceProxyType!, targetType);
}
}
@@ -748,12 +748,12 @@ internal class IntegrationMapper
}
}
- private static T ConvertType(object value)
+ private static T? ConvertType(object value)
{
var conversionType = typeof(T);
if (value is null || conversionType == typeof(object))
{
- return (T)value;
+ return (T?)value;
}
Type valueType = value.GetType();
diff --git a/src/OpenTelemetry.AutoInstrumentation/CallTarget/Handlers/IntegrationOptions.cs b/src/OpenTelemetry.AutoInstrumentation/CallTarget/Handlers/IntegrationOptions.cs
index 1184b667a..557491fec 100644
--- a/src/OpenTelemetry.AutoInstrumentation/CallTarget/Handlers/IntegrationOptions.cs
+++ b/src/OpenTelemetry.AutoInstrumentation/CallTarget/Handlers/IntegrationOptions.cs
@@ -34,10 +34,10 @@ internal static class IntegrationOptions
internal static void DisableIntegration() => _disableIntegration = true;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
- internal static void LogException(Exception exception, string message = null)
+ internal static void LogException(Exception exception, string? message = null)
{
// ReSharper disable twice ExplicitCallerInfoArgument
- Log.Error(exception, message ?? exception?.Message);
+ Log.Error(exception, message ?? exception.Message);
if (exception is DuckTypeException)
{
Log.Warning($"DuckTypeException has been detected, the integration <{typeof(TIntegration)}, {typeof(TTarget)}> will be disabled.");
@@ -50,7 +50,7 @@ internal static class IntegrationOptions
}
else if (exception is FileLoadException fileLoadException)
{
- if (fileLoadException.FileName.StartsWith("System.Diagnostics.DiagnosticSource") || fileLoadException.FileName.StartsWith("System.Runtime.CompilerServices.Unsafe"))
+ if (fileLoadException.FileName != null && (fileLoadException.FileName.StartsWith("System.Diagnostics.DiagnosticSource") || fileLoadException.FileName.StartsWith("System.Runtime.CompilerServices.Unsafe")))
{
Log.Warning($"FileLoadException for '{fileLoadException.FileName}' has been detected, the integration <{typeof(TIntegration)}, {typeof(TTarget)}> will be disabled.");
_disableIntegration = true;
diff --git a/src/OpenTelemetry.AutoInstrumentation/Configuration/CompositeConfigurationSource.cs b/src/OpenTelemetry.AutoInstrumentation/Configuration/CompositeConfigurationSource.cs
index 98cb993de..7ed064329 100644
--- a/src/OpenTelemetry.AutoInstrumentation/Configuration/CompositeConfigurationSource.cs
+++ b/src/OpenTelemetry.AutoInstrumentation/Configuration/CompositeConfigurationSource.cs
@@ -26,7 +26,7 @@ namespace OpenTelemetry.AutoInstrumentation.Configuration;
///
internal class CompositeConfigurationSource : IConfigurationSource, IEnumerable
{
- private readonly List _sources = new List();
+ private readonly List _sources = new();
///
/// Adds a new configuration source to this instance.
@@ -58,7 +58,7 @@ internal class CompositeConfigurationSource : IConfigurationSource, IEnumerable<
///
/// The key that identifies the setting.
/// The value of the setting, or null if not found.
- public string GetString(string key)
+ public string? GetString(string key)
{
return _sources.Select(source => source.GetString(key))
.FirstOrDefault(value => !string.IsNullOrEmpty(value));
diff --git a/src/OpenTelemetry.AutoInstrumentation/Configuration/EnvironmentConfigurationSource.cs b/src/OpenTelemetry.AutoInstrumentation/Configuration/EnvironmentConfigurationSource.cs
index 4446ace0c..0a616a17d 100644
--- a/src/OpenTelemetry.AutoInstrumentation/Configuration/EnvironmentConfigurationSource.cs
+++ b/src/OpenTelemetry.AutoInstrumentation/Configuration/EnvironmentConfigurationSource.cs
@@ -24,7 +24,7 @@ namespace OpenTelemetry.AutoInstrumentation.Configuration;
///
internal class EnvironmentConfigurationSource : StringConfigurationSource
{
- protected override string GetStringInternal(string key)
+ protected override string? GetStringInternal(string key)
{
try
{
diff --git a/src/OpenTelemetry.AutoInstrumentation/Configuration/EnvironmentConfigurationTracerHelper.cs b/src/OpenTelemetry.AutoInstrumentation/Configuration/EnvironmentConfigurationTracerHelper.cs
index 43c519ebd..b39284b88 100644
--- a/src/OpenTelemetry.AutoInstrumentation/Configuration/EnvironmentConfigurationTracerHelper.cs
+++ b/src/OpenTelemetry.AutoInstrumentation/Configuration/EnvironmentConfigurationTracerHelper.cs
@@ -69,6 +69,11 @@ internal static class EnvironmentConfigurationTracerHelper
private static TracerProviderBuilder SetSampler(this TracerProviderBuilder builder, TracerSettings settings)
{
+ if (settings.TracesSampler == null)
+ {
+ return builder;
+ }
+
var sampler = TracerSamplerHelper.GetSampler(settings.TracesSampler, settings.TracesSamplerArguments);
if (sampler == null)
diff --git a/src/OpenTelemetry.AutoInstrumentation/Configuration/IConfigurationSource.cs b/src/OpenTelemetry.AutoInstrumentation/Configuration/IConfigurationSource.cs
index 745e03e60..81ce54908 100644
--- a/src/OpenTelemetry.AutoInstrumentation/Configuration/IConfigurationSource.cs
+++ b/src/OpenTelemetry.AutoInstrumentation/Configuration/IConfigurationSource.cs
@@ -27,7 +27,7 @@ internal interface IConfigurationSource
///
/// The key that identifies the setting.
/// The value of the setting, or null if not found.
- string GetString(string key);
+ string? GetString(string key);
///
/// Gets the value of
diff --git a/src/OpenTelemetry.AutoInstrumentation/Configuration/IntegrationInfo.cs b/src/OpenTelemetry.AutoInstrumentation/Configuration/IntegrationInfo.cs
index f89bae24b..8343cd2c4 100644
--- a/src/OpenTelemetry.AutoInstrumentation/Configuration/IntegrationInfo.cs
+++ b/src/OpenTelemetry.AutoInstrumentation/Configuration/IntegrationInfo.cs
@@ -20,17 +20,12 @@ namespace OpenTelemetry.AutoInstrumentation.Configuration;
internal readonly struct IntegrationInfo
{
- public readonly string Name;
+ public readonly string? Name;
public readonly int Id;
public IntegrationInfo(string integrationName)
{
- if (integrationName == null)
- {
- throw new ArgumentNullException(nameof(integrationName));
- }
-
Name = integrationName;
Id = 0;
}
diff --git a/src/OpenTelemetry.AutoInstrumentation/Configuration/NameValueConfigurationSource.cs b/src/OpenTelemetry.AutoInstrumentation/Configuration/NameValueConfigurationSource.cs
index 5d8a8b4db..d70718a37 100644
--- a/src/OpenTelemetry.AutoInstrumentation/Configuration/NameValueConfigurationSource.cs
+++ b/src/OpenTelemetry.AutoInstrumentation/Configuration/NameValueConfigurationSource.cs
@@ -36,7 +36,7 @@ internal class NameValueConfigurationSource : StringConfigurationSource
_nameValueCollection = nameValueCollection;
}
- protected override string GetStringInternal(string key)
+ protected override string? GetStringInternal(string key)
{
return _nameValueCollection[key];
}
diff --git a/src/OpenTelemetry.AutoInstrumentation/Configuration/SdkSettings.cs b/src/OpenTelemetry.AutoInstrumentation/Configuration/SdkSettings.cs
index 50c77a46c..2f8dd8f72 100644
--- a/src/OpenTelemetry.AutoInstrumentation/Configuration/SdkSettings.cs
+++ b/src/OpenTelemetry.AutoInstrumentation/Configuration/SdkSettings.cs
@@ -31,7 +31,7 @@ internal class SdkSettings : Settings
if (!string.IsNullOrEmpty(propagators))
{
- foreach (var propagator in propagators.Split(Constants.ConfigurationValues.Separator))
+ foreach (var propagator in propagators!.Split(Constants.ConfigurationValues.Separator))
{
Propagators.Add(ParsePropagator(propagator));
}
diff --git a/src/OpenTelemetry.AutoInstrumentation/Configuration/Settings.cs b/src/OpenTelemetry.AutoInstrumentation/Configuration/Settings.cs
index 26efd8231..20b25c407 100644
--- a/src/OpenTelemetry.AutoInstrumentation/Configuration/Settings.cs
+++ b/src/OpenTelemetry.AutoInstrumentation/Configuration/Settings.cs
@@ -60,14 +60,14 @@ internal abstract class Settings
try
{
- return (T)typeof(T)
- .GetConstructor(new[] { typeof(IConfigurationSource) })
+ return (T)typeof(T)!
+ .GetConstructor(new[] { typeof(IConfigurationSource) })!
.Invoke(new object[] { configurationSource });
}
catch (TargetInvocationException ex)
{
// Unwrap the more informative internal exception
- throw ex.InnerException;
+ throw ex.InnerException ?? ex;
}
}
diff --git a/src/OpenTelemetry.AutoInstrumentation/Configuration/StringConfigurationSource.cs b/src/OpenTelemetry.AutoInstrumentation/Configuration/StringConfigurationSource.cs
index 1f7edba16..3c54bd057 100644
--- a/src/OpenTelemetry.AutoInstrumentation/Configuration/StringConfigurationSource.cs
+++ b/src/OpenTelemetry.AutoInstrumentation/Configuration/StringConfigurationSource.cs
@@ -25,7 +25,7 @@ namespace OpenTelemetry.AutoInstrumentation.Configuration;
internal abstract class StringConfigurationSource : IConfigurationSource
{
///
- public virtual string GetString(string key)
+ public virtual string? GetString(string key)
{
var value = GetStringInternal(key);
if (string.IsNullOrEmpty(value))
@@ -39,9 +39,9 @@ internal abstract class StringConfigurationSource : IConfigurationSource
///
public virtual int? GetInt32(string key)
{
- string value = GetString(key);
+ var value = GetString(key);
- return int.TryParse(value, out int result)
+ return int.TryParse(value, out var result)
? result
: (int?)null;
}
@@ -49,9 +49,9 @@ internal abstract class StringConfigurationSource : IConfigurationSource
///
public double? GetDouble(string key)
{
- string value = GetString(key);
+ var value = GetString(key);
- return double.TryParse(value, NumberStyles.Any, CultureInfo.InvariantCulture, out double result)
+ return double.TryParse(value, NumberStyles.Any, CultureInfo.InvariantCulture, out var result)
? result
: (double?)null;
}
@@ -60,8 +60,8 @@ internal abstract class StringConfigurationSource : IConfigurationSource
public virtual bool? GetBool(string key)
{
var value = GetString(key);
- return bool.TryParse(value, out bool result) ? result : null;
+ return bool.TryParse(value, out var result) ? result : null;
}
- protected abstract string GetStringInternal(string key);
+ protected abstract string? GetStringInternal(string key);
}
diff --git a/src/OpenTelemetry.AutoInstrumentation/Configuration/TracerSamplerHelper.cs b/src/OpenTelemetry.AutoInstrumentation/Configuration/TracerSamplerHelper.cs
index 152772585..19817c87d 100644
--- a/src/OpenTelemetry.AutoInstrumentation/Configuration/TracerSamplerHelper.cs
+++ b/src/OpenTelemetry.AutoInstrumentation/Configuration/TracerSamplerHelper.cs
@@ -21,7 +21,7 @@ namespace OpenTelemetry.AutoInstrumentation.Configuration;
internal static class TracerSamplerHelper
{
- public static Sampler GetSampler(string tracerSampler, string tracerSamplerArguments)
+ public static Sampler? GetSampler(string tracerSampler, string? tracerSamplerArguments)
{
switch (tracerSampler)
{
@@ -42,7 +42,7 @@ internal static class TracerSamplerHelper
return null;
}
- private static TraceIdRatioBasedSampler CreateTraceIdRatioBasedSampler(string arguments)
+ private static TraceIdRatioBasedSampler CreateTraceIdRatioBasedSampler(string? arguments)
{
const double defaultRatio = 1.0;
diff --git a/src/OpenTelemetry.AutoInstrumentation/Configuration/TracerSettings.cs b/src/OpenTelemetry.AutoInstrumentation/Configuration/TracerSettings.cs
index 21d20b2a1..1475fe407 100644
--- a/src/OpenTelemetry.AutoInstrumentation/Configuration/TracerSettings.cs
+++ b/src/OpenTelemetry.AutoInstrumentation/Configuration/TracerSettings.cs
@@ -111,12 +111,12 @@ internal class TracerSettings : Settings
///
/// Gets sampler to be used for traces.
///
- public string TracesSampler { get; }
+ public string? TracesSampler { get; }
///
/// Gets a value to be used as the sampler argument.
///
- public string TracesSamplerArguments { get; }
+ public string? TracesSamplerArguments { get; }
private static TracesExporter ParseTracesExporter(IConfigurationSource source)
{
diff --git a/src/OpenTelemetry.AutoInstrumentation/Diagnostics/SdkSelfDiagnosticsEventListener.cs b/src/OpenTelemetry.AutoInstrumentation/Diagnostics/SdkSelfDiagnosticsEventListener.cs
index 8dd34de7d..a3e1eb55c 100644
--- a/src/OpenTelemetry.AutoInstrumentation/Diagnostics/SdkSelfDiagnosticsEventListener.cs
+++ b/src/OpenTelemetry.AutoInstrumentation/Diagnostics/SdkSelfDiagnosticsEventListener.cs
@@ -34,23 +34,26 @@ internal class SdkSelfDiagnosticsEventListener : EventListener
private readonly object lockObj = new();
private readonly EventLevel logLevel;
private readonly ILogger log;
- private readonly List eventSourcesBeforeConstructor = new();
+ private readonly List? eventSourcesBeforeConstructor = new();
public SdkSelfDiagnosticsEventListener(EventLevel eventLevel, ILogger logger)
{
log = logger;
logLevel = eventLevel;
- List eventSources;
+ List? eventSources;
lock (lockObj)
{
eventSources = this.eventSourcesBeforeConstructor;
eventSourcesBeforeConstructor = null;
}
- foreach (var eventSource in eventSources)
+ if (eventSources != null)
{
- EnableEvents(eventSource, logLevel, EventKeywords.All);
+ foreach (var eventSource in eventSources)
+ {
+ EnableEvents(eventSource, logLevel, EventKeywords.All);
+ }
}
}
@@ -88,24 +91,34 @@ internal class SdkSelfDiagnosticsEventListener : EventListener
/// Data of the EventSource event.
protected override void OnEventWritten(EventWrittenEventArgs eventData)
{
- var payloadArray = new object[eventData.Payload.Count];
- eventData.Payload.CopyTo(payloadArray, 0);
+ object[] payloadArray;
+ if (eventData.Payload != null)
+ {
+ payloadArray = new object[eventData.Payload.Count];
+ eventData.Payload.CopyTo(payloadArray, 0);
+ }
+ else
+ {
+ payloadArray = Array.Empty