Skip to content

Commit

Permalink
[Instrumentation.GrpcCore] Nullable support (#1936)
Browse files Browse the repository at this point in the history
  • Loading branch information
IliaBrahinets authored Jul 5, 2024
1 parent 38cd963 commit d6aff08
Show file tree
Hide file tree
Showing 18 changed files with 116 additions and 88 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#nullable enable
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
OpenTelemetry.Instrumentation.GrpcCore.ClientTracingInterceptor
OpenTelemetry.Instrumentation.GrpcCore.ClientTracingInterceptor.ClientTracingInterceptor(OpenTelemetry.Instrumentation.GrpcCore.ClientTracingInterceptorOptions options) -> void
OpenTelemetry.Instrumentation.GrpcCore.ClientTracingInterceptor.ClientTracingInterceptor(OpenTelemetry.Instrumentation.GrpcCore.ClientTracingInterceptorOptions! options) -> void
OpenTelemetry.Instrumentation.GrpcCore.ClientTracingInterceptorOptions
OpenTelemetry.Instrumentation.GrpcCore.ClientTracingInterceptorOptions.ClientTracingInterceptorOptions() -> void
OpenTelemetry.Instrumentation.GrpcCore.ClientTracingInterceptorOptions.Propagator.get -> OpenTelemetry.Context.Propagation.TextMapPropagator
OpenTelemetry.Instrumentation.GrpcCore.ClientTracingInterceptorOptions.Propagator.get -> OpenTelemetry.Context.Propagation.TextMapPropagator!
OpenTelemetry.Instrumentation.GrpcCore.ClientTracingInterceptorOptions.RecordException.get -> bool
OpenTelemetry.Instrumentation.GrpcCore.ClientTracingInterceptorOptions.RecordException.set -> void
OpenTelemetry.Instrumentation.GrpcCore.ClientTracingInterceptorOptions.RecordMessageEvents.get -> bool
OpenTelemetry.Instrumentation.GrpcCore.ClientTracingInterceptorOptions.RecordMessageEvents.set -> void
OpenTelemetry.Instrumentation.GrpcCore.ServerTracingInterceptor
OpenTelemetry.Instrumentation.GrpcCore.ServerTracingInterceptor.ServerTracingInterceptor(OpenTelemetry.Instrumentation.GrpcCore.ServerTracingInterceptorOptions options) -> void
OpenTelemetry.Instrumentation.GrpcCore.ServerTracingInterceptor.ServerTracingInterceptor(OpenTelemetry.Instrumentation.GrpcCore.ServerTracingInterceptorOptions! options) -> void
OpenTelemetry.Instrumentation.GrpcCore.ServerTracingInterceptorOptions
OpenTelemetry.Instrumentation.GrpcCore.ServerTracingInterceptorOptions.Propagator.get -> OpenTelemetry.Context.Propagation.TextMapPropagator
OpenTelemetry.Instrumentation.GrpcCore.ServerTracingInterceptorOptions.Propagator.get -> OpenTelemetry.Context.Propagation.TextMapPropagator!
OpenTelemetry.Instrumentation.GrpcCore.ServerTracingInterceptorOptions.RecordException.get -> bool
OpenTelemetry.Instrumentation.GrpcCore.ServerTracingInterceptorOptions.RecordException.set -> void
OpenTelemetry.Instrumentation.GrpcCore.ServerTracingInterceptorOptions.RecordMessageEvents.get -> bool
OpenTelemetry.Instrumentation.GrpcCore.ServerTracingInterceptorOptions.RecordMessageEvents.set -> void
OpenTelemetry.Instrumentation.GrpcCore.ServerTracingInterceptorOptions.ServerTracingInterceptorOptions() -> void
OpenTelemetry.Trace.TracerProviderBuilderExtensions
override OpenTelemetry.Instrumentation.GrpcCore.ClientTracingInterceptor.AsyncClientStreamingCall<TRequest, TResponse>(Grpc.Core.Interceptors.ClientInterceptorContext<TRequest, TResponse> context, Grpc.Core.Interceptors.Interceptor.AsyncClientStreamingCallContinuation<TRequest, TResponse> continuation) -> Grpc.Core.AsyncClientStreamingCall<TRequest, TResponse>
override OpenTelemetry.Instrumentation.GrpcCore.ClientTracingInterceptor.AsyncDuplexStreamingCall<TRequest, TResponse>(Grpc.Core.Interceptors.ClientInterceptorContext<TRequest, TResponse> context, Grpc.Core.Interceptors.Interceptor.AsyncDuplexStreamingCallContinuation<TRequest, TResponse> continuation) -> Grpc.Core.AsyncDuplexStreamingCall<TRequest, TResponse>
override OpenTelemetry.Instrumentation.GrpcCore.ClientTracingInterceptor.AsyncServerStreamingCall<TRequest, TResponse>(TRequest request, Grpc.Core.Interceptors.ClientInterceptorContext<TRequest, TResponse> context, Grpc.Core.Interceptors.Interceptor.AsyncServerStreamingCallContinuation<TRequest, TResponse> continuation) -> Grpc.Core.AsyncServerStreamingCall<TResponse>
override OpenTelemetry.Instrumentation.GrpcCore.ClientTracingInterceptor.AsyncUnaryCall<TRequest, TResponse>(TRequest request, Grpc.Core.Interceptors.ClientInterceptorContext<TRequest, TResponse> context, Grpc.Core.Interceptors.Interceptor.AsyncUnaryCallContinuation<TRequest, TResponse> continuation) -> Grpc.Core.AsyncUnaryCall<TResponse>
override OpenTelemetry.Instrumentation.GrpcCore.ClientTracingInterceptor.BlockingUnaryCall<TRequest, TResponse>(TRequest request, Grpc.Core.Interceptors.ClientInterceptorContext<TRequest, TResponse> context, Grpc.Core.Interceptors.Interceptor.BlockingUnaryCallContinuation<TRequest, TResponse> continuation) -> TResponse
override OpenTelemetry.Instrumentation.GrpcCore.ServerTracingInterceptor.ClientStreamingServerHandler<TRequest, TResponse>(Grpc.Core.IAsyncStreamReader<TRequest> requestStream, Grpc.Core.ServerCallContext context, Grpc.Core.ClientStreamingServerMethod<TRequest, TResponse> continuation) -> System.Threading.Tasks.Task<TResponse>
override OpenTelemetry.Instrumentation.GrpcCore.ServerTracingInterceptor.DuplexStreamingServerHandler<TRequest, TResponse>(Grpc.Core.IAsyncStreamReader<TRequest> requestStream, Grpc.Core.IServerStreamWriter<TResponse> responseStream, Grpc.Core.ServerCallContext context, Grpc.Core.DuplexStreamingServerMethod<TRequest, TResponse> continuation) -> System.Threading.Tasks.Task
override OpenTelemetry.Instrumentation.GrpcCore.ServerTracingInterceptor.ServerStreamingServerHandler<TRequest, TResponse>(TRequest request, Grpc.Core.IServerStreamWriter<TResponse> responseStream, Grpc.Core.ServerCallContext context, Grpc.Core.ServerStreamingServerMethod<TRequest, TResponse> continuation) -> System.Threading.Tasks.Task
override OpenTelemetry.Instrumentation.GrpcCore.ServerTracingInterceptor.UnaryServerHandler<TRequest, TResponse>(TRequest request, Grpc.Core.ServerCallContext context, Grpc.Core.UnaryServerMethod<TRequest, TResponse> continuation) -> System.Threading.Tasks.Task<TResponse>
static OpenTelemetry.Trace.TracerProviderBuilderExtensions.AddGrpcCoreInstrumentation(this OpenTelemetry.Trace.TracerProviderBuilder builder) -> OpenTelemetry.Trace.TracerProviderBuilder
override OpenTelemetry.Instrumentation.GrpcCore.ClientTracingInterceptor.AsyncClientStreamingCall<TRequest, TResponse>(Grpc.Core.Interceptors.ClientInterceptorContext<TRequest!, TResponse!> context, Grpc.Core.Interceptors.Interceptor.AsyncClientStreamingCallContinuation<TRequest!, TResponse!>! continuation) -> Grpc.Core.AsyncClientStreamingCall<TRequest!, TResponse!>!
override OpenTelemetry.Instrumentation.GrpcCore.ClientTracingInterceptor.AsyncDuplexStreamingCall<TRequest, TResponse>(Grpc.Core.Interceptors.ClientInterceptorContext<TRequest!, TResponse!> context, Grpc.Core.Interceptors.Interceptor.AsyncDuplexStreamingCallContinuation<TRequest!, TResponse!>! continuation) -> Grpc.Core.AsyncDuplexStreamingCall<TRequest!, TResponse!>!
override OpenTelemetry.Instrumentation.GrpcCore.ClientTracingInterceptor.AsyncServerStreamingCall<TRequest, TResponse>(TRequest! request, Grpc.Core.Interceptors.ClientInterceptorContext<TRequest!, TResponse!> context, Grpc.Core.Interceptors.Interceptor.AsyncServerStreamingCallContinuation<TRequest!, TResponse!>! continuation) -> Grpc.Core.AsyncServerStreamingCall<TResponse!>!
override OpenTelemetry.Instrumentation.GrpcCore.ClientTracingInterceptor.AsyncUnaryCall<TRequest, TResponse>(TRequest! request, Grpc.Core.Interceptors.ClientInterceptorContext<TRequest!, TResponse!> context, Grpc.Core.Interceptors.Interceptor.AsyncUnaryCallContinuation<TRequest!, TResponse!>! continuation) -> Grpc.Core.AsyncUnaryCall<TResponse!>!
override OpenTelemetry.Instrumentation.GrpcCore.ClientTracingInterceptor.BlockingUnaryCall<TRequest, TResponse>(TRequest! request, Grpc.Core.Interceptors.ClientInterceptorContext<TRequest!, TResponse!> context, Grpc.Core.Interceptors.Interceptor.BlockingUnaryCallContinuation<TRequest!, TResponse!>! continuation) -> TResponse!
override OpenTelemetry.Instrumentation.GrpcCore.ServerTracingInterceptor.ClientStreamingServerHandler<TRequest, TResponse>(Grpc.Core.IAsyncStreamReader<TRequest!>! requestStream, Grpc.Core.ServerCallContext! context, Grpc.Core.ClientStreamingServerMethod<TRequest!, TResponse!>! continuation) -> System.Threading.Tasks.Task<TResponse!>!
override OpenTelemetry.Instrumentation.GrpcCore.ServerTracingInterceptor.DuplexStreamingServerHandler<TRequest, TResponse>(Grpc.Core.IAsyncStreamReader<TRequest!>! requestStream, Grpc.Core.IServerStreamWriter<TResponse!>! responseStream, Grpc.Core.ServerCallContext! context, Grpc.Core.DuplexStreamingServerMethod<TRequest!, TResponse!>! continuation) -> System.Threading.Tasks.Task!
override OpenTelemetry.Instrumentation.GrpcCore.ServerTracingInterceptor.ServerStreamingServerHandler<TRequest, TResponse>(TRequest! request, Grpc.Core.IServerStreamWriter<TResponse!>! responseStream, Grpc.Core.ServerCallContext! context, Grpc.Core.ServerStreamingServerMethod<TRequest!, TResponse!>! continuation) -> System.Threading.Tasks.Task!
override OpenTelemetry.Instrumentation.GrpcCore.ServerTracingInterceptor.UnaryServerHandler<TRequest, TResponse>(TRequest! request, Grpc.Core.ServerCallContext! context, Grpc.Core.UnaryServerMethod<TRequest!, TResponse!>! continuation) -> System.Threading.Tasks.Task<TResponse!>!
static OpenTelemetry.Trace.TracerProviderBuilderExtensions.AddGrpcCoreInstrumentation(this OpenTelemetry.Trace.TracerProviderBuilder! builder) -> OpenTelemetry.Trace.TracerProviderBuilder!
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,17 @@ internal class AsyncStreamReaderProxy<T> : IAsyncStreamReader<T>
/// <summary>
/// The on message action.
/// </summary>
private readonly Action<T> onMessage;
private readonly Action<T>? onMessage;

/// <summary>
/// The on stream end action.
/// </summary>
private readonly Action onStreamEnd;
private readonly Action? onStreamEnd;

/// <summary>
/// The on exception action.
/// </summary>
private readonly Action<Exception> onException;
private readonly Action<Exception>? onException;

/// <summary>
/// Initializes a new instance of the <see cref="AsyncStreamReaderProxy{T}"/> class.
Expand All @@ -43,7 +43,7 @@ internal class AsyncStreamReaderProxy<T> : IAsyncStreamReader<T>
/// <param name="onMessage">The on message action, if any.</param>
/// <param name="onStreamEnd">The on stream end action, if any.</param>
/// <param name="onException">The on exception action, if any.</param>
public AsyncStreamReaderProxy(IAsyncStreamReader<T> reader, Action<T> onMessage = null, Action onStreamEnd = null, Action<Exception> onException = null)
public AsyncStreamReaderProxy(IAsyncStreamReader<T> reader, Action<T>? onMessage = null, Action? onStreamEnd = null, Action<Exception>? onException = null)
{
this.reader = reader;
this.onMessage = onMessage;
Expand Down
2 changes: 2 additions & 0 deletions src/OpenTelemetry.Instrumentation.GrpcCore/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

* Updated OpenTelemetry core component version(s) to `1.9.0`.
([#1888](https://github.com/open-telemetry/opentelemetry-dotnet-contrib/pull/1888))
* Updated minimal supported version of `Grpc.Core.Api` to `2.43.0`.
([#1936](https://github.com/open-telemetry/opentelemetry-dotnet-contrib/pull/1936))

## 1.0.0-beta.6

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,17 @@ internal class ClientStreamWriterProxy<T> : IClientStreamWriter<T>
/// <summary>
/// The on write action.
/// </summary>
private readonly Action<T> onWrite;
private readonly Action<T>? onWrite;

/// <summary>
/// The on complete action.
/// </summary>
private readonly Action onComplete;
private readonly Action? onComplete;

/// <summary>
/// The on exception action.
/// </summary>
private readonly Action<Exception> onException;
private readonly Action<Exception>? onException;

/// <summary>
/// Initializes a new instance of the <see cref="ClientStreamWriterProxy{T}"/> class.
Expand All @@ -43,7 +43,7 @@ internal class ClientStreamWriterProxy<T> : IClientStreamWriter<T>
/// <param name="onWrite">The on write action if any.</param>
/// <param name="onComplete">The on complete action, if any.</param>
/// <param name="onException">The on exception action, if any.</param>
public ClientStreamWriterProxy(IClientStreamWriter<T> writer, Action<T> onWrite = null, Action onComplete = null, Action<Exception> onException = null)
public ClientStreamWriterProxy(IClientStreamWriter<T> writer, Action<T>? onWrite = null, Action? onComplete = null, Action<Exception>? onException = null)
{
this.writer = writer;
this.onWrite = onWrite;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public override TResponse BlockingUnaryCall<TRequest, TResponse>(
Guard.ThrowIfNull(context);
Guard.ThrowIfNull(continuation);

ClientRpcScope<TRequest, TResponse> rpcScope = null;
ClientRpcScope<TRequest, TResponse>? rpcScope = null;

try
{
Expand Down Expand Up @@ -72,7 +72,7 @@ public override AsyncUnaryCall<TResponse> AsyncUnaryCall<TRequest, TResponse>(
Guard.ThrowIfNull(context);
Guard.ThrowIfNull(continuation);

ClientRpcScope<TRequest, TResponse> rpcScope = null;
ClientRpcScope<TRequest, TResponse>? rpcScope = null;

try
{
Expand All @@ -93,8 +93,14 @@ public override AsyncUnaryCall<TResponse> AsyncUnaryCall<TRequest, TResponse>(
}
catch (AggregateException ex)
{
rpcScope.CompleteWithException(ex.InnerException);
throw ex.InnerException;
if (ex.InnerException != null)
{
rpcScope.CompleteWithException(ex.InnerException);
throw ex.InnerException;
}

rpcScope.CompleteWithException(ex);
throw;
}
},
TaskScheduler.Current);
Expand Down Expand Up @@ -125,7 +131,7 @@ public override AsyncClientStreamingCall<TRequest, TResponse> AsyncClientStreami
Guard.ThrowIfNull(context);
Guard.ThrowIfNull(continuation);

ClientRpcScope<TRequest, TResponse> rpcScope = null;
ClientRpcScope<TRequest, TResponse>? rpcScope = null;

try
{
Expand All @@ -150,8 +156,14 @@ public override AsyncClientStreamingCall<TRequest, TResponse> AsyncClientStreami
}
catch (AggregateException ex)
{
rpcScope.CompleteWithException(ex.InnerException);
throw ex.InnerException;
if (ex.InnerException != null)
{
rpcScope.CompleteWithException(ex.InnerException);
throw ex.InnerException;
}

rpcScope.CompleteWithException(ex);
throw;
}
},
TaskScheduler.Current);
Expand Down Expand Up @@ -184,7 +196,7 @@ public override AsyncServerStreamingCall<TResponse> AsyncServerStreamingCall<TRe
Guard.ThrowIfNull(context);
Guard.ThrowIfNull(continuation);

ClientRpcScope<TRequest, TResponse> rpcScope = null;
ClientRpcScope<TRequest, TResponse>? rpcScope = null;

try
{
Expand Down Expand Up @@ -226,7 +238,7 @@ public override AsyncDuplexStreamingCall<TRequest, TResponse> AsyncDuplexStreami
Guard.ThrowIfNull(context);
Guard.ThrowIfNull(continuation);

ClientRpcScope<TRequest, TResponse> rpcScope = null;
ClientRpcScope<TRequest, TResponse>? rpcScope = null;

try
{
Expand Down Expand Up @@ -277,7 +289,7 @@ private sealed class ClientRpcScope<TRequest, TResponse> : RpcScope<TRequest, TR
/// <summary>
/// The metadata setter action.
/// </summary>
private static readonly Action<Metadata, string, string> MetadataSetter = (metadata, key, value) => { metadata.Add(new Metadata.Entry(key, value)); };
private static readonly Action<Metadata?, string, string> MetadataSetter = (metadata, key, value) => { metadata?.Add(new Metadata.Entry(key, value)); };

/// <summary>
/// The context.
Expand All @@ -287,7 +299,7 @@ private sealed class ClientRpcScope<TRequest, TResponse> : RpcScope<TRequest, TR
/// <summary>
/// The parent activity.
/// </summary>
private readonly Activity parentActivity;
private readonly Activity? parentActivity;

/// <summary>
/// Initializes a new instance of the <see cref="ClientRpcScope{TRequest, TResponse}" /> class.
Expand Down Expand Up @@ -343,7 +355,7 @@ public ClientRpcScope(ClientInterceptorContext<TRequest, TResponse> context, Cli

this.SetActivity(rpcActivity);
options.Propagator.Inject(new PropagationContext(rpcActivity.Context, Baggage.Current), callOptions.Headers, MetadataSetter);
this.context = new ClientInterceptorContext<TRequest, TResponse>(context.Method, context.Host, callOptions);
this.context = new ClientInterceptorContext<TRequest, TResponse>(context.Method!, context.Host, callOptions);
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,5 @@ public class ClientTracingInterceptorOptions
/// <summary>
/// Gets or sets additional activity tags used during unit testing.
/// </summary>
internal IReadOnlyDictionary<string, object> AdditionalTags { get; set; }
internal IReadOnlyDictionary<string, object?>? AdditionalTags { get; set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ internal static class GrpcCoreInstrumentation
/// <summary>
/// The activity source name.
/// </summary>
internal static readonly string ActivitySourceName = AssemblyName.Name;
internal static readonly string ActivitySourceName = AssemblyName.Name!;

/// <summary>
/// The activity source.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
<Description>.NET gRPC Core based client and server interceptors for OpenTelemetry.</Description>
<PackageTags>$(PackageTags);gRPC Core;interceptors</PackageTags>
<MinVerTagPrefix>Instrumentation.GrpcCore-</MinVerTagPrefix>
<Nullable>disable</Nullable>
</PropertyGroup>

<!--Do not run Package Baseline Validation as this package has never released a stable version.
Expand All @@ -15,7 +14,7 @@

<ItemGroup>
<PackageReference Include="Google.Protobuf" Version="[3.15.0,4.0)" />
<PackageReference Include="Grpc.Core.Api" Version="[2.23.0,3.0)" />
<PackageReference Include="Grpc.Core.Api" Version="[2.43.0,3.0)" />
<PackageReference Include="OpenTelemetry.Api" Version="$(OpenTelemetryCoreLatestVersion)" />
</ItemGroup>

Expand Down
Loading

0 comments on commit d6aff08

Please sign in to comment.