Skip to content

Commit ba5c710

Browse files
authored
Added configuration to worker and client packages to suppress System.Net.Http.HttpClient methods (#27)
Signed-off-by: Whit Waldo <whit.waldo@innovian.net>
1 parent 8a61ace commit ba5c710

File tree

5 files changed

+39
-4
lines changed

5 files changed

+39
-4
lines changed

Directory.Packages.props

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
<PackageVersion Include="Microsoft.Extensions.Hosting" Version="9.0.8" />
1515
<PackageVersion Include="Microsoft.Extensions.Hosting.Abstractions" Version="9.0.8" />
1616
<PackageVersion Include="Microsoft.Extensions.Http" Version="9.0.8" />
17+
<PackageVersion Include="Microsoft.Extensions.Logging" Version="9.0.8" />
1718
<PackageVersion Include="Microsoft.Extensions.Logging.Abstractions" Version="9.0.8" />
1819
<PackageVersion Include="Microsoft.Extensions.Options" Version="9.0.8" />
1920
<PackageVersion Include="Microsoft.Extensions.Options.DataAnnotations" Version="9.0.8" />

src/Client/Core/Client.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ The client is responsible for interacting with orchestrations from outside the w
99
</PropertyGroup>
1010

1111
<ItemGroup>
12+
<PackageReference Include="Microsoft.Extensions.Logging" />
1213
<PackageReference Include="Microsoft.Extensions.Options" />
1314
</ItemGroup>
1415

src/Client/Core/DependencyInjection/ServiceCollectionExtensions.cs

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
// Copyright (c) Microsoft Corporation.
22
// Licensed under the MIT License.
33

4-
using DurableTask.Core.Serializing;
54
using Microsoft.Extensions.DependencyInjection;
65
using Microsoft.Extensions.DependencyInjection.Extensions;
6+
using Microsoft.Extensions.Logging;
77
using Microsoft.Extensions.Options;
88

99
namespace Dapr.DurableTask.Client;
@@ -91,14 +91,30 @@ static IServiceCollection ConfigureDurableOptions(IServiceCollection services, s
9191
}
9292
});
9393

94+
services.Configure<LoggerFilterOptions>(options =>
95+
{
96+
// Suppress verbose HttpClient logging
97+
options.Rules.Add(new LoggerFilterRule(null, "System.Net.Http.HttpClient", LogLevel.Warning, null));
98+
options.Rules.Add(new LoggerFilterRule(null, "Microsoft.Extensions.Http", LogLevel.Warning, null));
99+
100+
// Suppress noisy gRPC logging
101+
options.Rules.Add(new LoggerFilterRule(null, "Grpc.Net.Client", LogLevel.Warning, null));
102+
options.Rules.Add(new LoggerFilterRule(null, "Grpc.Core", LogLevel.Warning, null));
103+
options.Rules.Add(new LoggerFilterRule(null, "Grpc.AspNetCore.Server", LogLevel.Warning, null));
104+
105+
// Suppress other noisy infrastructure
106+
options.Rules.Add(new LoggerFilterRule(null, "System.Net.Http.SocketsHttpHandler", LogLevel.Warning, null));
107+
options.Rules.Add(new LoggerFilterRule(null, "System.Net.NameResolution", LogLevel.Warning, null));
108+
});
109+
94110
return services;
95111
}
96112

97113
static IDurableTaskClientBuilder GetBuilder(IServiceCollection services, string name, out bool added)
98114
{
99115
// To ensure the builders are tracked with this service collection, we use a singleton service descriptor as a
100116
// holder for all builders.
101-
ServiceDescriptor descriptor = services.FirstOrDefault(sd => sd.ServiceType == typeof(BuilderContainer));
117+
ServiceDescriptor? descriptor = services.FirstOrDefault(sd => sd.ServiceType == typeof(BuilderContainer));
102118

103119
if (descriptor is null)
104120
{

src/Worker/Core/DependencyInjection/ServiceCollectionExtensions.cs

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
// Copyright (c) Microsoft Corporation.
22
// Licensed under the MIT License.
33

4-
using DurableTask.Core.Serializing;
54
using Dapr.DurableTask.Worker.Hosting;
65
using Microsoft.Extensions.DependencyInjection;
6+
using Microsoft.Extensions.Logging;
77
using Microsoft.Extensions.Options;
88

99
namespace Dapr.DurableTask.Worker;
@@ -87,14 +87,30 @@ static IServiceCollection ConfigureDurableOptions(IServiceCollection services, s
8787
}
8888
});
8989

90+
services.Configure<LoggerFilterOptions>(options =>
91+
{
92+
// Suppress verbose HttpClient logging
93+
options.Rules.Add(new LoggerFilterRule(null, "System.Net.Http.HttpClient", LogLevel.Warning, null));
94+
options.Rules.Add(new LoggerFilterRule(null, "Microsoft.Extensions.Http", LogLevel.Warning, null));
95+
96+
// Suppress noisy gRPC logging
97+
options.Rules.Add(new LoggerFilterRule(null, "Grpc.Net.Client", LogLevel.Warning, null));
98+
options.Rules.Add(new LoggerFilterRule(null, "Grpc.Core", LogLevel.Warning, null));
99+
options.Rules.Add(new LoggerFilterRule(null, "Grpc.AspNetCore.Server", LogLevel.Warning, null));
100+
101+
// Suppress other noisy infrastructure
102+
options.Rules.Add(new LoggerFilterRule(null, "System.Net.Http.SocketsHttpHandler", LogLevel.Warning, null));
103+
options.Rules.Add(new LoggerFilterRule(null, "System.Net.NameResolution", LogLevel.Warning, null));
104+
});
105+
90106
return services;
91107
}
92108

93109
static IDurableTaskWorkerBuilder GetBuilder(IServiceCollection services, string name, out bool added)
94110
{
95111
// To ensure the builders are tracked with this service collection, we use a singleton service descriptor as a
96112
// holder for all builders.
97-
ServiceDescriptor descriptor = services.FirstOrDefault(sd => sd.ServiceType == typeof(BuilderContainer));
113+
ServiceDescriptor? descriptor = services.FirstOrDefault(sd => sd.ServiceType == typeof(BuilderContainer));
98114

99115
if (descriptor is null)
100116
{

src/Worker/Core/Worker.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ The worker is responsible for processing durable task work items.</PackageDescri
1010

1111
<ItemGroup>
1212
<PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" />
13+
<PackageReference Include="Microsoft.Extensions.Logging" />
1314
<PackageReference Include="Microsoft.Extensions.Options" />
1415
<PackageReference Include="System.Text.Json" />
1516
</ItemGroup>

0 commit comments

Comments
 (0)