Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

For build-from-source builds of .NET, opt-out of Microsoft telemetry #25935

Merged
merged 8 commits into from
Aug 9, 2022
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
6 changes: 5 additions & 1 deletion .vsts-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,17 @@ variables:
- ${{ if eq(variables['System.TeamProject'], 'public') }}:
- name: _InternalRuntimeDownloadArgs
value: ''
- name: _OfficialBuildArgs
value: ''
- ${{ if ne(variables['System.TeamProject'], 'public') }}:
- name: _DotNetPublishToBlobFeed
value: true
- name: _OfficialBuildArgs
value: /p:OfficialBuilder=Microsoft
- group: DotNetBuilds storage account read tokens
- name: _InternalRuntimeDownloadArgs
marcpopMSFT marked this conversation as resolved.
Show resolved Hide resolved
value: /p:DotNetRuntimeSourceFeed=https://dotnetbuilds.blob.core.windows.net/internal
/p:DotNetRuntimeSourceFeedKey=$(dotnetbuilds-internal-container-read-token-base64)
/p:DotNetRuntimeSourceFeedKey=$(dotnetbuilds-internal-container-read-token-base64)
- ${{ if and(ne(variables['System.TeamProject'], 'public'), notin(variables['Build.Reason'], 'PullRequest')) }}:
- group: DotNet-CLI-SDLValidation-Params

Expand Down
1 change: 1 addition & 0 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
<!-- <ArtifactsShippingSymbolsDir>$(ArtifactsDir)symbols\$(Configuration)\Shipping</ArtifactsShippingSymbolsDir> -->

<DefineConstants Condition="'$(ContinuousIntegrationBuild)' == 'true'">$(DefineConstants);CI_BUILD</DefineConstants>
<DefineConstants Condition="'$(OfficialBuilder)' == 'Microsoft'">$(DefineConstants);MICROSOFT_ENABLE_TELEMETRY</DefineConstants>
<DefineConstants Condition="'$(DotNetBuildFromSource)' == 'true'">$(DefineConstants);DOT_NET_BUILD_FROM_SOURCE</DefineConstants>
</PropertyGroup>

Expand Down
3 changes: 2 additions & 1 deletion eng/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ jobs:
$(_OfficialBuildIdArgs)
/p:Test=false
$(_InternalRuntimeDownloadArgs)
$(_OfficialBuildArgs)
displayName: Build
env:
BuildConfig: $(_BuildConfig)
Expand Down Expand Up @@ -480,4 +481,4 @@ jobs:
ArtifactName: '$(_AgentOSName)_$(Agent.JobName)_$(Build.BuildNumber)'
publishLocation: Container
continueOnError: true
condition: always()
condition: always()
2 changes: 1 addition & 1 deletion src/Cli/dotnet/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ internal static int ProcessArgs(string[] args, TimeSpan startupTime, ITelemetry
bool generateAspNetCertificate =
environmentProvider.GetEnvironmentVariableAsBool("DOTNET_GENERATE_ASPNET_CERTIFICATE", defaultValue: true);
bool telemetryOptout =
environmentProvider.GetEnvironmentVariableAsBool("DOTNET_CLI_TELEMETRY_OPTOUT", defaultValue: false);
environmentProvider.GetEnvironmentVariableAsBool(EnvironmentVariableNames.TELEMETRY_OPTOUT, defaultValue: CompileOptions.TelemetryOptOutDefault);
bool addGlobalToolsToPath =
environmentProvider.GetEnvironmentVariableAsBool("DOTNET_ADD_GLOBAL_TOOLS_TO_PATH", defaultValue: true);
bool nologo =
Expand Down
4 changes: 2 additions & 2 deletions src/Cli/dotnet/Telemetry/Telemetry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ public class Telemetry : ITelemetry
private Task _trackEventTask = null;

private const string InstrumentationKey = "74cc1c9e-3e6e-4d05-b3fc-dde9101d0254";
private const string TelemetryOptout = "DOTNET_CLI_TELEMETRY_OPTOUT";

public bool Enabled { get; }

Expand All @@ -49,7 +48,8 @@ public Telemetry(
environmentProvider = new EnvironmentProvider();
}

Enabled = !environmentProvider.GetEnvironmentVariableAsBool(TelemetryOptout, false) && PermissionExists(sentinel);
Enabled = !environmentProvider.GetEnvironmentVariableAsBool(EnvironmentVariableNames.TELEMETRY_OPTOUT, defaultValue: CompileOptions.TelemetryOptOutDefault)
&& PermissionExists(sentinel);

if (!Enabled)
{
Expand Down
1 change: 1 addition & 0 deletions src/Cli/dotnet/dotnet.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
<Compile Remove="commands\dotnet-new\**" />
<Compile Include="commands\dotnet-new\**\*.cs" />
<Compile Include="..\..\Resolvers\Microsoft.DotNet.MSBuildSdkResolver\FXVersion.cs" />
<Compile Include="$(RepoRoot)src\Common\CompileOptions.cs" LinkBase="Common" />
<Compile Include="$(RepoRoot)src\Common\EnvironmentVariableNames.cs" LinkBase="Common" />
<Compile Include="$(RepoRoot)src\Common\WorkloadFileBasedInstall.cs" LinkBase="Common" />
<Compile Remove="commands\dotnet-workload\list\VisualStudioWorkloads.cs" Condition="'$(DotNetBuildFromSource)' == 'true'" />
Expand Down
15 changes: 15 additions & 0 deletions src/Common/CompileOptions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Copyright (c) .NET Foundation and contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

namespace Microsoft.DotNet.Cli
{
static class CompileOptions
{
public const bool TelemetryOptOutDefault =
#if MICROSOFT_ENABLE_TELEMETRY
false;
#else
true;
#endif
}
}
1 change: 1 addition & 0 deletions src/Common/EnvironmentVariableNames.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@ static class EnvironmentVariableNames
public static readonly string WORKLOAD_UPDATE_NOTIFY_DISABLE = "DOTNET_CLI_WORKLOAD_UPDATE_NOTIFY_DISABLE";
public static readonly string WORKLOAD_UPDATE_NOTIFY_INTERVAL_HOURS = "DOTNET_CLI_WORKLOAD_UPDATE_NOTIFY_INTERVAL_HOURS";
public static readonly string WORKLOAD_DISABLE_PACK_GROUPS = "DOTNET_CLI_WORKLOAD_DISABLE_PACK_GROUPS";
public static readonly string TELEMETRY_OPTOUT = "DOTNET_CLI_TELEMETRY_OPTOUT";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,10 @@
<AutoGen>True</AutoGen>
<DependentUpon>Resources.resx</DependentUpon>
</Compile>


<Compile Include="$(RepoRoot)src\Common\EnvironmentVariableNames.cs" LinkBase="Common"/>
<Compile Include="$(RepoRoot)src\Common\CompileOptions.cs" LinkBase="Common"/>

<AdditionalContent Include="$(PublishRoot)\Targets\**\*.*">
<Pack>true</Pack>
<PackagePath>targets</PackagePath>
Expand Down
4 changes: 2 additions & 2 deletions src/WebSdk/Publish/Tasks/WebConfigTelemetry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
using System.IO;
using System.Text.RegularExpressions;
using System.Xml.Linq;
using Microsoft.DotNet.Cli;

namespace Microsoft.NET.Sdk.Publish.Tasks
{
public class WebConfigTelemetry
{
private const string TelemetryOptout = "DOTNET_CLI_TELEMETRY_OPTOUT";
// An example of a project line looks like this:
// Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ClassLibrary1", "ClassLibrary1\ClassLibrary1.csproj", "{05A5AD00-71B5-4612-AF2F-9EA9121C4111}"
private static readonly Lazy<Regex> s_crackProjectLine = new Lazy<Regex>(
Expand All @@ -31,7 +31,7 @@ public static XDocument AddTelemetry(XDocument webConfig, string projectGuid, bo
{
try
{
bool isCLIOptOutEnabled = EnvironmentHelper.GetEnvironmentVariableAsBool(TelemetryOptout);
bool isCLIOptOutEnabled = EnvironmentHelper.GetEnvironmentVariableAsBool(EnvironmentVariableNames.TELEMETRY_OPTOUT, defaultValue: CompileOptions.TelemetryOptOutDefault);
if (string.IsNullOrEmpty(projectGuid) && !ignoreProjectGuid && !isCLIOptOutEnabled)
{
projectGuid = GetProjectGuidFromSolutionFile(solutionFileFullPath, projectFileFullPath);
Expand Down