diff --git a/src/Compiler/Facilities/DiagnosticsLogger.fs b/src/Compiler/Facilities/DiagnosticsLogger.fs index 04cb35a2e8e..e5869fe04b2 100644 --- a/src/Compiler/Facilities/DiagnosticsLogger.fs +++ b/src/Compiler/Facilities/DiagnosticsLogger.fs @@ -882,17 +882,17 @@ type StackGuard(maxDepth: int, name: string) = [] path: string, [] line: int ) = - use _ = - Activity.start - "DiagnosticsLogger.StackGuard.Guard" - [| - Activity.Tags.stackGuardName, name - Activity.Tags.stackGuardCurrentDepth, string depth - Activity.Tags.stackGuardMaxDepth, string maxDepth - Activity.Tags.callerMemberName, memberName - Activity.Tags.callerFilePath, path - Activity.Tags.callerLineNumber, string line - |] + + Activity.addEventWithTags + "DiagnosticsLogger.StackGuard.Guard" + (seq { + Activity.Tags.stackGuardName, box name + Activity.Tags.stackGuardCurrentDepth, depth + Activity.Tags.stackGuardMaxDepth, maxDepth + Activity.Tags.callerMemberName, memberName + Activity.Tags.callerFilePath, path + Activity.Tags.callerLineNumber, line + }) depth <- depth + 1 diff --git a/src/Compiler/Utilities/Activity.fs b/src/Compiler/Utilities/Activity.fs index e2d7e78fcb6..2d204864f69 100644 --- a/src/Compiler/Utilities/Activity.fs +++ b/src/Compiler/Utilities/Activity.fs @@ -7,6 +7,7 @@ open System.Diagnostics open System.IO open System.Text open Internal.Utilities.Library +open System.Collections.Generic module ActivityNames = @@ -102,12 +103,17 @@ module internal Activity = let startNoTags (name: string) : IDisposable MaybeNull = activitySource.StartActivity name - let addEvent name = + let addEventWithTags name (tags: (string * objnull) seq) = match Activity.Current with | null -> () - | activity when activity.Source = activitySource -> activity.AddEvent(ActivityEvent name) |> ignore + | activity when activity.Source = activitySource -> + let collection = tags |> Seq.map KeyValuePair |> ActivityTagsCollection + let event = new ActivityEvent(name, tags = collection) + activity.AddEvent event |> ignore | _ -> () + let addEvent name = addEventWithTags name Seq.empty + module Profiling = module Tags = diff --git a/src/Compiler/Utilities/Activity.fsi b/src/Compiler/Utilities/Activity.fsi index 6e7244f5e59..041b2998765 100644 --- a/src/Compiler/Utilities/Activity.fsi +++ b/src/Compiler/Utilities/Activity.fsi @@ -46,6 +46,8 @@ module internal Activity = val addEvent: name: string -> unit + val addEventWithTags: name: string -> tags: (string * objnull) seq -> unit + module Profiling = val startAndMeasureEnvironmentStats: name: string -> IDisposable MaybeNull val addConsoleListener: unit -> IDisposable diff --git a/tests/FSharp.Test.Utilities/XunitHelpers.fs b/tests/FSharp.Test.Utilities/XunitHelpers.fs index 2747bdc5a63..ce4d47b9635 100644 --- a/tests/FSharp.Test.Utilities/XunitHelpers.fs +++ b/tests/FSharp.Test.Utilities/XunitHelpers.fs @@ -168,7 +168,16 @@ type FSharpXunitFramework(sink: IMessageSink) = cleanUpTemporaryDirectoryOfThisTestRun () traceProvider.ForceFlush() |> ignore traceProvider.Dispose() - base.Dispose() + base.Dispose() + + // Group test run under single activity, to make traces more readable. + // Otherwise this overriden method is not necessary and can be removed. + override this.CreateExecutor (assemblyName) = + { new XunitTestFrameworkExecutor(assemblyName, this.SourceInformationProvider, this.DiagnosticMessageSink) with + override _.RunTestCases(testCases, executionMessageSink, executionOptions) = + use _ = Activity.start $"{assemblyName.Name} {Runtime.InteropServices.RuntimeInformation.FrameworkDescription}" [] + base.RunTestCases(testCases, executionMessageSink, executionOptions) + } override this.CreateDiscoverer (assemblyInfo) = { new XunitTestFrameworkDiscoverer(assemblyInfo, this.SourceInformationProvider, this.DiagnosticMessageSink) with diff --git a/vsintegration/Vsix/VisualFSharpFull/VisualFSharp.Core.targets b/vsintegration/Vsix/VisualFSharpFull/VisualFSharp.Core.targets index f3c3ce40b79..16d69751fd7 100644 --- a/vsintegration/Vsix/VisualFSharpFull/VisualFSharp.Core.targets +++ b/vsintegration/Vsix/VisualFSharpFull/VisualFSharp.Core.targets @@ -110,7 +110,19 @@ False - + + + {65e0e82a-eace-4787-8994-888674c2fe87} + FSharp.Editor + ReferenceCopyLocalPathsOutputGroup%3bBuiltProjectOutputGroup%3bGetCopyToOutputDirectoryItems%3bPkgDefProjectOutputGroup%3bSatelliteDllsProjectOutputGroup%3b + DebugSymbolsProjectOutputGroup%3b + true + All + 2 + True + + + {65e0e82a-eace-4787-8994-888674c2fe87} FSharp.Editor BuiltProjectOutputGroup%3bGetCopyToOutputDirectoryItems%3bPkgDefProjectOutputGroup%3bSatelliteDllsProjectOutputGroup%3b diff --git a/vsintegration/src/FSharp.Editor/Common/Logging.fs b/vsintegration/src/FSharp.Editor/Common/Logging.fs index a69779e9acc..cf531c65384 100644 --- a/vsintegration/src/FSharp.Editor/Common/Logging.fs +++ b/vsintegration/src/FSharp.Editor/Common/Logging.fs @@ -7,6 +7,8 @@ open Microsoft.VisualStudio.Shell open Microsoft.VisualStudio.Shell.Interop open Microsoft.VisualStudio.FSharp.Editor +open FSharp.Compiler.Diagnostics + [] type LogType = | Info @@ -116,7 +118,12 @@ module Logging = let logExceptionWithContext (ex: Exception, context) = logErrorf "Context: %s\nException Message: %s\nStack Trace: %s" context ex.Message ex.StackTrace +#if DEBUG module Activity = + + open OpenTelemetry.Resources + open OpenTelemetry.Trace + let listen filter = let indent (activity: Activity) = let rec loop (activity: Activity) n = @@ -145,4 +152,17 @@ module Activity = ActivitySource.AddActivityListener(listener) + let export () = + OpenTelemetry.Sdk + .CreateTracerProviderBuilder() + .AddSource(ActivityNames.FscSourceName) + .SetResourceBuilder( + ResourceBuilder + .CreateDefault() + .AddService(serviceName = "F#", serviceVersion = "1.0.0") + ) + .AddOtlpExporter() + .Build() + let listenToAll () = listen "" +#endif diff --git a/vsintegration/src/FSharp.Editor/FSharp.Editor.fsproj b/vsintegration/src/FSharp.Editor/FSharp.Editor.fsproj index 2ec608dda20..5fedad089dd 100644 --- a/vsintegration/src/FSharp.Editor/FSharp.Editor.fsproj +++ b/vsintegration/src/FSharp.Editor/FSharp.Editor.fsproj @@ -194,6 +194,7 @@ + diff --git a/vsintegration/src/FSharp.Editor/LanguageService/LanguageService.fs b/vsintegration/src/FSharp.Editor/LanguageService/LanguageService.fs index 18cb516b6a9..55cd1b622b3 100644 --- a/vsintegration/src/FSharp.Editor/LanguageService/LanguageService.fs +++ b/vsintegration/src/FSharp.Editor/LanguageService/LanguageService.fs @@ -341,6 +341,7 @@ type internal FSharpPackage() as this = let mutable solutionEventsOpt = None #if DEBUG + let _traceProvider = Logging.Activity.export () let _logger = Logging.Activity.listenToAll () // Logging.Activity.listen "IncrementalBuild" #endif