Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[OTLP exporter] Remove dependency on deprecated gRPC library #4860

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<ItemGroup>
<PackageVersion Include="Google.Protobuf" Version="[3.19.4,4.0)" />
<PackageVersion Include="Grpc" Version="[2.44.0,3.0)" />
<PackageVersion Include="Grpc.Net.Client" Version="[2.52.0,3.0)" />
<PackageVersion Include="Grpc.Net.Client" Version="[2.56.0,3.0)" />
<PackageVersion Include="Microsoft.AspNetCore.Http.Abstractions" Version="[2.1.1,6.0)" />
<PackageVersion Include="Microsoft.AspNetCore.Http.Features" Version="[2.1.1,6.0)" />
<PackageVersion Include="Microsoft.CSharp" Version="[4.7.0]" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,8 @@
// </copyright>

using Grpc.Core;
using OpenTelemetry.Internal;
#if NETSTANDARD2_1 || NET6_0_OR_GREATER
using Grpc.Net.Client;
#endif
using OpenTelemetry.Internal;

namespace OpenTelemetry.Exporter.OpenTelemetryProtocol.Implementation.ExportClient;

Expand All @@ -38,11 +36,7 @@ protected BaseOtlpGrpcExportClient(OtlpExporterOptions options)
this.TimeoutMilliseconds = options.TimeoutMilliseconds;
}

#if NETSTANDARD2_1 || NET6_0_OR_GREATER
internal GrpcChannel Channel { get; set; }
#else
internal Channel Channel { get; set; }
#endif

internal Uri Endpoint { get; }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ private static int CalculateNextRetryDelay(int nextRetryDelayMilliseconds)
{
Debug.Assert(headers != null, "headers was null");

#if NETSTANDARD2_1_OR_GREATER || NET6_0_OR_GREATER
#if NET6_0_OR_GREATER
return statusCode == HttpStatusCode.TooManyRequests || statusCode == HttpStatusCode.ServiceUnavailable
#else
return statusCode == (HttpStatusCode)429 || statusCode == HttpStatusCode.ServiceUnavailable
Expand Down Expand Up @@ -207,7 +207,7 @@ private static bool IsHttpStatusCodeRetryable(HttpStatusCode statusCode, bool _)
{
switch (statusCode)
{
#if NETSTANDARD2_1_OR_GREATER || NET6_0_OR_GREATER
#if NET6_0_OR_GREATER
case HttpStatusCode.TooManyRequests:
#else
case (HttpStatusCode)429:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>$(DefaultTargetFrameworks);netstandard2.1</TargetFrameworks>
<TargetFrameworks>$(DefaultTargetFrameworks)</TargetFrameworks>
Copy link
Member

@cijothomas cijothomas Sep 19, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

<DefaultTargetFrameworks>net6.0;netstandard2.0;net462</DefaultTargetFrameworks>

For quick/easy ref while reviewing PR

<DefaultTargetFrameworks>net6.0;netstandard2.0;net462</DefaultTargetFrameworks>

<Description>OpenTelemetry protocol exporter for OpenTelemetry .NET</Description>
<PackageTags>$(PackageTags);OTLP</PackageTags>
<MinVerTagPrefix>core-</MinVerTagPrefix>
Expand All @@ -15,8 +15,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Grpc.Net.Client" Condition="'$(TargetFramework)' == 'netstandard2.1' OR '$(TargetFramework)' == 'net6.0'" />
<PackageReference Include="Grpc" Condition="'$(TargetFramework)' == 'netstandard2.0' OR '$(TargetFramework)' == 'net462'" />
<PackageReference Include="Grpc.Net.Client" />
<PackageReference Include="Google.Protobuf" />
<PackageReference Include="Grpc.Tools" PrivateAssets="All" />
<PackageReference Include="System.Reflection.Emit.Lightweight" Condition="'$(TargetFramework)' != 'net6.0'" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,8 @@
#endif
using System.Reflection;
using Grpc.Core;
using OpenTelemetry.Exporter.OpenTelemetryProtocol.Implementation.ExportClient;
#if NETSTANDARD2_1 || NET6_0_OR_GREATER
using Grpc.Net.Client;
#endif
using OpenTelemetry.Exporter.OpenTelemetryProtocol.Implementation.ExportClient;
using LogOtlpCollector = OpenTelemetry.Proto.Collector.Logs.V1;
using MetricsOtlpCollector = OpenTelemetry.Proto.Collector.Metrics.V1;
using TraceOtlpCollector = OpenTelemetry.Proto.Collector.Trace.V1;
Expand All @@ -31,32 +29,14 @@ namespace OpenTelemetry.Exporter;

internal static class OtlpExporterOptionsExtensions
{
#if NETSTANDARD2_1 || NET6_0_OR_GREATER
public static GrpcChannel CreateChannel(this OtlpExporterOptions options)
#else
public static Channel CreateChannel(this OtlpExporterOptions options)
#endif
{
if (options.Endpoint.Scheme != Uri.UriSchemeHttp && options.Endpoint.Scheme != Uri.UriSchemeHttps)
{
throw new NotSupportedException($"Endpoint URI scheme ({options.Endpoint.Scheme}) is not supported. Currently only \"http\" and \"https\" are supported.");
}

#if NETSTANDARD2_1 || NET6_0_OR_GREATER
return GrpcChannel.ForAddress(options.Endpoint);
#else
ChannelCredentials channelCredentials;
if (options.Endpoint.Scheme == Uri.UriSchemeHttps)
{
channelCredentials = new SslCredentials();
}
else
{
channelCredentials = ChannelCredentials.Insecure;
}

return new Channel(options.Endpoint.Authority, channelCredentials);
#endif
}

public static Metadata GetMetadataFromHeaders(this OtlpExporterOptions options)
Expand Down