Repository navigation
Avoid copying Activity tags and links when sampling - #135277
martincostello wants to merge 3 commits into
Conversation
Do not copy links and tags when creating a new `Activity` when `ActivitySamplingResult.PropagationData` is specified. Fixes dotnet#135007.
|
Azure Pipelines: Successfully started running 3 pipeline(s). 13 pipeline(s) were filtered out due to trigger conditions. There may be pipelines that require an authorized user to comment /azp run to run. |
|
Tagging subscribers to this area: @steveisok, @dotnet/area-system-diagnostics-tracing |
|
Tagging subscribers to this area: @dotnet/area-system-diagnostics-activity |
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
Sampler tags violate their documented contract, and the behavioral change needs compatibility documentation.
Review effort: Balanced
Findings: 1
What changed in this PR
Optimizes Activity creation for PropagationData sampling.
Changes:
- Skips copying creation tags, links, and sampler tags.
- Adds coverage for parent formats and multiple listeners.
| File | Description |
|---|---|
Activity.cs |
Conditionally skips data copying. |
ActivitySourceTests.cs |
Tests the revised sampling behavior. |
| // Links and tags are unnecessary for activities sampled as PropagationData, so skip copying them. | ||
| bool copyData = request != ActivitySamplingResult.PropagationData; |
There was a problem hiding this comment.
@martincostello The SamplingTags documentation promises that tags added during sampling are added to a created activity. Could we leave if (samplerTags != null) ungated and update the test to expect those tags under PropagationData?
This would not address the separate compatibility concern for creation tags and links. We should weigh that observable change against the measured benefit and document it if we proceed.
- Harden check for skipping tags. - Don't skip sampler tags.
| // Links and creation tags are unnecessary for activities sampled as PropagationData, so skip copying them. | ||
| bool copyData = request is ActivitySamplingResult.AllData or ActivitySamplingResult.AllDataAndRecorded; |
There was a problem hiding this comment.
The documentation concern is valid. Here is suggested replacement wording for the tags and links parameter documentation in ActivitySource.cs, to apply consistently to the two CreateActivity overloads and three StartActivity overloads that accept those parameters.
/// <param name="tags">
/// The optional tags made available to sampling callbacks and copied to the created activity
/// only when the combined sampling result is <see cref="ActivitySamplingResult.AllData"/>
/// or <see cref="ActivitySamplingResult.AllDataAndRecorded"/>.
/// </param>
/// <param name="links">
/// The optional links made available to sampling callbacks and copied to the created activity
/// only when the combined sampling result is <see cref="ActivitySamplingResult.AllData"/>
/// or <see cref="ActivitySamplingResult.AllDataAndRecorded"/>.
/// </param>This wording applies only to caller-supplied creation tags and links. Tags added through ActivityCreationOptions.SamplingTags are still copied when the combined result is PropagationData.
The block above is for manual application to ActivitySource.cs, not to the Activity.cs lines attached to this thread. ActivitySource.cs is not currently part of the PR diff, so this is not a directly applicable suggestion here.
Update `ActivitySource,CreateActivity()` parameter documentation for `tags` and `links` for new behaviour.

Do not copy links and tags when creating a new
ActivitywhenActivitySamplingResult.PropagationDatais specified.Fixes #135007.
Benchmarks
BenchmarkDotNet, default job,
--inProcess --affinity 4095, creating, starting and stopping an activity with the listener returning the given sampling result.mainvs. PR; the tag set is the 9 tags ASP.NET Core-style server instrumentation passes at creation, plus one link. Ratios are PR / main (lower is better).PropagationDataNoTagsPropagationDataNineTagsPropagationDataNineTagsAndLinkAllDataAndRecordedNoTagsAllDataAndRecordedNineTagsAllDataAndRecordedNineTagsAndLinkBenchmark Code