-
Notifications
You must be signed in to change notification settings - Fork 93
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
[log4net] bridge + trace context injection #3825
Conversation
src/OpenTelemetry.AutoInstrumentation/Configurations/LogInstrumentation.cs
Outdated
Show resolved
Hide resolved
...y.AutoInstrumentation/Instrumentations/Log4Net/Integrations/AppenderCollectionIntegration.cs
Outdated
Show resolved
Hide resolved
test/test-applications/integrations/TestApplication.Log4NetBridge/Program.cs
Show resolved
Hide resolved
I'm still looking into one problematic scenario, and extracting message template and args that were used for logging, but any feedback at this point would be welcome. |
@@ -3,6 +3,7 @@ | |||
<ItemGroup> | |||
<PackageReference Include="Newtonsoft.Json" /> | |||
<PackageReference Include="Xunit.SkippableFact" /> | |||
<PackageReference Include="log4net" /> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would consider moving tests related to the dependencies to the separate package. To avoid brining here transitive dependencies.
...y.AutoInstrumentation/Instrumentations/Log4Net/Integrations/AppenderCollectionIntegration.cs
Outdated
Show resolved
Hide resolved
...y.AutoInstrumentation/Instrumentations/Log4Net/Integrations/AppenderCollectionIntegration.cs
Outdated
Show resolved
Hide resolved
src/OpenTelemetry.AutoInstrumentation/Instrumentations/Log4Net/OpenTelemetryLog4NetAppender.cs
Outdated
Show resolved
Hide resolved
I added trace context injection, extraction of format string and args. I updated the PR description to better reflect scope of the changes in this PR. |
|
||
> [!IMPORTANT] | ||
> log4net bridge and trace context injection are experimental features. | ||
> Both instrumentations can be disabled by setting `OTEL_DOTNET_AUTO_LOGS_LOG4NET_INSTRUMENTATION_ENABLED` to `false`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see the env variable OTEL_DOTNET_AUTO_LOGS_LOG4NET_INSTRUMENTATION_ENABLED
anywhere, only OTEL_DOTNET_AUTO_LOGS_ENABLE_LOG4NET_BRIDGE
. Am I missing something?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have two levels
- Injecting context to the log files by standard funtionality https://github.com/open-telemetry/opentelemetry-dotnet-instrumentation/pull/3825/files#diff-77b3519370ff48f6caf7c316f0ece966f2f0871c40e9381d451d2c5b1c76b40fR124
- Bridging everything to the exporter (typically OTLP) by
OTEL_DOTNET_AUTO_LOGS_ENABLE_LOG4NET_BRIDGE
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall LGTM, good job putting together the changes and the testing
Why
Towards #3822
What
Initial implementation of
log4net
bridge and injection of trace context.Bytecode instrumentation for
log4net
that adds appender exporting logs in OTLP using LogsApi.Bytecode instrumentation targets and some of the implementation similar to Datadog's
log4net
DirectLogSubmission/trace context injection implementation. @zacharycmontoya PTAL and approve from Datadog's side.Logs bridge is disabled by default. In order to enable it,
OTEL_DOTNET_AUTO_LOGS_ENABLE_LOG4NET_BRIDGE
env variable needs to be set.Trace context injection is enabled by default.
I added an internal doc with a short description of instrumentation added in this PR, and known limitations.
If
*Format
overloads (e.gInfoFormat
) are used for logging, format string is used as a body of a log record, and args are added as attributes. If additionallyOTEL_DOTNET_AUTO_LOGS_INCLUDE_FORMATTED_MESSAGE
is set,log4net.rendered_message
attribute is added with a content of a formatted message. Sample output:Notes:
Most of the LogsApi from OpenTelemetry .NET SDK is not public in non-rc builds. Due to this, and to achieve acceptable peformance, expressions are used to initialize delegates used for sending logs.
In order to avoid adding multiple appenders serving the same purpose, as a simple workaround for now, this integration is enabled only if
ILogger
integration is not initialized.Tests
Included in PR.
Checklist
CHANGELOG.md
is updated.