Skip to content

Seed CLI telemetry session IDs from CI workflow context - #54447

Merged
baronfel merged 6 commits into
mainfrom
copilot/trace-user-sessions-cli
Jul 31, 2026
Merged

Seed CLI telemetry session IDs from CI workflow context#54447
baronfel merged 6 commits into
mainfrom
copilot/trace-user-sessions-cli

Conversation

Copilot AI commented May 26, 2026

Copy link
Copy Markdown
Contributor

The CLI had a per-process telemetry session ID, but no first-class way to correlate multiple dotnet invocations that belong to the same CI workflow. This updates the CLI to honor DOTNET_CLI_TELEMETRY_SESSIONID as the initial session seed and documents how CI integrations can set it consistently.

  • CLI session seeding

    • TelemetryClient now uses DOTNET_CLI_TELEMETRY_SESSIONID when no explicit session ID is provided.
    • This preserves existing explicit-session behavior while enabling cross-invocation correlation for workflow-scoped sessions.
  • MSBuild forwarding coverage

    • Added focused tests to verify:
      • environment-seeded session IDs become TelemetryClient.CurrentSessionId
      • explicit session IDs still take precedence
      • forwarded MSBuild invocations receive the seeded DOTNET_CLI_TELEMETRY_SESSIONID
  • Docs

    • Documented DOTNET_CLI_TELEMETRY_SESSIONID in telemetry docs and CLI README.
    • Added concrete GitHub Actions and Azure DevOps examples showing how to stamp a workflow/job-scoped identifier once and let subsequent dotnet invocations inherit it.
  • Repo CI integration

    • Repo GitHub Actions workflow now sets:
      DOTNET_CLI_TELEMETRY_SESSIONID: gha-${{ github.repository_id }}-${{ github.run_id }}-${{ github.run_attempt }}
    • Repo AzDo pipelines now set:
      DOTNET_CLI_TELEMETRY_SESSIONID: azdo-$(System.CollectionId)-$(System.TeamProjectId)-$(Build.BuildId)

Example:

var initialSessionId = !string.IsNullOrEmpty(sessionId)
    ? sessionId
    : environmentProvider.GetEnvironmentVariable(EnvironmentVariableNames.DOTNET_CLI_TELEMETRY_SESSIONID);

CurrentSessionId ??= !string.IsNullOrEmpty(initialSessionId)
    ? initialSessionId
    : Guid.NewGuid().ToString();

Agent-Logs-Url: https://github.com/dotnet/sdk/sessions/d2467965-adc9-4e5a-a8c2-9076fee7b771

Co-authored-by: baronfel <573979+baronfel@users.noreply.github.com>
Comment thread documentation/project-docs/telemetry.md Outdated
baronfel and others added 2 commits May 26, 2026 10:09
Copilot AI changed the title [WIP] Add support for tracing user sessions across GHA and AzDo Seed CLI telemetry session IDs from CI workflow context May 26, 2026
Copilot AI requested a review from baronfel May 26, 2026 15:13
@baronfel
baronfel requested a review from a team May 26, 2026 15:19
@baronfel
baronfel marked this pull request as ready for review May 26, 2026 15:19
@baronfel
baronfel requested a review from MiYanni as a code owner May 26, 2026 15:19
Copilot AI review requested due to automatic review settings May 26, 2026 15:19

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates the .NET SDK CLI telemetry implementation to allow CI systems to correlate multiple dotnet invocations by seeding the in-process telemetry session ID from DOTNET_CLI_TELEMETRY_SESSIONID, and adds test/doc/CI updates to support that workflow.

Changes:

  • Seed TelemetryClient.CurrentSessionId from DOTNET_CLI_TELEMETRY_SESSIONID when no explicit session ID is provided.
  • Add/adjust tests to validate environment seeding, explicit session ID precedence, and MSBuild forwarding behavior.
  • Document the new environment variable and set it in selected CI YAML definitions.

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
src/Cli/dotnet/Telemetry/TelemetryClient.cs Seeds session ID from DOTNET_CLI_TELEMETRY_SESSIONID before falling back to GUID generation.
test/dotnet.Tests/TelemetryTests/TelemetryClientTests.cs Adds unit coverage for environment-seeded vs explicit session ID behavior; serializes tests touching static telemetry state.
test/dotnet.Tests/CommandTests/MSBuild/GivenMsbuildForwardingApp.cs Adds coverage ensuring MSBuild forwarding propagates the seeded telemetry session ID.
documentation/project-docs/telemetry.md Documents DOTNET_CLI_TELEMETRY_SESSIONID and clarifies session ID may be non-GUID correlation identifiers.
src/Cli/dotnet/README.md Adds DOTNET_CLI_TELEMETRY_SESSIONID to CLI environment variable documentation.
.github/workflows/copilot-setup-steps.yml Sets DOTNET_CLI_TELEMETRY_SESSIONID in the Copilot setup workflow environment.
.vsts-pr.yml Sets DOTNET_CLI_TELEMETRY_SESSIONID in AzDO PR pipeline variables.
.vsts-ci.yml Sets DOTNET_CLI_TELEMETRY_SESSIONID in AzDO CI pipeline variables.

Comment on lines 84 to 90
// Other in-process tests (GivenADotnetFirstTimeUseConfigurerWithStateSetup) use "test"
// for session ID, so ignore if they already set it
if (sessionId != "test")
{
(sessionId == null || Guid.TryParse(sessionId, out _))
.Should().BeTrue("DOTNET_CLI_TELEMETRY_SESSIONID should be null or current session id");
}
Comment thread .github/workflows/copilot-setup-steps.yml
Comment thread documentation/project-docs/telemetry.md
@github-actions

Copy link
Copy Markdown
Contributor

Due to lack of recent activity, this PR has been labeled as 'Stale'. It will be closed if no further activity occurs within 7 more days. Any new comment will remove the label.

@github-actions github-actions Bot added the stale label Jul 25, 2026
@baronfel baronfel removed the stale label Jul 25, 2026
@baronfel

Copy link
Copy Markdown
Member

@copilot please fix the merge conflicts in this pull request.

Co-authored-by: baronfel <573979+baronfel@users.noreply.github.com>
Copilot AI requested review from lbussell and mthalman as code owners July 25, 2026 16:52
Copilot AI requested a review from MichaelSimons as a code owner July 25, 2026 16:52

Copilot AI commented Jul 25, 2026

Copy link
Copy Markdown
Contributor Author

@copilot please fix the merge conflicts in this pull request.

Fixed by merging origin/main and resolving the conflicts in TelemetryClientTests and GivenMsbuildForwardingApp in commit bb97748.

Copilot AI requested a review from baronfel July 25, 2026 16:52
Comment thread .github/workflows/copilot-setup-steps.yml
Comment thread documentation/project-docs/telemetry.md
Co-authored-by: baronfel <573979+baronfel@users.noreply.github.com>
Copilot AI requested a review from baronfel July 25, 2026 18:40
@baronfel
baronfel requested a review from marcpopMSFT July 27, 2026 16:01
@marcpopMSFT

Copy link
Copy Markdown
Member

Only question I have is how do we ensure future yml changes end up including this change. Should we update a doc somewhere so copilot sees that when adding/editing yml in the future? Can be a separate PR.

@marcpopMSFT

Copy link
Copy Markdown
Member

Another thought I had was how to get this into arcade so we seed the session id for all our repo builds. Not sure how to seed it into all workflows as those don't go through arcade.

@baronfel

Copy link
Copy Markdown
Member

Only question I have is how do we ensure future yml changes end up including this change. Should we update a doc somewhere so copilot sees that when adding/editing yml in the future? Can be a separate PR.

Good thought - will poke an agent/get a note into our reviewer docs/skills.

Another thought I had was how to get this into arcade so we seed the session id for all our repo builds. Not sure how to seed it into all workflows as those don't go through arcade.

Also a great idea - will log an issue for this at the arcade repo for discussion.

@baronfel
baronfel merged commit 14cea59 into main Jul 31, 2026
32 checks passed
@baronfel
baronfel deleted the copilot/trace-user-sessions-cli branch July 31, 2026 17:50
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 11.0-rc1 milestone Aug 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Trace 'user sessions' in a first-class manner across GHA and AzDo

4 participants