Skip to content

Commit

Permalink
Merge pull request NuGet#19 from TheCakeIsNaOH/disable-telemetry
Browse files Browse the repository at this point in the history
(NuGet#9) Disable telemetry emission
  • Loading branch information
gep13 authored Jan 12, 2023
2 parents 7512130 + 45435a8 commit f1e5db2
Show file tree
Hide file tree
Showing 9 changed files with 177 additions and 22 deletions.
31 changes: 30 additions & 1 deletion src/NuGet.Core/NuGet.Common/Telemetry/TelemetryActivity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,27 @@ private TelemetryActivity(Guid parentId, TelemetryEvent telemetryEvent, Guid ope
/// End with <see cref="EndIntervalMeasure(string)"/>
/// The intervals cannot overlap. For non-overlapping intervals <see cref="StartIndependentInterval(string)"/>
/// </summary>
//////////////////////////////////////////////////////////
// Start - Chocolatey Specific Modification
//////////////////////////////////////////////////////////
[Conditional("TELEMETRYCONDITION")]
//////////////////////////////////////////////////////////
// End - Chocolatey Specific Modification
//////////////////////////////////////////////////////////
public void StartIntervalMeasure()
{
_intervalWatch.Restart();
}

/// <summary> End interval measure. </summary>
/// <param name="propertyName"> Property name to represents the interval. </param>
//////////////////////////////////////////////////////////
// Start - Chocolatey Specific Modification
//////////////////////////////////////////////////////////
[Conditional("TELEMETRYCONDITION")]
//////////////////////////////////////////////////////////
// End - Chocolatey Specific Modification
//////////////////////////////////////////////////////////
public void EndIntervalMeasure(string propertyName)
{
_intervalWatch.Stop();
Expand Down Expand Up @@ -129,7 +143,15 @@ protected virtual void Dispose(bool disposing)
TelemetryEvent[interval.Item1] = interval.Item2.TotalSeconds;
}

NuGetTelemetryService.EmitTelemetryEvent(TelemetryEvent);
//////////////////////////////////////////////////////////
// Start - Chocolatey Specific Modification
//////////////////////////////////////////////////////////

//NuGetTelemetryService.EmitTelemetryEvent(TelemetryEvent);

//////////////////////////////////////////////////////////
// End - Chocolatey Specific Modification
//////////////////////////////////////////////////////////
}

_telemetryActivity?.Dispose();
Expand All @@ -140,6 +162,13 @@ protected virtual void Dispose(bool disposing)

/// <summary> Emit a singular telemetry event. </summary>
/// <param name="TelemetryEvent"> Telemetry event. </param>
//////////////////////////////////////////////////////////
// Start - Chocolatey Specific Modification
//////////////////////////////////////////////////////////
[Conditional("TELEMETRYCONDITION")]
//////////////////////////////////////////////////////////
// End - Chocolatey Specific Modification
//////////////////////////////////////////////////////////
public static void EmitTelemetryEvent(TelemetryEvent TelemetryEvent)
{
NuGetTelemetryService?.EmitTelemetryEvent(TelemetryEvent);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,13 @@ public static IEnumerable<object[]> GetInstallActionTestData()
}
}

[Theory]
//////////////////////////////////////////////////////////
// Start - Chocolatey Specific Modification
//////////////////////////////////////////////////////////
[Theory(Skip = "Intentionally broken by Chocolatey changes")]
//////////////////////////////////////////////////////////
// End - Chocolatey Specific Modification
//////////////////////////////////////////////////////////
[MemberData(nameof(GetInstallActionTestData))]
public async Task CreateInstallAction_OnInstallingProject_EmitsPkgWasTransitiveTelemetryAndTabAndIsSolutionPropertiesAsync(ContractsItemFilter activeTab, bool isSolutionLevel, string packageIdToInstall, bool? expectedPkgWasTransitive)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2386,7 +2386,13 @@ await SimpleTestPackageUtility.CreateFolderFeedV3Async(
}
}

[Fact]
//////////////////////////////////////////////////////////
// Start - Chocolatey Specific Modification
//////////////////////////////////////////////////////////
[Fact(Skip = "Intentionally broken by Chocolatey changes")]
//////////////////////////////////////////////////////////
// End - Chocolatey Specific Modification
//////////////////////////////////////////////////////////
public async Task TestPackageManager_RaiseTelemetryEvents()
{
// set up telemetry service
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,13 @@ public async Task CreatePackageFeedAsync_WithTransitiveOriginsExpFlag_OnlyInstal
Assert.Null(recommender);
}

[Fact]
//////////////////////////////////////////////////////////
// Start - Chocolatey Specific Modification
//////////////////////////////////////////////////////////
[Fact(Skip = "Intentionally broken by Chocolatey changes")]
//////////////////////////////////////////////////////////
// End - Chocolatey Specific Modification
//////////////////////////////////////////////////////////
public async Task CreatePackageFeedAsync_ProjectPMUIInstalledTab_EmitsCounterfactualTelemetryAsync()
{
// Arrange
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,13 @@ await PerformOperationAsync(async (projectManager) =>
}
}

[Fact]
//////////////////////////////////////////////////////////
// Start - Chocolatey Specific Modification
//////////////////////////////////////////////////////////
[Fact(Skip = "Intentionally broken by Chocolatey changes")]
//////////////////////////////////////////////////////////
// End - Chocolatey Specific Modification
//////////////////////////////////////////////////////////
public async Task GetInstalledPackagesAsync_WhenProjectReturnsNullPackageReference_NullIsRemoved()
{
const string projectName = "a";
Expand Down Expand Up @@ -799,7 +805,13 @@ private async Task GetInstalledAndTransitivePackagesAsync_TransitiveOriginsWithL
x => Assert.Equal(x.Identity, new PackageIdentity("packageX", NuGetVersion.Parse("3.0.0"))));
}

[Fact]
//////////////////////////////////////////////////////////
// Start - Chocolatey Specific Modification
//////////////////////////////////////////////////////////
[Fact(Skip = "Intentionally broken by Chocolatey changes")]
//////////////////////////////////////////////////////////
// End - Chocolatey Specific Modification
//////////////////////////////////////////////////////////
private async Task GetInstalledAndTransitivePackagesAsync_WithCpsPackageReferenceProject_OneTransitiveReferenceAndEmitsCounterfactualTelemetryAsync()
{
// packageA_2.0.0 -> packageB_1.0.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,13 @@ public void TelemetryOnceEmitter_NullOrEmptyEventName_Throws(string eventName)
Assert.Throws<ArgumentException>(() => new TelemetryOnceEmitter(eventName));
}

[Fact]
//////////////////////////////////////////////////////////
// Start - Chocolatey Specific Modification
//////////////////////////////////////////////////////////
[Fact(Skip = "Intentionally broken by Chocolatey changes")]
//////////////////////////////////////////////////////////
// End - Chocolatey Specific Modification
//////////////////////////////////////////////////////////
public void EmitIfNeeded_TwoCalls_EmitsTelemetryOnce()
{
// Arrange
Expand All @@ -54,7 +60,13 @@ public void EmitIfNeeded_TwoCalls_EmitsTelemetryOnce()
Assert.Equal(1, _telemetryEvents.Count);
}

[Fact]
//////////////////////////////////////////////////////////
// Start - Chocolatey Specific Modification
//////////////////////////////////////////////////////////
[Fact(Skip = "Intentionally broken by Chocolatey changes")]
//////////////////////////////////////////////////////////
// End - Chocolatey Specific Modification
//////////////////////////////////////////////////////////
public async Task EmitIfNeeded_MultipleThreads_EmitsOnceAsync()
{
// Arrange
Expand Down Expand Up @@ -84,7 +96,13 @@ public async Task EmitIfNeeded_MultipleThreads_EmitsOnceAsync()
Assert.Contains(_telemetryEvents, e => e.Name == logger.EventName);
}

[Fact]
//////////////////////////////////////////////////////////
// Start - Chocolatey Specific Modification
//////////////////////////////////////////////////////////
[Fact(Skip = "Intentionally broken by Chocolatey changes")]
//////////////////////////////////////////////////////////
// End - Chocolatey Specific Modification
//////////////////////////////////////////////////////////]
public void Reset_WithAlreadyEmitted_Restarts()
{
// Arrange
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,13 @@ await target.CopyPackagesToOriginalCaseAsync(
}
}

[Fact]
//////////////////////////////////////////////////////////
// Start - Chocolatey Specific Modification
//////////////////////////////////////////////////////////
[Fact(Skip = "Intentionally broken by Chocolatey changes")]
//////////////////////////////////////////////////////////
// End - Chocolatey Specific Modification
//////////////////////////////////////////////////////////
public async Task CopyPackagesToOriginalCaseAsync_EmitsTelemetryWithParentIdAsync()
{
// Set up telemetry service
Expand Down
24 changes: 21 additions & 3 deletions test/NuGet.Core.Tests/NuGet.Commands.Test/RestoreCommandTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2692,7 +2692,13 @@ public async Task RestoreCommand_CentralVersion_ErrorWhenVersionOverrideUsedButI
}
}

[Fact]
//////////////////////////////////////////////////////////
// Start - Chocolatey Specific Modification
//////////////////////////////////////////////////////////
[Fact(Skip = "Intentionally broken by Chocolatey changes")]
//////////////////////////////////////////////////////////
// End - Chocolatey Specific Modification
//////////////////////////////////////////////////////////
public async Task ExecuteAsync_WithSinglePackage_PopulatesCorrectTelemetry()
{
// Arrange
Expand Down Expand Up @@ -2765,7 +2771,13 @@ await SimpleTestPackageUtility.CreateFolderFeedV3Async(
projectInformationEvent["FallbackFoldersCount"].Should().Be(0);
}

[Fact]
//////////////////////////////////////////////////////////
// Start - Chocolatey Specific Modification
//////////////////////////////////////////////////////////
[Fact(Skip = "Intentionally broken by Chocolatey changes")]
//////////////////////////////////////////////////////////
// End - Chocolatey Specific Modification
//////////////////////////////////////////////////////////
public async Task ExecuteAsync_WithSinglePackage_WhenNoOping_PopulatesCorrectTelemetry()
{
// Arrange
Expand Down Expand Up @@ -2841,7 +2853,13 @@ await SimpleTestPackageUtility.CreateFolderFeedV3Async(
projectInformationEvent["FallbackFoldersCount"].Should().Be(0);
}

[Fact]
//////////////////////////////////////////////////////////
// Start - Chocolatey Specific Modification
//////////////////////////////////////////////////////////
[Fact(Skip = "Intentionally broken by Chocolatey changes")]
//////////////////////////////////////////////////////////
// End - Chocolatey Specific Modification
//////////////////////////////////////////////////////////
public async Task ExecuteAsync_WithPartiallyPopulatedGlobalPackagesFolder_PopulatesNewlyInstalledPackagesTelemetry()
{
// Arrange
Expand Down
72 changes: 63 additions & 9 deletions test/NuGet.Core.Tests/NuGet.Common.Test/TelemetryActivityTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,13 @@ public TelemetryActivityTests()
TelemetryActivity.NuGetTelemetryService = _telemetryService.Object;
}

[Fact]
//////////////////////////////////////////////////////////
// Start - Chocolatey Specific Modification
//////////////////////////////////////////////////////////
[Fact(Skip = "Intentionally broken by Chocolatey changes")]
//////////////////////////////////////////////////////////
// End - Chocolatey Specific Modification
//////////////////////////////////////////////////////////
public void Dispose_WithOperationIdAndWithoutParentId_EmitsOperationIdAndNotParentId()
{
Guid operationId;
Expand All @@ -49,7 +55,13 @@ public void Dispose_WithOperationIdAndWithoutParentId_EmitsOperationIdAndNotPare
Assert.Equal(operationId.ToString(), _telemetryEvent["OperationId"]);
}

[Fact]
//////////////////////////////////////////////////////////
// Start - Chocolatey Specific Modification
//////////////////////////////////////////////////////////
[Fact(Skip = "Intentionally broken by Chocolatey changes")]
//////////////////////////////////////////////////////////
// End - Chocolatey Specific Modification
//////////////////////////////////////////////////////////
public void Dispose_WithOperationIdAndParentId_EmitsOperationIdAndParentId()
{
var parentId = Guid.NewGuid();
Expand All @@ -64,7 +76,13 @@ public void Dispose_WithOperationIdAndParentId_EmitsOperationIdAndParentId()
Assert.Equal(operationId.ToString(), _telemetryEvent["OperationId"]);
}

[Fact]
//////////////////////////////////////////////////////////
// Start - Chocolatey Specific Modification
//////////////////////////////////////////////////////////
[Fact(Skip = "Intentionally broken by Chocolatey changes")]
//////////////////////////////////////////////////////////
// End - Chocolatey Specific Modification
//////////////////////////////////////////////////////////
public void Dispose_WithIntervalMeasure_EmitsIntervalMeasure()
{
const string measureName = "testInterval";
Expand All @@ -83,7 +101,13 @@ public void Dispose_WithIntervalMeasure_EmitsIntervalMeasure()
Assert.True(actualCount >= secondsToWait, $"The telemetry duration count should at least be {secondsToWait} seconds.");
}

[Fact]
//////////////////////////////////////////////////////////
// Start - Chocolatey Specific Modification
//////////////////////////////////////////////////////////
[Fact(Skip = "Intentionally broken by Chocolatey changes")]
//////////////////////////////////////////////////////////
// End - Chocolatey Specific Modification
//////////////////////////////////////////////////////////
public void Dispose_WithEmptyParentId_EmitsNoParentId()
{
var parentId = Guid.Empty;
Expand All @@ -95,7 +119,13 @@ public void Dispose_WithEmptyParentId_EmitsNoParentId()
Assert.Null(_telemetryEvent["ParentId"]);
}

[Fact]
//////////////////////////////////////////////////////////
// Start - Chocolatey Specific Modification
//////////////////////////////////////////////////////////
[Fact(Skip = "Intentionally broken by Chocolatey changes")]
//////////////////////////////////////////////////////////
// End - Chocolatey Specific Modification
//////////////////////////////////////////////////////////
public void Dispose_Always_EmitsStartTime()
{
using (var telemetry = TelemetryActivity.Create(CreateNewTelemetryEvent()))
Expand All @@ -109,7 +139,13 @@ public void Dispose_Always_EmitsStartTime()
TelemetryUtility.VerifyDateTimeFormat(startTime);
}

[Fact]
//////////////////////////////////////////////////////////
// Start - Chocolatey Specific Modification
//////////////////////////////////////////////////////////
[Fact(Skip = "Intentionally broken by Chocolatey changes")]
//////////////////////////////////////////////////////////
// End - Chocolatey Specific Modification
//////////////////////////////////////////////////////////
public void Dispose_Always_EmitsEndTime()
{
using (var telemetry = TelemetryActivity.Create(CreateNewTelemetryEvent()))
Expand All @@ -123,7 +159,13 @@ public void Dispose_Always_EmitsEndTime()
TelemetryUtility.VerifyDateTimeFormat(endTime);
}

[Fact]
//////////////////////////////////////////////////////////
// Start - Chocolatey Specific Modification
//////////////////////////////////////////////////////////
[Fact(Skip = "Intentionally broken by Chocolatey changes")]
//////////////////////////////////////////////////////////
// End - Chocolatey Specific Modification
//////////////////////////////////////////////////////////
public void Dispose_Always_EmitsDuration()
{
using (var telemetry = TelemetryActivity.Create(CreateNewTelemetryEvent()))
Expand Down Expand Up @@ -156,7 +198,13 @@ public void Dispose_will_dispose_activity()
Assert.True(_activityDisposed);
}

[Fact]
//////////////////////////////////////////////////////////
// Start - Chocolatey Specific Modification
//////////////////////////////////////////////////////////
[Fact(Skip = "Intentionally broken by Chocolatey changes")]
//////////////////////////////////////////////////////////
// End - Chocolatey Specific Modification
//////////////////////////////////////////////////////////
public void Dispose_IndependentInterval_EmitsIntervalMeasure()
{
const string measureName = nameof(Dispose_IndependentInterval_EmitsIntervalMeasure);
Expand All @@ -176,7 +224,13 @@ public void Dispose_IndependentInterval_EmitsIntervalMeasure()
Assert.True(actualCount >= secondsToWait, $"The telemetry duration count should at least be {secondsToWait} seconds.");
}

[Fact]
//////////////////////////////////////////////////////////
// Start - Chocolatey Specific Modification
//////////////////////////////////////////////////////////
[Fact(Skip = "Intentionally broken by Chocolatey changes")]
//////////////////////////////////////////////////////////
// End - Chocolatey Specific Modification
//////////////////////////////////////////////////////////
public void Dispose_WithIndependentInterval_DoesNotClashWithNonoverlappingInterval()
{
const string independentInterval = "independentTestInterval";
Expand Down

0 comments on commit f1e5db2

Please sign in to comment.