Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
using Microsoft.CodeAnalysis.Host.Mef;
using Microsoft.CodeAnalysis.Internal.Log;
using Microsoft.CodeAnalysis.Shared.Extensions;
using Microsoft.CodeAnalysis.Telemetry;
using Microsoft.CodeAnalysis.Text;
using Microsoft.VisualStudio.LanguageServices.Implementation.TaskList;
using Roslyn.Utilities;
Expand All @@ -27,6 +28,7 @@ internal sealed class VisualStudioProject

private readonly VisualStudioWorkspaceImpl _workspace;
private readonly HostDiagnosticUpdateSource _hostDiagnosticUpdateSource;
private readonly IWorkspaceTelemetryService _telemetryService;

/// <summary>
/// Provides dynamic source files for files added through <see cref="AddDynamicSourceFile" />.
Expand Down Expand Up @@ -138,6 +140,8 @@ internal VisualStudioProject(
_dynamicFileInfoProviders = dynamicFileInfoProviders;
_hostDiagnosticUpdateSource = hostDiagnosticUpdateSource;

_telemetryService = _workspace.Services.GetRequiredService<IWorkspaceTelemetryService>();

Id = id;
Language = language;
_displayName = displayName;
Expand Down Expand Up @@ -195,7 +199,7 @@ private void ChangeProjectProperty<T>(ref T field, T newValue, Func<Solution, So

field = newValue;

if (logThrowAwayTelemetry)
if (logThrowAwayTelemetry && _telemetryService.HasActiveSession)
{
TryReportCompilationThrownAway(_workspace.CurrentSolution.State, Id);
}
Expand Down