This repository has been archived by the owner on Jul 30, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add ServiceClientTracingLogger to log Azure Search requests and respo…
…nses (#654) Related to NuGet/Engineering#2664
- Loading branch information
1 parent
952deb3
commit fc445c5
Showing
13 changed files
with
134 additions
and
84 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
||
using System.Net; | ||
using System.Threading.Tasks; | ||
using Autofac; | ||
using Microsoft.Extensions.Configuration; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Microsoft.Rest; | ||
using NuGet.Jobs; | ||
|
||
namespace NuGet.Services.AzureSearch | ||
{ | ||
public abstract class AzureSearchJob<T> : JsonConfigurationJob where T : IAzureSearchCommand | ||
{ | ||
public override async Task Run() | ||
{ | ||
ServicePointManager.DefaultConnectionLimit = 64; | ||
ServicePointManager.MaxServicePointIdleTime = 10000; | ||
|
||
var tracingInterceptor = _serviceProvider.GetRequiredService<IServiceClientTracingInterceptor>(); | ||
try | ||
{ | ||
ServiceClientTracing.IsEnabled = true; | ||
ServiceClientTracing.AddTracingInterceptor(tracingInterceptor); | ||
|
||
await _serviceProvider.GetRequiredService<T>().ExecuteAsync(); | ||
} | ||
finally | ||
{ | ||
ServiceClientTracing.RemoveTracingInterceptor(tracingInterceptor); | ||
} | ||
} | ||
|
||
protected override void ConfigureAutofacServices(ContainerBuilder containerBuilder) | ||
{ | ||
containerBuilder.AddAzureSearch(); | ||
} | ||
|
||
protected override void ConfigureJobServices(IServiceCollection services, IConfigurationRoot configurationRoot) | ||
{ | ||
services.AddAzureSearch(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
||
using System.Threading.Tasks; | ||
|
||
namespace NuGet.Services.AzureSearch | ||
{ | ||
public interface IAzureSearchCommand | ||
{ | ||
Task ExecuteAsync(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
src/NuGet.Services.AzureSearch/ServiceClientTracingLogger.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.Net.Http; | ||
using Microsoft.Extensions.Logging; | ||
using Microsoft.Rest; | ||
|
||
namespace NuGet.Services.AzureSearch | ||
{ | ||
public class ServiceClientTracingLogger : IServiceClientTracingInterceptor | ||
{ | ||
private const string Prefix = "ServiceClient "; | ||
private readonly ILogger<ServiceClientTracingLogger> _logger; | ||
|
||
public ServiceClientTracingLogger(ILogger<ServiceClientTracingLogger> logger) | ||
{ | ||
_logger = logger ?? throw new ArgumentNullException(nameof(logger)); | ||
} | ||
|
||
public void SendRequest(string invocationId, HttpRequestMessage request) | ||
{ | ||
_logger.LogInformation( | ||
Prefix + "invocation {InvocationId} sending request: {Method} {RequestUri}", | ||
invocationId, | ||
request.Method, | ||
request.RequestUri); | ||
} | ||
|
||
public void ReceiveResponse(string invocationId, HttpResponseMessage response) | ||
{ | ||
_logger.LogInformation( | ||
Prefix + "invocation {InvocationId} received response: {StatusCode} {ReasonPhrase}", | ||
invocationId, | ||
(int)response.StatusCode, | ||
response.ReasonPhrase); | ||
} | ||
|
||
public void Configuration(string source, string name, string value) | ||
{ | ||
} | ||
|
||
public void EnterMethod(string invocationId, object instance, string method, IDictionary<string, object> parameters) | ||
{ | ||
} | ||
|
||
public void ExitMethod(string invocationId, object returnValue) | ||
{ | ||
} | ||
|
||
public void Information(string message) | ||
{ | ||
} | ||
|
||
public void TraceError(string invocationId, Exception exception) | ||
{ | ||
} | ||
} | ||
} |