Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ private void PostTelemetry(bool isCommit)
if (_suggestionsPanelTelemetry is not null)
{
RoslynDebug.Assert(_suggestionsDropdownTelemetry is null);
RoslynTelemetry.Log(FunctionId.Copilot_Rename, KeyValueLogMessage.Create(m =>
RoslynTelemetry.Current.Log(FunctionId.Copilot_Rename, KeyValueLogMessage.Create(m =>
{
m[nameof(isCommit)] = isCommit;
m["UseSuggestionsPanel"] = true;
Expand All @@ -61,7 +61,7 @@ private void PostTelemetry(bool isCommit)
else
{
RoslynDebug.Assert(_suggestionsDropdownTelemetry is not null);
RoslynTelemetry.Log(FunctionId.Copilot_Rename, KeyValueLogMessage.Create(m =>
RoslynTelemetry.Current.Log(FunctionId.Copilot_Rename, KeyValueLogMessage.Create(m =>
{
m[nameof(isCommit)] = isCommit;
m["UseDropDown"] = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ private async Task DispatchSynchronizeTextChangesAsync(

// Update aggregated telemetry with success status of sending the synchronization data.
var metricName = wasSynchronized.Value ? SynchronizeTextChangesStatusSucceededMetricName : SynchronizeTextChangesStatusFailedMetricName;
RoslynTelemetry.Count(FunctionId.ChecksumUpdater_SynchronizeTextChangesStatus, metricName, 1);
RoslynTelemetry.Current.Count(FunctionId.ChecksumUpdater_SynchronizeTextChangesStatus, metricName, 1);

return;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ private async Task InvokeAsync()
{
try
{
using var _ = RoslynTelemetry.RecordBlockTime(FunctionId.SuggestedAction_Application_Summary, $"Total");
using var _ = RoslynTelemetry.Current.RecordBlockTime(FunctionId.SuggestedAction_Application_Summary, $"Total");

using var token = SourceProvider.OperationListener.BeginAsyncOperation($"{nameof(EditorSuggestedAction)}.{nameof(Invoke)}");
using var context = SourceProvider.UIThreadOperationExecutor.BeginExecute(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,14 +104,14 @@ await document.Project.Solution.Services.GetRequiredService<IWorkspaceStatusServ

try
{
using var _2 = RoslynTelemetry.RecordBlockTime(FunctionId.SuggestedAction_Summary, $"Total");
using var _2 = RoslynTelemetry.Current.RecordBlockTime(FunctionId.SuggestedAction_Summary, $"Total");

// Collectors are in priority order. So just walk them from highest to lowest.
foreach (var collector in collectors)
{
if (TryGetPriority(collector.Priority) is CodeActionRequestPriority priority)
{
using var _3 = RoslynTelemetry.RecordBlockTime(FunctionId.SuggestedAction_Summary, $"Total.Pri{(int)priority}");
using var _3 = RoslynTelemetry.Current.RecordBlockTime(FunctionId.SuggestedAction_Summary, $"Total.Pri{(int)priority}");

var allSets = GetCodeFixesAndRefactoringsAsync(
state, requestedActionCategories, document,
Expand Down Expand Up @@ -219,7 +219,7 @@ await document.Project.Solution.Services.GetRequiredService<IWorkspaceStatusServ

async Task<ImmutableArray<CodeAnalysis.Suggestions.SuggestedActionSet>> GetCodeFixesAsync()
{
using var _ = RoslynTelemetry.RecordBlockTime(FunctionId.SuggestedAction_Summary, $"Total.Pri{priority.GetPriorityInt()}.{nameof(GetCodeFixesAsync)}");
using var _ = RoslynTelemetry.Current.RecordBlockTime(FunctionId.SuggestedAction_Summary, $"Total.Pri{priority.GetPriorityInt()}.{nameof(GetCodeFixesAsync)}");

if (owner._codeFixService == null ||
!supportsFeatureService.SupportsCodeFixes(target.SubjectBuffer) ||
Expand All @@ -235,7 +235,7 @@ await document.Project.Solution.Services.GetRequiredService<IWorkspaceStatusServ

async Task<ImmutableArray<CodeAnalysis.Suggestions.SuggestedActionSet>> GetRefactoringsAsync()
{
using var _ = RoslynTelemetry.RecordBlockTime(FunctionId.SuggestedAction_Summary, $"Total.Pri{priority.GetPriorityInt()}.{nameof(GetRefactoringsAsync)}");
using var _ = RoslynTelemetry.Current.RecordBlockTime(FunctionId.SuggestedAction_Summary, $"Total.Pri{priority.GetPriorityInt()}.{nameof(GetRefactoringsAsync)}");

if (!selection.HasValue)
{
Expand Down
14 changes: 7 additions & 7 deletions src/Features/Core/Portable/CodeFixes/Service/CodeFixService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,11 @@ private DiagnosticIdFilter GetShouldIncludeDiagnosticPredicate(
public async Task<CodeFixCollection?> GetMostSevereFixAsync(
TextDocument document, TextSpan range, CodeActionRequestPriority? priority, CancellationToken cancellationToken)
{
using var _ = RoslynTelemetry.RecordBlockTime(FunctionId.CodeFix_Summary, $"Pri{priority.GetPriorityInt()}.{nameof(GetMostSevereFixAsync)}");
using var _ = RoslynTelemetry.Current.RecordBlockTime(FunctionId.CodeFix_Summary, $"Pri{priority.GetPriorityInt()}.{nameof(GetMostSevereFixAsync)}");

ImmutableArray<DiagnosticData> allDiagnostics;

using (RoslynTelemetry.RecordBlockTime(
using (RoslynTelemetry.Current.RecordBlockTime(
FunctionId.CodeFix_Summary, $"Pri{priority.GetPriorityInt()}.{nameof(GetMostSevereFixAsync)}.{nameof(IDiagnosticAnalyzerService.GetDiagnosticsForSpanAsync)}"))
{
var service = document.Project.Solution.Services.GetRequiredService<IDiagnosticAnalyzerService>();
Expand Down Expand Up @@ -173,7 +173,7 @@ public async IAsyncEnumerable<CodeFixCollection> StreamFixesAsync(
CodeActionRequestPriority? priority,
[EnumeratorCancellation] CancellationToken cancellationToken)
{
using var _ = RoslynTelemetry.RecordBlockTime(FunctionId.CodeFix_Summary, $"Pri{priority.GetPriorityInt()}");
using var _ = RoslynTelemetry.Current.RecordBlockTime(FunctionId.CodeFix_Summary, $"Pri{priority.GetPriorityInt()}");

// We only need to compute suppression/configuration fixes when request priority is
// 'CodeActionPriorityRequest.Lowest' or no priority was provided at all (so all providers should run).
Expand All @@ -191,7 +191,7 @@ public async IAsyncEnumerable<CodeFixCollection> StreamFixesAsync(
// user-invoked diagnostic requests, for example, user invoked Ctrl + Dot operation for lightbulb.
ImmutableArray<DiagnosticData> diagnostics;

using (RoslynTelemetry.RecordBlockTime(
using (RoslynTelemetry.Current.RecordBlockTime(
FunctionId.CodeFix_Summary, $"Pri{priority.GetPriorityInt()}.{nameof(IDiagnosticAnalyzerService.GetDiagnosticsForSpanAsync)}"))
{
var service = document.Project.Solution.Services.GetRequiredService<IDiagnosticAnalyzerService>();
Expand Down Expand Up @@ -286,7 +286,7 @@ private static SortedDictionary<TextSpan, List<DiagnosticData>> ConvertToMap(
{
cancellationToken.ThrowIfCancellationRequested();

using var _ = RoslynTelemetry.RecordBlockTime(FunctionId.CodeFix_Summary, $"{nameof(GetDocumentFixAllForIdInSpanAsync)}");
using var _ = RoslynTelemetry.Current.RecordBlockTime(FunctionId.CodeFix_Summary, $"{nameof(GetDocumentFixAllForIdInSpanAsync)}");
ImmutableArray<DiagnosticData> diagnostics;

if (textSpan is null)
Expand All @@ -295,7 +295,7 @@ private static SortedDictionary<TextSpan, List<DiagnosticData>> ConvertToMap(
textSpan = new TextSpan(0, text.Length);
}

using (RoslynTelemetry.RecordBlockTime(
using (RoslynTelemetry.Current.RecordBlockTime(
FunctionId.CodeFix_Summary, $"{nameof(GetDocumentFixAllForIdInSpanAsync)}.{nameof(IDiagnosticAnalyzerService.GetDiagnosticsForSpanAsync)}"))
{
var service = document.Project.Solution.Services.GetRequiredService<IDiagnosticAnalyzerService>();
Expand Down Expand Up @@ -534,7 +534,7 @@ private async IAsyncEnumerable<CodeFixCollection> StreamFixesAsync(
m[TelemetryKeys.LanguageName] = document.Project.Language;
}, (fixerName, document));

using var _ = RoslynTelemetry.LogBlockTime(FunctionId.CodeFix_Delay, logMessage, CodeFixTelemetryDelay);
using var _ = RoslynTelemetry.Current.LogBlockTime(FunctionId.CodeFix_Delay, logMessage, CodeFixTelemetryDelay);

var codeFixCollection = await TryGetFixesOrConfigurationsAsync(
document, span, diagnostics, fixAllForInSpan, fixer,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ public async Task<ImmutableArray<CodeRefactoring>> GetRefactoringsAsync(
CodeActionRequestPriority? priority,
CancellationToken cancellationToken)
{
using (RoslynTelemetry.RecordBlockTime(FunctionId.CodeRefactoring_Summary, $"Pri{priority.GetPriorityInt()}"))
using (RoslynTelemetry.Current.RecordBlockTime(FunctionId.CodeRefactoring_Summary, $"Pri{priority.GetPriorityInt()}"))
using (Logger.LogBlock(FunctionId.Refactoring_CodeRefactoringService_GetRefactoringsAsync, cancellationToken))
{
using var _ = PooledDictionary<CodeRefactoringProvider, int>.GetInstance(out var providerToIndex);
Expand Down Expand Up @@ -213,7 +213,7 @@ public async Task<ImmutableArray<CodeRefactoring>> GetRefactoringsAsync(
}, (providerName, document));

using (RoslynEventSource.LogInformationalBlock(FunctionId.Refactoring_CodeRefactoringService_GetRefactoringsAsync, providerName, cancellationToken))
using (RoslynTelemetry.LogBlockTime(FunctionId.CodeRefactoring_Delay, logMessage, CodeRefactoringTelemetryDelay))
using (RoslynTelemetry.Current.LogBlockTime(FunctionId.CodeRefactoring_Delay, logMessage, CodeRefactoringTelemetryDelay))
{
var refactoring = await @this.GetRefactoringFromProviderAsync(
document, state, provider, cancellationToken).ConfigureAwait(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public async Task<ImmutableArray<DiagnosticData>> GetDiagnosticsForSpanInProcess
using var _2 = ArrayBuilder<DiagnosticAnalyzer>.GetInstance(out var semanticSpanBasedAnalyzers);
using var _3 = ArrayBuilder<DiagnosticAnalyzer>.GetInstance(out var semanticDocumentBasedAnalyzers);

using var _4 = RoslynTelemetry.RecordBlockTime(FunctionId.RequestDiagnostics_Summary, $"Pri{priority.GetPriorityInt()}");
using var _4 = RoslynTelemetry.Current.RecordBlockTime(FunctionId.RequestDiagnostics_Summary, $"Pri{priority.GetPriorityInt()}");

foreach (var analyzer in analyzers)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ async ValueTask<ImmutableArray<DiagnosticData>> GetSyntaxDiagnosticsInProcessAsy

if (_lazySyntaxDiagnostics == null)
{
using var _ = RoslynTelemetry.RecordBlockTime(FunctionId.RequestDiagnostics_Summary, $"{nameof(GetSyntaxDiagnosticsInProcessAsync)}.{nameof(GetAnalysisResultInProcessAsync)}");
using var _ = RoslynTelemetry.Current.RecordBlockTime(FunctionId.RequestDiagnostics_Summary, $"{nameof(GetSyntaxDiagnosticsInProcessAsync)}.{nameof(GetAnalysisResultInProcessAsync)}");

var analysisScope = AnalysisScope.WithAnalyzers(_compilationBasedAnalyzersInAnalysisScope);
var syntaxDiagnostics = await GetAnalysisResultInProcessAsync(analysisScope).ConfigureAwait(false);
Expand Down Expand Up @@ -252,7 +252,7 @@ async ValueTask<ImmutableArray<DiagnosticData>> GetSemanticDiagnosticsInProcessA

if (_lazySemanticDiagnostics == null)
{
using var _ = RoslynTelemetry.RecordBlockTime(FunctionId.RequestDiagnostics_Summary, $"{nameof(GetSemanticDiagnosticsInProcessAsync)}.{nameof(GetAnalysisResultInProcessAsync)}");
using var _ = RoslynTelemetry.Current.RecordBlockTime(FunctionId.RequestDiagnostics_Summary, $"{nameof(GetSemanticDiagnosticsInProcessAsync)}.{nameof(GetAnalysisResultInProcessAsync)}");

var analysisScope = AnalysisScope.WithAnalyzers(_compilationBasedAnalyzersInAnalysisScope);
var semanticDiagnostics = await GetAnalysisResultInProcessAsync(analysisScope).ConfigureAwait(false);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Licensed to the .NET Foundation under one or more agreements.
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

Expand Down Expand Up @@ -36,7 +36,9 @@ public async Task RealRequestsProduceAggregatedTelemetry()
{
var poster = new RecordingPoster();
using var sink = VSMetricSink.TestAccessor.CreateSink(poster);
using var registration = RoslynTelemetry.AddMetricSink(sink);

using var telemetry = RoslynTelemetry.SetCurrent(new RoslynTelemetry());
using var registration = RoslynTelemetry.Current.AddMetricSink(sink);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Should the tests now just create instances of RoslynTelemetry() so we're not implicitly using static state anymore?


var server = await CreateLanguageServerAsync();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ public void InitializeSession(string telemetryLevel, string? sessionId, bool isD
var metricSink = new VSMetricSink(session);
_registrations =
[
RoslynTelemetry.AddEventSink(TelemetryEventSink.Create(session, logDelta: true)),
RoslynTelemetry.AddMetricSink(metricSink),
RoslynTelemetry.Current.AddEventSink(TelemetryEventSink.Create(session, logDelta: true)),
RoslynTelemetry.Current.AddMetricSink(metricSink),
metricSink,
];

Expand All @@ -116,7 +116,7 @@ public void Dispose()
if (_telemetrySession is { } session)
{
FeaturesSessionTelemetry.Report();
RoslynTelemetry.Flush();
RoslynTelemetry.Current.Flush();

Comment thread
dibarbet marked this conversation as resolved.
foreach (var registration in _registrations)
registration.Dispose();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Licensed to the .NET Foundation under one or more agreements.
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

Expand Down Expand Up @@ -43,7 +43,7 @@ public static void ReportProjectLoadStarted()
protected override void IncreaseFindDocumentCount(string workspaceCountMetricName)
{
var projectsLoaded = s_initialProjectLoadCompleted;
RoslynTelemetry.Count(FunctionId.LSP_FindDocumentInWorkspace, workspaceCountMetricName, 1,
RoslynTelemetry.Current.Count(FunctionId.LSP_FindDocumentInWorkspace, workspaceCountMetricName, 1,
new("server", ServerTypeName),
new("workspace", workspaceCountMetricName),
new("projectsLoaded", projectsLoaded));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,15 @@ public void UpdateFindDocumentTelemetryData(bool success, string? workspaceKind)

protected virtual void IncreaseFindDocumentCount(string workspaceCounterMetricName)
{
RoslynTelemetry.Count(FunctionId.LSP_FindDocumentInWorkspace, workspaceCounterMetricName, 1,
RoslynTelemetry.Current.Count(FunctionId.LSP_FindDocumentInWorkspace, workspaceCounterMetricName, 1,
new("server", ServerTypeName),
new("workspace", workspaceCounterMetricName));
}

public void UpdateUsedForkedSolutionCounter(bool usedForkedSolution)
{
var metricName = usedForkedSolution ? "ForkedCount" : "NonForkedCount";
RoslynTelemetry.Count(FunctionId.LSP_UsedForkedSolution, metricName, 1,
RoslynTelemetry.Current.Count(FunctionId.LSP_UsedForkedSolution, metricName, 1,
new("server", ServerTypeName),
new("usedForkedSolution", usedForkedSolution));
}
Expand All @@ -53,10 +53,10 @@ public void UpdateTelemetryData(
Result result)
{
// Store the request time metrics per LSP method.
RoslynTelemetry.Record(FunctionId.LSP_TimeInQueue, "TimeInQueue", (long)queuedDuration.TotalMilliseconds,
RoslynTelemetry.Current.Record(FunctionId.LSP_TimeInQueue, "TimeInQueue", (long)queuedDuration.TotalMilliseconds,
new("server", ServerTypeName));

RoslynTelemetry.Record(FunctionId.LSP_RequestDuration, "RequestDuration", (long)requestDuration.TotalMilliseconds,
RoslynTelemetry.Current.Record(FunctionId.LSP_RequestDuration, "RequestDuration", (long)requestDuration.TotalMilliseconds,
new("server", ServerTypeName),
new("method", methodName),
new("language", language));
Expand All @@ -69,7 +69,7 @@ public void UpdateTelemetryData(
_ => throw ExceptionUtilities.UnexpectedValue(result)
};

RoslynTelemetry.Count(FunctionId.LSP_RequestCounter, metricName, 1,
RoslynTelemetry.Current.Count(FunctionId.LSP_RequestCounter, metricName, 1,
new("server", ServerTypeName),
new("method", methodName),
new("language", language));
Expand All @@ -79,7 +79,7 @@ public void Dispose()
{
// Ensure that telemetry logged for this server instance is flushed before potentially creating a new instance.
// This is also called on disposal of the telemetry session, but will no-op if already flushed.
RoslynTelemetry.Flush();
RoslynTelemetry.Current.Flush();
}

internal enum Result
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,11 @@ public void InitializeTelemetrySession(TelemetrySession telemetrySession, bool l
Contract.ThrowIfFalse(CurrentSession is null);

var metricSink = new VSMetricSink(telemetrySession);
Debug.Assert(RoslynTelemetry.IsDefault(RoslynTelemetry.Current));
_registrations =
[
.. CreateEventSinks(telemetrySession, logDelta).SelectAsArray(RoslynTelemetry.AddEventSink),
RoslynTelemetry.AddMetricSink(metricSink),
.. CreateEventSinks(telemetrySession, logDelta).SelectAsArray(RoslynTelemetry.Current.AddEventSink),
RoslynTelemetry.Current.AddMetricSink(metricSink),
Comment thread
dibarbet marked this conversation as resolved.
metricSink,
];

Expand Down Expand Up @@ -70,7 +71,7 @@ public void Dispose()
{
// Ensure any aggregate telemetry is flushed when the catalog is destroyed.
// It is fine for this to be called multiple times - if telemetry has already been flushed this will no-op.
RoslynTelemetry.Flush();
RoslynTelemetry.Current.Flush();

Comment thread
dibarbet marked this conversation as resolved.
foreach (var registration in _registrations)
registration.Dispose();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1949,7 +1949,7 @@ void M()
Assert.Equal("CSharp.ConflictMarkerResolution.CSharpResolveConflictMarkerCodeFixProvider", result.CodeFixAnalysis.DiagnosticIdToProviderName["CS8300"].Single());

var logger = new TestTelemetryEventSink();
using var _ = RoslynTelemetry.AddEventSink(logger);
using var _ = RoslynTelemetry.Current.AddEventSink(logger);
TestTelemetryEventSink.TestScope scope;
using (CopilotChangeAnalysisUtilities.LogCopilotChangeAnalysis("TestCode", accepted: true, "TestProposalId", result, CancellationToken.None))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public static async Task CodeActionAsync(
if (!RoslynString.IsNullOrEmpty(applyFix))
{
var codeActionLogger = new CodeActionLogger();
using var loggerRegistration = RoslynTelemetry.AddEventSink(codeActionLogger);
using var loggerRegistration = RoslynTelemetry.Current.AddEventSink(codeActionLogger);

var result = await textViewWindowVerifier.TestServices.Editor.ApplyLightBulbActionAsync(applyFix, fixAllScope, blockUntilComplete, cancellationToken);

Expand Down
2 changes: 1 addition & 1 deletion src/Workspaces/Core/Portable/CodeActions/CodeAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ public Task<ImmutableArray<CodeActionOperation>> GetPreviewOperationsAsync(Cance
internal async Task<ImmutableArray<CodeActionOperation>> GetPreviewOperationsAsync(
Solution originalSolution, CancellationToken cancellationToken)
{
using var _ = RoslynTelemetry.RecordBlockTime(FunctionId.SuggestedAction_Preview_Summary, $"Total");
using var _ = RoslynTelemetry.Current.RecordBlockTime(FunctionId.SuggestedAction_Preview_Summary, $"Total");

var operations = await this.ComputePreviewOperationsAsync(cancellationToken).ConfigureAwait(false);

Expand Down
Loading