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

Add netstandard2.0 target to Grpc.Net.Client instrumentation #3105

Merged
merged 14 commits into from
May 6, 2022

Conversation

alanwest
Copy link
Member

@alanwest alanwest commented Mar 29, 2022

This is important for users consuming Grpc.Net.Client in .NET Framework applications.

There have been two previous attempts to introduce a netstandard2.0 build of the Grpc.Net.Client instrumentation

We did not merge this previous PRs due to trickiness with testing the instrumentation's functionality for .NET Framework. Much of the current test suite spins up an in-process ASP.NET Core gRPC server. This is not possible for the net462 target.

I've modified one of the existing tests to use a mock HttpClient, so that starting an in-process gRPC server is unnecessary.

The code that mocks up the HttpClient was fork-lifted from here: https://github.com/grpc/grpc-dotnet/tree/master/test/Shared.

This PR does not port the entire Grpc.Net.Client test suite to run on .NET Framework. Many of the tests test both the instrumentation of the gRPC call and the underlying HttpClient call. To my knowledge, testing the underlying HttpClient call requires making a real call since the mock HttpClient will not invoke the HttpClient instrumentation.

@github-actions
Copy link
Contributor

github-actions bot commented Apr 8, 2022

This PR was marked stale due to lack of activity and will be closed in 7 days. Commenting or Pushing will instruct the bot to automatically remove the label. This bot runs once per day.

@github-actions github-actions bot added the Stale label Apr 8, 2022
@github-actions
Copy link
Contributor

Closed as inactive. Feel free to reopen if this PR is still being worked on.

@github-actions github-actions bot closed this Apr 15, 2022
@alanwest alanwest reopened this May 3, 2022
Comment on lines +52 to +58
var httpClient = ClientTestHelpers.CreateTestClient(async request =>
{
var streamContent = await ClientTestHelpers.CreateResponseContent(new HelloReply());
var response = ResponseUtils.CreateResponse(HttpStatusCode.OK, streamContent, grpcStatusCode: global::Grpc.Core.StatusCode.OK);
response.TrailingHeaders().Add("grpc-message", "value");
return response;
});
Copy link
Member Author

@alanwest alanwest May 3, 2022

Choose a reason for hiding this comment

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

This test uses the pattern used to mock an http client in the grpc-dotnet project for testing the Grpc.Net.Client. It demonstrates that the gRPC client instrumentation is invoked correctly for .NET Framework and modern .NET.

For example:
https://github.com/grpc/grpc-dotnet/blob/eb813a798aa3c1009de65dc7e2c490106abd1401/test/Grpc.Net.Client.Tests/DiagnosticsTests.cs#L38-L45

@@ -104,6 +117,7 @@ public void GrpcClientCallsAreCollectedSuccessfully(string baseAddress, bool sho
Assert.Equal(0, activity.GetTagValue(SemanticConventions.AttributeRpcGrpcStatusCode));
}

#if !NETFRAMEWORK
Copy link
Member Author

Choose a reason for hiding this comment

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

Many of the tests in this suite require an actual end-to-end call using a non-mocked HttpClient. To test the same functionality for .NET Framework, we would need to devise a more complicated integration test. Most likely involving spinning up Windows containers.

I'm proposing we acknowledge the short-comings of this test suite for .NET Framework and we ship a netstandard2.0 version of the gRPC client instrumentation anyways.

Copy link
Member

Choose a reason for hiding this comment

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

Agreed!

@alanwest alanwest changed the title Add Grpc.Net.Client test that does not require a gRPC server Add netstandard2.0 target to Grpc.Net.Client instrumentation May 3, 2022
@alanwest alanwest removed the Stale label May 3, 2022
@alanwest alanwest marked this pull request as ready for review May 3, 2022 20:09
@alanwest alanwest requested a review from a team as a code owner May 3, 2022 20:09
@codecov
Copy link

codecov bot commented May 3, 2022

Codecov Report

Merging #3105 (d5b025a) into main (e8659f7) will decrease coverage by 0.04%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #3105      +/-   ##
==========================================
- Coverage   85.58%   85.54%   -0.05%     
==========================================
  Files         261      261              
  Lines        9395     9395              
==========================================
- Hits         8041     8037       -4     
- Misses       1354     1358       +4     
Impacted Files Coverage Δ
...emetry.Api/Internal/OpenTelemetryApiEventSource.cs 73.52% <0.00%> (-8.83%) ⬇️
src/OpenTelemetry/BatchExportProcessor.cs 87.36% <0.00%> (-2.11%) ⬇️
...Telemetry/Internal/SelfDiagnosticsEventListener.cs 97.65% <0.00%> (+0.78%) ⬆️

@cijothomas cijothomas merged commit 95500ff into open-telemetry:main May 6, 2022
@alanwest alanwest deleted the alanwest/grpc-client-test branch July 6, 2022 15:13
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.

None yet

3 participants