Skip to content

Commit aa73ce3

Browse files
[otlp] Remove Grpc.Core support for .NET Framework and .NET Standard 2.0 in OTLP exporter (#6229)
1 parent f183a6a commit aa73ce3

18 files changed

+239
-174
lines changed

Directory.Packages.props

+3-9
Original file line numberDiff line numberDiff line change
@@ -57,15 +57,6 @@
5757
even during major version bumps, so compatibility is not a concern here.
5858
-->
5959
<PackageVersion Include="System.Diagnostics.DiagnosticSource" Version="$(LatestRuntimeOutOfBandVer)" />
60-
61-
<!--
62-
We use conservative versions of these packages where an upgrade might
63-
introduce breaking changes.
64-
-->
65-
<PackageVersion Include="Google.Protobuf" Version="[3.22.5,4.0)" />
66-
<PackageVersion Include="Grpc" Version="[2.44.0,3.0)" />
67-
<PackageVersion Include="Grpc.Core" Version="[2.44.0,3.0)" />
68-
<PackageVersion Include="Grpc.Net.Client" Version="[2.52.0,3.0)" />
6960
</ItemGroup>
7061

7162
<ItemGroup>
@@ -97,6 +88,9 @@
9788
<PackageVersion Include="Grpc.AspNetCore" Version="[2.59.0,3.0)" />
9889
<PackageVersion Include="Grpc.AspNetCore.Server" Version="[2.59.0, 3.0)" />
9990
<PackageVersion Include="Grpc.Tools" Version="[2.59.0,3.0)" />
91+
<PackageVersion Include="Google.Protobuf" Version="[3.22.5,4.0)" />
92+
<PackageVersion Include="Grpc" Version="[2.44.0,3.0)" />
93+
<PackageVersion Include="Grpc.Net.Client" Version="[2.52.0,3.0)" />
10094
<PackageVersion Include="Microsoft.CSharp" Version="[4.7.0]" />
10195
<PackageVersion Include="Microsoft.CodeAnalysis.PublicApiAnalyzers" Version="[3.11.0-beta1.23525.2]" />
10296
<PackageVersion Include="Microsoft.Coyote" Version="1.7.11" />

src/OpenTelemetry.Exporter.OpenTelemetryProtocol/CHANGELOG.md

+10
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,16 @@ Notes](../../RELEASENOTES.md).
77

88
## Unreleased
99

10+
* **Breaking Change**: .NET Framework and .NET Standard builds now default to
11+
exporting over OTLP/HTTP instead of OTLP/gRPC. **This change could result in a
12+
failure to export telemetry unless appropriate measures are taken.**
13+
Additionally, if you explicitly configure the exporter to use OTLP/gRPC it may
14+
result in a `NotSupportedException` without further configuration. Please
15+
carefully review issue
16+
([#6209](https://github.com/open-telemetry/opentelemetry-dotnet/pull/6209))
17+
for additional information and workarounds.
18+
([#6229](https://github.com/open-telemetry/opentelemetry-dotnet/pull/6229))
19+
1020
## 1.11.2
1121

1222
Released 2025-Mar-04

src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/ExportClient/GrpcExportClient.cs

-109
This file was deleted.

src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/ExportClient/OtlpExportClient.cs

+2
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,9 @@ protected OtlpExportClient(OtlpExporterOptions options, HttpClient httpClient, s
3535
Guard.ThrowIfNull(signalPath);
3636

3737
Uri exporterEndpoint;
38+
#pragma warning disable CS0618 // Suppressing gRPC obsolete warning
3839
if (options.Protocol == OtlpExportProtocol.Grpc)
40+
#pragma warning restore CS0618 // Suppressing gRPC obsolete warning
3941
{
4042
exporterEndpoint = options.Endpoint.AppendPathIfNotPresent(signalPath);
4143
}

src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OpenTelemetry.Exporter.OpenTelemetryProtocol.csproj

-4
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,6 @@
2323
<ProjectReference Include="$(RepoRoot)\src\OpenTelemetry\OpenTelemetry.csproj" />
2424
</ItemGroup>
2525

26-
<ItemGroup>
27-
<PackageReference Include="Grpc.Core" Condition="'$(TargetFramework)' == 'netstandard2.0' OR '$(TargetFramework)' == '$(NetFrameworkMinimumSupportedVersion)'" />
28-
</ItemGroup>
29-
3026
<ItemGroup>
3127
<Reference Include="System.Net.Http" Condition="'$(TargetFramework)' == '$(NetFrameworkMinimumSupportedVersion)'" />
3228
</ItemGroup>

src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExportProtocol.cs

+3
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ public enum OtlpExportProtocol : byte
1111
/// <summary>
1212
/// OTLP over gRPC (corresponds to 'grpc' Protocol configuration option). Used as default.
1313
/// </summary>
14+
#if NET462_OR_GREATER || NETSTANDARD2_0
15+
[Obsolete("CAUTION: OTLP/gRPC is no longer supported for .NET Framework or .NET Standard targets without supplying a properly configured HttpClientFactory. It is strongly encouraged that you migrate to using OTLP/HTTPPROTOBUF.")]
16+
#endif
1417
Grpc = 0,
1518

1619
/// <summary>

src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExportProtocolParser.cs

+2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ public static bool TryParse(string value, out OtlpExportProtocol result)
1010
switch (value?.Trim())
1111
{
1212
case "grpc":
13+
#pragma warning disable CS0618 // Suppressing gRPC obsolete warning
1314
result = OtlpExportProtocol.Grpc;
15+
#pragma warning restore CS0618 // Suppressing gRPC obsolete warning
1416
return true;
1517
case "http/protobuf":
1618
result = OtlpExportProtocol.HttpProtobuf;

src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExporterOptions.cs

+6
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,11 @@ public class OtlpExporterOptions : IOtlpExporterOptions
2626
{
2727
internal const string DefaultGrpcEndpoint = "http://localhost:4317";
2828
internal const string DefaultHttpEndpoint = "http://localhost:4318";
29+
#if NET462_OR_GREATER || NETSTANDARD2_0
30+
internal const OtlpExportProtocol DefaultOtlpExportProtocol = OtlpExportProtocol.HttpProtobuf;
31+
#else
2932
internal const OtlpExportProtocol DefaultOtlpExportProtocol = OtlpExportProtocol.Grpc;
33+
#endif
3034

3135
internal static readonly KeyValuePair<string, string>[] StandardHeaders = new KeyValuePair<string, string>[]
3236
{
@@ -84,7 +88,9 @@ public Uri Endpoint
8488
{
8589
if (this.endpoint == null)
8690
{
91+
#pragma warning disable CS0618 // Suppressing gRPC obsolete warning
8792
return this.Protocol == OtlpExportProtocol.Grpc
93+
#pragma warning restore CS0618 // Suppressing gRPC obsolete warning
8894
? new Uri(DefaultGrpcEndpoint)
8995
: new Uri(DefaultHttpEndpoint);
9096
}

src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExporterOptionsExtensions.cs

+2-41
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,6 @@
99
using OpenTelemetry.Exporter.OpenTelemetryProtocol.Implementation;
1010
using OpenTelemetry.Exporter.OpenTelemetryProtocol.Implementation.ExportClient;
1111
using OpenTelemetry.Exporter.OpenTelemetryProtocol.Implementation.Transmission;
12-
#if NET462_OR_GREATER || NETSTANDARD2_0
13-
using Grpc.Core;
14-
#endif
1512

1613
namespace OpenTelemetry.Exporter;
1714

@@ -25,30 +22,6 @@ internal static class OtlpExporterOptionsExtensions
2522
private const string MetricsHttpServicePath = "v1/metrics";
2623
private const string LogsHttpServicePath = "v1/logs";
2724

28-
#if NET462_OR_GREATER || NETSTANDARD2_0
29-
public static Channel CreateChannel(this OtlpExporterOptions options)
30-
{
31-
if (options.Endpoint.Scheme != Uri.UriSchemeHttp && options.Endpoint.Scheme != Uri.UriSchemeHttps)
32-
{
33-
throw new NotSupportedException($"Endpoint URI scheme ({options.Endpoint.Scheme}) is not supported. Currently only \"http\" and \"https\" are supported.");
34-
}
35-
36-
ChannelCredentials channelCredentials;
37-
if (options.Endpoint.Scheme == Uri.UriSchemeHttps)
38-
{
39-
channelCredentials = new SslCredentials();
40-
}
41-
else
42-
{
43-
channelCredentials = ChannelCredentials.Insecure;
44-
}
45-
46-
return new Channel(options.Endpoint.Authority, channelCredentials);
47-
}
48-
49-
public static Metadata GetMetadataFromHeaders(this OtlpExporterOptions options) => options.GetHeaders<Metadata>((m, k, v) => m.Add(k, v));
50-
#endif
51-
5225
public static THeaders GetHeaders<THeaders>(this OtlpExporterOptions options, Action<THeaders, string, string> addHeader)
5326
where THeaders : new()
5427
{
@@ -129,25 +102,12 @@ public static IExportClient GetExportClient(this OtlpExporterOptions options, Ot
129102
{
130103
var httpClient = options.HttpClientFactory?.Invoke() ?? throw new InvalidOperationException("OtlpExporterOptions was missing HttpClientFactory or it returned null.");
131104

105+
#pragma warning disable CS0618 // Suppressing gRPC obsolete warning
132106
if (options.Protocol != OtlpExportProtocol.Grpc && options.Protocol != OtlpExportProtocol.HttpProtobuf)
133107
{
134108
throw new NotSupportedException($"Protocol {options.Protocol} is not supported.");
135109
}
136110

137-
#if NET462_OR_GREATER || NETSTANDARD2_0
138-
if (options.Protocol == OtlpExportProtocol.Grpc)
139-
{
140-
var servicePath = otlpSignalType switch
141-
{
142-
OtlpSignalType.Traces => TraceGrpcServicePath,
143-
OtlpSignalType.Metrics => MetricsGrpcServicePath,
144-
OtlpSignalType.Logs => LogsGrpcServicePath,
145-
_ => throw new NotSupportedException($"OtlpSignalType {otlpSignalType} is not supported."),
146-
};
147-
return new GrpcExportClient(options, servicePath);
148-
}
149-
#endif
150-
151111
return otlpSignalType switch
152112
{
153113
OtlpSignalType.Traces => options.Protocol == OtlpExportProtocol.Grpc
@@ -164,6 +124,7 @@ public static IExportClient GetExportClient(this OtlpExporterOptions options, Ot
164124

165125
_ => throw new NotSupportedException($"OtlpSignalType {otlpSignalType} is not supported."),
166126
};
127+
#pragma warning restore CS0618 // Suppressing gRPC obsolete warning
167128
}
168129

169130
public static void TryEnableIHttpClientFactoryIntegration(this OtlpExporterOptions options, IServiceProvider serviceProvider, string httpClientName)

src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpLogExporterHelperExtensions.cs

+11
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,17 @@ internal static BaseProcessor<LogRecord> BuildOtlpLogExporter(
284284
Debug.Assert(sdkLimitOptions != null, "sdkLimitOptions was null");
285285
Debug.Assert(experimentalOptions != null, "experimentalOptions was null");
286286

287+
#if NET462_OR_GREATER || NETSTANDARD2_0
288+
#pragma warning disable CS0618 // Suppressing gRPC obsolete warning
289+
if (exporterOptions!.Protocol == OtlpExportProtocol.Grpc &&
290+
ReferenceEquals(exporterOptions.HttpClientFactory, exporterOptions.DefaultHttpClientFactory))
291+
#pragma warning restore CS0618 // Suppressing gRPC obsolete warning
292+
{
293+
throw new NotSupportedException("OtlpExportProtocol.Grpc with the default HTTP client factory is not supported on .NET Framework or .NET Standard 2.0." +
294+
"Please switch to OtlpExportProtocol.HttpProtobuf or provide a custom HttpClientFactory.");
295+
}
296+
#endif
297+
287298
if (!skipUseOtlpExporterRegistrationCheck)
288299
{
289300
serviceProvider!.EnsureNoUseOtlpExporterRegistrations();

src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpMetricExporterExtensions.cs

+11
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,17 @@ internal static MetricReader BuildOtlpExporterMetricReader(
168168
Debug.Assert(metricReaderOptions != null, "metricReaderOptions was null");
169169
Debug.Assert(experimentalOptions != null, "experimentalOptions was null");
170170

171+
#if NET462_OR_GREATER || NETSTANDARD2_0
172+
#pragma warning disable CS0618 // Suppressing gRPC obsolete warning
173+
if (exporterOptions!.Protocol == OtlpExportProtocol.Grpc &&
174+
ReferenceEquals(exporterOptions.HttpClientFactory, exporterOptions.DefaultHttpClientFactory))
175+
#pragma warning restore CS0618 // Suppressing gRPC obsolete warning
176+
{
177+
throw new NotSupportedException("OtlpExportProtocol.Grpc with the default HTTP client factory is not supported on .NET Framework or .NET Standard 2.0." +
178+
"Please switch to OtlpExportProtocol.HttpProtobuf or provide a custom HttpClientFactory.");
179+
}
180+
#endif
181+
171182
if (!skipUseOtlpExporterRegistrationCheck)
172183
{
173184
serviceProvider!.EnsureNoUseOtlpExporterRegistrations();

src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpTraceExporterHelperExtensions.cs

+11
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,17 @@ internal static BaseProcessor<Activity> BuildOtlpExporterProcessor(
129129
Debug.Assert(experimentalOptions != null, "experimentalOptions was null");
130130
Debug.Assert(batchExportProcessorOptions != null, "batchExportProcessorOptions was null");
131131

132+
#if NET462_OR_GREATER || NETSTANDARD2_0
133+
#pragma warning disable CS0618 // Suppressing gRPC obsolete warning
134+
if (exporterOptions!.Protocol == OtlpExportProtocol.Grpc &&
135+
ReferenceEquals(exporterOptions.HttpClientFactory, exporterOptions.DefaultHttpClientFactory))
136+
#pragma warning restore CS0618 // Suppressing gRPC obsolete warning
137+
{
138+
throw new NotSupportedException("OtlpExportProtocol.Grpc with the default HTTP client factory is not supported on .NET Framework or .NET Standard 2.0." +
139+
"Please switch to OtlpExportProtocol.HttpProtobuf or provide a custom HttpClientFactory.");
140+
}
141+
#endif
142+
132143
if (!skipUseOtlpExporterRegistrationCheck)
133144
{
134145
serviceProvider!.EnsureNoUseOtlpExporterRegistrations();

test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/IntegrationTest/IntegrationTests.cs

+6
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ public void Dispose()
3434
this.openTelemetryEventListener.Dispose();
3535
}
3636

37+
#pragma warning disable CS0618 // Suppressing gRPC obsolete warning
3738
[InlineData(OtlpExportProtocol.Grpc, ":4317", ExportProcessorType.Batch, false)]
3839
[InlineData(OtlpExportProtocol.HttpProtobuf, ":4318/v1/traces", ExportProcessorType.Batch, false)]
3940
[InlineData(OtlpExportProtocol.Grpc, ":4317", ExportProcessorType.Batch, true)]
@@ -44,6 +45,7 @@ public void Dispose()
4445
[InlineData(OtlpExportProtocol.HttpProtobuf, ":4318/v1/traces", ExportProcessorType.Simple, true)]
4546
[InlineData(OtlpExportProtocol.Grpc, ":5317", ExportProcessorType.Simple, true, "https")]
4647
[InlineData(OtlpExportProtocol.HttpProtobuf, ":5318/v1/traces", ExportProcessorType.Simple, true, "https")]
48+
#pragma warning restore CS0618 // Suppressing gRPC obsolete warning
4749
[Trait("CategoryName", "CollectorIntegrationTests")]
4850
[SkipUnlessEnvVarFoundTheory(CollectorHostnameEnvVarName)]
4951
public void TraceExportResultIsSuccess(OtlpExportProtocol protocol, string endpoint, ExportProcessorType exportProcessorType, bool forceFlush, string scheme = "http")
@@ -118,6 +120,7 @@ public void TraceExportResultIsSuccess(OtlpExportProtocol protocol, string endpo
118120
}
119121
}
120122

123+
#pragma warning disable CS0618 // Suppressing gRPC obsolete warning
121124
[InlineData(OtlpExportProtocol.Grpc, ":4317", false, false)]
122125
[InlineData(OtlpExportProtocol.HttpProtobuf, ":4318/v1/metrics", false, false)]
123126
[InlineData(OtlpExportProtocol.Grpc, ":4317", false, true)]
@@ -128,6 +131,7 @@ public void TraceExportResultIsSuccess(OtlpExportProtocol protocol, string endpo
128131
[InlineData(OtlpExportProtocol.HttpProtobuf, ":4318/v1/metrics", true, true)]
129132
[InlineData(OtlpExportProtocol.Grpc, ":5317", true, true, "https")]
130133
[InlineData(OtlpExportProtocol.HttpProtobuf, ":5318/v1/metrics", true, true, "https")]
134+
#pragma warning restore CS0618 // Suppressing gRPC obsolete warning
131135
[Trait("CategoryName", "CollectorIntegrationTests")]
132136
[SkipUnlessEnvVarFoundTheory(CollectorHostnameEnvVarName)]
133137
public void MetricExportResultIsSuccess(OtlpExportProtocol protocol, string endpoint, bool useManualExport, bool forceFlush, string scheme = "http")
@@ -202,12 +206,14 @@ public void MetricExportResultIsSuccess(OtlpExportProtocol protocol, string endp
202206
}
203207
}
204208

209+
#pragma warning disable CS0618 // Suppressing gRPC obsolete warning
205210
[InlineData(OtlpExportProtocol.Grpc, ":4317", ExportProcessorType.Batch)]
206211
[InlineData(OtlpExportProtocol.HttpProtobuf, ":4318/v1/logs", ExportProcessorType.Batch)]
207212
[InlineData(OtlpExportProtocol.Grpc, ":4317", ExportProcessorType.Simple)]
208213
[InlineData(OtlpExportProtocol.HttpProtobuf, ":4318/v1/logs", ExportProcessorType.Simple)]
209214
[InlineData(OtlpExportProtocol.Grpc, ":5317", ExportProcessorType.Simple, "https")]
210215
[InlineData(OtlpExportProtocol.HttpProtobuf, ":5318/v1/logs", ExportProcessorType.Simple, "https")]
216+
#pragma warning restore CS0618 // Suppressing gRPC obsolete warning
211217
[Trait("CategoryName", "CollectorIntegrationTests")]
212218
[SkipUnlessEnvVarFoundTheory(CollectorHostnameEnvVarName)]
213219
public void LogExportResultIsSuccess(OtlpExportProtocol protocol, string endpoint, ExportProcessorType exportProcessorType, string scheme = "http")

0 commit comments

Comments
 (0)