Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Telemetry for codefixes #14994

Merged
merged 2 commits into from
Mar 28, 2023
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
22 changes: 21 additions & 1 deletion vsintegration/src/FSharp.Editor/CodeFix/CodeFixHelpers.fs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,25 @@ open System.Threading
open Microsoft.CodeAnalysis.Text
open Microsoft.CodeAnalysis.CodeFixes
open Microsoft.CodeAnalysis.CodeActions
open Microsoft.VisualStudio.FSharp.Editor.Telemetry

[<RequireQualifiedAccess>]
module internal CodeFixHelpers =
let createTextChangeCodeFix (title: string, context: CodeFixContext, computeTextChanges: unit -> Async<TextChange[] option>) =
let props: (string * obj) list =
[
"title", title

// The following can help building a unique but anonymized codefix target:
// #projectid#documentid#span
// Then we can check if the codefix was actually activated after its creation.
"context.document.project.id", context.Document.Project.Id.Id.ToString()
"context.document.id", context.Document.Id.Id.ToString()
"context.span", context.Span.ToString()
]

TelemetryReporter.reportEvent "codefixregistered" props

CodeAction.Create(
title,
(fun (cancellationToken: CancellationToken) ->
Expand All @@ -20,7 +35,12 @@ module internal CodeFixHelpers =

match changesOpt with
| None -> return context.Document
| Some textChanges -> return context.Document.WithText(sourceText.WithChanges(textChanges))
| Some textChanges ->
// Note: "activated" doesn't mean "applied".
// It's one step prior to that:
// e.g. when one clicks (Ctrl + .) and looks at the potential change.
TelemetryReporter.reportEvent "codefixactivated" props
return context.Document.WithText(sourceText.WithChanges(textChanges))
}
|> RoslynHelpers.StartAsyncAsTask(cancellationToken)),
title
Expand Down
10 changes: 5 additions & 5 deletions vsintegration/src/FSharp.Editor/Telemetry/TelemetryReporter.fs
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ open Microsoft.VisualStudio.Telemetry

module TelemetryReporter =

let eventPrefix = "dotnet/fsharp/"
let propPrefix = "dotnet.fsharp."
let private eventPrefix = "dotnet/fsharp/"
let private propPrefix = "dotnet.fsharp."

let getFullEventName name = eventPrefix + name
let getFullPropName name = propPrefix + name
let private getFullEventName name = eventPrefix + name
let private getFullPropName name = propPrefix + name

let createEvent name (props: (string * obj) list) =
let private createEvent name (props: (string * obj) list) =
let event = TelemetryEvent(getFullEventName name)

props
Expand Down