diff --git a/src/Microsoft.Diagnostics.Monitoring.WebApi/Controllers/DiagController.cs b/src/Microsoft.Diagnostics.Monitoring.WebApi/Controllers/DiagController.cs index db544ac5504..435f24f92ef 100644 --- a/src/Microsoft.Diagnostics.Monitoring.WebApi/Controllers/DiagController.cs +++ b/src/Microsoft.Diagnostics.Monitoring.WebApi/Controllers/DiagController.cs @@ -75,10 +75,17 @@ public DiagController(ILogger logger, { defaultProcessInfo = await _diagnosticServices.GetProcessAsync(null, HttpContext.RequestAborted); } - catch (Exception) + catch (ArgumentException) { // Unable to locate a default process; no action required } + catch (InvalidOperationException) + { + } + catch (Exception ex) when (!(ex is OperationCanceledException)) + { + _logger.DefaultProcessUnexpectedFailure(ex); + } IList processesIdentifiers = new List(); foreach (IProcessInfo p in await _diagnosticServices.GetProcessesAsync(processFilter: null, HttpContext.RequestAborted)) diff --git a/src/Microsoft.Diagnostics.Monitoring.WebApi/LoggingExtensions.cs b/src/Microsoft.Diagnostics.Monitoring.WebApi/LoggingExtensions.cs index f583c437ea8..81ee488d273 100644 --- a/src/Microsoft.Diagnostics.Monitoring.WebApi/LoggingExtensions.cs +++ b/src/Microsoft.Diagnostics.Monitoring.WebApi/LoggingExtensions.cs @@ -45,6 +45,12 @@ internal static class LoggingExtensions logLevel: LogLevel.Warning, formatString: Strings.LogFormatString_ThrottledEndpoint); + private static readonly Action _defaultProcessUnexpectedFailure = + LoggerMessage.Define( + eventId: new EventId(7, "DefaultProcessUnexpectedFailure"), + logLevel: LogLevel.Warning, + formatString: Strings.LogFormatString_DefaultProcessUnexpectedFailure); + public static void RequestFailed(this ILogger logger, Exception ex) { _requestFailed(logger, ex); @@ -74,5 +80,10 @@ public static void WrittenToHttpStream(this ILogger logger) { _writtenToHttpStream(logger, null); } + + public static void DefaultProcessUnexpectedFailure(this ILogger logger, Exception ex) + { + _defaultProcessUnexpectedFailure(logger, ex); + } } } diff --git a/src/Microsoft.Diagnostics.Monitoring.WebApi/ProcessInfoImpl.cs b/src/Microsoft.Diagnostics.Monitoring.WebApi/ProcessInfoImpl.cs index 3a55dc2e993..ae2dfd8c847 100644 --- a/src/Microsoft.Diagnostics.Monitoring.WebApi/ProcessInfoImpl.cs +++ b/src/Microsoft.Diagnostics.Monitoring.WebApi/ProcessInfoImpl.cs @@ -92,7 +92,10 @@ public static async Task FromEndpointInfoAsync(IEndpointInfo endpo commandLine = await commandLineSource.Task; } - catch + catch (PipelineException) + { + } + catch (OperationCanceledException) { } finally diff --git a/src/Microsoft.Diagnostics.Monitoring.WebApi/Strings.Designer.cs b/src/Microsoft.Diagnostics.Monitoring.WebApi/Strings.Designer.cs index 250fd8afa02..6a9e494d2fc 100644 --- a/src/Microsoft.Diagnostics.Monitoring.WebApi/Strings.Designer.cs +++ b/src/Microsoft.Diagnostics.Monitoring.WebApi/Strings.Designer.cs @@ -222,6 +222,15 @@ internal static string ErrorMessage_ValueNotString { } } + /// + /// Looks up a localized string similar to Failed to determine the default process.. + /// + internal static string LogFormatString_DefaultProcessUnexpectedFailure { + get { + return ResourceManager.GetString("LogFormatString_DefaultProcessUnexpectedFailure", resourceCulture); + } + } + /// /// Looks up a localized string similar to Egressed artifact to {location}. /// diff --git a/src/Microsoft.Diagnostics.Monitoring.WebApi/Strings.resx b/src/Microsoft.Diagnostics.Monitoring.WebApi/Strings.resx index 5391d98f4b7..5798c58b700 100644 --- a/src/Microsoft.Diagnostics.Monitoring.WebApi/Strings.resx +++ b/src/Microsoft.Diagnostics.Monitoring.WebApi/Strings.resx @@ -194,6 +194,11 @@ Value must be of type string. Gets a string similar to "Value must be of type string.". + + Failed to determine the default process. + Gets the format string that is printed in the 7:DefaultProcessUnexpectedFailure event. +0 Format Parameters + Egressed artifact to {location} Gets the format string that is printed in the 4:EgressedArtifact event. diff --git a/src/Tools/dotnet-monitor/Egress/FileSystem/FileSystemEgressProvider.cs b/src/Tools/dotnet-monitor/Egress/FileSystem/FileSystemEgressProvider.cs index 11d8b37d9ac..21557466a16 100644 --- a/src/Tools/dotnet-monitor/Egress/FileSystem/FileSystemEgressProvider.cs +++ b/src/Tools/dotnet-monitor/Egress/FileSystem/FileSystemEgressProvider.cs @@ -18,9 +18,12 @@ namespace Microsoft.Diagnostics.Tools.Monitor.Egress.FileSystem internal class FileSystemEgressProvider : EgressProvider { + ILogger _logger; + public FileSystemEgressProvider(ILogger logger) : base(logger) { + _logger = logger; } public override async Task EgressAsync( @@ -75,8 +78,9 @@ public override async Task EgressAsync( File.Delete(intermediateFilePath); } } - catch (Exception) + catch (Exception ex) { + _logger.IntermediateFileDeletionFailed(intermediateFilePath, ex); } } } diff --git a/src/Tools/dotnet-monitor/FilteredEndpointInfoSource.cs b/src/Tools/dotnet-monitor/FilteredEndpointInfoSource.cs index a8f8a73928d..c04b6f82f4e 100644 --- a/src/Tools/dotnet-monitor/FilteredEndpointInfoSource.cs +++ b/src/Tools/dotnet-monitor/FilteredEndpointInfoSource.cs @@ -63,8 +63,9 @@ public FilteredEndpointInfoSource( _runtimeInstanceCookieToFilterOut = runtimeInstanceCookie; } } - catch (Exception) + catch (Exception ex) { + clientSourceLogger.RuntimeInstanceCookieFailedToFilterSelf(ex); } // If connecting to runtime instances, filter self out. In listening mode, it's likely diff --git a/src/Tools/dotnet-monitor/LoggingEventIds.cs b/src/Tools/dotnet-monitor/LoggingEventIds.cs index 6cc193069e8..c445892de78 100644 --- a/src/Tools/dotnet-monitor/LoggingEventIds.cs +++ b/src/Tools/dotnet-monitor/LoggingEventIds.cs @@ -71,7 +71,10 @@ internal enum LoggingEventIds QueueOptionsPartiallySet = 58, WritingMessageToQueueFailed = 59, ExperienceSurvey = 60, - DiagnosticPortNotInListenModeForCollectionRules = 61 + DiagnosticPortNotInListenModeForCollectionRules = 61, + RuntimeInstanceCookieFailedToFilterSelf = 62, + ParsingUrlFailed = 63, + IntermediateFileDeletionFailed = 64 } internal static class LoggingEventIdsExtensions diff --git a/src/Tools/dotnet-monitor/LoggingExtensions.cs b/src/Tools/dotnet-monitor/LoggingExtensions.cs index c5beefe7926..bcb0309112d 100644 --- a/src/Tools/dotnet-monitor/LoggingExtensions.cs +++ b/src/Tools/dotnet-monitor/LoggingExtensions.cs @@ -339,6 +339,24 @@ internal static class LoggingExtensions logLevel: LogLevel.Warning, formatString: Strings.LogFormatString_DiagnosticPortNotInListenModeForCollectionRules); + private static readonly Action _runtimeInstanceCookieFailedToFilterSelf = + LoggerMessage.Define( + eventId: LoggingEventIds.RuntimeInstanceCookieFailedToFilterSelf.EventId(), + logLevel: LogLevel.Debug, + formatString: Strings.LogFormatString_RuntimeInstanceCookieFailedToFilterSelf); + + private static readonly Action _parsingUrlFailed = + LoggerMessage.Define( + eventId: LoggingEventIds.ParsingUrlFailed.EventId(), + logLevel: LogLevel.Warning, + formatString: Strings.LogFormatString_ParsingUrlFailed); + + private static readonly Action _intermediateFileDeletionFailed = + LoggerMessage.Define( + eventId: LoggingEventIds.IntermediateFileDeletionFailed.EventId(), + logLevel: LogLevel.Debug, + formatString: Strings.LogFormatString_IntermediateFileDeletionFailed); + public static void EgressProviderInvalidOptions(this ILogger logger, string providerName) { _egressProviderInvalidOptions(logger, providerName, null); @@ -623,5 +641,20 @@ public static void DiagnosticPortNotInListenModeForCollectionRules(this ILogger { _diagnosticPortNotInListenModeForCollectionRules(logger, null); } + + public static void RuntimeInstanceCookieFailedToFilterSelf(this ILogger logger, Exception ex) + { + _runtimeInstanceCookieFailedToFilterSelf(logger, ex); + } + + public static void ParsingUrlFailed(this ILogger logger, string url, Exception ex) + { + _parsingUrlFailed(logger, url, ex); + } + + public static void IntermediateFileDeletionFailed(this ILogger logger, string intermediateFilePath, Exception ex) + { + _intermediateFileDeletionFailed(logger, intermediateFilePath, ex); + } } } diff --git a/src/Tools/dotnet-monitor/Startup.cs b/src/Tools/dotnet-monitor/Startup.cs index 5086cfff423..127c9c39617 100644 --- a/src/Tools/dotnet-monitor/Startup.cs +++ b/src/Tools/dotnet-monitor/Startup.cs @@ -155,8 +155,9 @@ public void Configure( { address = BindingAddress.Parse(url); } - catch (Exception) + catch (FormatException ex) { + logger.ParsingUrlFailed(url, ex); continue; } diff --git a/src/Tools/dotnet-monitor/Strings.Designer.cs b/src/Tools/dotnet-monitor/Strings.Designer.cs index b971ca6dddc..320ec0d937d 100644 --- a/src/Tools/dotnet-monitor/Strings.Designer.cs +++ b/src/Tools/dotnet-monitor/Strings.Designer.cs @@ -915,6 +915,15 @@ internal static string LogFormatString_InsecureAutheticationConfiguration { } } + /// + /// Looks up a localized string similar to The intermediate file at the following path could not be deleted: {path}. + /// + internal static string LogFormatString_IntermediateFileDeletionFailed { + get { + return ResourceManager.GetString("LogFormatString_IntermediateFileDeletionFailed", resourceCulture); + } + } + /// /// Looks up a localized string similar to Invalid action reference '{actionReference}'.. /// @@ -987,6 +996,15 @@ internal static string LogFormatString_OptionsValidationFailure { } } + /// + /// Looks up a localized string similar to The provided url could not be parsed: {url}. + /// + internal static string LogFormatString_ParsingUrlFailed { + get { + return ResourceManager.GetString("LogFormatString_ParsingUrlFailed", resourceCulture); + } + } + /// /// Looks up a localized string similar to The queue {0} does not exist; ensure that the {queueName} and {queueAccountUri} fields are set correctly.. /// @@ -1014,6 +1032,15 @@ internal static string LogFormatString_RunningElevated { } } + /// + /// Looks up a localized string similar to Unable to get the runtime instance cookie of the current process.. + /// + internal static string LogFormatString_RuntimeInstanceCookieFailedToFilterSelf { + get { + return ResourceManager.GetString("LogFormatString_RuntimeInstanceCookieFailedToFilterSelf", resourceCulture); + } + } + /// /// Looks up a localized string similar to Setting the environment variable {variableName} in process {processId}.. /// diff --git a/src/Tools/dotnet-monitor/Strings.resx b/src/Tools/dotnet-monitor/Strings.resx index cc08e8249b7..210326a423c 100644 --- a/src/Tools/dotnet-monitor/Strings.resx +++ b/src/Tools/dotnet-monitor/Strings.resx @@ -565,6 +565,9 @@ Gets the format string that is printed in the 14:InsecureAutheticationConfiguration event. 0 Format Parameters + + The intermediate file at the following path could not be deleted: {path} + Invalid action reference '{actionReference}'. @@ -605,6 +608,9 @@ 1 Format Parameter: 1. failure: The failure message from validation + + The provided url could not be parsed: {url} + The queue {0} does not exist; ensure that the {queueName} and {queueAccountUri} fields are set correctly. Gets the format string that is printed in the 57:QueueDoesNotExist event. @@ -625,6 +631,9 @@ Gets the format string that is printed in the 19:RunningElevated event. 0 Format Parameters + + Unable to get the runtime instance cookie of the current process. + Setting the environment variable {variableName} in process {processId}. Gets the format string that is printed in the 54:SetEnvironmentVariable event.