From 814206dd216ef31ef1957b2bd9d8b2de2ea3f3db Mon Sep 17 00:00:00 2001 From: Cijo Thomas Date: Thu, 23 Feb 2023 11:18:15 +0530 Subject: [PATCH] Improve log message written by selfdiagnostics to file. (#4219) --- .../Internal/SelfDiagnosticsConfigRefresher.cs | 6 +++--- .../Internal/SelfDiagnosticsConfigRefresherTest.cs | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/OpenTelemetry/Internal/SelfDiagnosticsConfigRefresher.cs b/src/OpenTelemetry/Internal/SelfDiagnosticsConfigRefresher.cs index 924b044d7..5590a8fae 100644 --- a/src/OpenTelemetry/Internal/SelfDiagnosticsConfigRefresher.cs +++ b/src/OpenTelemetry/Internal/SelfDiagnosticsConfigRefresher.cs @@ -30,7 +30,7 @@ namespace OpenTelemetry.Internal /// internal class SelfDiagnosticsConfigRefresher : IDisposable { - public static readonly byte[] MessageOnNewFile = Encoding.UTF8.GetBytes("Successfully opened file.\n"); + public static readonly byte[] MessageOnNewFile = Encoding.UTF8.GetBytes("If you are seeing this message, it means that the OpenTelemetry SDK has successfully created the log file used to write self-diagnostic logs. This file will be appended with logs as they appear. If you do not see any logs following this line, it means no logs of the configured LogLevel is occurring. You may change the LogLevel to show lower log levels, so that logs of lower severities will be shown.\n"); private const int ConfigurationUpdatePeriodMilliSeconds = 10000; @@ -208,7 +208,7 @@ namespace OpenTelemetry.Internal // Because the API [MemoryMappedFile.CreateFromFile][1](the string version) behaves differently on // .NET Framework and .NET Core, here I am using the [FileStream version][2] of it. - // Taking the last four prameter values from [.NET Framework] + // Taking the last four parameter values from [.NET Framework] // (https://referencesource.microsoft.com/#system.core/System/IO/MemoryMappedFiles/MemoryMappedFile.cs,148) // and [.NET Core] // (https://github.com/dotnet/runtime/blob/master/src/libraries/System.IO.MemoryMappedFiles/src/System/IO/MemoryMappedFiles/MemoryMappedFile.cs#L152) @@ -263,7 +263,7 @@ namespace OpenTelemetry.Internal this.cancellationTokenSource.Dispose(); } - // Dispose EventListner before files, because EventListner writes to files. + // Dispose EventListener before files, because EventListener writes to files. if (this.eventListener != null) { this.eventListener.Dispose(); diff --git a/test/OpenTelemetry.Tests/Internal/SelfDiagnosticsConfigRefresherTest.cs b/test/OpenTelemetry.Tests/Internal/SelfDiagnosticsConfigRefresherTest.cs index 5d07c85ad..56b55b41f 100644 --- a/test/OpenTelemetry.Tests/Internal/SelfDiagnosticsConfigRefresherTest.cs +++ b/test/OpenTelemetry.Tests/Internal/SelfDiagnosticsConfigRefresherTest.cs @@ -70,8 +70,9 @@ namespace OpenTelemetry.Internal.Tests // Emitting event of EventLevel.Error OpenTelemetrySdkEventSource.Log.SpanProcessorException("Event string sample", "Exception string sample"); + string expectedMessage = "Unknown error in SpanProcessor event '{0}': '{1}'.{Event string sample}{Exception string sample}"; - int bufferSize = 512; + int bufferSize = 2 * (MessageOnNewFileString.Length + expectedMessage.Length); byte[] actualBytes = ReadFile(bufferSize); string logText = Encoding.UTF8.GetString(actualBytes); Assert.StartsWith(MessageOnNewFileString, logText); @@ -79,7 +80,6 @@ namespace OpenTelemetry.Internal.Tests // The event was captured string logLine = logText.Substring(MessageOnNewFileString.Length); string logMessage = ParseLogMessage(logLine); - string expectedMessage = "Unknown error in SpanProcessor event '{0}': '{1}'.{Event string sample}{Exception string sample}"; Assert.StartsWith(expectedMessage, logMessage); } finally