Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 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
12 changes: 3 additions & 9 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,6 @@
even during major version bumps, so compatibility is not a concern here.
-->
<PackageVersion Include="System.Diagnostics.DiagnosticSource" Version="$(LatestRuntimeOutOfBandVer)" />

<!--
We use conservative versions of these packages where an upgrade might
introduce breaking changes.
-->
<PackageVersion Include="Google.Protobuf" Version="[3.22.5,4.0)" />
<PackageVersion Include="Grpc" Version="[2.44.0,3.0)" />
<PackageVersion Include="Grpc.Core" Version="[2.44.0,3.0)" />
<PackageVersion Include="Grpc.Net.Client" Version="[2.52.0,3.0)" />
</ItemGroup>

<ItemGroup>
Expand Down Expand Up @@ -97,6 +88,9 @@
<PackageVersion Include="Grpc.AspNetCore" Version="[2.59.0,3.0)" />
<PackageVersion Include="Grpc.AspNetCore.Server" Version="[2.59.0, 3.0)" />
<PackageVersion Include="Grpc.Tools" Version="[2.59.0,3.0)" />
<PackageVersion Include="Google.Protobuf" Version="[3.22.5,4.0)" />
<PackageVersion Include="Grpc" Version="[2.44.0,3.0)" />
<PackageVersion Include="Grpc.Net.Client" Version="[2.52.0,3.0)" />
<PackageVersion Include="Microsoft.CSharp" Version="[4.7.0]" />
<PackageVersion Include="Microsoft.CodeAnalysis.PublicApiAnalyzers" Version="[3.11.0-beta1.23525.2]" />
<PackageVersion Include="Microsoft.Coyote" Version="1.7.11" />
Expand Down
10 changes: 10 additions & 0 deletions src/OpenTelemetry.Exporter.OpenTelemetryProtocol/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,16 @@ Notes](../../RELEASENOTES.md).

## Unreleased

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

## 1.11.2

Released 2025-Mar-04
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ protected OtlpExportClient(OtlpExporterOptions options, HttpClient httpClient, s
Guard.ThrowIfNull(signalPath);

Uri exporterEndpoint;
#pragma warning disable CS0618 // Suppressing gRPC obsolete warning
if (options.Protocol == OtlpExportProtocol.Grpc)
#pragma warning restore CS0618 // Suppressing gRPC obsolete warning
{
exporterEndpoint = options.Endpoint.AppendPathIfNotPresent(signalPath);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,6 @@
<ProjectReference Include="$(RepoRoot)\src\OpenTelemetry\OpenTelemetry.csproj" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Grpc.Core" Condition="'$(TargetFramework)' == 'netstandard2.0' OR '$(TargetFramework)' == '$(NetFrameworkMinimumSupportedVersion)'" />
</ItemGroup>

<ItemGroup>
<Reference Include="System.Net.Http" Condition="'$(TargetFramework)' == '$(NetFrameworkMinimumSupportedVersion)'" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ public enum OtlpExportProtocol : byte
/// <summary>
/// OTLP over gRPC (corresponds to 'grpc' Protocol configuration option). Used as default.
/// </summary>
#if NET462_OR_GREATER || NETSTANDARD2_0
[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/HTTP.")]
#endif
Grpc = 0,

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ public static bool TryParse(string value, out OtlpExportProtocol result)
switch (value?.Trim())
{
case "grpc":
#pragma warning disable CS0618 // Suppressing gRPC obsolete warning
result = OtlpExportProtocol.Grpc;
#pragma warning restore CS0618 // Suppressing gRPC obsolete warning
return true;
case "http/protobuf":
result = OtlpExportProtocol.HttpProtobuf;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,11 @@ public class OtlpExporterOptions : IOtlpExporterOptions
{
internal const string DefaultGrpcEndpoint = "http://localhost:4317";
internal const string DefaultHttpEndpoint = "http://localhost:4318";
#if NET462_OR_GREATER || NETSTANDARD2_0
internal const OtlpExportProtocol DefaultOtlpExportProtocol = OtlpExportProtocol.HttpProtobuf;
#else
internal const OtlpExportProtocol DefaultOtlpExportProtocol = OtlpExportProtocol.Grpc;
#endif

internal static readonly KeyValuePair<string, string>[] StandardHeaders = new KeyValuePair<string, string>[]
{
Expand Down Expand Up @@ -84,7 +88,9 @@ public Uri Endpoint
{
if (this.endpoint == null)
{
#pragma warning disable CS0618 // Suppressing gRPC obsolete warning
return this.Protocol == OtlpExportProtocol.Grpc
#pragma warning restore CS0618 // Suppressing gRPC obsolete warning
? new Uri(DefaultGrpcEndpoint)
: new Uri(DefaultHttpEndpoint);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@
using OpenTelemetry.Exporter.OpenTelemetryProtocol.Implementation;
using OpenTelemetry.Exporter.OpenTelemetryProtocol.Implementation.ExportClient;
using OpenTelemetry.Exporter.OpenTelemetryProtocol.Implementation.Transmission;
#if NET462_OR_GREATER || NETSTANDARD2_0
using Grpc.Core;
#endif

namespace OpenTelemetry.Exporter;

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

#if NET462_OR_GREATER || NETSTANDARD2_0
public static Channel CreateChannel(this OtlpExporterOptions options)
{
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.");
}

ChannelCredentials channelCredentials;
if (options.Endpoint.Scheme == Uri.UriSchemeHttps)
{
channelCredentials = new SslCredentials();
}
else
{
channelCredentials = ChannelCredentials.Insecure;
}

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

public static Metadata GetMetadataFromHeaders(this OtlpExporterOptions options) => options.GetHeaders<Metadata>((m, k, v) => m.Add(k, v));
#endif

public static THeaders GetHeaders<THeaders>(this OtlpExporterOptions options, Action<THeaders, string, string> addHeader)
where THeaders : new()
{
Expand Down Expand Up @@ -129,25 +102,12 @@ public static IExportClient GetExportClient(this OtlpExporterOptions options, Ot
{
var httpClient = options.HttpClientFactory?.Invoke() ?? throw new InvalidOperationException("OtlpExporterOptions was missing HttpClientFactory or it returned null.");

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

#if NET462_OR_GREATER || NETSTANDARD2_0
if (options.Protocol == OtlpExportProtocol.Grpc)
{
var servicePath = otlpSignalType switch
{
OtlpSignalType.Traces => TraceGrpcServicePath,
OtlpSignalType.Metrics => MetricsGrpcServicePath,
OtlpSignalType.Logs => LogsGrpcServicePath,
_ => throw new NotSupportedException($"OtlpSignalType {otlpSignalType} is not supported."),
};
return new GrpcExportClient(options, servicePath);
}
#endif

return otlpSignalType switch
{
OtlpSignalType.Traces => options.Protocol == OtlpExportProtocol.Grpc
Expand All @@ -164,6 +124,7 @@ public static IExportClient GetExportClient(this OtlpExporterOptions options, Ot

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

public static void TryEnableIHttpClientFactoryIntegration(this OtlpExporterOptions options, IServiceProvider serviceProvider, string httpClientName)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,17 @@ internal static BaseProcessor<LogRecord> BuildOtlpLogExporter(
Debug.Assert(sdkLimitOptions != null, "sdkLimitOptions was null");
Debug.Assert(experimentalOptions != null, "experimentalOptions was null");

#if NET462_OR_GREATER || NETSTANDARD2_0
#pragma warning disable CS0618 // Suppressing gRPC obsolete warning
if (exporterOptions!.Protocol == OtlpExportProtocol.Grpc &&
ReferenceEquals(exporterOptions.HttpClientFactory, exporterOptions.DefaultHttpClientFactory))
#pragma warning restore CS0618 // Suppressing gRPC obsolete warning
{
throw new NotSupportedException("OtlpExportProtocol.Grpc with the default HTTP client factory is not supported on .NET Framework or .NET Standard 2.0." +
"Please switch to OtlpExportProtocol.HttpProtobuf or provide a custom HttpClientFactory.");
}
#endif

if (!skipUseOtlpExporterRegistrationCheck)
{
serviceProvider!.EnsureNoUseOtlpExporterRegistrations();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,17 @@ internal static MetricReader BuildOtlpExporterMetricReader(
Debug.Assert(metricReaderOptions != null, "metricReaderOptions was null");
Debug.Assert(experimentalOptions != null, "experimentalOptions was null");

#if NET462_OR_GREATER || NETSTANDARD2_0
#pragma warning disable CS0618 // Suppressing gRPC obsolete warning
if (exporterOptions!.Protocol == OtlpExportProtocol.Grpc &&
ReferenceEquals(exporterOptions.HttpClientFactory, exporterOptions.DefaultHttpClientFactory))
#pragma warning restore CS0618 // Suppressing gRPC obsolete warning
{
throw new NotSupportedException("OtlpExportProtocol.Grpc with the default HTTP client factory is not supported on .NET Framework or .NET Standard 2.0." +
"Please switch to OtlpExportProtocol.HttpProtobuf or provide a custom HttpClientFactory.");
}
#endif

if (!skipUseOtlpExporterRegistrationCheck)
{
serviceProvider!.EnsureNoUseOtlpExporterRegistrations();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,17 @@ internal static BaseProcessor<Activity> BuildOtlpExporterProcessor(
Debug.Assert(experimentalOptions != null, "experimentalOptions was null");
Debug.Assert(batchExportProcessorOptions != null, "batchExportProcessorOptions was null");

#if NET462_OR_GREATER || NETSTANDARD2_0
#pragma warning disable CS0618 // Suppressing gRPC obsolete warning
if (exporterOptions!.Protocol == OtlpExportProtocol.Grpc &&
ReferenceEquals(exporterOptions.HttpClientFactory, exporterOptions.DefaultHttpClientFactory))
#pragma warning restore CS0618 // Suppressing gRPC obsolete warning
{
throw new NotSupportedException("OtlpExportProtocol.Grpc with the default HTTP client factory is not supported on .NET Framework or .NET Standard 2.0." +
"Please switch to OtlpExportProtocol.HttpProtobuf or provide a custom HttpClientFactory.");
}
#endif

if (!skipUseOtlpExporterRegistrationCheck)
{
serviceProvider!.EnsureNoUseOtlpExporterRegistrations();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public void Dispose()
this.openTelemetryEventListener.Dispose();
}

#pragma warning disable CS0618 // Suppressing gRPC obsolete warning
[InlineData(OtlpExportProtocol.Grpc, ":4317", ExportProcessorType.Batch, false)]
[InlineData(OtlpExportProtocol.HttpProtobuf, ":4318/v1/traces", ExportProcessorType.Batch, false)]
[InlineData(OtlpExportProtocol.Grpc, ":4317", ExportProcessorType.Batch, true)]
Expand All @@ -44,6 +45,7 @@ public void Dispose()
[InlineData(OtlpExportProtocol.HttpProtobuf, ":4318/v1/traces", ExportProcessorType.Simple, true)]
[InlineData(OtlpExportProtocol.Grpc, ":5317", ExportProcessorType.Simple, true, "https")]
[InlineData(OtlpExportProtocol.HttpProtobuf, ":5318/v1/traces", ExportProcessorType.Simple, true, "https")]
#pragma warning restore CS0618 // Suppressing gRPC obsolete warning
[Trait("CategoryName", "CollectorIntegrationTests")]
[SkipUnlessEnvVarFoundTheory(CollectorHostnameEnvVarName)]
public void TraceExportResultIsSuccess(OtlpExportProtocol protocol, string endpoint, ExportProcessorType exportProcessorType, bool forceFlush, string scheme = "http")
Expand Down Expand Up @@ -118,6 +120,7 @@ public void TraceExportResultIsSuccess(OtlpExportProtocol protocol, string endpo
}
}

#pragma warning disable CS0618 // Suppressing gRPC obsolete warning
[InlineData(OtlpExportProtocol.Grpc, ":4317", false, false)]
[InlineData(OtlpExportProtocol.HttpProtobuf, ":4318/v1/metrics", false, false)]
[InlineData(OtlpExportProtocol.Grpc, ":4317", false, true)]
Expand All @@ -128,6 +131,7 @@ public void TraceExportResultIsSuccess(OtlpExportProtocol protocol, string endpo
[InlineData(OtlpExportProtocol.HttpProtobuf, ":4318/v1/metrics", true, true)]
[InlineData(OtlpExportProtocol.Grpc, ":5317", true, true, "https")]
[InlineData(OtlpExportProtocol.HttpProtobuf, ":5318/v1/metrics", true, true, "https")]
#pragma warning restore CS0618 // Suppressing gRPC obsolete warning
[Trait("CategoryName", "CollectorIntegrationTests")]
[SkipUnlessEnvVarFoundTheory(CollectorHostnameEnvVarName)]
public void MetricExportResultIsSuccess(OtlpExportProtocol protocol, string endpoint, bool useManualExport, bool forceFlush, string scheme = "http")
Expand Down Expand Up @@ -202,12 +206,14 @@ public void MetricExportResultIsSuccess(OtlpExportProtocol protocol, string endp
}
}

#pragma warning disable CS0618 // Suppressing gRPC obsolete warning
[InlineData(OtlpExportProtocol.Grpc, ":4317", ExportProcessorType.Batch)]
[InlineData(OtlpExportProtocol.HttpProtobuf, ":4318/v1/logs", ExportProcessorType.Batch)]
[InlineData(OtlpExportProtocol.Grpc, ":4317", ExportProcessorType.Simple)]
[InlineData(OtlpExportProtocol.HttpProtobuf, ":4318/v1/logs", ExportProcessorType.Simple)]
[InlineData(OtlpExportProtocol.Grpc, ":5317", ExportProcessorType.Simple, "https")]
[InlineData(OtlpExportProtocol.HttpProtobuf, ":5318/v1/logs", ExportProcessorType.Simple, "https")]
#pragma warning restore CS0618 // Suppressing gRPC obsolete warning
[Trait("CategoryName", "CollectorIntegrationTests")]
[SkipUnlessEnvVarFoundTheory(CollectorHostnameEnvVarName)]
public void LogExportResultIsSuccess(OtlpExportProtocol protocol, string endpoint, ExportProcessorType exportProcessorType, string scheme = "http")
Expand Down
Loading