Skip to content

Commit 6a07aa6

Browse files
Update default value of DD_LOGS_INJECTION to true (#7336)
## Summary of changes - updates the default value of DD_LOGS_INJECTION to be true - this change will enable log injection for structured logging frameworks by default ## Reason for change - Phase 1 of Trace Log Correlation [RFC](https://docs.google.com/document/d/1Okl7hQcJgA9NdQ8msSVu5P2cPQOx139K9s9f3C_bTho/edit?tab=t.0) ## Implementation details ## Test coverage ## Other details <!-- Fixes #{issue} --> <!-- ⚠️ Note: Where possible, please obtain 2 approvals prior to merging. Unless CODEOWNERS specifies otherwise, for external teams it is typically best to have one review from a team member, and one review from apm-dotnet. Trivial changes do not require 2 reviews. MergeQueue is NOT enabled in this repository. If you have write access to the repo, the PR has 1-2 approvals (see above), and all of the required checks have passed, you can use the Squash and Merge button to merge the PR. If you don't have write access, or you need help, reach out in the #apm-dotnet channel in Slack. --> --------- Co-authored-by: Zach Montoya <[email protected]>
1 parent 015d218 commit 6a07aa6

File tree

18 files changed

+23
-62
lines changed

18 files changed

+23
-62
lines changed

tracer/build/_build/Build.ExplorationTests.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,9 @@ Dictionary<string, string> GetEnvironmentVariables(ExplorationTestDescription te
166166
{
167167
["DD_TRACE_LOG_DIRECTORY"] = TestLogsDirectory,
168168
["DD_SERVICE"] = "exploration_tests",
169-
["DD_VERSION"] = Version
169+
["DD_VERSION"] = Version,
170+
// Disable logs injection for exploration tests to avoid interfering with third-party test expectations
171+
["DD_LOGS_INJECTION"] = "false"
170172
};
171173

172174
switch (ExplorationTestUseCase)

tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/ManualInstrumentation/Configuration/TracerSettings/PopulateDictionaryIntegration.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ internal static void PopulateSettings(Dictionary<string, object?> values, Trace.
5858
values[TracerSettingKeyConstants.HeaderTags] = settings.HeaderTags;
5959
values[TracerSettingKeyConstants.KafkaCreateConsumerScopeEnabledKey] = settings.KafkaCreateConsumerScopeEnabled;
6060
#pragma warning disable DD0002 // This API is only for public usage and should not be called internally (there's no internal version currently)
61-
values[TracerSettingKeyConstants.LogsInjectionEnabledKey] = settings.LogSubmissionSettings.LogsInjectionEnabled;
61+
values[TracerSettingKeyConstants.LogsInjectionEnabledKey] = settings.LogsInjectionEnabled;
6262
#pragma warning restore DD0002
6363
values[TracerSettingKeyConstants.MaxTracesSubmittedPerSecondKey] = settings.MaxTracesSubmittedPerSecond;
6464
values[TracerSettingKeyConstants.ServiceNameKey] = settings.ServiceName;

tracer/src/Datadog.Trace/Configuration/TracerSettings.cs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ public record TracerSettings
5252
// These values can all be overwritten by dynamic config
5353
private readonly bool _traceEnabled;
5454
private readonly bool _apmTracingEnabled;
55+
private readonly bool _logsInjectionEnabled;
5556
private readonly bool _isDataStreamsMonitoringEnabled;
5657
private readonly bool _isDataStreamsMonitoringInDefaultState;
5758
private readonly ReadOnlyDictionary<string, string> _headerTags;
@@ -302,6 +303,10 @@ internal TracerSettings(IConfigurationSource? source, IConfigurationTelemetry te
302303
.WithKeys(ConfigurationKeys.ApmTracingEnabled)
303304
.AsBool(defaultValue: true);
304305

306+
_logsInjectionEnabled = config
307+
.WithKeys(ConfigurationKeys.LogsInjectionEnabled)
308+
.AsBool(defaultValue: true);
309+
305310
if (AzureAppServiceMetadata?.IsUnsafeToTrace == true)
306311
{
307312
telemetry.Record(ConfigurationKeys.TraceEnabled, false, ConfigurationOrigins.Calculated);
@@ -910,11 +915,10 @@ static void RecordDisabledIntegrationsTelemetry(IntegrationSettingsCollection in
910915
/// <summary>
911916
/// Gets a value indicating whether correlation identifiers are
912917
/// automatically injected into the logging context.
913-
/// Default is <c>false</c>, unless <see cref="ConfigurationKeys.DirectLogSubmission.EnabledIntegrations"/>
914-
/// enables Direct Log Submission.
918+
/// Default is <c>true</c>.
915919
/// </summary>
916920
/// <seealso cref="ConfigurationKeys.LogsInjectionEnabled"/>
917-
public bool LogsInjectionEnabled => DynamicSettings.LogsInjectionEnabled ?? LogSubmissionSettings.LogsInjectionEnabled;
921+
public bool LogsInjectionEnabled => DynamicSettings.LogsInjectionEnabled ?? _logsInjectionEnabled;
918922

919923
/// <summary>
920924
/// Gets a value indicating the maximum number of traces set to AutoKeep (p1) per second.

tracer/src/Datadog.Trace/Logging/DirectSubmission/DirectLogSubmissionSettings.cs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -169,9 +169,6 @@ public DirectLogSubmissionSettings(IConfigurationSource? source, IConfigurationT
169169

170170
ValidationErrors = validationErrors;
171171
IsEnabled = isEnabled;
172-
173-
// Logs injection is enabled by default if direct log submission is enabled, otherwise disabled by default
174-
LogsInjectionEnabled = config.WithKeys(ConfigurationKeys.LogsInjectionEnabled).AsBool(defaultValue: isEnabled);
175172
}
176173

177174
/// <summary>
@@ -238,11 +235,6 @@ public DirectLogSubmissionSettings(IConfigurationSource? source, IConfigurationT
238235
/// </summary>
239236
internal string ApiKey { get; }
240237

241-
/// <summary>
242-
/// Gets or sets a value indicating whether logs injection is enabled or disabled
243-
/// </summary>
244-
internal bool LogsInjectionEnabled { get; set; }
245-
246238
public IEnumerable<string> EnabledIntegrationNames
247239
=> SupportedIntegrations.Where(x => _enabledIntegrations?[(int)x] == true).Select(x => IntegrationRegistry.GetName(x));
248240

tracer/test/Datadog.Trace.ClrProfiler.IntegrationTests/Log4NetTests.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,6 @@ public static System.Collections.Generic.IEnumerable<object[]> GetTestData()
7474
public async Task InjectsLogsWhenEnabled(string packageVersion, bool enableLogShipping, bool enable128BitInjection)
7575
{
7676
SetInstrumentationVerification();
77-
SetEnvironmentVariable("DD_LOGS_INJECTION", "true");
7877
SetEnvironmentVariable("DD_TRACE_128_BIT_TRACEID_LOGGING_ENABLED", enable128BitInjection ? "true" : "false");
7978
using var logsIntake = new MockLogsIntake();
8079
if (enableLogShipping)
@@ -197,7 +196,6 @@ public async Task DirectlyShipsLogs(string packageVersion)
197196
using var logsIntake = new MockLogsIntake();
198197

199198
SetInstrumentationVerification();
200-
SetEnvironmentVariable("DD_LOGS_INJECTION", "true");
201199
SetEnvironmentVariable("INCLUDE_CROSS_DOMAIN_CALL", "false");
202200
EnableDirectLogSubmission(logsIntake.Port, nameof(IntegrationId.Log4Net), hostName);
203201

tracer/test/Datadog.Trace.ClrProfiler.IntegrationTests/NLogTests.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,6 @@ public static IEnumerable<object[]> DoesNotInjectLogsWhenDisabledTestData()
271271
[Trait("SupportsInstrumentationVerification", "True")]
272272
public async Task InjectsLogsWhenEnabled(string packageVersion, DirectLogSubmission enableLogShipping, string context, ConfigurationType configType, Enable128BitInjection enable128BitInjection)
273273
{
274-
SetEnvironmentVariable("DD_LOGS_INJECTION", "true");
275274
SetEnvironmentVariable("DD_TRACE_128_BIT_TRACEID_LOGGING_ENABLED", enable128BitInjection == Enable128BitInjection.Enable ? "true" : "false");
276275
SetInstrumentationVerification();
277276
using var logsIntake = new MockLogsIntake();

tracer/test/Datadog.Trace.ClrProfiler.IntegrationTests/SerilogTests.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,6 @@ public async Task DirectlyShipsLogs_Pre_2_12_0(
125125

126126
private async Task InjectsLogsWhenEnabledBase(string packageVersion, bool enableLogShipping, bool loadFromConfig, bool enable128BitInjection)
127127
{
128-
SetEnvironmentVariable("DD_LOGS_INJECTION", "true");
129128
SetEnvironmentVariable("DD_TRACE_128_BIT_TRACEID_LOGGING_ENABLED", enable128BitInjection ? "true" : "false");
130129
SetSerilogConfiguration(loadFromConfig);
131130
SetInstrumentationVerification();
@@ -184,7 +183,6 @@ private async Task DirectlyShipsLogsBase(string packageVersion, bool loadFromCon
184183

185184
SetInstrumentationVerification();
186185
SetSerilogConfiguration(loadFromConfig);
187-
SetEnvironmentVariable("DD_LOGS_INJECTION", "true");
188186
SetEnvironmentVariable("INCLUDE_CROSS_DOMAIN_CALL", "false");
189187
SetEnvironmentVariable("DD_TRACE_128_BIT_TRACEID_LOGGING_ENABLED", enable128BitInjection ? "true" : "false");
190188
EnableDirectLogSubmission(logsIntake.Port, nameof(IntegrationId.Serilog), hostName);

tracer/test/Datadog.Trace.ClrProfiler.IntegrationTests/VersionConflict/ILoggerVersionConflict2xTests.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ public ILoggerVersionConflict2xTests(ITestOutputHelper output)
2929
: base(output, "LogsInjection.ILogger.VersionConflict.2x")
3030
{
3131
SetServiceVersion("1.0.0");
32-
SetEnvironmentVariable("DD_LOGS_INJECTION", "true");
3332

3433
// When doing log injection for CI, only emit 64-bit trace-ids.
3534
// By default, the version conflict results in both 64-bit trace-ids

tracer/test/Datadog.Trace.ClrProfiler.IntegrationTests/VersionConflict/Log4NetVersionConflict2xTests.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,6 @@ public Log4NetVersionConflict2xTests(ITestOutputHelper output)
4242
[Trait("RunOnWindows", "True")]
4343
public async Task InjectsLogsWhenEnabled()
4444
{
45-
SetEnvironmentVariable("DD_LOGS_INJECTION", "true");
46-
4745
var expectedCorrelatedTraceCount = 1;
4846
var expectedCorrelatedSpanCount = 8;
4947

tracer/test/Datadog.Trace.ClrProfiler.IntegrationTests/VersionConflict/NLog10VersionConflict2xTests.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,6 @@ public NLog10VersionConflict2xTests(ITestOutputHelper output)
3535
[Trait("RunOnWindows", "True")]
3636
public async Task InjectsLogsWhenEnabled()
3737
{
38-
SetEnvironmentVariable("DD_LOGS_INJECTION", "true");
39-
4038
var expectedCorrelatedTraceCount = 1;
4139
var expectedCorrelatedSpanCount = 8;
4240

0 commit comments

Comments
 (0)