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

Conversation

tmds
Copy link
Member

@tmds tmds commented Jun 9, 2022

We opt-out by setting DOTNET_CLI_TELEMETRY_OPTOUT at 'dotnet' Main
to ensure that anything that checks the variable later, including MSBuild Tasks,
will see the value.

Fixes #24474

cc @omajid @richlander @baronfel @jkotas

@richlander
Copy link
Member

This isn't quite what I was expecting. Disable telemetry is still relying on setting an ENV. Don't we want something much more fundamental, where no ENVs are set by default AND telemetry is not enabled?

@tmds
Copy link
Member Author

tmds commented Jun 9, 2022

This isn't quite what I was expecting. Disable telemetry is still relying on setting an ENV. Don't we want something much more fundamental, where no ENVs are set by default AND telemetry is not enabled?

There are two ways to implement this:

  • Either, when the program starts, set the env to not enable telemetry (when it was not set).
  • Or, update all places where where the env is read so the default value matches the build-time setting.

I've opted for the first because that was simplest to implement.
I can change to the second if that is preferred. That will require changing all code that reads the envvar. And, anything that checks the envvar outside this repo will not be aware telemetry should be disabled by default.

@richlander
Copy link
Member

It feels like the other option is the "right" architectural choice. That approach would mean there is a literal guarantee that telemetry can never be enabled through some accidental gesture.

@kasperk81
Copy link
Contributor

this is also needed in src/WebSdk/Publish/Tasks/WebConfigTelemetry.cs?

@tmds
Copy link
Member Author

tmds commented Jun 13, 2022

this is also needed in src/WebSdk/Publish/Tasks/WebConfigTelemetry.cs?

Yes, this is needed everywhere where something reads the envvar. And why I mentioned MSBuild Tasks in the initial message.

Imo the safest is to set the envvar at startup to ensure every location that checks it (which maybe does not live in this repo?) is aware telemetry is disabled.

@richlander indicates he expects the PR to update locations that check to envvar in this repo to be updated. If the repo owners confirm this is their preference also, I'll update the PR to use that approach.

@KalleOlaviNiemitalo
Copy link

I thought you could have a test that searches for "DOTNET_CLI_TELEMETRY_OPTOUT" in the binaries after a source build, but:

  • The string is encoded in UTF-16 in the UserString heap but in UTF-8 elsewhere, complicating the search.
  • It is okay for Microsoft.DotNet.Configurer.dll to contain the TelemetryMessage string resource that mentions the environment variable, even if telemetry was disabled at compile time.

@tmds
Copy link
Member Author

tmds commented Jun 14, 2022

@KalleOlaviNiemitalo for this PR I'd like to scope to make the behavior opt-in rather than exclude it. If excluding gets implemented, that can be a useful test.

@tmds
Copy link
Member Author

tmds commented Jun 14, 2022

@dsplaisted @baronfel question: do you prefer this being implemented as:

  • DOTNET_CLI_TELEMETRY_OPTOUT envvar getting set at start, so it affects all readers of the envvar.
  • or by updating all locations where DOTNET_CLI_TELEMETRY_OPTOUT gets read to use a different defaultValue?

@KalleOlaviNiemitalo
Copy link

Is the environment variable read by any tools that are published to NuGet.org? Perhaps, even if a user installs a source-built SDK and does not expect it to send telemetry, the user might not expect this SDK to tell separately-installed tools not to send telemetry either.

@richlander
Copy link
Member

We are typically hesitant for the SDK to set ENVs automatically (for any scenario). It can have unexpected consequences across process boundaries. I'm unaware of any scenario where tools would still have telemetry enabled that we need to worry about. My understanding is that telemetry is solely enabled by the system we're looking at in this PR.

@tmds tmds requested a review from vijayrkn as a code owner June 20, 2022 08:42
@marcpopMSFT
Copy link
Member

For the test failure on the Darwin leg, you can cherry pick this commit or wait for this PR to go in which includes that commit.

@@ -21,6 +21,7 @@
<!-- <ArtifactsShippingSymbolsDir>$(ArtifactsDir)symbols\$(Configuration)\Shipping</ArtifactsShippingSymbolsDir> -->

<DefineConstants Condition="'$(ContinuousIntegrationBuild)' == 'true'">$(DefineConstants);CI_BUILD</DefineConstants>
<DefineConstants Condition="'$(DotNetBuildFromSource)' != 'true'">$(DefineConstants);MICROSOFT_ENABLE_TELEMETRY</DefineConstants>
Copy link
Member

Choose a reason for hiding this comment

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

Per my understanding, with the naive build of the product, MICROSOFT_ENABLE_TELEMETRY will be set. Isn't that not what we want?

How about the follow?

Suggested change
<DefineConstants Condition="'$(DotNetBuildFromSource)' != 'true'">$(DefineConstants);MICROSOFT_ENABLE_TELEMETRY</DefineConstants>
<DefineConstants Condition="'$(MicrosoftOfficialBuild)' == 'true'">$(DefineConstants);MICROSOFT_ENABLE_TELEMETRY</DefineConstants>

Copy link
Member Author

Choose a reason for hiding this comment

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

What is there works to opt-out of telemetry for open-source builds of .NET.
DotNetBuildFromSource is used throughout the different repositories to detect that.

I'm not familiar with MicrosoftOfficialBuild. It's not used in this repo yet.
I'll apply the suggestion.

Copy link
Member

Choose a reason for hiding this comment

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

MicrosoftOfficialBuild is something I made up. We would just need the official build to set that condition and then everything would be perfect.

Can we do that @marcpopMSFT, for the official SDK build?

Copy link
Member

Choose a reason for hiding this comment

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

That's more of an engineering system question as items like ContinuousIntegrationBuild are set in the scripts that live in the eng\common folder it looks like. @mmitche do you know where MicrosoftOfficialBuild would need to be set so that our official builds would include that? that probably needs to be set before this PR can go in.

Copy link
Member

Choose a reason for hiding this comment

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

It would need to be set in the YAML files in this repo, similar to how we enable other Microsoft specific switches in our build. e.g. https://github.com/dotnet/sdk/blob/main/.vsts-ci.yml#L34-L35

I think this will end up being a common pattern with potentially other organizations having their own logic in shared code. Perhaps we change this to something like OfficialBuilder, setting it to Microsoft for us, or perhaps BuildOrganization?

Thoughts @richlander?

Copy link
Member

Choose a reason for hiding this comment

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

I'm not particularl on the name, but something like that sounds good.

Copy link
Member

Choose a reason for hiding this comment

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

Let's go for OfficialBuilder

Copy link
Member

Choose a reason for hiding this comment

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

We can always change it later if someone has a better name.

Copy link
Member Author

Choose a reason for hiding this comment

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

It would need to be set in the YAML files in this repo, similar to how we enable other Microsoft specific switches in our build. e.g. https://github.com/dotnet/sdk/blob/main/.vsts-ci.yml#L34-L35

I've added it to this location.

Let's go for OfficialBuilder

My personal preference was to use the existing DotNetBuildFromSource rather than introduce something new.

@tmds
Copy link
Member Author

tmds commented Jun 28, 2022

@marcpopMSFT can you review the PR, and give your input here: #25935 (comment)?

@tmds
Copy link
Member Author

tmds commented Jul 5, 2022

Is this ready to merge?

.vsts-ci.yml Outdated Show resolved Hide resolved
Directory.Build.props Outdated Show resolved Hide resolved
Directory.Build.props Outdated Show resolved Hide resolved
Directory.Build.props Outdated Show resolved Hide resolved
Copy link
Member

@baronfel baronfel left a comment

Choose a reason for hiding this comment

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

Looks good! Needs a rebase to incorporate changes from main in the meantime though.

@richlander
Copy link
Member

Can we make this PR land this week? That'd would be really excellent for ensuring we make .NET 7.

@baronfel
Copy link
Member

baronfel commented Aug 9, 2022

Merged in the CI fix from main, let's see if we can get to green now.

…by default.

We opt-out by setting DOTNET_CLI_TELEMETRY_OPTOUT at 'dotnet' Main
to ensure that anything that checks the variable later, including MSBuild Tasks,
will see the value.
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.

Opt out of sending telemetry data by default for non-Microsoft builds
8 participants