Skip to content

Commit af884cf

Browse files
a bit more polishing
1 parent 4539aa2 commit af884cf

File tree

6 files changed

+14
-10
lines changed

6 files changed

+14
-10
lines changed

src/Build/BackEnd/BuildManager/BuildManager.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -463,9 +463,6 @@ private void UpdatePriority(Process p, ProcessPriorityClass priority)
463463
/// <exception cref="InvalidOperationException">Thrown if a build is already in progress.</exception>
464464
public void BeginBuild(BuildParameters parameters)
465465
{
466-
#if NETFRAMEWORK
467-
TelemetryManager.Instance.Initialize(isStandalone: false);
468-
#endif
469466
if (_previousLowPriority != null)
470467
{
471468
if (parameters.LowPriority != _previousLowPriority)
@@ -3010,6 +3007,8 @@ private ILoggingService CreateLoggingService(
30103007

30113008
if (_buildParameters.IsTelemetryEnabled)
30123009
{
3010+
TelemetryManager.Instance.Initialize(isStandalone: false);
3011+
30133012
// We do want to dictate our own forwarding logger (otherwise CentralForwardingLogger with minimum transferred importance MessageImportance.Low is used)
30143013
// In the future we might optimize for single, in-node build scenario - where forwarding logger is not needed (but it's just quick pass-through)
30153014
LoggerDescription forwardingLoggerDescription = new LoggerDescription(
@@ -3242,6 +3241,8 @@ private void Dispose(bool disposing)
32423241
s_singletonInstance = null;
32433242
}
32443243

3244+
TelemetryManager.Instance?.Dispose();
3245+
32453246
_disposed = true;
32463247
}
32473248
}

src/Framework/Telemetry/BuildTelemetry.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ internal class BuildTelemetry : TelemetryBase, IActivityTelemetryDataHolder
106106
public string? BuildEngineFrameworkName { get; set; }
107107

108108
/// <summary>
109-
/// Create a list of properties sent to VS telemetry with the information whether they should be hashed.
109+
/// Create a list of properties sent to VS telemetry.
110110
/// </summary>
111111
public Dictionary<string, object> GetActivityProperties()
112112
{

src/Framework/Telemetry/TelemetryManager.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ namespace Microsoft.Build.Framework.Telemetry
1919
internal class TelemetryManager
2020
{
2121
#if NETFRAMEWORK
22+
// Telemetry API key for Visual Studio telemetry service.
2223
private const string CollectorApiKey = "f3e86b4023cc43f0be495508d51f588a-f70d0e59-0fb0-4473-9f19-b4024cc340be-7296";
2324

2425
private static TelemetrySession? _telemetrySession;

src/Framework/Telemetry/VSTelemetryActivity.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@
99

1010
namespace Microsoft.Build.Framework.Telemetry
1111
{
12+
/// <summary>
13+
/// Represents a Visual Studio telemetry activity that wraps a <see cref="TelemetryScope{T}"/>.
14+
/// This class provides an implementation of <see cref="IActivity"/> for the VS Telemetry system,
15+
/// allowing telemetry data to be collected and sent when running on .NET Framework.
16+
/// </summary>
1217
internal class VsTelemetryActivity : IActivity
1318
{
1419
private readonly TelemetryScope<OperationEvent> _scope;

src/MSBuild/XMake.cs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -251,9 +251,7 @@ string[] args
251251
KnownTelemetry.PartialBuildTelemetry = new BuildTelemetry { StartAt = DateTime.UtcNow, IsStandaloneExecution = true};
252252

253253
// Initialize VSTelemetry
254-
#if NETFRAMEWORK
255-
TelemetryManager.Instance.Initialize(isStandalone: true);
256-
#endif
254+
TelemetryManager.Instance?.Initialize(isStandalone: true);
257255

258256
using PerformanceLogEventListener eventListener = PerformanceLogEventListener.Create();
259257

@@ -302,9 +300,8 @@ string[] args
302300
DumpCounters(false /* log to console */);
303301
}
304302

305-
#if NETFRAMEWORK
306-
TelemetryManager.Instance.Dispose();
307-
#endif
303+
TelemetryManager.Instance?.Dispose();
304+
308305
return exitCode;
309306
}
310307

0 commit comments

Comments
 (0)