Skip to content

Commit

Permalink
Improve log message written by selfdiagnostics to file. (#4219)
Browse files Browse the repository at this point in the history
  • Loading branch information
cijothomas committed Feb 23, 2023
1 parent 7139c7a commit 814206d
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
6 changes: 3 additions & 3 deletions src/OpenTelemetry/Internal/SelfDiagnosticsConfigRefresher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ namespace OpenTelemetry.Internal
/// </summary>
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;

Expand Down Expand Up @@ -208,7 +208,7 @@ private void OpenLogFile(string newLogDirectory, int newFileSize)

// 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)
Expand Down Expand Up @@ -263,7 +263,7 @@ private void Dispose(bool disposing)
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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,16 +70,16 @@ public void SelfDiagnosticsConfigRefresher_CaptureAsConfigured()

// 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);

// 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
Expand Down

0 comments on commit 814206d

Please sign in to comment.