From f653a7db6cd47936499250f6a47f8b84ce19d7df Mon Sep 17 00:00:00 2001 From: Petr Date: Mon, 13 Mar 2023 17:43:34 +0100 Subject: [PATCH 1/3] First take on the F# telemetry --- .../src/FSharp.Editor/FSharp.Editor.fsproj | 1 + .../src/FSharp.Editor/Hints/Hints.fs | 6 +++- .../src/FSharp.Editor/Hints/RoslynAdapter.fs | 4 +++ .../LanguageService/LanguageService.fs | 2 ++ .../LanguageService/WorkspaceExtensions.fs | 2 ++ .../Telemetry/TelemetryReporter.fs | 28 +++++++++++++++++++ 6 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 vsintegration/src/FSharp.Editor/Telemetry/TelemetryReporter.fs diff --git a/vsintegration/src/FSharp.Editor/FSharp.Editor.fsproj b/vsintegration/src/FSharp.Editor/FSharp.Editor.fsproj index 4e83825b9b8..70a2a009e54 100644 --- a/vsintegration/src/FSharp.Editor/FSharp.Editor.fsproj +++ b/vsintegration/src/FSharp.Editor/FSharp.Editor.fsproj @@ -28,6 +28,7 @@ + diff --git a/vsintegration/src/FSharp.Editor/Hints/Hints.fs b/vsintegration/src/FSharp.Editor/Hints/Hints.fs index 9e6bab5c297..221c56742fa 100644 --- a/vsintegration/src/FSharp.Editor/Hints/Hints.fs +++ b/vsintegration/src/FSharp.Editor/Hints/Hints.fs @@ -15,4 +15,8 @@ module Hints = Kind: HintKind Range: range Parts: TaggedText list - } \ No newline at end of file + } + + let serialize = function + | TypeHint -> "type" + | ParameterNameHint -> "parameterName" \ No newline at end of file diff --git a/vsintegration/src/FSharp.Editor/Hints/RoslynAdapter.fs b/vsintegration/src/FSharp.Editor/Hints/RoslynAdapter.fs index f79e1dba1fa..668cd3cb2fd 100644 --- a/vsintegration/src/FSharp.Editor/Hints/RoslynAdapter.fs +++ b/vsintegration/src/FSharp.Editor/Hints/RoslynAdapter.fs @@ -6,6 +6,7 @@ open System.Collections.Immutable open System.ComponentModel.Composition open Microsoft.CodeAnalysis.ExternalAccess.FSharp.InlineHints open Microsoft.VisualStudio.FSharp.Editor +open Microsoft.VisualStudio.FSharp.Editor.Telemetry // So the Roslyn interface is called IFSharpInlineHintsService // but our implementation is called just HintsService. @@ -27,6 +28,9 @@ type internal RoslynAdapter if hintKinds.IsEmpty then return ImmutableArray.Empty else + let hintKindsSerialized = hintKinds |> Set.map Hints.serialize |> String.concat "," + TelemetryReporter.reportEvent "hints" [("hints.kinds", hintKindsSerialized)] + let! sourceText = document.GetTextAsync cancellationToken |> Async.AwaitTask let! nativeHints = HintService.getHintsForDocument diff --git a/vsintegration/src/FSharp.Editor/LanguageService/LanguageService.fs b/vsintegration/src/FSharp.Editor/LanguageService/LanguageService.fs index 821a0ab8aad..c573fe87611 100644 --- a/vsintegration/src/FSharp.Editor/LanguageService/LanguageService.fs +++ b/vsintegration/src/FSharp.Editor/LanguageService/LanguageService.fs @@ -27,6 +27,7 @@ open Microsoft.CodeAnalysis.ExternalAccess.FSharp open Microsoft.CodeAnalysis.Host open Microsoft.CodeAnalysis.Host.Mef open Microsoft.VisualStudio.FSharp.Editor.WorkspaceExtensions +open Microsoft.VisualStudio.FSharp.Editor.Telemetry open System.Threading.Tasks #nowarn "9" // NativePtr.toNativeInt @@ -93,6 +94,7 @@ type internal FSharpWorkspaceServiceFactory None let getSource filename = + TelemetryReporter.reportEvent "livebuffers" [] workspace.CurrentSolution.TryGetDocumentFromPath(filename) |> Option.map(fun document -> let text = document.GetTextAsync().Result diff --git a/vsintegration/src/FSharp.Editor/LanguageService/WorkspaceExtensions.fs b/vsintegration/src/FSharp.Editor/LanguageService/WorkspaceExtensions.fs index dc0d09dca3f..88f388edfe8 100644 --- a/vsintegration/src/FSharp.Editor/LanguageService/WorkspaceExtensions.fs +++ b/vsintegration/src/FSharp.Editor/LanguageService/WorkspaceExtensions.fs @@ -6,6 +6,7 @@ open System.Runtime.CompilerServices open System.Threading open System.Threading.Tasks open Microsoft.CodeAnalysis +open Microsoft.VisualStudio.FSharp.Editor.Telemetry open FSharp.Compiler open FSharp.Compiler.CodeAnalysis open FSharp.Compiler.Symbols @@ -226,6 +227,7 @@ type Project with let documents = this.Documents |> Seq.filter (fun document -> not (canSkipDocuments.Contains document.FilePath)) if this.IsFastFindReferencesEnabled then + TelemetryReporter.reportEvent "fastfindreferences" [] do! documents |> Seq.map (fun doc -> Task.Run(fun () -> diff --git a/vsintegration/src/FSharp.Editor/Telemetry/TelemetryReporter.fs b/vsintegration/src/FSharp.Editor/Telemetry/TelemetryReporter.fs new file mode 100644 index 00000000000..f4f91d7f7d0 --- /dev/null +++ b/vsintegration/src/FSharp.Editor/Telemetry/TelemetryReporter.fs @@ -0,0 +1,28 @@ +// Copyright (c) Microsoft Corporation. All Rights Reserved. See License.txt in the project root for license information. + +namespace Microsoft.VisualStudio.FSharp.Editor.Telemetry + +open Microsoft.VisualStudio.Telemetry + +module TelemetryReporter = + + let eventPrefix = "dotnet/fsharp/" + let propPrefix = "dotnet.fsharp." + + let getFullEventName name = eventPrefix + name + let getFullPropName name = propPrefix + name + + let createEvent name (props: (string * obj) list) = + let event = TelemetryEvent (getFullEventName name) + + props + |> List.map (fun (k, v) -> getFullPropName k, v) + |> List.iter event.Properties.Add + + event + + let reportEvent name props = + let session = TelemetryService.DefaultSession + let event = createEvent name props + session.PostEvent event + From b7095a5deccb4faf434ee32e43c686e2467cf1b4 Mon Sep 17 00:00:00 2001 From: Petr Date: Tue, 14 Mar 2023 10:49:30 +0100 Subject: [PATCH 2/3] Update Hints.fs --- vsintegration/src/FSharp.Editor/Hints/Hints.fs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/vsintegration/src/FSharp.Editor/Hints/Hints.fs b/vsintegration/src/FSharp.Editor/Hints/Hints.fs index 221c56742fa..99bc26409e2 100644 --- a/vsintegration/src/FSharp.Editor/Hints/Hints.fs +++ b/vsintegration/src/FSharp.Editor/Hints/Hints.fs @@ -17,6 +17,7 @@ module Hints = Parts: TaggedText list } - let serialize = function + let serialize kind = + match kind with | TypeHint -> "type" | ParameterNameHint -> "parameterName" \ No newline at end of file From 660e833f54d087d47b63ff0c7b29dca2a335c6fc Mon Sep 17 00:00:00 2001 From: Petr Date: Tue, 14 Mar 2023 12:20:33 +0100 Subject: [PATCH 3/3] up --- .../src/FSharp.Editor/LanguageService/LanguageService.fs | 3 ++- .../src/FSharp.Editor/LanguageService/WorkspaceExtensions.fs | 2 -- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/vsintegration/src/FSharp.Editor/LanguageService/LanguageService.fs b/vsintegration/src/FSharp.Editor/LanguageService/LanguageService.fs index c573fe87611..f43894370db 100644 --- a/vsintegration/src/FSharp.Editor/LanguageService/LanguageService.fs +++ b/vsintegration/src/FSharp.Editor/LanguageService/LanguageService.fs @@ -94,7 +94,6 @@ type internal FSharpWorkspaceServiceFactory None let getSource filename = - TelemetryReporter.reportEvent "livebuffers" [] workspace.CurrentSolution.TryGetDocumentFromPath(filename) |> Option.map(fun document -> let text = document.GetTextAsync().Result @@ -106,6 +105,8 @@ type internal FSharpWorkspaceServiceFactory | _ -> let checker = lazy + TelemetryReporter.reportEvent "languageservicestarted" [] + let editorOptions = let editorOptions = workspace.Services.GetService() diff --git a/vsintegration/src/FSharp.Editor/LanguageService/WorkspaceExtensions.fs b/vsintegration/src/FSharp.Editor/LanguageService/WorkspaceExtensions.fs index 88f388edfe8..dc0d09dca3f 100644 --- a/vsintegration/src/FSharp.Editor/LanguageService/WorkspaceExtensions.fs +++ b/vsintegration/src/FSharp.Editor/LanguageService/WorkspaceExtensions.fs @@ -6,7 +6,6 @@ open System.Runtime.CompilerServices open System.Threading open System.Threading.Tasks open Microsoft.CodeAnalysis -open Microsoft.VisualStudio.FSharp.Editor.Telemetry open FSharp.Compiler open FSharp.Compiler.CodeAnalysis open FSharp.Compiler.Symbols @@ -227,7 +226,6 @@ type Project with let documents = this.Documents |> Seq.filter (fun document -> not (canSkipDocuments.Contains document.FilePath)) if this.IsFastFindReferencesEnabled then - TelemetryReporter.reportEvent "fastfindreferences" [] do! documents |> Seq.map (fun doc -> Task.Run(fun () ->