Skip to content

Commit 5458bc0

Browse files
JamesNKjtattermusch
authored andcommitted
Server call handler logger name shouldn't be service type name (#497) (#500)
1 parent 9cc68a7 commit 5458bc0

File tree

9 files changed

+52
-24
lines changed

9 files changed

+52
-24
lines changed

src/Grpc.AspNetCore.Server/Internal/CallHandlers/ServerCallHandlerBase.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ internal abstract class ServerCallHandlerBase<TService, TRequest, TResponse>
3232
where TRequest : class
3333
where TResponse : class
3434
{
35+
private const string LoggerName = "Grpc.AspNetCore.Server.ServerCallHandler";
36+
3537
protected Method<TRequest, TResponse> Method { get; }
3638
protected GrpcServiceOptions ServiceOptions { get; }
3739
protected IGrpcServiceActivator<TService> ServiceActivator { get; }
@@ -49,7 +51,7 @@ protected ServerCallHandlerBase(
4951
ServiceOptions = serviceOptions;
5052
ServiceActivator = serviceActivator;
5153
ServiceProvider = serviceProvider;
52-
Logger = loggerFactory.CreateLogger(typeof(TService));
54+
Logger = loggerFactory.CreateLogger(LoggerName);
5355
}
5456

5557
public Task HandleCallAsync(HttpContext httpContext)

test/FunctionalTests/Client/CancellationTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ private async Task CancelInParallel(int tasks, bool waitForHeaders, int interati
5353
{
5454
SetExpectedErrorsFilter(writeContext =>
5555
{
56-
if (writeContext.LoggerName == "SERVER FunctionalTestsWebsite.Services.StreamService")
56+
if (writeContext.LoggerName == TestConstants.ServerCallHandlerTestName)
5757
{
5858
// Kestrel cancellation error message
5959
if (writeContext.Exception is IOException &&

test/FunctionalTests/Client/StreamingTests.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
using System.Threading;
2323
using System.Threading.Tasks;
2424
using Google.Protobuf;
25+
using Grpc.AspNetCore.FunctionalTests.Infrastructure;
2526
using Grpc.Core;
2627
using Grpc.Net.Client;
2728
using Grpc.Tests.Shared;
@@ -368,7 +369,7 @@ writeContext.Exception is InvalidOperationException &&
368369
return true;
369370
}
370371

371-
if (writeContext.LoggerName == "SERVER FunctionalTestsWebsite.Services.StreamService")
372+
if (writeContext.LoggerName == TestConstants.ServerCallHandlerTestName)
372373
{
373374
return true;
374375
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#region Copyright notice and license
2+
3+
// Copyright 2019 The gRPC Authors
4+
//
5+
// Licensed under the Apache License, Version 2.0 (the "License");
6+
// you may not use this file except in compliance with the License.
7+
// You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing, software
12+
// distributed under the License is distributed on an "AS IS" BASIS,
13+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
// See the License for the specific language governing permissions and
15+
// limitations under the License.
16+
17+
#endregion
18+
19+
namespace Grpc.AspNetCore.FunctionalTests.Infrastructure
20+
{
21+
internal static class TestConstants
22+
{
23+
public const string ServerCallHandlerTestName = "SERVER Grpc.AspNetCore.Server.ServerCallHandler";
24+
}
25+
}

test/FunctionalTests/Server/ClientStreamingMethodTests.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,15 +81,15 @@ public async Task CompleteThenIncompleteMessage_ErrorResponse()
8181
// Arrange
8282
SetExpectedErrorsFilter(writeContext =>
8383
{
84-
if (writeContext.LoggerName == "SERVER " + typeof(CounterService).FullName &&
84+
if (writeContext.LoggerName == TestConstants.ServerCallHandlerTestName &&
8585
writeContext.EventId.Name == "RpcConnectionError" &&
8686
writeContext.State.ToString() == "Error status code 'Internal' raised." &&
8787
GetRpcExceptionDetail(writeContext.Exception) == "Incomplete message.")
8888
{
8989
return true;
9090
}
9191

92-
if (writeContext.LoggerName == "SERVER " + typeof(CounterService).FullName &&
92+
if (writeContext.LoggerName == TestConstants.ServerCallHandlerTestName &&
9393
writeContext.EventId.Name == "ErrorReadingMessage" &&
9494
writeContext.State.ToString() == "Error reading message." &&
9595
GetRpcExceptionDetail(writeContext.Exception) == "Incomplete message.")
@@ -139,7 +139,7 @@ public async Task ServerMethodReturnsNull_FailureResponse()
139139

140140
SetExpectedErrorsFilter(writeContext =>
141141
{
142-
return writeContext.LoggerName == "SERVER " + typeof(DynamicService).FullName &&
142+
return writeContext.LoggerName == TestConstants.ServerCallHandlerTestName &&
143143
writeContext.EventId.Name == "RpcConnectionError" &&
144144
writeContext.State.ToString() == "Error status code 'Cancelled' raised." &&
145145
GetRpcExceptionDetail(writeContext.Exception) == "No message returned from method.";
@@ -246,7 +246,7 @@ async Task<CounterReply> AccumulateCount(IAsyncStreamReader<CounterRequest> requ
246246
// Arrange
247247
SetExpectedErrorsFilter(writeContext =>
248248
{
249-
return writeContext.LoggerName == "SERVER " + typeof(DynamicService).FullName;
249+
return writeContext.LoggerName == TestConstants.ServerCallHandlerTestName;
250250
});
251251

252252
var method = Fixture.DynamicGrpc.AddClientStreamingMethod<CounterRequest, CounterReply>(AccumulateCount);

test/FunctionalTests/Server/CompressionTests.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -223,14 +223,14 @@ public async Task SendCompressedMessageWithIdentity_ReturnInternalError()
223223
// Arrange
224224
SetExpectedErrorsFilter(writeContext =>
225225
{
226-
if (writeContext.LoggerName == "SERVER " + typeof(GreeterService).FullName &&
226+
if (writeContext.LoggerName == TestConstants.ServerCallHandlerTestName &&
227227
writeContext.EventId.Name == "RpcConnectionError" &&
228228
writeContext.State.ToString() == "Error status code 'Internal' raised.")
229229
{
230230
return true;
231231
}
232232

233-
if (writeContext.LoggerName == "SERVER " + typeof(GreeterService).FullName &&
233+
if (writeContext.LoggerName == TestConstants.ServerCallHandlerTestName &&
234234
writeContext.EventId.Name == "ErrorReadingMessage" &&
235235
writeContext.State.ToString() == "Error reading message.")
236236
{
@@ -291,15 +291,15 @@ public async Task SendCompressedMessageWithUnsupportedEncoding_ReturnUnimplement
291291
// Arrange
292292
SetExpectedErrorsFilter(writeContext =>
293293
{
294-
if (writeContext.LoggerName == "SERVER " + typeof(GreeterService).FullName &&
294+
if (writeContext.LoggerName == TestConstants.ServerCallHandlerTestName &&
295295
writeContext.EventId.Name == "RpcConnectionError" &&
296296
writeContext.State.ToString() == "Error status code 'Unimplemented' raised." &&
297297
GetRpcExceptionDetail(writeContext.Exception) == "Unsupported grpc-encoding value 'DOES_NOT_EXIST'. Supported encodings: identity, gzip")
298298
{
299299
return true;
300300
}
301301

302-
if (writeContext.LoggerName == "SERVER " + typeof(GreeterService).FullName &&
302+
if (writeContext.LoggerName == TestConstants.ServerCallHandlerTestName &&
303303
writeContext.EventId.Name == "ErrorReadingMessage" &&
304304
writeContext.State.ToString() == "Error reading message." &&
305305
GetRpcExceptionDetail(writeContext.Exception) == "Unsupported grpc-encoding value 'DOES_NOT_EXIST'. Supported encodings: identity, gzip")
@@ -360,15 +360,15 @@ public async Task SendCompressedMessageWithoutEncodingHeader_ServerErrorResponse
360360
// Arrange
361361
SetExpectedErrorsFilter(writeContext =>
362362
{
363-
if (writeContext.LoggerName == "SERVER " + typeof(GreeterService).FullName &&
363+
if (writeContext.LoggerName == TestConstants.ServerCallHandlerTestName &&
364364
writeContext.EventId.Name == "RpcConnectionError" &&
365365
writeContext.State.ToString() == "Error status code 'Internal' raised." &&
366366
GetRpcExceptionDetail(writeContext.Exception) == "Request did not include grpc-encoding value with compressed message.")
367367
{
368368
return true;
369369
}
370370

371-
if (writeContext.LoggerName == "SERVER " + typeof(GreeterService).FullName &&
371+
if (writeContext.LoggerName == TestConstants.ServerCallHandlerTestName &&
372372
writeContext.EventId.Name == "ErrorReadingMessage" &&
373373
writeContext.State.ToString() == "Error reading message." &&
374374
GetRpcExceptionDetail(writeContext.Exception) == "Request did not include grpc-encoding value with compressed message.")

test/FunctionalTests/Server/DeadlineTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ static async Task WriteUntilError(HelloRequest request, IServerStreamWriter<Hell
146146
// Arrange
147147
SetExpectedErrorsFilter(writeContext =>
148148
{
149-
return writeContext.LoggerName == "SERVER " + typeof(DynamicService).FullName &&
149+
return writeContext.LoggerName == TestConstants.ServerCallHandlerTestName &&
150150
writeContext.EventId.Name == "ErrorExecutingServiceMethod" &&
151151
writeContext.State.ToString() == "Error when executing service method 'WriteUntilError'." &&
152152
writeContext.Exception!.Message == "Cannot write message after request is complete.";

test/FunctionalTests/Server/MaxMessageSizeTests.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,15 @@ public async Task ReceivedMessageExceedsSize_ThrowError()
3636
// Arrange
3737
SetExpectedErrorsFilter(writeContext =>
3838
{
39-
if (writeContext.LoggerName == "SERVER " + typeof(GreeterService).FullName &&
39+
if (writeContext.LoggerName == TestConstants.ServerCallHandlerTestName &&
4040
writeContext.EventId.Name == "RpcConnectionError" &&
4141
writeContext.State.ToString() == "Error status code 'ResourceExhausted' raised." &&
4242
GetRpcExceptionDetail(writeContext.Exception) == "Received message exceeds the maximum configured message size.")
4343
{
4444
return true;
4545
}
4646

47-
if (writeContext.LoggerName == "SERVER " + typeof(GreeterService).FullName &&
47+
if (writeContext.LoggerName == TestConstants.ServerCallHandlerTestName &&
4848
writeContext.EventId.Name == "ErrorReadingMessage" &&
4949
writeContext.State.ToString() == "Error reading message." &&
5050
GetRpcExceptionDetail(writeContext.Exception) == "Received message exceeds the maximum configured message size.")
@@ -78,15 +78,15 @@ public async Task SentMessageExceedsSize_ThrowError()
7878
// Arrange
7979
SetExpectedErrorsFilter(writeContext =>
8080
{
81-
if (writeContext.LoggerName == "SERVER " + typeof(GreeterService).FullName &&
81+
if (writeContext.LoggerName == TestConstants.ServerCallHandlerTestName &&
8282
writeContext.EventId.Name == "RpcConnectionError" &&
8383
writeContext.State.ToString() == "Error status code 'ResourceExhausted' raised." &&
8484
GetRpcExceptionDetail(writeContext.Exception) == "Sending message exceeds the maximum configured message size.")
8585
{
8686
return true;
8787
}
8888

89-
if (writeContext.LoggerName == "SERVER " + typeof(GreeterService).FullName &&
89+
if (writeContext.LoggerName == TestConstants.ServerCallHandlerTestName &&
9090
writeContext.EventId.Name == "ErrorSendingMessage" &&
9191
writeContext.State.ToString() == "Error sending message." &&
9292
GetRpcExceptionDetail(writeContext.Exception) == "Sending message exceeds the maximum configured message size.")

test/FunctionalTests/Server/UnaryMethodTests.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -101,14 +101,14 @@ public async Task AdditionalDataAfterStreamedMessage_ErrorResponse()
101101
// Arrange
102102
SetExpectedErrorsFilter(writeContext =>
103103
{
104-
if (writeContext.LoggerName == "SERVER " + typeof(GreeterService).FullName &&
104+
if (writeContext.LoggerName == TestConstants.ServerCallHandlerTestName &&
105105
writeContext.EventId.Name == "RpcConnectionError" &&
106106
writeContext.State.ToString() == "Error status code 'Internal' raised.")
107107
{
108108
return true;
109109
}
110110

111-
if (writeContext.LoggerName == "SERVER " + typeof(GreeterService).FullName &&
111+
if (writeContext.LoggerName == TestConstants.ServerCallHandlerTestName &&
112112
writeContext.EventId.Name == "ErrorReadingMessage" &&
113113
writeContext.State.ToString() == "Error reading message.")
114114
{
@@ -164,7 +164,7 @@ static async Task<HelloReply> ReturnHeadersTwice(HelloRequest request, ServerCal
164164
// Arrange
165165
SetExpectedErrorsFilter(writeContext =>
166166
{
167-
return writeContext.LoggerName == "SERVER " + typeof(DynamicService).FullName &&
167+
return writeContext.LoggerName == TestConstants.ServerCallHandlerTestName &&
168168
writeContext.EventId.Name == "ErrorExecutingServiceMethod" &&
169169
writeContext.State.ToString() == "Error when executing service method 'ReturnHeadersTwice'." &&
170170
writeContext.Exception!.Message == "Response headers can only be sent once per call.";
@@ -200,7 +200,7 @@ public async Task ServerMethodReturnsNull_FailureResponse()
200200

201201
SetExpectedErrorsFilter(writeContext =>
202202
{
203-
return writeContext.LoggerName == "SERVER " + typeof(DynamicService).FullName &&
203+
return writeContext.LoggerName == TestConstants.ServerCallHandlerTestName &&
204204
writeContext.EventId.Name == "RpcConnectionError" &&
205205
writeContext.State.ToString() == "Error status code 'Cancelled' raised." &&
206206
GetRpcExceptionDetail(writeContext.Exception) == "No message returned from method.";
@@ -239,7 +239,7 @@ public async Task ServerMethodThrowsExceptionWithTrailers_FailureResponse()
239239

240240
SetExpectedErrorsFilter(writeContext =>
241241
{
242-
return writeContext.LoggerName == "SERVER " + typeof(DynamicService).FullName &&
242+
return writeContext.LoggerName == TestConstants.ServerCallHandlerTestName &&
243243
writeContext.EventId.Name == "RpcConnectionError" &&
244244
writeContext.State.ToString() == "Error status code 'Unknown' raised." &&
245245
GetRpcExceptionDetail(writeContext.Exception) == "User error";
@@ -316,7 +316,7 @@ static Task<Empty> ReturnContextInfoInTrailers(Empty request, ServerCallContext
316316

317317
SetExpectedErrorsFilter(writeContext =>
318318
{
319-
return writeContext.LoggerName == "SERVER " + typeof(DynamicService).FullName &&
319+
return writeContext.LoggerName == TestConstants.ServerCallHandlerTestName &&
320320
writeContext.EventId.Name == "ErrorExecutingServiceMethod";
321321
});
322322

0 commit comments

Comments
 (0)