Skip to content

Commit 0667bea

Browse files
zacharycmontoyaandrewlock
authored andcommitted
[Tracing] Update the default value of DD_TRACE_128_BIT_TRACEID_LOGGING_ENABLED to true (#6751)
Updates the default value of the `DD_TRACE_128_BIT_TRACEID_LOGGING_ENABLED` configuration from `false` to `true`. Before: Automatic logs injection, by default, injects the trace-id as a decimal number representing the lower 64-bits of the trace-id, regardless if the trace-id had a 128-bit or 64-bit value. Now: Automatic logs injection, by default, injects the trace-id as a 32-character hexadecimal number representing the 128-bit value when the trace-id is a 128-bit value and as a decimal number (same as before) when the trace-id is a 64-bit value. This also implements a new behavior so when `DD_TRACE_128_BIT_TRACEID_GENERATION_ENABLED=false`, then `DD_TRACE_128_BIT_TRACEID_LOGGING_ENABLED` will also be configured to `false`, unless explicitly overridden by user configuration. --------- Co-authored-by: Andrew Lock <[email protected]>
1 parent 7571c51 commit 0667bea

File tree

8 files changed

+65
-40
lines changed

8 files changed

+65
-40
lines changed

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -803,8 +803,11 @@ internal static class FeatureFlags
803803
/// <summary>
804804
/// Enables injecting 128-bit trace ids into logs as a hexadecimal string.
805805
/// If disabled, 128-bit trace ids will be truncated to the lower 64 bits,
806-
/// and all trace ids will be injected as decimal strings
807-
/// Default value is <c>false</c> (disabled).
806+
/// and injected as decimal strings. 64-bit trace ids are
807+
/// always injected as decimal strings, regardless of this setting.
808+
/// Default value is <c>true</c> (enabled).
809+
/// If <see cref="ConfigurationKeys.FeatureFlags.TraceId128BitGenerationEnabled"/> is set to <c>false</c>,
810+
/// this setting will also be set to <c>false</c>.
808811
/// </summary>
809812
public const string TraceId128BitLoggingEnabled = "DD_TRACE_128_BIT_TRACEID_LOGGING_ENABLED";
810813

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -664,7 +664,7 @@ _ when x.ToBoolean() is { } boolean => boolean,
664664
.AsBool(true);
665665
TraceId128BitLoggingEnabled = config
666666
.WithKeys(ConfigurationKeys.FeatureFlags.TraceId128BitLoggingEnabled)
667-
.AsBool(false);
667+
.AsBool(TraceId128BitGenerationEnabled);
668668

669669
CommandsCollectionEnabled = config
670670
.WithKeys(ConfigurationKeys.FeatureFlags.CommandsCollectionEnabled)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ public void ValidateLogCorrelation(
9797
string packageVersion = "",
9898
bool disableLogCorrelation = false,
9999
Func<string, bool> additionalInjectedLogFilter = null,
100-
bool use128Bits = false)
100+
bool use128Bits = true)
101101
{
102102
foreach (var test in logFileTestCases)
103103
{

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,13 @@ public ILoggerVersionConflict2xTests(ITestOutputHelper output)
3030
{
3131
SetServiceVersion("1.0.0");
3232
SetEnvironmentVariable("DD_LOGS_INJECTION", "true");
33+
34+
// When doing log injection for CI, only emit 64-bit trace-ids.
35+
// By default, the version conflict results in both 64-bit trace-ids
36+
// and 128-bit trace-ids, which complicates the log correlation validation.
37+
// If we can remove the netcoreapp2.1 test application, then we can remove this
38+
// and start root spans with the automatic tracer so that we always generate 128-bit trace-ids.
39+
SetEnvironmentVariable("DD_TRACE_128_BIT_TRACEID_LOGGING_ENABLED", "false");
3340
}
3441

3542
[SkippableFact]
@@ -58,7 +65,7 @@ public async Task InjectsLogs()
5865
var spans = agent.WaitForSpans(1, 2500);
5966
spans.Should().HaveCountGreaterOrEqualTo(1);
6067

61-
ValidateLogCorrelation(spans, _logFiles, expectedCorrelatedTraceCount, expectedCorrelatedSpanCount);
68+
ValidateLogCorrelation(spans, _logFiles, expectedCorrelatedTraceCount, expectedCorrelatedSpanCount, use128Bits: false);
6269
}
6370
}
6471
}

tracer/test/Datadog.Trace.ClrProfiler.Managed.Tests/AutoInstrumentation/Logging/ILogger/DatadogLoggingScopeTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// <copyright file="DatadogLoggingScopeTests.cs" company="Datadog">
1+
// <copyright file="DatadogLoggingScopeTests.cs" company="Datadog">
22
// Unless explicitly stated otherwise all files in this repository are licensed under the Apache 2 License.
33
// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2017 Datadog, Inc.
44
// </copyright>
@@ -50,7 +50,7 @@ public void OutputsJsonFormattedStringWhenActiveTrace()
5050

5151
var actual = scope.ToString();
5252

53-
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}""";
53+
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}""";
5454
actual.Should().Be(expected);
5555
}
5656
}

tracer/test/Datadog.Trace.Tests/Configuration/ConfigurationSourceTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ public ConfigurationSourceTests()
9090
yield return (s => s.ServiceNameMappings, new string[0]);
9191

9292
yield return (s => s.TraceId128BitGenerationEnabled, true);
93-
yield return (s => s.TraceId128BitLoggingEnabled, false);
93+
yield return (s => s.TraceId128BitLoggingEnabled, true);
9494
}
9595

9696
public static IEnumerable<(string Key, string Value, Func<TracerSettings, object> Getter, object Expected)> GetBreakingChangeTestData()

tracer/test/Datadog.Trace.Tests/Configuration/TracerSettingsTests.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1050,10 +1050,13 @@ public void TraceId128BitGenerationEnabled(string value, bool expected)
10501050
var settings = new TracerSettings(source);
10511051

10521052
settings.TraceId128BitGenerationEnabled.Should().Be(expected);
1053+
1054+
// Additional behavior: Ensure that TraceId128BitLoggingEnabled is configured to the same value as TraceId128BitGenerationEnabled
1055+
settings.TraceId128BitLoggingEnabled.Should().Be(expected);
10531056
}
10541057

10551058
[Theory]
1056-
[MemberData(nameof(BooleanTestCases), false)]
1059+
[MemberData(nameof(BooleanTestCases), true)]
10571060
public void TraceId128BitLoggingEnabled(string value, bool expected)
10581061
{
10591062
var source = CreateConfigurationSource((ConfigurationKeys.FeatureFlags.TraceId128BitLoggingEnabled, value));

tracer/test/test-applications/integrations/dependency-libs/LogsInjectionHelper.VersionConflict/LoggingMethods.cs

Lines changed: 43 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -17,56 +17,68 @@ public static int RunLoggingProcedure(Action<string> logAction)
1717
{
1818
try
1919
{
20-
logAction($"{ExcludeMessagePrefix}Starting manual1 Datadog scope.");
21-
using (Tracer.Instance.StartActive("manual1"))
20+
logAction($"{ExcludeMessagePrefix}Starting scopes.");
21+
22+
// Start a trace using the latest automatic tracer so that we
23+
// automatically create a 128-bit trace-id and properly set the _dd.p.tid tag.
24+
// This is only done to make the testing logic easier, since all of the trace-id's
25+
// will have 128-bit trace-id's.
26+
//
27+
// Note: This is not necessary for real applications, as the backend will still be able to
28+
// correlate the 64-bit trace-id's from the manual side and the 128-bit trace-id's
29+
// from the automatic side.
30+
using (TracerUtils.StartAutomaticTraceHigherAssemblyVersion("automatic0"))
2231
{
23-
logAction($"Trace: manual1");
24-
using (TracerUtils.StartAutomaticTraceHigherAssemblyVersion("automatic2"))
32+
using (Tracer.Instance.StartActive("manual1"))
2533
{
26-
logAction($"Trace: manual1-automatic2");
27-
using (Tracer.Instance.StartActive("manual3"))
34+
logAction($"Trace: manual1");
35+
using (TracerUtils.StartAutomaticTraceHigherAssemblyVersion("automatic2"))
2836
{
29-
logAction($"Trace: manual1-automatic2-manual3");
30-
using (Tracer.Instance.StartActive("manual4"))
37+
logAction($"Trace: manual1-automatic2");
38+
using (Tracer.Instance.StartActive("manual3"))
3139
{
32-
logAction($"Trace: manual1-automatic2-manual3-manual4");
33-
34-
using (TracerUtils.StartAutomaticTraceHigherAssemblyVersion("automatic5"))
40+
logAction($"Trace: manual1-automatic2-manual3");
41+
using (Tracer.Instance.StartActive("manual4"))
3542
{
36-
logAction($"Trace: manual1-automatic2-manual3-manual4-automatic5");
37-
}
43+
logAction($"Trace: manual1-automatic2-manual3-manual4");
3844

39-
logAction($"Trace: manual1-automatic2-manual3-manual4");
40-
}
45+
using (TracerUtils.StartAutomaticTraceHigherAssemblyVersion("automatic5"))
46+
{
47+
logAction($"Trace: manual1-automatic2-manual3-manual4-automatic5");
48+
}
4149

42-
logAction($"Trace: manual1-automatic2-manual3");
50+
logAction($"Trace: manual1-automatic2-manual3-manual4");
51+
}
4352

44-
using (TracerUtils.StartAutomaticTraceHigherAssemblyVersion("automatic4"))
45-
{
46-
logAction($"Trace: manual1-automatic2-manual3-automatic4");
47-
using (TracerUtils.StartAutomaticTraceHigherAssemblyVersion("automatic5"))
53+
logAction($"Trace: manual1-automatic2-manual3");
54+
55+
using (TracerUtils.StartAutomaticTraceHigherAssemblyVersion("automatic4"))
4856
{
49-
logAction($"Trace: manual1-automatic2-manual3-automatic4-automatic5");
50-
using (Tracer.Instance.StartActive("manual6"))
57+
logAction($"Trace: manual1-automatic2-manual3-automatic4");
58+
using (TracerUtils.StartAutomaticTraceHigherAssemblyVersion("automatic5"))
5159
{
52-
logAction($"Trace: manual1-automatic2-manual3-automatic4-automatic5-manual6");
60+
logAction($"Trace: manual1-automatic2-manual3-automatic4-automatic5");
61+
using (Tracer.Instance.StartActive("manual6"))
62+
{
63+
logAction($"Trace: manual1-automatic2-manual3-automatic4-automatic5-manual6");
64+
}
65+
66+
logAction($"Trace: manual1-automatic2-manual3-automatic4-automatic5");
5367
}
5468

55-
logAction($"Trace: manual1-automatic2-manual3-automatic4-automatic5");
69+
logAction($"Trace: manual1-automatic2-manual3-automatic4");
5670
}
5771

58-
logAction($"Trace: manual1-automatic2-manual3-automatic4");
72+
logAction($"Trace: manual1-automatic2-manual3");
5973
}
60-
61-
logAction($"Trace: manual1-automatic2-manual3");
74+
logAction($"Trace: manual1-automatic2");
6275
}
63-
logAction($"Trace: manual1-automatic2");
64-
}
6576

66-
logAction($"Trace: manual1");
77+
logAction($"Trace: manual1");
78+
}
6779
}
6880

69-
logAction($"{ExcludeMessagePrefix}Exited manual1 Datadog scope.");
81+
logAction($"{ExcludeMessagePrefix}Exited scopes.");
7082
}
7183
catch (Exception ex)
7284
{

0 commit comments

Comments
 (0)