|
| 1 | +--- |
| 2 | +title: "Breaking change: ActivitySource.CreateActivity and ActivitySource.StartActivity behavior changes" |
| 3 | +description: Learn about the .NET 10.0 breaking change in core .NET libraries where ActivitySource.CreateActivity and ActivitySource.StartActivity behavior is modified. |
| 4 | +ms.date: 01/30/2025 |
| 5 | +--- |
| 6 | +# ActivitySource.CreateActivity and ActivitySource.StartActivity behavior change |
| 7 | + |
| 8 | +The <xref:System.Diagnostics.ActivitySource.CreateActivity*?displayProperty=nameWithType> and <xref:System.Diagnostics.ActivitySource.StartActivity*?displayProperty=nameWithType> APIs only return an `Activity` when there is a registered listener which decides the instance should be created. This is generally known as sampling. |
| 9 | + |
| 10 | +The <xref:System.Diagnostics.ActivitySamplingResult?displayProperty=nameWithType> enum defines the possible sampling decisions. |
| 11 | + |
| 12 | +When creating an `Activity` without a parent, `ActivitySamplingResult` drives whether the `Activity` is created and then how the `Recorded` and `IsAllDataRequested` properties are set: |
| 13 | + |
| 14 | +|ActivitySamplingResult|Activity created|Activity.Recorded|Activity.IsAllDataRequested| |
| 15 | +|---|---|---|---| |
| 16 | +|None|No||| |
| 17 | +|PropagationData|Yes|False|False| |
| 18 | +|AllData|Yes|False|True| |
| 19 | +|AllDataAndRecorded|Yes|True|True| |
| 20 | + |
| 21 | +It is also possible to create an `Activity` with a parent. The parent could be in the same process, or it could be a remote parent propagated to the current process. |
| 22 | + |
| 23 | +## Previous behavior |
| 24 | + |
| 25 | +When creating an `Activity` as `PropagationData` with a parent marked as `Recorded`: |
| 26 | + |
| 27 | +|ActivitySamplingResult|Activity created|Activity.Recorded|Activity.IsAllDataRequested| |
| 28 | +|---|---|---|---| |
| 29 | +|PropagationData|Yes|True|False| |
| 30 | + |
| 31 | +## New behavior |
| 32 | + |
| 33 | +When creating an `Activity` as `PropagationData` with a parent marked as `Recorded`: |
| 34 | + |
| 35 | +|ActivitySamplingResult|Activity created|Activity.Recorded|Activity.IsAllDataRequested| |
| 36 | +|---|---|---|---| |
| 37 | +|PropagationData|Yes|False|False| |
| 38 | + |
| 39 | +## Version introduced |
| 40 | + |
| 41 | +.NET 10 Preview 1 |
| 42 | + |
| 43 | +## Type of breaking change |
| 44 | + |
| 45 | +This change is a [behavioral change](../../categories.md#behavioral-change). |
| 46 | + |
| 47 | +## Reason for change |
| 48 | + |
| 49 | +The existing behavior does not follow the OpenTelemetry specification. |
| 50 | + |
| 51 | +## Recommended action |
| 52 | + |
| 53 | +Users who have implemented `ActivityListener.Sample` directly AND use `ActivitySamplingResult.PropagationData` should verify they are not reliant on the flawed behavior. `Activity.ActivityTraceFlags` may be set to `Recorded` after the `CreateActivity` or `StartActivity` call to restore the previous behavior. |
| 54 | + |
| 55 | +Users using OpenTelemetry .NET should verify their sampler configuration. The default OpenTelemetry .NET configuration uses a parent-based algorithm which is not impacted. Only users who have customized the sampler should verify the behavior. |
| 56 | + |
| 57 | +## Affected APIs |
| 58 | + |
| 59 | +- <xref:System.Diagnostics.ActivitySource.CreateActivity?displayProperty=fullName> |
| 60 | +- <xref:System.Diagnostics.ActivitySource.StartActivity?displayProperty=fullName> |
0 commit comments