Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/add-lockdown-label.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ permissions:
actions: write # For managing the operation state cache
issues: write

env:
DOTNET_CLI_TELEMETRY_SESSIONID: gha-${{ github.repository_id }}-${{ github.run_id }}-${{ github.run_attempt }}

jobs:
add-label:
runs-on: ubuntu-latest
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/add-servicing-consider-label.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ permissions:
contents: read
pull-requests: write

env:
DOTNET_CLI_TELEMETRY_SESSIONID: gha-${{ github.repository_id }}-${{ github.run_id }}-${{ github.run_attempt }}

jobs:
add-servicing-label:
runs-on: ubuntu-latest
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/aot-size-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ on:
permissions: read-all

env:
DOTNET_CLI_TELEMETRY_SESSIONID: gha-${{ github.repository_id }}-${{ github.run_id }}-${{ github.run_attempt }}
AZDO_ORG: dnceng-public
AZDO_PROJECT: public
AZDO_PIPELINE_ID: "101"
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/backport.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ permissions:
pull-requests: write
actions: write

env:
DOTNET_CLI_TELEMETRY_SESSIONID: gha-${{ github.repository_id }}-${{ github.run_id }}-${{ github.run_attempt }}

jobs:
backport:
uses: dotnet/arcade/.github/workflows/backport-base.yml@main
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/check-vendored-files.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ concurrency:
group: vendored-files-check
cancel-in-progress: false

env:
DOTNET_CLI_TELEMETRY_SESSIONID: gha-${{ github.repository_id }}-${{ github.run_id }}-${{ github.run_attempt }}

jobs:
validate:
name: Validate manifest
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/copilot-setup-steps.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ jobs:

copilot-setup-steps:
runs-on: ubuntu-latest
env:
DOTNET_CLI_TELEMETRY_SESSIONID: gha-${{ github.repository_id }}-${{ github.run_id }}-${{ github.run_attempt }}
Comment thread
marcpopMSFT marked this conversation as resolved.
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/detect-netsdk-diagnostics.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ on:

permissions: read-all

env:
DOTNET_CLI_TELEMETRY_SESSIONID: gha-${{ github.repository_id }}-${{ github.run_id }}-${{ github.run_attempt }}

jobs:
detect-diagnostics:
name: Detect New NETSDK Diagnostic Codes
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/fix-completions-on-comment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ permissions:
contents: read

env:
DOTNET_CLI_TELEMETRY_SESSIONID: gha-${{ github.repository_id }}-${{ github.run_id }}-${{ github.run_attempt }}
REPO_NAME: ${{ github.event.repository.name }}
RUN_URL: https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}

Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/inter-branch-merge-flow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ permissions:
contents: write
pull-requests: write

env:
DOTNET_CLI_TELEMETRY_SESSIONID: gha-${{ github.repository_id }}-${{ github.run_id }}-${{ github.run_attempt }}

jobs:
Merge:
uses: dotnet/arcade/.github/workflows/inter-branch-merge-base.yml@main
1 change: 1 addition & 0 deletions .github/workflows/labeler-cache-retention.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ on:
default: "ACTIVE"

env:
DOTNET_CLI_TELEMETRY_SESSIONID: gha-${{ github.repository_id }}-${{ github.run_id }}-${{ github.run_attempt }}
CACHE_KEY: ${{ inputs.cache_key || 'ACTIVE' }}

jobs:
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/labeler-predict-issues.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ on:
default: "ACTIVE"

env:
DOTNET_CLI_TELEMETRY_SESSIONID: gha-${{ github.repository_id }}-${{ github.run_id }}-${{ github.run_attempt }}
# Do not allow failure for jobs triggered automatically (as this causes red noise on the workflows list)
ALLOW_FAILURE: ${{ github.event_name == 'workflow_dispatch' }}

Expand Down
1 change: 1 addition & 0 deletions .github/workflows/labeler-predict-pulls.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ on:
default: "ACTIVE"

env:
DOTNET_CLI_TELEMETRY_SESSIONID: gha-${{ github.repository_id }}-${{ github.run_id }}-${{ github.run_attempt }}
# Do not allow failure for jobs triggered automatically (this can block PR merge)
ALLOW_FAILURE: ${{ github.event_name == 'workflow_dispatch' }}

Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/labeler-promote.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ on:
permissions:
actions: write

env:
DOTNET_CLI_TELEMETRY_SESSIONID: gha-${{ github.repository_id }}-${{ github.run_id }}-${{ github.run_attempt }}

jobs:
promote-issues:
if: ${{ inputs.issues }}
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/labeler-train.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ on:
default: "staged"

env:
DOTNET_CLI_TELEMETRY_SESSIONID: gha-${{ github.repository_id }}-${{ github.run_id }}-${{ github.run_attempt }}
CACHE_KEY: ${{ inputs.cache_key_suffix }}
REPOSITORY: ${{ github.repository }}
LABEL_PREFIX: "Area-"
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/pr-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ on:
permissions:
contents: read
pull-requests: read
env:
DOTNET_CLI_TELEMETRY_SESSIONID: gha-${{ github.repository_id }}-${{ github.run_id }}-${{ github.run_attempt }}

jobs:
allowed-labels:
runs-on: ubuntu-latest
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/remove-lockdown-label.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ permissions:
actions: write
pull-requests: write

env:
DOTNET_CLI_TELEMETRY_SESSIONID: gha-${{ github.repository_id }}-${{ github.run_id }}-${{ github.run_attempt }}

jobs:
remove-labels:
# Only run on the main repository, not forks
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/stale.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ on:
workflow_dispatch: # Allow manual trigger for testing

env:
DOTNET_CLI_TELEMETRY_SESSIONID: gha-${{ github.repository_id }}-${{ github.run_id }}-${{ github.run_attempt }}
KBE_LABEL: 'Known Build Error'
STALE_LABEL: 'stale'
KEEP_OPEN_LABEL: 'keep-open'
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/update-man-pages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ permissions:
contents: write
pull-requests: write

env:
DOTNET_CLI_TELEMETRY_SESSIONID: gha-${{ github.repository_id }}-${{ github.run_id }}-${{ github.run_attempt }}

jobs:
update-man-pages:
runs-on: ubuntu-latest
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/update-static-web-assets-baselines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ on:
permissions:
contents: read

env:
DOTNET_CLI_TELEMETRY_SESSIONID: gha-${{ github.repository_id }}-${{ github.run_id }}-${{ github.run_attempt }}

jobs:
metadata:
name: Fetch Pull Request Metadata
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/update-xlf-on-comment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ permissions:
contents: read

env:
DOTNET_CLI_TELEMETRY_SESSIONID: gha-${{ github.repository_id }}-${{ github.run_id }}-${{ github.run_attempt }}
REPO_NAME: ${{ github.event.repository.name }}
RUN_URL: https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}
jobs:
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/validate-pat-pool.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ on:
# No GitHub API permissions needed
permissions: {}

env:
DOTNET_CLI_TELEMETRY_SESSIONID: gha-${{ github.repository_id }}-${{ github.run_id }}-${{ github.run_attempt }}

jobs:
validate:
environment: copilot-pat-pool
Expand Down
2 changes: 2 additions & 0 deletions .vsts-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ variables:
- template: /eng/pipelines/templates/variables/sdk-defaults.yml
# Variables used: DncEngInternalBuildPool
- template: /eng/common/templates-official/variables/pool-providers.yml
- name: DOTNET_CLI_TELEMETRY_SESSIONID
value: azdo-$(System.CollectionId)-$(System.TeamProjectId)-$(Build.BuildId)
# Helix testing requires a token when internally run.
# Variables used: HelixApiAccessToken
- group: DotNet-HelixApi-Access
Expand Down
2 changes: 2 additions & 0 deletions .vsts-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ variables:
- template: /eng/pipelines/templates/variables/sdk-defaults.yml
# Variables used: DncEngPublicBuildPool
- template: /eng/common/templates/variables/pool-providers.yml
- name: DOTNET_CLI_TELEMETRY_SESSIONID
value: azdo-$(System.CollectionId)-$(System.TeamProjectId)-$(Build.BuildId)

resources:
containers:
Expand Down
7 changes: 6 additions & 1 deletion documentation/project-docs/telemetry.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ The .NET SDK telemetry can be disabled using the following environment variable:
- Values: `false`, `0`, or `no` to allow messages
- Default: `false` (messages are displayed)
- Note: This flag does not affect telemetry collection itself
- **`DOTNET_CLI_TELEMETRY_SESSIONID`**: Seeds the initial telemetry session ID
- When set, the CLI uses this value instead of generating a new GUID for the first `TelemetryClient` created in the process
- This is useful for correlating multiple `dotnet` invocations that belong to the same CI workflow, job, or higher-level user session
- If not set, the CLI generates a new GUID per process as before

Comment thread
baronfel marked this conversation as resolved.

- **`DOTNET_CLI_TELEMETRY_DISABLE_TRACE_EXPORT`**: Set to `1`, `true`, or `yes` to disable exporting trace
telemetry to Azure Monitor (both persistence and upload). Metrics/OTLP export and the local disk log are
Expand Down Expand Up @@ -125,7 +130,7 @@ Every telemetry event automatically includes these common properties:
| **Product Type** | Type of .NET product | Product identifier |
| **Libc Release** | Libc release information | Libc release version |
| **Libc Version** | Libc version information | Libc version number |
| **SessionId** | Unique session identifier | GUID |
| **SessionId** | Unique session identifier | GUID or CI-specific correlation identifier |

## Telemetry Events

Expand Down
4 changes: 4 additions & 0 deletions src/Cli/dotnet/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,3 +85,7 @@ Specifies the location of the servicing index to use by the shared host when loa
`DOTNET_CLI_TELEMETRY_OPTOUT`

Specifies whether data about the .NET Core tools usage is collected and sent to Microsoft. **true** to opt-out of the telemetry feature (values true, 1 or yes accepted); otherwise, **false** (values false, 0 or no accepted). If not set, it defaults to **false**, that is, the telemetry feature is on.

`DOTNET_CLI_TELEMETRY_SESSIONID`

Seeds the initial telemetry session identifier for the current `dotnet` process. When set, multiple `dotnet` invocations can share the same value to correlate telemetry across a CI workflow or other higher-level session.
6 changes: 5 additions & 1 deletion src/Cli/dotnet/Telemetry/TelemetryClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,11 @@ public TelemetryClient(string? sessionId, IEnvironmentProvider? environmentProvi
s_tracerProvider ??= s_tracerProviderBuilder.Build();
}

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

CurrentSessionId ??= !string.IsNullOrEmpty(initialSessionId) ? initialSessionId : Guid.NewGuid().ToString();
s_commonProperties = new TelemetryCommonProperties().GetTelemetryCommonProperties(CurrentSessionId);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@

#nullable disable

using Microsoft.DotNet.Cli;
using Microsoft.DotNet.Cli.Commands.MSBuild;
using Microsoft.DotNet.Cli.Telemetry;
using Microsoft.DotNet.Cli.Utils;
using Moq;

namespace Microsoft.DotNet.Cli.MSBuild.Tests
{
Expand All @@ -19,7 +23,7 @@ public GivenMsbuildForwardingApp()
public void DotnetExeIsExecuted()
{
var msbuildPath = "<msbuildpath>";
new MSBuildForwardingApp(new string[0], msbuildPath)
new MSBuildForwardingApp(Array.Empty<string>(), msbuildPath)
.GetProcessStartInfo().FileName.Should().EndWith("dotnet.exe");
}

Expand All @@ -28,7 +32,7 @@ public void DotnetExeIsExecuted()
public void DotnetIsExecuted()
{
var msbuildPath = "<msbuildpath>";
new MSBuildForwardingApp(new string[0], msbuildPath)
new MSBuildForwardingApp(Array.Empty<string>(), msbuildPath)
.GetProcessStartInfo().FileName.Should().EndWith("dotnet");
}

Expand All @@ -39,7 +43,7 @@ public void DotnetIsExecuted()
public void ItSetsEnvironmentalVariables(string envVarName)
{
var msbuildPath = "<msbuildpath>";
var startInfo = new MSBuildForwardingApp(new string[0], msbuildPath).GetProcessStartInfo();
var startInfo = new MSBuildForwardingApp(Array.Empty<string>(), msbuildPath).GetProcessStartInfo();
startInfo.Environment.ContainsKey(envVarName).Should().BeTrue();
}

Expand All @@ -48,7 +52,7 @@ public void ItSetsMSBuildExtensionPathToExistingPath()
{
var msbuildPath = "<msbuildpath>";
var envVar = "MSBuildExtensionsPath";
new DirectoryInfo(new MSBuildForwardingApp(new string[0], msbuildPath)
new DirectoryInfo(new MSBuildForwardingApp(Array.Empty<string>(), msbuildPath)
.GetProcessStartInfo()
.Environment[envVar])
.Should()
Expand All @@ -60,7 +64,7 @@ public void ItSetsMSBuildSDKsPathToExistingPath()
{
var msbuildPath = "<msbuildpath>";
var envVar = "MSBuildSDKsPath";
new DirectoryInfo(new MSBuildForwardingApp(new string[0], msbuildPath)
new DirectoryInfo(new MSBuildForwardingApp(Array.Empty<string>(), msbuildPath)
.GetProcessStartInfo()
.Environment[envVar])
.Should()
Expand All @@ -72,7 +76,7 @@ public void ItSetsOrIgnoresTelemetrySessionId()
{
var msbuildPath = "<msbuildpath>";
var envVar = "DOTNET_CLI_TELEMETRY_SESSIONID";
var startInfo = new MSBuildForwardingApp(new string[0], msbuildPath)
var startInfo = new MSBuildForwardingApp(Array.Empty<string>(), msbuildPath)
.GetProcessStartInfo();

string sessionId = startInfo.Environment[envVar];
Expand All @@ -83,16 +87,49 @@ public void ItSetsOrIgnoresTelemetrySessionId()
// 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");
(sessionId == null || Guid.TryParse(sessionId, out _) || sessionId == TelemetryClient.CurrentSessionId)
.Should().BeTrue("DOTNET_CLI_TELEMETRY_SESSIONID should be null, current session id, or a guid");
}
}

[TestMethod]
[DoNotParallelize]
public void ItUsesSeededTelemetrySessionId()
{
const string sessionId = "gha-12345-1";
var msbuildPath = "<msbuildpath>";
var environmentProvider = new Mock<IEnvironmentProvider>(MockBehavior.Strict);

TelemetryClient.DisabledForTests = true;
TelemetryClient.DisabledForTests = false;

try
{
environmentProvider
.Setup(p => p.GetEnvironmentVariableAsBool(EnvironmentVariableNames.TELEMETRY_OPTOUT, It.IsAny<bool>()))
.Returns(false);
environmentProvider
.Setup(p => p.GetEnvironmentVariable(EnvironmentVariableNames.DOTNET_CLI_TELEMETRY_SESSIONID))
.Returns(sessionId);

_ = new TelemetryClient(sessionId: null, environmentProvider: environmentProvider.Object);

var startInfo = new MSBuildForwardingApp(Array.Empty<string>(), msbuildPath)
.GetProcessStartInfo();

startInfo.Environment["DOTNET_CLI_TELEMETRY_SESSIONID"].Should().Be(sessionId);
}
finally
{
TelemetryClient.DisabledForTests = true;
}
}

[TestMethod]
public void ItDoesNotSetCurrentWorkingDirectory()
{
var msbuildPath = "<msbuildpath>";
var startInfo = new MSBuildForwardingApp(new string[0], msbuildPath)
var startInfo = new MSBuildForwardingApp(Array.Empty<string>(), msbuildPath)
.GetProcessStartInfo().WorkingDirectory.Should().Be("");
}

Expand Down
Loading
Loading