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: use Grpc.Net.Client for netstandard2.1 #1662

Merged

Conversation

alanwest
Copy link
Member

@alanwest alanwest commented Dec 17, 2020

Fixes #1651

Changes

This PR introduces a netstandard2.1 build of the OTLP exporter. This enables the exporter to use Grpc.Net.Client instead of the native gRPC library for .NET Core 3.0+ applications.

We have had a number of issues with the native gRPC library that are resolved by using Grpc.Net.Client. Also, Grpc.Net.Client is reportedly fast on .NET 5.

This PR does introduce some breaking changes to the OtlpExporterOptions which needed to be adapted for use with Grpc.Net.Client.

For significant contributions please make sure you have completed the following items:

  • CHANGELOG.md updated for non-trivial changes
  • Design discussion issue #
  • Changes in public API reviewed

@alanwest alanwest requested a review from a team December 17, 2020 00:44
@alanwest alanwest changed the title Use Grpc.Net.Client for netstandard2.1 OTLP exporter: use Grpc.Net.Client for netstandard2.1 Dec 17, 2020
Comment on lines 57 to 58
// Enable support for unencrypted HTTP2
AppContext.SetSwitch("System.Net.Http.SocketsHttpHandler.Http2UnencryptedSupport", true);
Copy link
Member Author

Choose a reason for hiding this comment

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

This is required when calling insecure (i.e. http not https) gRPC service. This is no longer required for .NET 5.

I can document this in the readme.

Copy link
Member

Choose a reason for hiding this comment

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

It would probably be good to have that note in the README.

// Enable OpenTelemetry for the sources "Samples.SampleServer" and "Samples.SampleClient"
// and use OTLP exporter.
using var openTelemetry = Sdk.CreateTracerProviderBuilder()
.AddSource("Samples.SampleClient", "Samples.SampleServer")
.SetResourceBuilder(ResourceBuilder.CreateDefault().AddService("otlp-test"))
.AddOtlpExporter(opt => opt.Endpoint = endpoint)
.AddOtlpExporter(opt => opt.Endpoint = new Uri(endpoint))
Copy link
Member Author

Choose a reason for hiding this comment

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

For the netstandard2.1 build, I changed the Endpoint to be a Uri instead of string. This is because if the scheme is not present then the client throws:

System.ArgumentException: Only 'http' and 'https' schemes are allowed.

I figure using Uri helps mitigate this.

/// <summary>
/// Gets or sets the gRPC channel options.
/// </summary>
public GrpcChannelOptions GrpcChannelOptions { get; set; }
Copy link
Member Author

Choose a reason for hiding this comment

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

The GrpcChannelOptions class in Grpc.Net.Client should cover functionality previously covered with the Credentials and ChannelOptions configuration options.

@codecov
Copy link

codecov bot commented Dec 17, 2020

Codecov Report

Merging #1662 (c5bb486) into master (94c2755) will increase coverage by 0.01%.
The diff coverage is 87.50%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1662      +/-   ##
==========================================
+ Coverage   81.80%   81.82%   +0.01%     
==========================================
  Files         245      245              
  Lines        6607     6613       +6     
==========================================
+ Hits         5405     5411       +6     
  Misses       1202     1202              
Impacted Files Coverage Δ
...try.Exporter.OpenTelemetryProtocol/OtlpExporter.cs 57.44% <75.00%> (+1.63%) ⬆️
...orter.OpenTelemetryProtocol/OtlpExporterOptions.cs 100.00% <100.00%> (ø)
...us/Implementation/PrometheusExporterEventSource.cs 72.72% <0.00%> (+9.09%) ⬆️

@alanwest
Copy link
Member Author

We lack test coverage for sending data with a legit gRPC client - even prior to this PR. The existing unit tests all use this mock NoopTraceServiceClient

private class NoopTraceServiceClient : OtlpCollector.TraceService.ITraceServiceClient

I'd like to expand the coverage here, but haven't had a chance yet. I've manually tested the work in this PR pretty extensively. Depending on what folks would prefer, I can either expand the test coverage as part of this PR or in a follow up.

Copy link
Member

@CodeBlanch CodeBlanch left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Member

@cijothomas cijothomas left a comment

Choose a reason for hiding this comment

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

LGTM.
Separately, we can modify the readme and examples to show both pre 3.0 and post 3.0 app code snippets, to help when people upgrade to newer .net versions?

@cijothomas cijothomas merged commit 4e4f95b into open-telemetry:master Jan 4, 2021
@alanwest alanwest deleted the alanwest/oltp-use-grpc-dotnet branch March 9, 2021 18:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

OTLP exporter improvements
5 participants