diff --git a/tracer/missing-nullability-files.csv b/tracer/missing-nullability-files.csv
index 64b040254928..a1b2f4a03ce9 100644
--- a/tracer/missing-nullability-files.csv
+++ b/tracer/missing-nullability-files.csv
@@ -585,7 +585,6 @@ src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Logging/Log4Net/DirectSubmissi
src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Logging/Log4Net/DirectSubmission/ILoggingEventLegacyDuck.cs
src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Logging/Log4Net/DirectSubmission/LevelDuck.cs
src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Logging/Log4Net/DirectSubmission/LevelDuckExtensions.cs
-src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Logging/Log4Net/LogsInjection/AppenderAttachedImplIntegration.cs
src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Logging/Log4Net/LogsInjection/ILoggingEvent.cs
src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Logging/NLog/DirectSubmission/NLogConstants.cs
src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Logging/NLog/LogsInjection/DiagnosticContextHelper.cs
diff --git a/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Logging/Log4Net/LogsInjection/AppenderAttachedImplIntegration.cs b/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Logging/Log4Net/LogsInjection/AppenderAttachedImplIntegration.cs
index fcb837269b32..b850322af03d 100644
--- a/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Logging/Log4Net/LogsInjection/AppenderAttachedImplIntegration.cs
+++ b/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Logging/Log4Net/LogsInjection/AppenderAttachedImplIntegration.cs
@@ -3,10 +3,13 @@
// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2017 Datadog, Inc.
//
+#nullable enable
+
using System;
using System.ComponentModel;
using Datadog.Trace.ClrProfiler.AutoInstrumentation.Logging;
using Datadog.Trace.ClrProfiler.CallTarget;
+using Datadog.Trace.Logging;
namespace Datadog.Trace.ClrProfiler.AutoInstrumentation.Log4Net
{
@@ -26,6 +29,9 @@ namespace Datadog.Trace.ClrProfiler.AutoInstrumentation.Log4Net
[EditorBrowsable(EditorBrowsableState.Never)]
public sealed class AppenderAttachedImplIntegration
{
+ private static readonly IDatadogLogger Log = DatadogLogging.GetLoggerFor(typeof(AppenderAttachedImplIntegration));
+ private static bool _loggedNullSettings;
+
///
/// OnMethodBegin callback
///
@@ -44,9 +50,25 @@ internal static CallTargetState OnMethodBegin(TTarget in
var tracer = Tracer.Instance;
- var mutableSettings = tracer.CurrentTraceSettings.Settings;
+ var mutableSettings = tracer.CurrentTraceSettings?.Settings;
+ if (mutableSettings is null)
+ {
+ if (!_loggedNullSettings)
+ {
+ _loggedNullSettings = true;
+ Log.Debug("log4net logs-injection skipped: CurrentTraceSettings was null.");
+ }
+
+ return CallTargetState.GetDefault();
+ }
+
+ if (!mutableSettings.LogsInjectionEnabled)
+ {
+ return CallTargetState.GetDefault();
+ }
+
var properties = loggingEvent.Properties;
- if (mutableSettings.LogsInjectionEnabled && properties != null && !properties.Contains(CorrelationIdentifier.ServiceKey))
+ if (properties is not null && !properties.Contains(CorrelationIdentifier.ServiceKey))
{
properties[CorrelationIdentifier.ServiceKey] = mutableSettings.DefaultServiceName;
properties[CorrelationIdentifier.VersionKey] = mutableSettings.ServiceVersion ?? string.Empty;
@@ -60,7 +82,7 @@ internal static CallTargetState OnMethodBegin(TTarget in
}
}
- return new CallTargetState(scope: null, state: null);
+ return CallTargetState.GetDefault();
}
///
@@ -73,7 +95,7 @@ internal static CallTargetState OnMethodBegin(TTarget in
/// Exception instance in case the original code threw an exception.
/// Calltarget state value
/// A response value, in an async scenario will be T of Task of T
- internal static CallTargetReturn OnMethodEnd(TTarget instance, TReturn returnValue, Exception exception, in CallTargetState state)
+ internal static CallTargetReturn OnMethodEnd(TTarget instance, TReturn returnValue, Exception? exception, in CallTargetState state)
{
return new CallTargetReturn(returnValue);
}