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

Move closer to OpenTelemetry logging configuration #129

Merged
merged 5 commits into from
Jul 16, 2024

Conversation

Mpdreamz
Copy link
Member

This replaces ELASTIC_OTEL_LOG_DIRECTORY and ELASTIC_OTEL_LOG_LEVEL with OTEL_DOTNET_AUTO_LOG_DIRECTORY and OTEL_LOG_LEVEL.

  • OTEL_DOTNET_AUTO_LOG_DIRECTORY enables global file logging both in auto instrumentation and manual instrumentation.
  • LogLevel.Trace does not exist in OTEL, we fallback to Debug OTEL fallsback to Information.
  • We treat LogLevel.Debug as a switch to enable global logging.
  • If we are running in a container and global logging is enabled we now default to standardout and not file unless configured explicitly

This replaces `ELASTIC_OTEL_LOG_DIRECTORY` and `ELASTIC_OTEL_LOG_LEVEL` with `OTEL_DOTNET_AUTO_LOG_DIRECTORY` and `OTEL_LOG_LEVEL`.

- `OTEL_DOTNET_AUTO_LOG_DIRECTORY` enables global file logging both in auto instrumentation and manual instrumentation.
- `LogLevel.Trace` does not exist in OTEL, we fallback to `Debug` OTEL fallsback to `Information`.
- We treat `LogLevel.Debug` as a switch to enable global logging.
- If we are running in a container and global logging is enabled we now default to standardout and not file unless configured explicitly
stevejgordon
stevejgordon previously approved these changes Jul 16, 2024
Copy link
Contributor

@stevejgordon stevejgordon left a comment

Choose a reason for hiding this comment

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

Changes LGTM. A couple of tests to address.

Copy link
Contributor

@stevejgordon stevejgordon left a comment

Choose a reason for hiding this comment

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

LGTM

@Mpdreamz Mpdreamz merged commit b7ab23f into main Jul 16, 2024
5 checks passed
@Mpdreamz Mpdreamz deleted the fix/log-environment-vars-use-otel branch July 16, 2024 10:04
Mpdreamz added a commit to elastic/apm-agent-dotnet that referenced this pull request Jul 23, 2024
This ensures we can specify file logging globally and uniformly. Greatly simplifying the debug-ability of the agent.

The preferred way is to set any or all of the following:


* `ELASTIC_OTEL_LOG_TARGETS` (to anything but `none`) 
  * if only set to `stdout` no file will be created but global logging will kicking )
* `OTEL_DOTNET_AUTO_LOG_DIRECTORY`
* `OTEL_LOG_LEVEL`  
  * `trace` `debug` will enable global file logging if the other two variables are not set  explicitly.

This ensure we have one way to debug both our proprietary agent as well as the [Elastic OpenTelemetry Distribution](https://github.com/elastic/elastic-otel-dotnet).

See: elastic/elastic-otel-dotnet#129

For backwards compatible reasons the profiler variables are also supported:

* `ELASTIC_APM_PROFILER_LOG`
* `ELASTIC_APM_PROFILER_LOG_DIR`
* `ELASTIC_APM_PROFILER_LOG_TARGETS` 

Globally setting 

* `ELASTIC_APM_LOG_LEVEL` and `ELASTIC_APM_LOG_DIRECTORY` is also supported but not preferred.


Setting these in any of our supported deploy scenarios:

* Manual instrumentation (nuget)
  * ASP.NET (classic)
  * ASP.NET core
    * NOTE: we now log to both the configured ILogger and our global logging.
* Auto Instrumentation
  * Profiler
  * Startup hooks
    To keep support existing deploys this now always globally logs to file if only `ELASTIC_APM_STARTUP_HOOKS_LOGGING` is set as well.
 


This further updates our docs for the profiler and troubleshooting to prefer `ELASTIC_OTEL_*` variables. 

The profiler is updated to read the same environment variables as managed code.
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.

2 participants