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

SNOW-1814669 fix logging diagnostic info #1063

Merged
merged 1 commit into from
Nov 25, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 27 additions & 21 deletions Snowflake.Data/Core/Tools/Diagnostics.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime;
using System.Runtime.InteropServices;
Expand All @@ -18,33 +17,40 @@
private static string GetDiagnosticInfo()
{
StringBuilder info = new StringBuilder("System Diagnostics:\n");
info.AppendLine($"{"OS", PadRight}: {OsName()}");
info.AppendLine($"{"OS Description", PadRight}: {RuntimeInformation.OSDescription}");
info.AppendLine($"{"OS Architecture", PadRight}: {RuntimeInformation.OSArchitecture}");
info.AppendLine($"{"OS Version", PadRight}: {Environment.OSVersion}");
info.AppendLine($"{"OS x64", PadRight}: {Environment.Is64BitOperatingSystem}");
info.AppendLine($"{"Processor Architecture", PadRight}: {RuntimeInformation.ProcessArchitecture}");
info.AppendLine($"{"Processor Count", PadRight}: {Environment.ProcessorCount}");
info.AppendLine($"{".NET Framework", PadRight}: {RuntimeInformation.FrameworkDescription}");
info.AppendLine($"{"CLR Runtime Version", PadRight}: {Environment.Version}");
info.AppendLine($"{"App x64", PadRight}: {Environment.Is64BitProcess}");
info.AppendLine($"{"GC Server Mode", PadRight}: {GCSettings.IsServerGC}");
info.AppendLine($"{"GC LOH Compaction Mode", PadRight}: {GCSettings.LargeObjectHeapCompactionMode}");
info.AppendLine($"{"GC Latency Mode", PadRight}: {GCSettings.LatencyMode}");
info.AppendLine($"{"GC Total Memory", PadRight}: {GC.GetTotalMemory(false)}");
AppendAssemblyInfo(info, Assembly.GetEntryAssembly(), "App");
AppendAssemblyInfo(info, Assembly.GetExecutingAssembly(), "Driver");
try
{
info.AppendLine($"{"OS",PadRight}: {OsName()}");
info.AppendLine($"{"OS Description",PadRight}: {RuntimeInformation.OSDescription}");
info.AppendLine($"{"OS Architecture",PadRight}: {RuntimeInformation.OSArchitecture}");
info.AppendLine($"{"OS Version",PadRight}: {Environment.OSVersion}");
info.AppendLine($"{"OS x64",PadRight}: {Environment.Is64BitOperatingSystem}");
info.AppendLine($"{"Processor Architecture",PadRight}: {RuntimeInformation.ProcessArchitecture}");
info.AppendLine($"{"Processor Count",PadRight}: {Environment.ProcessorCount}");
info.AppendLine($"{".NET Framework",PadRight}: {RuntimeInformation.FrameworkDescription}");
info.AppendLine($"{"CLR Runtime Version",PadRight}: {Environment.Version}");
info.AppendLine($"{"App x64",PadRight}: {Environment.Is64BitProcess}");
info.AppendLine($"{"GC Server Mode",PadRight}: {GCSettings.IsServerGC}");
info.AppendLine($"{"GC LOH Compaction Mode",PadRight}: {GCSettings.LargeObjectHeapCompactionMode}");
info.AppendLine($"{"GC Latency Mode",PadRight}: {GCSettings.LatencyMode}");
info.AppendLine($"{"GC Total Memory",PadRight}: {GC.GetTotalMemory(false)}");
AppendAssemblyInfo(info, Assembly.GetEntryAssembly(), "App");
AppendAssemblyInfo(info, Assembly.GetExecutingAssembly(), "Driver");
}
catch (Exception exception)
{
var errorMessage = $"Error caught while collecting diagnostic info: {exception.Message}";
s_logger.Error(errorMessage, exception);
info.AppendLine(errorMessage);
}

Check warning on line 44 in Snowflake.Data/Core/Tools/Diagnostics.cs

View check run for this annotation

Codecov / codecov/patch

Snowflake.Data/Core/Tools/Diagnostics.cs#L39-L44

Added lines #L39 - L44 were not covered by tests
return info.ToString();
}

private static void AppendAssemblyInfo(StringBuilder info, Assembly assembly, string assemblyTag)
{
if (assembly != null)
{
var assemblyVersion = FileVersionInfo.GetVersionInfo(assembly.Location);
info.AppendLine($"{assemblyTag + " Name", PadRight}: {assemblyVersion.InternalName}");
info.AppendLine($"{assemblyTag + " File", PadRight}: {assemblyVersion.FileName}");
info.AppendLine($"{assemblyTag + " Version", PadRight}: {assemblyVersion.FileVersion}");
info.AppendLine($"{assemblyTag + "Name",PadRight}: {assembly.GetName().Name}");
info.AppendLine($"{assemblyTag + "Version",PadRight}: {assembly.GetName().Version}");
}
}

Expand Down
Loading