Skip to content

[Tracing] Update the default value of DD_TRACE_128_BIT_TRACEID_LOGGING_ENABLED to true #6751

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

Merged
merged 6 commits into from
Mar 19, 2025
Merged
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
7 changes: 5 additions & 2 deletions tracer/src/Datadog.Trace/Configuration/ConfigurationKeys.cs
Original file line number Diff line number Diff line change
Expand Up @@ -793,8 +793,11 @@ internal static class FeatureFlags
/// <summary>
/// Enables injecting 128-bit trace ids into logs as a hexadecimal string.
/// If disabled, 128-bit trace ids will be truncated to the lower 64 bits,
/// and all trace ids will be injected as decimal strings
/// Default value is <c>false</c> (disabled).
/// and injected as decimal strings. 64-bit trace ids are
/// always injected as decimal strings, regardless of this setting.
/// Default value is <c>true</c> (enabled).
/// If <see cref="ConfigurationKeys.FeatureFlags.TraceId128BitGenerationEnabled"/> is set to <c>false</c>,
/// this setting will also be set to <c>false</c>.
/// </summary>
public const string TraceId128BitLoggingEnabled = "DD_TRACE_128_BIT_TRACEID_LOGGING_ENABLED";

Expand Down
2 changes: 1 addition & 1 deletion tracer/src/Datadog.Trace/Configuration/TracerSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -664,7 +664,7 @@ _ when x.ToBoolean() is { } boolean => boolean,
.AsBool(true);
TraceId128BitLoggingEnabled = config
.WithKeys(ConfigurationKeys.FeatureFlags.TraceId128BitLoggingEnabled)
.AsBool(false);
.AsBool(TraceId128BitGenerationEnabled);

CommandsCollectionEnabled = config
.WithKeys(ConfigurationKeys.FeatureFlags.CommandsCollectionEnabled)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public void ValidateLogCorrelation(
string packageVersion = "",
bool disableLogCorrelation = false,
Func<string, bool> additionalInjectedLogFilter = null,
bool use128Bits = false)
bool use128Bits = true)
{
foreach (var test in logFileTestCases)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@ public ILoggerVersionConflict2xTests(ITestOutputHelper output)
{
SetServiceVersion("1.0.0");
SetEnvironmentVariable("DD_LOGS_INJECTION", "true");

// When doing log injection for CI, only emit 64-bit trace-ids.
// By default, the version conflict results in both 64-bit trace-ids
// and 128-bit trace-ids, which complicates the log correlation validation.
// If we can remove the netcoreapp2.1 test application, then we can remove this
// and start root spans with the automatic tracer so that we always generate 128-bit trace-ids.
SetEnvironmentVariable("DD_TRACE_128_BIT_TRACEID_LOGGING_ENABLED", "false");
}

[SkippableFact]
Expand Down Expand Up @@ -58,7 +65,7 @@ public async Task InjectsLogs()
var spans = agent.WaitForSpans(1, 2500);
spans.Should().HaveCountGreaterOrEqualTo(1);

ValidateLogCorrelation(spans, _logFiles, expectedCorrelatedTraceCount, expectedCorrelatedSpanCount);
ValidateLogCorrelation(spans, _logFiles, expectedCorrelatedTraceCount, expectedCorrelatedSpanCount, use128Bits: false);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// <copyright file="DatadogLoggingScopeTests.cs" company="Datadog">
// <copyright file="DatadogLoggingScopeTests.cs" company="Datadog">
// Unless explicitly stated otherwise all files in this repository are licensed under the Apache 2 License.
// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2017 Datadog, Inc.
// </copyright>
Expand Down Expand Up @@ -50,7 +50,7 @@ public void OutputsJsonFormattedStringWhenActiveTrace()

var actual = scope.ToString();

var expected = @$"dd_service:""TestService"", dd_env:""test"", dd_version:""1.2.3"", dd_trace_id:""{spanScope.Span.TraceId}"", dd_span_id:""{spanScope.Span.SpanId}""";
var expected = @$"dd_service:""TestService"", dd_env:""test"", dd_version:""1.2.3"", dd_trace_id:""{((Span)spanScope.Span).TraceId128}"", dd_span_id:""{spanScope.Span.SpanId}""";
actual.Should().Be(expected);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public ConfigurationSourceTests()
yield return (s => s.ServiceNameMappings, new string[0]);

yield return (s => s.TraceId128BitGenerationEnabled, true);
yield return (s => s.TraceId128BitLoggingEnabled, false);
yield return (s => s.TraceId128BitLoggingEnabled, true);
}

public static IEnumerable<(string Key, string Value, Func<TracerSettings, object> Getter, object Expected)> GetBreakingChangeTestData()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1050,10 +1050,13 @@ public void TraceId128BitGenerationEnabled(string value, bool expected)
var settings = new TracerSettings(source);

settings.TraceId128BitGenerationEnabled.Should().Be(expected);

// Additional behavior: Ensure that TraceId128BitLoggingEnabled is configured to the same value as TraceId128BitGenerationEnabled
settings.TraceId128BitLoggingEnabled.Should().Be(expected);
}

[Theory]
[MemberData(nameof(BooleanTestCases), false)]
[MemberData(nameof(BooleanTestCases), true)]
public void TraceId128BitLoggingEnabled(string value, bool expected)
{
var source = CreateConfigurationSource((ConfigurationKeys.FeatureFlags.TraceId128BitLoggingEnabled, value));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,56 +17,68 @@ public static int RunLoggingProcedure(Action<string> logAction)
{
try
{
logAction($"{ExcludeMessagePrefix}Starting manual1 Datadog scope.");
using (Tracer.Instance.StartActive("manual1"))
logAction($"{ExcludeMessagePrefix}Starting scopes.");

// Start a trace using the latest automatic tracer so that we
// automatically create a 128-bit trace-id and properly set the _dd.p.tid tag.
// This is only done to make the testing logic easier, since all of the trace-id's
// will have 128-bit trace-id's.
//
// Note: This is not necessary for real applications, as the backend will still be able to
// correlate the 64-bit trace-id's from the manual side and the 128-bit trace-id's
// from the automatic side.
using (TracerUtils.StartAutomaticTraceHigherAssemblyVersion("automatic0"))
{
logAction($"Trace: manual1");
using (TracerUtils.StartAutomaticTraceHigherAssemblyVersion("automatic2"))
using (Tracer.Instance.StartActive("manual1"))
{
logAction($"Trace: manual1-automatic2");
using (Tracer.Instance.StartActive("manual3"))
logAction($"Trace: manual1");
using (TracerUtils.StartAutomaticTraceHigherAssemblyVersion("automatic2"))
{
logAction($"Trace: manual1-automatic2-manual3");
using (Tracer.Instance.StartActive("manual4"))
logAction($"Trace: manual1-automatic2");
using (Tracer.Instance.StartActive("manual3"))
{
logAction($"Trace: manual1-automatic2-manual3-manual4");

using (TracerUtils.StartAutomaticTraceHigherAssemblyVersion("automatic5"))
logAction($"Trace: manual1-automatic2-manual3");
using (Tracer.Instance.StartActive("manual4"))
{
logAction($"Trace: manual1-automatic2-manual3-manual4-automatic5");
}
logAction($"Trace: manual1-automatic2-manual3-manual4");

logAction($"Trace: manual1-automatic2-manual3-manual4");
}
using (TracerUtils.StartAutomaticTraceHigherAssemblyVersion("automatic5"))
{
logAction($"Trace: manual1-automatic2-manual3-manual4-automatic5");
}

logAction($"Trace: manual1-automatic2-manual3");
logAction($"Trace: manual1-automatic2-manual3-manual4");
}

using (TracerUtils.StartAutomaticTraceHigherAssemblyVersion("automatic4"))
{
logAction($"Trace: manual1-automatic2-manual3-automatic4");
using (TracerUtils.StartAutomaticTraceHigherAssemblyVersion("automatic5"))
logAction($"Trace: manual1-automatic2-manual3");

using (TracerUtils.StartAutomaticTraceHigherAssemblyVersion("automatic4"))
{
logAction($"Trace: manual1-automatic2-manual3-automatic4-automatic5");
using (Tracer.Instance.StartActive("manual6"))
logAction($"Trace: manual1-automatic2-manual3-automatic4");
using (TracerUtils.StartAutomaticTraceHigherAssemblyVersion("automatic5"))
{
logAction($"Trace: manual1-automatic2-manual3-automatic4-automatic5-manual6");
logAction($"Trace: manual1-automatic2-manual3-automatic4-automatic5");
using (Tracer.Instance.StartActive("manual6"))
{
logAction($"Trace: manual1-automatic2-manual3-automatic4-automatic5-manual6");
}

logAction($"Trace: manual1-automatic2-manual3-automatic4-automatic5");
}

logAction($"Trace: manual1-automatic2-manual3-automatic4-automatic5");
logAction($"Trace: manual1-automatic2-manual3-automatic4");
}

logAction($"Trace: manual1-automatic2-manual3-automatic4");
logAction($"Trace: manual1-automatic2-manual3");
}

logAction($"Trace: manual1-automatic2-manual3");
logAction($"Trace: manual1-automatic2");
}
logAction($"Trace: manual1-automatic2");
}

logAction($"Trace: manual1");
logAction($"Trace: manual1");
}
}

logAction($"{ExcludeMessagePrefix}Exited manual1 Datadog scope.");
logAction($"{ExcludeMessagePrefix}Exited scopes.");
}
catch (Exception ex)
{
Expand Down
Loading