Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion tracer/missing-nullability-files.csv
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@
// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2017 Datadog, Inc.
// </copyright>

#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
{
Expand All @@ -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;

/// <summary>
/// OnMethodBegin callback
/// </summary>
Expand All @@ -44,9 +50,25 @@ internal static CallTargetState OnMethodBegin<TTarget, TLoggingEvent>(TTarget in

var tracer = Tracer.Instance;

var mutableSettings = tracer.CurrentTraceSettings.Settings;
var mutableSettings = tracer.CurrentTraceSettings?.Settings;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I wonder if this is the case if we'd need to guard this elsewhere for other instrumentations, if so something that we can do later

if (mutableSettings is null)
{
if (!_loggedNullSettings)
{
_loggedNullSettings = true;
Log.Debug("log4net logs-injection skipped: CurrentTraceSettings was null.");

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Unsure how valuable this is, if the theory here is correct there will only be an occasional missed injection

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

(at least as I understand it)

}

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;
Expand All @@ -60,7 +82,7 @@ internal static CallTargetState OnMethodBegin<TTarget, TLoggingEvent>(TTarget in
}
}

return new CallTargetState(scope: null, state: null);
return CallTargetState.GetDefault();
}

/// <summary>
Expand All @@ -73,7 +95,7 @@ internal static CallTargetState OnMethodBegin<TTarget, TLoggingEvent>(TTarget in
/// <param name="exception">Exception instance in case the original code threw an exception.</param>
/// <param name="state">Calltarget state value</param>
/// <returns>A response value, in an async scenario will be T of Task of T</returns>
internal static CallTargetReturn<TReturn> OnMethodEnd<TTarget, TReturn>(TTarget instance, TReturn returnValue, Exception exception, in CallTargetState state)
internal static CallTargetReturn<TReturn> OnMethodEnd<TTarget, TReturn>(TTarget instance, TReturn returnValue, Exception? exception, in CallTargetState state)
{
return new CallTargetReturn<TReturn>(returnValue);
}
Expand Down
Loading