Uh oh!
There was an error while loading. Please reload this page.
Add ActivityTraceFlags.RandomTraceId flag - #124851
Conversation
Tagging subscribers to this area: @dotnet/area-system-diagnostics-activity |
There was a problem hiding this comment.
Pull request overview
Adds support for the W3C Trace Context Level 2 random trace-flags bit by introducing ActivityTraceFlags.RandomTraceId and ensuring Activities created with the default trace-id generator set/propagate this flag.
Changes:
- Add
ActivityTraceFlags.RandomTraceIdto the public API surface. - Add
Activity.RandomizedTraceIdconvenience property and set the flag when the default random trace-id generator is used. - Expand
ActivityTestscoverage for parsing/propagating the new flag and validating default generation behavior.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| src/libraries/System.Diagnostics.DiagnosticSource/src/System/Diagnostics/Activity.cs | Introduces RandomizedTraceId, sets RandomTraceId when using the default generator, and adds the new enum flag. |
| src/libraries/System.Diagnostics.DiagnosticSource/ref/System.Diagnostics.DiagnosticSourceActivity.cs | Updates reference assembly API surface for the new property and enum member. |
| src/libraries/System.Diagnostics.DiagnosticSource/tests/ActivityTests.cs | Adds/extends unit tests for RandomTraceId parsing, propagation, and default generation behavior. |
Comments suppressed due to low confidence (1)
src/libraries/System.Diagnostics.DiagnosticSource/src/System/Diagnostics/Activity.cs:950
- The XML documentation for RandomizedTraceId/Recorded refers to
W3CIdFlags.*, but there is no public (or internal)W3CIdFlagstype; the flag enum isActivityTraceFlags. Update the docs to referenceActivityTraceFlags.RandomTraceId/ActivityTraceFlags.Recorded(or describe the W3C trace-flags field generically) to avoid misleading API docs.
/// <summary>
/// True if the W3CIdFlags.RandomTraceId flag is set.
/// </summary>
public bool RandomizedTraceId { get => (ActivityTraceFlags & ActivityTraceFlags.RandomTraceId) != 0; }
/// <summary>
/// True if the W3CIdFlags.Recorded flag is set.
/// </summary>
public bool Recorded { get => (ActivityTraceFlags & ActivityTraceFlags.Recorded) != 0; }
tarekgh
commented
Feb 25, 2026
@Kielek thanks for submitting it. We need to design review it before we proceed with the changes. I have converted this PR to be draft for now till we do that. If you like we can temporary close the PR and then reactive it back when ready. |
Draft Pull Request was automatically closed for 30 days of inactivity. Please let us know if you'd like to reopen it. |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Kielek
commented
Apr 8, 2026
@tarekgh, thank you for adjusting this PR to he API-review decision. |
- Propagate RandomTraceId from parent to child activities in GenerateW3CId() so the flag follows the trace ID per W3C Trace Context Level 2. - Fix EventSourceLogger to use activity.Recorded instead of comparing ActivityTraceFlags to None, which broke with the new RandomTraceId flag. - Update test assertions in DiagnosticSourceEventSourceBridgeTests to expect RandomTraceId on activities using the default random generator.
4c37109 to
3c0d7fcCompareUh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
- Output full ActivityTraceFlags value instead of just Recorded bit in EventSourceLogger, so all flags are propagated to consumers. - Update EventSourceLoggerTest assertion to match. - Fix typo in test method name: Speciifc -> Specific.
Uh oh!
There was an error while loading. Please reload this page.
tarekgh
commented
Apr 9, 2026
/ba-g failures are unrelated and seen in other PRs. |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
…#124851) dotnet/runtime#124851 ("Add ActivityTraceFlags.RandomTraceId flag", W3C Trace Context Level 2) changes how ActivityTraceFlags are emitted into EventPipe events: - Microsoft.Extensions.Logging.EventSource now emits the flags field as the raw integer ("0".."3") rather than just "0"/"1", and emits string.Empty (instead of null) for trace/span IDs when no current Activity exists. - ActivitySource-created activities now have RandomTraceId set automatically, so DiagnosticSourceEventSource Stop events carry flag values this consumer did not recognize. - net 8 servicing runtimes now honor ParentRatioSampler in the FilterAndPayloadSpec, where they previously dropped it. Make the consumer tolerant of these wire-format shifts: * LogRecordFactory: IsNullOrEmpty for trace/span IDs; integer parse with bit-mask for trace flags via new ParseActivityTraceFlags helper. * TraceEventExtensions: tolerant ActivityTraceFlags parse that masks unknown bits (handles either integer or comma-separated name form). * DistributedTracesPipelineUnitTests: drop the obsolete net 8 carveout in TestTracesPipelineWithSamplingRatio; all supported TFMs now produce a single un-recorded activity here. Also bump MicrosoftExtensionsLoggingEventSourceVersion 8.0.3 -> 10.0.5 (the 8.0.3 pin does not exist on the public feeds and was being substituted to 9.0.0 with NU1603 treated as error). Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Fixes#124509
Brings support for RandomTraceId flag known from W3C context propagation level 2.
More details in linked issue.