-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Description
Description
System.Diagnostics.W3CPropagator rejects the received traceparent
value if either digit of the two-digit version
field is "f". According to https://www.w3.org/TR/2021/REC-trace-context-1-20211123/#version, only the version "ff" is invalid; others like "0f" or "f1" should not be rejected.
Reproduction Steps
TraceParentDemo.csproj:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<OutputType>Exe</OutputType>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="System.Diagnostics.DiagnosticSource" Version="10.0.0-preview.5.25277.114" />
</ItemGroup>
</Project>
Program.cs:
using System;
using System.Collections.Generic;
using System.Diagnostics;
namespace TraceParentDemo
{
public static class Program
{
public static void Main()
{
DistributedContextPropagator propagator = DistributedContextPropagator.CreateW3CPropagator();
propagator.ExtractTraceIdAndState(new object(), GetHeader, out string traceId, out string traceState);
Console.WriteLine(traceId ?? "Trace ID is not available");
}
private static void GetHeader(object carrier, string fieldName, out string fieldValue, out IEnumerable<string> fieldValues)
{
switch (fieldName)
{
case "traceparent":
fieldValue = "0f-4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-00";
fieldValues = null;
break;
default:
fieldValue = null;
fieldValues = null;
break;
}
}
}
}
dotnet run
Expected behavior
The program should output "0f-4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-00".
Actual behavior
The program outputs "Trace ID is not available".
Regression?
It is somewhat of a regression. Although the DistributedContextPropagator.CreateW3CPropagator() method is new in version 10 of the System.Diagnostics.DiagnosticSource package, the DistributedContextPropagator.Current property was changed to have the same behaviour by default.
Known Workarounds
Derive your own class from DistributedContextPropagator, copy the code from W3CPropagator, and fix the bug.
Configuration
No response
Other information
The impact of this bug is low because W3C has only defined version "00" of the traceparent
header so far. I expect it will take several decades before the version reaches "0f".
This code came from #114583. Note the ||
operator.
runtime/src/libraries/System.Diagnostics.DiagnosticSource/src/System/Diagnostics/W3CPropagator.cs
Lines 609 to 612 in eef526e
if (traceParent[0] == 'f' || traceParent[1] == 'f' || IsInvalidTraceParentCharacter(traceParent[0]) || IsInvalidTraceParentCharacter(traceParent[1])) | |
{ | |
return true; | |
} |
Cc: @tarekgh