[Breaking change]: ActivitySource does not retain creation tags or links for PropagationData
Maintainer thường phản hồi trong vòng 1 ngày
@BillWagner đang làm issue này rồi.
Từ ngày 7/10/2026.
Đánh giá
Issue này chưa được đánh giá.
Mô tả
Description
When an ActivityListener samples an activity as ActivitySamplingResult.PropagationData, ActivitySource.CreateActivity and ActivitySource.StartActivity no longer copy caller-supplied creation tags and links to the created Activity. The tags and links remain available to the sampling callback through ActivityCreationOptions<T>.Tags and ActivityCreationOptions<T>.Links.
For more information, see dotnet/runtime#135277.
Version
.NET 12 Preview 1
Previous behavior
CreateActivity and StartActivity copied caller-supplied creation tags and links to the returned Activity even when the combined sampling result was PropagationData.
using System.Diagnostics;
using ActivitySource source = new("Example");
using ActivityListener listener = new()
{
ShouldListenTo = activitySource => ReferenceEquals(activitySource, source),
Sample = (ref ActivityCreationOptions<ActivityContext> _) =>
ActivitySamplingResult.PropagationData,
};
ActivitySource.AddActivityListener(listener);
using Activity activity = source.StartActivity(
"Request",
ActivityKind.Server,
default(ActivityContext),
tags: [new("http.request.method", "GET")],
links: [new ActivityLink(default)])!;
// The activity retained the creation tag and link.
Console.WriteLine(activity.TagObjects.Count()); // 1
Console.WriteLine(activity.Links.Count()); // 1
New behavior
When the combined sampling result is PropagationData, caller-supplied creation tags and links are not copied to the created Activity.
using System.Diagnostics;
using ActivitySource source = new("Example");
using ActivityListener listener = new()
{
ShouldListenTo = activitySource => ReferenceEquals(activitySource, source),
Sample = (ref ActivityCreationOptions<ActivityContext> options) =>
{
// Creation tags and links remain available to the sampler.
Console.WriteLine(options.Tags.Count());
Console.WriteLine(options.Links.Count());
return ActivitySamplingResult.PropagationData;
},
};
ActivitySource.AddActivityListener(listener);
using Activity activity = source.StartActivity(
"Request",
ActivityKind.Server,
default(ActivityContext),
tags: [new("http.request.method", "GET")],
links: [new ActivityLink(default)])!;
// The activity does not retain the creation tag or link.
Console.WriteLine(activity.TagObjects.Count()); // 0
Console.WriteLine(activity.Links.Count()); // 0
Tags added by a sampler through ActivityCreationOptions<T>.SamplingTags continue to be copied to the created activity. If any listener returns ActivitySamplingResult.AllData or ActivitySamplingResult.AllDataAndRecorded, the combined sampling result requests all data and the caller-supplied creation tags and links are retained.
Type of breaking change
- Binary incompatible: Existing binaries might encounter a breaking change in behavior, such as failure to load or execute, and if so, require recompilation.
- Source incompatible: When recompiled using the new SDK or component or to target the new runtime, existing source code might require source changes to compile successfully.
- Behavioral change: Existing binaries might behave differently at run time.
Reason for change
PropagationData creates an activity only to propagate its identity and baggage; tags and links are unnecessary on the created activity. Avoiding their copies reduces the time and allocations for sampled-out operations while preserving their availability to samplers. For example, the PR reduced allocations from 976 B to 416 B when creating an activity with nine tags and one link.
Recommended action
Applications whose samplers need to examine creation tags or links require no changes; continue to read them from ActivityCreationOptions<T>.Tags and ActivityCreationOptions<T>.Links.
Applications that need caller-supplied creation tags or links on the returned Activity or in ActivityStarted callbacks must have a listener return ActivitySamplingResult.AllData or ActivitySamplingResult.AllDataAndRecorded for those activities. Do not return PropagationData when those properties must be retained. This retains the data but also requests all activity data and its associated allocation cost.
Feature area
Core .NET libraries
Affected APIs
All overloads that accept tags and links:
System.Diagnostics.ActivitySource.CreateActivitySystem.Diagnostics.ActivitySource.StartActivity
- Ngôn ngữ chính
- Không có dữ liệu ngôn ngữ
- Star
- 4.8k
- Fork
- 6.1k
- Merge trung bình
- 22 giờ 46 phút
- Pull request đã merge (30 ngày)
- 296
Chuẩn bị môi trường
Khởi chạy dev container của dự án ngay trên trình duyệt, bằng tài khoản GitHub của bạn.
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của dotnet/docs
-
ExamenĐang mởdotnet-csharp/svc lang-reference/subsvc needs-more-info
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 66/100
dotnet/docs#56845 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Update the .NET Framework 3.5 on Windows 11 FAQ to mention Windows 11 26H2Có thể đã có người làm @BillWagner đã nhận 3 ngày trước. Đang mở:pushpin: seQUESTered dotnet/svc
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 78/100
dotnet/docs#56791 · 1 reaction · 2 người được giao ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 86/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Improve description of `limitations of extensions`Có thể đã có người làm @Manish-1kumar đã nhận 12 ngày trước. Đang mởadvanced-concepts/subsvc dotnet-csharp/svc
Độ khó 1/5 1-3 giờ Mức phù hợp với người mới 84/100
dotnet/docs#56626 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Document unit-test / theory-data impact of .NET 11 double→decimal conversionCó thể đã có người làm @SkyDevLab đã nhận 22 ngày trước. Đang mở:watch: Not Triaged dotnet-fundamentals/svc
Độ khó 1/5 1-3 giờ Mức phù hợp với người mới 88/100
Maintainer thường phản hồi trong vòng 1 ngày