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

Logging improvements #456

Merged
merged 6 commits into from
Apr 11, 2022
Merged

Conversation

lachmatt
Copy link
Contributor

@lachmatt lachmatt commented Apr 6, 2022

Why

Remove console logging.

Fixes #334

What

Simple logging to a file, based on logic from loader:

  • uses modified FileSink from loader
  • bounded log file size
  • noop logger is used in case of problems with constructing file-based logger

Possible improvements:

  • file rolling
  • more efficient logging
  • better formatting
  • log entries formatting consistent with native logs

Tests

Smoke tests.

@lachmatt lachmatt requested a review from a team April 6, 2022 07:35
}
}

logDirectory = CreateDirectoryIfMissing(logDirectory) ?? Path.GetTempPath();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need a respective doc update to reflect this fallback.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed in 829226d

@pjanotti
Copy link
Contributor

pjanotti commented Apr 6, 2022

Added a related issue #457

Copy link
Contributor

@pjanotti pjanotti left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM - @lachmatt could you please rebase and rebuild so you fix the change that came with the addition of the EventListener

Copy link
Member

@pellared pellared left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

little things


if (logDirectory == null)
{
var nativeLogFile = Environment.GetEnvironmentVariable(ConfigurationKeys.LogPath);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how about renaming nativeLogFile to something more or less like envVarValue ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed in 3bd2baa

docs/config.md Outdated
@@ -58,6 +58,8 @@ Default logs directory paths are:
- Windows: `%ProgramData%\OpenTelemetry .NET AutoInstrumentation\logs`
- Linux: `/var/log/opentelemetry/dotnet`

If there is a problem with creation of the default directory, the path of the current user's [temporary folder](https://docs.microsoft.com/en-us/dotnet/api/System.IO.Path.GetTempPath?view=net-6.0) is used.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
If there is a problem with creation of the default directory, the path of the current user's [temporary folder](https://docs.microsoft.com/en-us/dotnet/api/System.IO.Path.GetTempPath?view=net-6.0) is used.
If there is a problem with the creation of the default directory,
the path of the current user's [temporary folder](https://docs.microsoft.com/en-us/dotnet/api/System.IO.Path.GetTempPath?view=net-6.0)
is used.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed in 3bd2baa

Copy link
Contributor

@zacharycmontoya zacharycmontoya left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, however since #458 was merged, the following files may need to be updated for tests to pass:

  • src/OpenTelemetry.AutoInstrumentation/Diagnostics/SdkSelfDiagnosticsEventListener.cs
  • test/OpenTelemetry.AutoInstrumentation.Tests/Diagnostics/SdkSelfDiagnosticsEventListenerTests.cs

@pellared pellared mentioned this pull request Apr 11, 2022
@pjanotti pjanotti merged commit d8fed50 into open-telemetry:main Apr 11, 2022
@lachmatt lachmatt deleted the logging-improvements branch April 11, 2022 16:37
Comment on lines +87 to +101
/// <summary>
/// Configuration key for setting the directory for the profiler's log files.
/// If set, this setting takes precedence over environment variable OTEL_DOTNET_AUTO_LOG_PATH.
/// If not set, default is
/// "%ProgramData%"\OpenTelemetry .NET AutoInstrumentation\logs\" on Windows or
/// "/var/log/opentelemetry/dotnet/" on Linux.
/// </summary>
public const string LogDirectory = "OTEL_DOTNET_AUTO_LOG_DIRECTORY";

/// <summary>
/// Configuration key for setting the path for the profiler's native log file.
/// Environment variable OTEL_DOTNET_AUTO_LOG_DIRECTORY takes precedence over this setting, if set.
/// </summary>
public const string LogPath = "OTEL_DOTNET_AUTO_LOG_PATH";

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to have both settings?

Copy link
Contributor Author

@lachmatt lachmatt Apr 12, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added them both here, because both need to be checked to be consistent with StartupLogger, which takes them into account when deciding on log directory.

Copy link
Member

@pellared pellared Apr 12, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess it is also used in the native logger. I created an issue to remove one of them: #476

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, better to have a single env var and use the same for native and managed.

Another thing that we may want to consider post-beta is: the native log is one file for multiple applications so it is not symmetrical to the managed one. Perhaps it will make the user's life simpler if the logs of a single run were easier to "group".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

AutoInstrumentation is polluting stdout
7 participants