|
| 1 | +--- |
| 2 | +title: "Breaking change - Default trace context propagator updated to W3C standard" |
| 3 | +description: "Learn about the breaking change in .NET 10 where the default trace context propagator is switched from Legacy to W3C." |
| 4 | +ms.date: 4/21/2025 |
| 5 | +ai-usage: ai-assisted |
| 6 | +ms.custom: https://github.com/dotnet/docs/issues/45793 |
| 7 | +--- |
| 8 | + |
| 9 | +# Default trace context propagator updated to W3C standard |
| 10 | + |
| 11 | +The default trace context propagator has been switched from the legacy propagator to the W3C propagator. The new propagator uses the `baggage` header instead of `Correlation-Context`, enforces W3C-compliant encoding, and supports only W3C-formatted trace parent IDs. |
| 12 | + |
| 13 | +## Version introduced |
| 14 | + |
| 15 | +.NET 10 Preview 4 |
| 16 | + |
| 17 | +## Previous behavior |
| 18 | + |
| 19 | +The <xref:System.Diagnostics.DistributedContextPropagator.CreateDefaultPropagator?displayProperty=nameWithType> method returned an instance of the legacy propagator. By default, <xref:System.Diagnostics.DistributedContextPropagator.Current?displayProperty=nameWithType> was set to this legacy instance. |
| 20 | + |
| 21 | +## New behavior |
| 22 | + |
| 23 | +The <xref:System.Diagnostics.DistributedContextPropagator.CreateDefaultPropagator?displayProperty=nameWithType> method now returns an instance of the W3C propagator. By default, <xref:System.Diagnostics.DistributedContextPropagator.Current?displayProperty=nameWithType> is set to this W3C instance. |
| 24 | + |
| 25 | +Example of setting the default propagator to the legacy propagator: |
| 26 | + |
| 27 | +```csharp |
| 28 | +DistributedContextPropagator.Current = DistributedContextPropagator.CreatePreW3CPropagator(); |
| 29 | +``` |
| 30 | + |
| 31 | +## Type of breaking change |
| 32 | + |
| 33 | +This is a [behavioral change](../../categories.md#behavioral-change). |
| 34 | + |
| 35 | +## Reason for change |
| 36 | + |
| 37 | +This change ensures full compliance with the W3C Trace Context and Baggage specifications. The W3C propagator enforces strict formatting for trace parent, trace state, and baggage keys and values, aligning with the W3C standards. The legacy propagator was more lenient and used the non-standard `Correlation-Context` header for baggage propagation. |
| 38 | + |
| 39 | +For more details, see the following GitHub issues: |
| 40 | + |
| 41 | +- [Pull Request #114583](https://github.com/dotnet/runtime/pull/114583) |
| 42 | +- [Issue #114584](https://github.com/dotnet/runtime/issues/114584) |
| 43 | + |
| 44 | +## Recommended action |
| 45 | + |
| 46 | +If you need to retain the legacy behavior, use the `DistributedContextPropagator.CreatePreW3CPropagator()` method to retrieve the legacy propagator instance. Set it as the current propagator as shown below: |
| 47 | + |
| 48 | +```csharp |
| 49 | +DistributedContextPropagator.Current = DistributedContextPropagator.CreatePreW3CPropagator(); |
| 50 | +``` |
| 51 | + |
| 52 | +## Affected APIs |
| 53 | + |
| 54 | +- <xref:System.Diagnostics.DistributedContextPropagator.Current?displayProperty=fullName> |
| 55 | +- <xref:System.Diagnostics.DistributedContextPropagator.CreateDefaultPropagator?displayProperty=fullName> |
0 commit comments