diff --git a/vsintegration/src/FSharp.Editor/Common/Logging.fs b/vsintegration/src/FSharp.Editor/Common/Logging.fs index 4800b0127799bb412dcef236577c17de8a93c0e6..db961a883aee17fa3fb77fadfff33642cf01063c 100644 --- a/vsintegration/src/FSharp.Editor/Common/Logging.fs +++ b/vsintegration/src/FSharp.Editor/Common/Logging.fs @@ -71,19 +71,19 @@ type Logger [] ([)>] ser match self.FSharpLoggingPane, msgType with | None, _ -> () | Some pane, LogType.Message -> - String.Format("[F#][{0}{1}] {2}{3}", "", time, msg, Environment.NewLine) + String.Format("[{0}{1}] {2}{3}", "", time, msg, Environment.NewLine) |> pane.OutputString |> ignore | Some pane, LogType.Info -> - String.Format("[F#][{0}{1}] {2}{3}", "INFO ", time, msg, Environment.NewLine) + String.Format("[{0}{1}] {2}{3}", "INFO ", time, msg, Environment.NewLine) |> pane.OutputString |> ignore | Some pane, LogType.Warn -> - String.Format("[F#][{0}{1}] {2}{3}", "WARN ", time, msg, Environment.NewLine) + String.Format("[{0}{1}] {2}{3}", "WARN ", time, msg, Environment.NewLine) |> pane.OutputString |> ignore | Some pane, LogType.Error -> - String.Format("[F#][{0}{1}] {2}{3}", "ERROR ", time, msg, Environment.NewLine) + String.Format("[{0}{1}] {2}{3}", "ERROR ", time, msg, Environment.NewLine) |> pane.OutputString |> ignore @@ -112,3 +112,34 @@ module Logging = let logExceptionWithContext (ex: Exception, context) = logErrorf "Context: %s\nException Message: %s\nStack Trace: %s" context ex.Message ex.StackTrace + +module Activity = + let listen filter = + let indent (activity: Activity) = + let rec loop (activity: Activity) n = + if activity.Parent <> null then + loop (activity.Parent) (n + 1) + else + n + + String.replicate (loop activity 0) " " + + let collectTags (activity: Activity) = + [ for tag in activity.Tags -> $"{tag.Key}: %A{tag.Value}" ] + |> String.concat ", " + + let listener = + new ActivityListener( + ShouldListenTo = (fun source -> source.Name = FSharp.Compiler.Diagnostics.ActivityNames.FscSourceName), + Sample = + (fun context -> + if context.Name.Contains(filter) then + ActivitySamplingResult.AllDataAndRecorded + else + ActivitySamplingResult.None), + ActivityStarted = (fun a -> logMsg $"{indent a}{a.OperationName} {collectTags a}") + ) + + ActivitySource.AddActivityListener(listener) + + let listenToAll () = listen "" diff --git a/vsintegration/src/FSharp.Editor/LanguageService/LanguageService.fs b/vsintegration/src/FSharp.Editor/LanguageService/LanguageService.fs index 0b51e1c781835fc040bd93c4f6110efda2e5cf1c..6f63b565f0eb05d74f0b5753e5b67b0446633933 100644 --- a/vsintegration/src/FSharp.Editor/LanguageService/LanguageService.fs +++ b/vsintegration/src/FSharp.Editor/LanguageService/LanguageService.fs @@ -321,6 +321,11 @@ type internal FSharpPackage() as this = let mutable solutionEventsOpt = None +#if DEBUG + let _logger = Logging.Activity.listenToAll () + // Logging.Activity.listen "IncrementalBuild" +#endif + // FSI-LINKAGE-POINT: unsited init do Microsoft.VisualStudio.FSharp.Interactive.Hooks.fsiConsoleWindowPackageCtorUnsited (this :> Package)