From aa294be57f8d5df0a1acb66a40a14889b494b321 Mon Sep 17 00:00:00 2001 From: Claudiu Guiman Date: Wed, 15 May 2024 13:02:42 -0400 Subject: [PATCH 01/10] [ParameterCapturingService] Remove ILogger and IServiceProvider. (#6625) --- .../HostingStartup.cs | 1 - .../FunctionProbes/FunctionProbesManager.cs | 13 +- .../ParameterCapturingLogger.cs | 168 ------------------ .../ParameterCapturingService.cs | 37 +--- .../ParameterCapturingLoggerTests.cs | 102 ----------- .../FunctionProbes/FunctionProbesScenario.cs | 8 +- 6 files changed, 10 insertions(+), 319 deletions(-) delete mode 100644 src/Microsoft.Diagnostics.Monitoring.HostingStartup/ParameterCapturing/ParameterCapturingLogger.cs delete mode 100644 src/Tests/Microsoft.Diagnostics.Monitoring.HostingStartup.UnitTests/ParameterCapturing/ParameterCapturingLoggerTests.cs diff --git a/src/Microsoft.Diagnostics.Monitoring.HostingStartup/HostingStartup.cs b/src/Microsoft.Diagnostics.Monitoring.HostingStartup/HostingStartup.cs index 613cff749d3..13fa379d089 100644 --- a/src/Microsoft.Diagnostics.Monitoring.HostingStartup/HostingStartup.cs +++ b/src/Microsoft.Diagnostics.Monitoring.HostingStartup/HostingStartup.cs @@ -26,7 +26,6 @@ public void Configure(IWebHostBuilder builder) if (ToolIdentifiers.IsEnvVarEnabled(InProcessFeaturesIdentifiers.EnvironmentVariables.ParameterCapturing.Enable)) { - services.AddSingleton(); services.AddHostedService(); } }); diff --git a/src/Microsoft.Diagnostics.Monitoring.HostingStartup/ParameterCapturing/FunctionProbes/FunctionProbesManager.cs b/src/Microsoft.Diagnostics.Monitoring.HostingStartup/ParameterCapturing/FunctionProbes/FunctionProbesManager.cs index a30600f7d90..2515e186653 100644 --- a/src/Microsoft.Diagnostics.Monitoring.HostingStartup/ParameterCapturing/FunctionProbes/FunctionProbesManager.cs +++ b/src/Microsoft.Diagnostics.Monitoring.HostingStartup/ParameterCapturing/FunctionProbes/FunctionProbesManager.cs @@ -5,7 +5,6 @@ using Microsoft.Diagnostics.Monitoring.HostingStartup.ParameterCapturing.ObjectFormatting; using Microsoft.Diagnostics.Monitoring.StartupHook; using Microsoft.Diagnostics.Tools.Monitor.Profiler; -using Microsoft.Extensions.Logging; using System; using System.Collections.Generic; using System.Collections.ObjectModel; @@ -71,14 +70,11 @@ private static extern void RegisterFunctionProbeCallbacks( public event EventHandler? OnProbeFault; - private readonly ILogger _logger; - - public FunctionProbesManager(ILogger logger) + public FunctionProbesManager() { ProfilerResolver.InitializeResolver(); _disposalToken = _disposalTokenSource.Token; - _logger = logger; // // CONSIDER: @@ -103,8 +99,6 @@ public FunctionProbesManager(ILogger logger) private void OnRegistration(int hresult) { - _logger.LogDebug(ParameterCapturingStrings.ProbeManagementCallback, nameof(OnRegistration), hresult); - TransitionStateFromHr(_probeRegistrationTaskSource, hresult, expectedState: ProbeStateUninitialized, succeededState: ProbeStateUninstalled, @@ -113,8 +107,6 @@ private void OnRegistration(int hresult) private void OnInstallation(int hresult) { - _logger.LogDebug(ParameterCapturingStrings.ProbeManagementCallback, nameof(OnInstallation), hresult); - TransitionStateFromHr(_installationTaskSource, hresult, expectedState: ProbeStateInstalling, succeededState: ProbeStateInstalled, @@ -123,8 +115,6 @@ private void OnInstallation(int hresult) private void OnUninstallation(int hresult) { - _logger.LogDebug(ParameterCapturingStrings.ProbeManagementCallback, nameof(OnUninstallation), hresult); - TransitionStateFromHr(_uninstallationTaskSource, hresult, expectedState: ProbeStateUninstalling, succeededState: ProbeStateUninstalled, @@ -304,7 +294,6 @@ public async Task StartCapturingAsync(IList methods, IFunctionProbes { using IDisposable _ = linkedCancellationToken.Register(() => { - _logger.LogDebug(ParameterCapturingStrings.CancellationRequestedDuringProbeInstallation, token.IsCancellationRequested, _disposalToken.IsCancellationRequested); _installationTaskSource?.TrySetCanceled(linkedCancellationToken); // diff --git a/src/Microsoft.Diagnostics.Monitoring.HostingStartup/ParameterCapturing/ParameterCapturingLogger.cs b/src/Microsoft.Diagnostics.Monitoring.HostingStartup/ParameterCapturing/ParameterCapturingLogger.cs deleted file mode 100644 index fa47674e379..00000000000 --- a/src/Microsoft.Diagnostics.Monitoring.HostingStartup/ParameterCapturing/ParameterCapturingLogger.cs +++ /dev/null @@ -1,168 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -using Microsoft.Diagnostics.Monitoring.HostingStartup.ParameterCapturing.FunctionProbes; -using Microsoft.Diagnostics.Monitoring.StartupHook; -using Microsoft.Extensions.Logging; -using System; -using System.Collections.Concurrent; -using System.Diagnostics; -using System.Globalization; -using System.Linq; -using System.Threading; - -namespace Microsoft.Diagnostics.Monitoring.HostingStartup.ParameterCapturing -{ - internal sealed class ParameterCapturingLogger : IDisposable - { - private record QueuedLogStatement(string Format, string[] Args, KeyValueLogScope Scope); - - internal static class Scopes - { - private const string Prefix = "DotnetMonitor_"; - - public const string TimeStamp = Prefix + "Timestamp"; - - public const string ThreadId = Prefix + "ThreadId"; - - public const string ActivityId = Prefix + "ActivityId"; - public const string ActivityIdFormat = Prefix + "ActivityIdFormat"; - - public static class CaptureSite - { - private const string Prefix = Scopes.Prefix + "CaptureSite_"; - - public const string MethodName = Prefix + "MethodName"; - public const string ModuleName = Prefix + "ModuleName"; - public const string TypeName = Prefix + "TypeName"; - } - } - - private readonly ILogger _userLogger; - private readonly ILogger _systemLogger; - private readonly Thread _thread; - private BlockingCollection _messages; - private uint _droppedMessageCounter; - private const int BackgroundLoggingCapacity = 1024; - private const string BackgroundLoggingThreadName = "[dotnet-monitor] Probe Logging Thread"; - private long _disposedState; - - private static readonly string[] ExcludedThreads = new[] - { - "Console logger queue processing thread", - }; - - public ParameterCapturingLogger(ILogger userLogger, ILogger systemLogger) - { - _userLogger = userLogger; - _systemLogger = systemLogger; - _thread = new Thread(ThreadProc); - - _thread.Priority = ThreadPriority.BelowNormal; - _thread.IsBackground = true; - _thread.Name = BackgroundLoggingThreadName; - _messages = new BlockingCollection(BackgroundLoggingCapacity); - _thread.Start(); - } - - public bool ShouldLog() - { - // Probes should not attempt to log on the console logging thread - // or on the background thread that is used to log system messages. - - if (Environment.CurrentManagedThreadId == _thread.ManagedThreadId) - { - return false; - } - if (ExcludedThreads.Contains(Thread.CurrentThread.Name)) - { - return false; - } - - return true; - } - - public void Log(ParameterCaptureMode mode, MethodTemplateString methodTemplateString, string[] args) - { - DisposableHelper.ThrowIfDisposed(ref _disposedState); - - KeyValueLogScope scope = GenerateScope(methodTemplateString); - - if (mode == ParameterCaptureMode.Inline) - { - Log(_userLogger, methodTemplateString.Template, args, scope); - } - else if (mode == ParameterCaptureMode.Background) - { - if (!_messages.TryAdd(new QueuedLogStatement(methodTemplateString.Template, args, scope))) - { - Interlocked.Increment(ref _droppedMessageCounter); - } - } - } - - private static KeyValueLogScope GenerateScope(MethodTemplateString methodTemplateString) - { - KeyValueLogScope scope = new(); - - // Store timestamp as ISO 8601 compliant - scope.Values.Add(Scopes.TimeStamp, DateTime.UtcNow.ToString("o", CultureInfo.InvariantCulture)); - scope.Values.Add(Scopes.ThreadId, Environment.CurrentManagedThreadId); - - scope.Values.Add(Scopes.CaptureSite.MethodName, methodTemplateString.MethodName); - scope.Values.Add(Scopes.CaptureSite.ModuleName, methodTemplateString.ModuleName); - scope.Values.Add(Scopes.CaptureSite.TypeName, methodTemplateString.TypeName); - - Activity? currentActivity = Activity.Current; - if (currentActivity?.Id != null) - { - scope.Values.Add(Scopes.ActivityId, currentActivity.Id); - scope.Values.Add(Scopes.ActivityIdFormat, currentActivity.IdFormat); - } - - return scope; - } - - private void ThreadProc() - { - using IDisposable _ = MonitorExecutionContextTracker.MonitorScope(); - - try - { - while (_messages.TryTake(out QueuedLogStatement? entry, Timeout.InfiniteTimeSpan)) - { - Log(_systemLogger, entry.Format, entry.Args, entry.Scope); - } - } - catch (ObjectDisposedException) - { - } - catch - { - } - } - - public void Complete() - { - // NOTE We currently do not wait for the background thread in production code - _messages.CompleteAdding(); - _thread.Join(); - } - - private static void Log(ILogger logger, string format, string[] args, KeyValueLogScope scope) - { - using var _ = logger.BeginScope(scope); - logger.Log(LogLevel.Information, format, args); - } - - public void Dispose() - { - if (!DisposableHelper.CanDispose(ref _disposedState)) - { - return; - } - _messages.CompleteAdding(); - _messages.Dispose(); - } - } -} diff --git a/src/Microsoft.Diagnostics.Monitoring.HostingStartup/ParameterCapturing/ParameterCapturingService.cs b/src/Microsoft.Diagnostics.Monitoring.HostingStartup/ParameterCapturing/ParameterCapturingService.cs index 0599943c75c..76b72dc9008 100644 --- a/src/Microsoft.Diagnostics.Monitoring.HostingStartup/ParameterCapturing/ParameterCapturingService.cs +++ b/src/Microsoft.Diagnostics.Monitoring.HostingStartup/ParameterCapturing/ParameterCapturingService.cs @@ -9,9 +9,7 @@ using Microsoft.Diagnostics.Tools.Monitor.ParameterCapturing; using Microsoft.Diagnostics.Tools.Monitor.Profiler; using Microsoft.Diagnostics.Tools.Monitor.StartupHook; -using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; -using Microsoft.Extensions.Logging; using System; using System.Collections.Generic; using System.Reflection; @@ -30,11 +28,8 @@ internal sealed class ParameterCapturingService : BackgroundService, IParameterC private readonly ParameterCapturingEventSource _eventSource = new(); private readonly AsyncParameterCapturingEventSource? _asyncEventSource; private readonly ParameterCapturingPipeline? _pipeline; - private readonly ParameterCapturingLogger? _parameterCapturingLogger; - private readonly ILogger? _logger; - - public ParameterCapturingService(IServiceProvider services) + public ParameterCapturingService() { using IDisposable _ = MonitorExecutionContextTracker.MonitorScope(); @@ -52,19 +47,9 @@ public ParameterCapturingService(IServiceProvider services) StartupHookCommand.StopCapturingParameters, OnStopMessage); - IMethodDescriptionValidator _methodDescriptionValidator = services.GetRequiredService(); - - _logger = services.GetService>() - ?? throw new NotSupportedException(ParameterCapturingStrings.FeatureUnsupported_NoLogger); - - ILogger userLogger = services.GetService>() - ?? throw new NotSupportedException(ParameterCapturingStrings.FeatureUnsupported_NoLogger); - - ILogger systemLogger = services.GetService>() - ?? throw new NotSupportedException(ParameterCapturingStrings.FeatureUnsupported_NoLogger); + IMethodDescriptionValidator _methodDescriptionValidator = new MethodDescriptionValidator(); - _parameterCapturingLogger = new(userLogger, systemLogger); - FunctionProbesManager probeManager = new(_logger); + FunctionProbesManager probeManager = new(); _pipeline = new ParameterCapturingPipeline(probeManager, this, _methodDescriptionValidator); @@ -84,32 +69,21 @@ public ParameterCapturingService(IServiceProvider services) public void CapturingStart(StartCapturingParametersPayload request, IList methods) { _eventSource.CapturingStart(request.RequestId); - _logger?.LogInformation( - ParameterCapturingStrings.StartParameterCapturingFormatString, - request.Duration, - methods.Count); } public void CapturingStop(Guid requestId) { _eventSource.CapturingStop(requestId); - _logger?.LogInformation(ParameterCapturingStrings.StopParameterCapturing); } public void FailedToCapture(Guid requestId, ParameterCapturingEvents.CapturingFailedReason reason, string details) { _eventSource.FailedToCapture(requestId, reason, details); - if (reason == ParameterCapturingEvents.CapturingFailedReason.UnresolvedMethods) - { - _logger?.LogWarning(details); - } } public void ProbeFault(Guid requestId, InstrumentedMethod faultingMethod) { - // TODO: Report back this fault on ParameterCapturingEventSource. - _logger?.LogWarning(ParameterCapturingStrings.StoppingParameterCapturingDueToProbeFault, faultingMethod.MethodTemplateString.Template); - + // TODO: Report back this fault on ParameterCapturingEventSource. try { _pipeline?.RequestStop(requestId); @@ -128,7 +102,7 @@ private bool IsAvailable() private void OnStartMessage(StartCapturingParametersPayload payload) { - if (!IsAvailable() || _pipeline == null || _parameterCapturingLogger == null || _asyncEventSource == null) + if (!IsAvailable() || _pipeline == null || _asyncEventSource == null) { BroadcastServiceState(); return; @@ -233,7 +207,6 @@ public override void Dispose() SharedInternals.MessageDispatcher?.UnregisterCallback(StartupHookCommand.StopCapturingParameters); _pipeline?.Dispose(); - _parameterCapturingLogger?.Dispose(); _asyncEventSource?.Dispose(); diff --git a/src/Tests/Microsoft.Diagnostics.Monitoring.HostingStartup.UnitTests/ParameterCapturing/ParameterCapturingLoggerTests.cs b/src/Tests/Microsoft.Diagnostics.Monitoring.HostingStartup.UnitTests/ParameterCapturing/ParameterCapturingLoggerTests.cs deleted file mode 100644 index 1d897e48cc8..00000000000 --- a/src/Tests/Microsoft.Diagnostics.Monitoring.HostingStartup.UnitTests/ParameterCapturing/ParameterCapturingLoggerTests.cs +++ /dev/null @@ -1,102 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -using Microsoft.Diagnostics.Monitoring.HostingStartup.ParameterCapturing; -using Microsoft.Diagnostics.Monitoring.HostingStartup.ParameterCapturing.FunctionProbes; -using Microsoft.Diagnostics.Monitoring.TestCommon; -using Microsoft.Extensions.Logging; -using System; -using System.Collections.Generic; -using System.Diagnostics; -using System.Reflection; -using Xunit; - -namespace Microsoft.Diagnostics.Monitoring.HostingStartup.UnitTests.ParameterCapturing -{ - [TargetFrameworkMonikerTrait(TargetFrameworkMonikerExtensions.CurrentTargetFrameworkMoniker)] - public class ParameterCapturingLoggerTests - { - private readonly MethodInfo _testMethod = typeof(ParameterCapturingLoggerTests).GetMethod(nameof(TestMethod), BindingFlags.Static | BindingFlags.NonPublic); - private static void TestMethod() { } - - [Theory] - [InlineData(ParameterCaptureMode.Inline, typeof(DotnetMonitor.ParameterCapture.UserCode))] - [InlineData(ParameterCaptureMode.Background, typeof(DotnetMonitor.ParameterCapture.SystemCode))] - internal void LoggingCategories(ParameterCaptureMode mode, Type categoryType) - { - // Arrange & Act - IList entries = TestCore(mode); - - // Assert - LogRecordEntry entry = Assert.Single(entries); - Assert.Equal(categoryType.FullName, entry.Category); - - return; - } - - [Theory] - [InlineData(ParameterCaptureMode.Inline)] - [InlineData(ParameterCaptureMode.Background)] - internal void ScopeData(ParameterCaptureMode mode) - { - // Arrange - using Activity loggingActivity = new("ScopeDataTest"); - Activity.Current = loggingActivity; - loggingActivity.Start(); - - Dictionary expectedScope = new() - { - { ParameterCapturingLogger.Scopes.ActivityId, loggingActivity.Id }, - { ParameterCapturingLogger.Scopes.ActivityIdFormat, loggingActivity.IdFormat }, - { ParameterCapturingLogger.Scopes.ThreadId, Environment.CurrentManagedThreadId }, - { ParameterCapturingLogger.Scopes.CaptureSite.MethodName, _testMethod.Name }, - { ParameterCapturingLogger.Scopes.CaptureSite.TypeName, _testMethod.DeclaringType.FullName }, - { ParameterCapturingLogger.Scopes.CaptureSite.ModuleName, _testMethod.Module.Name } - }; - - // Act - IList entries = TestCore(mode); - - // Assert - LogRecordEntry entry = Assert.Single(entries); - IReadOnlyList> rawScope = Assert.Single(entry.Scopes); - - Dictionary scopeData = new(rawScope); - - // Validate variant data first. - - // Timestamp - Assert.True(scopeData.Remove(ParameterCapturingLogger.Scopes.TimeStamp, out object rawTimeStamp)); - string timeStampStr = Assert.IsType(rawTimeStamp); - Assert.True(DateTime.TryParse(timeStampStr, out _)); - - // Static data - Assert.Equal(expectedScope, scopeData); - - return; - } - - private IList TestCore(ParameterCaptureMode mode) - { - Assert.NotNull(_testMethod); - - // Arrange - LogRecord logRecord = new(); - ILoggerFactory factory = LoggerFactory.Create(builder => builder.AddProvider(new TestLoggerProvider(logRecord))); - - MethodTemplateString message = new(_testMethod); - - // Act - using (ParameterCapturingLogger logger = new(factory.CreateLogger(), factory.CreateLogger())) - { - logger.Log(mode, message, Array.Empty()); - - // Force the logger to drain the background queue before we dispose it. - logger.Complete(); - } - - // Assert - return logRecord.Events; - } - } -} diff --git a/src/Tests/Microsoft.Diagnostics.Monitoring.UnitTestApp/Scenarios/FunctionProbes/FunctionProbesScenario.cs b/src/Tests/Microsoft.Diagnostics.Monitoring.UnitTestApp/Scenarios/FunctionProbes/FunctionProbesScenario.cs index 65de7d25c9b..a4889756faf 100644 --- a/src/Tests/Microsoft.Diagnostics.Monitoring.UnitTestApp/Scenarios/FunctionProbes/FunctionProbesScenario.cs +++ b/src/Tests/Microsoft.Diagnostics.Monitoring.UnitTestApp/Scenarios/FunctionProbes/FunctionProbesScenario.cs @@ -70,10 +70,10 @@ public static CliCommand Command() CliCommand testCaseCommand = new(subCommand); testCaseCommand.SetAction((result, token) => { - return ScenarioHelpers.RunScenarioAsync(async logger => + return ScenarioHelpers.RunScenarioAsync(async _ => { PerFunctionProbeProxy probeProxy = new PerFunctionProbeProxy(); - using FunctionProbesManager probeManager = new(logger); + using FunctionProbesManager probeManager = new(); await testCase(probeManager, probeProxy, token); @@ -389,9 +389,9 @@ private static async Task Test_DontProbeInMonitorContextAsync(FunctionProbesMana public static Task ValidateNoMutatingProfilerAsync(ParseResult result, CancellationToken token) { - return ScenarioHelpers.RunScenarioAsync(logger => + return ScenarioHelpers.RunScenarioAsync(_ => { - Assert.Throws(() => new FunctionProbesManager(logger)); + Assert.Throws(() => new FunctionProbesManager()); return Task.FromResult(0); }, token); From 60a6925b14d467445112e1607c1b44bba26cd284 Mon Sep 17 00:00:00 2001 From: Claudiu Guiman Date: Wed, 15 May 2024 14:55:18 -0400 Subject: [PATCH 02/10] Remove MethodTemplateString (#6645) --- .../FunctionProbes/InstrumentedMethod.cs | 8 - .../MethodTemplateString.cs | 198 ------------------ .../MethodTemplateStringTests.cs | 43 ---- 3 files changed, 249 deletions(-) delete mode 100644 src/Microsoft.Diagnostics.Monitoring.HostingStartup/ParameterCapturing/MethodTemplateString.cs delete mode 100644 src/Tests/Microsoft.Diagnostics.Monitoring.HostingStartup.UnitTests/ParameterCapturing/MethodTemplateStringTests.cs diff --git a/src/Microsoft.Diagnostics.Monitoring.HostingStartup/ParameterCapturing/FunctionProbes/InstrumentedMethod.cs b/src/Microsoft.Diagnostics.Monitoring.HostingStartup/ParameterCapturing/FunctionProbes/InstrumentedMethod.cs index 52843a8bf03..e1b65a2f497 100644 --- a/src/Microsoft.Diagnostics.Monitoring.HostingStartup/ParameterCapturing/FunctionProbes/InstrumentedMethod.cs +++ b/src/Microsoft.Diagnostics.Monitoring.HostingStartup/ParameterCapturing/FunctionProbes/InstrumentedMethod.cs @@ -21,7 +21,6 @@ public InstrumentedMethod(MethodInfo method, ParameterBoxingInstructions[] boxin { FunctionId = method.GetFunctionId(); SupportedParameters = BoxingInstructions.AreParametersSupported(boxingInstructions); - MethodTemplateString = new MethodTemplateString(method); //TODO: remove! MethodSignature = new MethodSignature(method); foreach (bool isParameterSupported in SupportedParameters) { @@ -68,13 +67,6 @@ private static ParameterCaptureMode ComputeCaptureMode(MethodInfo method) /// public bool[] SupportedParameters { get; } - /// - /// A template string that contains the full method name with parameter names and - /// format items for each supported parameter. - /// - /// TODO: remove! - public MethodTemplateString MethodTemplateString { get; } - /// /// Information about the method (name, parameter types, parameter names). /// diff --git a/src/Microsoft.Diagnostics.Monitoring.HostingStartup/ParameterCapturing/MethodTemplateString.cs b/src/Microsoft.Diagnostics.Monitoring.HostingStartup/ParameterCapturing/MethodTemplateString.cs deleted file mode 100644 index 76e5a0134c3..00000000000 --- a/src/Microsoft.Diagnostics.Monitoring.HostingStartup/ParameterCapturing/MethodTemplateString.cs +++ /dev/null @@ -1,198 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -using System; -using System.Reflection; -using System.Text; - -namespace Microsoft.Diagnostics.Monitoring.HostingStartup.ParameterCapturing -{ - internal sealed class MethodTemplateString - { - private static class Tokens - { - private static class Internal - { - public const string Prefix = "<"; - public const string Postfix = ">"; - } - - public static class Types - { - public const char ArityDelimiter = '`'; - public const char Separator = '.'; - public const string Unknown = Internal.Prefix + "unknown" + Internal.Postfix; - } - - public static class Parameters - { - public const char Start = '('; - public const string Separator = ", "; - public const string NameValueSeparator = ": "; - public const char End = ')'; - - public static class Modifiers - { - public const char Separator = ' '; - public const string RefOrRefLike = "ref"; - public const string In = "in"; - public const string Out = "out"; - } - - public static class Names - { - public const string ImplicitThis = "this"; - public const string Unknown = Internal.Prefix + "unknown" + Internal.Postfix; - } - } - - public static class Generics - { - public const char Start = '<'; - public const string Separator = ", "; - public const char End = '>'; - } - } - - - public string ModuleName { get; } - public string TypeName { get; } - public string MethodName { get; } - - public string Template { get; } - - public MethodTemplateString(MethodInfo method) - { - ModuleName = GetModuleName(method); - TypeName = GetDeclaringTypeName(method); - MethodName = GetMethodName(method); - - Template = string.Concat( - TypeName, - Tokens.Types.Separator, - MethodName, - Tokens.Parameters.Start, - GetTemplatedParameters(method), - Tokens.Parameters.End); - } - - private static string GetModuleName(MethodInfo method) => method.Module.Name; - - private static string GetDeclaringTypeName(MethodInfo method) - { - StringBuilder builder = new(); - - // For a generic declaring type, trim the arity information and replace it with the known generic argument names. - string declaringTypeName = method.DeclaringType?.FullName?.Split(Tokens.Types.ArityDelimiter)?[0] ?? Tokens.Types.Unknown; - builder.Append(declaringTypeName); - EmitGenericArguments(builder, method.DeclaringType?.GetGenericArguments()); - - return builder.ToString(); - } - - private static string GetMethodName(MethodInfo method) - { - StringBuilder builder = new(); - - builder.Append(method.Name); - EmitGenericArguments(builder, method.GetGenericArguments()); - - return builder.ToString(); - } - - private static string GetTemplatedParameters(MethodInfo method) - { - StringBuilder builder = new(); - - int parameterIndex = 0; - ParameterInfo[] explicitParameters = method.GetParameters(); - - // Implicit this - if (method.HasImplicitThis()) - { - EmitParameter( - builder, - method.DeclaringType, - Tokens.Parameters.Names.ImplicitThis); - parameterIndex++; - } - - foreach (ParameterInfo paramInfo in explicitParameters) - { - if (parameterIndex != 0) - { - builder.Append(Tokens.Parameters.Separator); - } - - string name = paramInfo.Name ?? Tokens.Parameters.Names.Unknown; - EmitParameter( - builder, - paramInfo.ParameterType, - name, - paramInfo); - - parameterIndex++; - } - - return builder.ToString(); - } - - private static void EmitParameter(StringBuilder stringBuilder, Type? type, string name, ParameterInfo? paramInfo = null) - { - stringBuilder.AppendLine(); - stringBuilder.Append('\t'); - - // Modifiers - if (paramInfo?.IsIn == true) - { - stringBuilder.Append(Tokens.Parameters.Modifiers.In); - stringBuilder.Append(Tokens.Parameters.Modifiers.Separator); - } - else if (paramInfo?.IsOut == true) - { - stringBuilder.Append(Tokens.Parameters.Modifiers.Out); - stringBuilder.Append(Tokens.Parameters.Modifiers.Separator); - } - else if (type?.IsByRef == true || - type?.IsByRefLike == true) - { - stringBuilder.Append(Tokens.Parameters.Modifiers.RefOrRefLike); - stringBuilder.Append(Tokens.Parameters.Modifiers.Separator); - } - - // Name - stringBuilder.Append(name); - stringBuilder.Append(Tokens.Parameters.NameValueSeparator); - - // Value - EmitFormatItem(stringBuilder, name); - } - - private static void EmitGenericArguments(StringBuilder stringBuilder, Type[]? genericArgs) - { - if (genericArgs == null || genericArgs.Length == 0) - { - return; - } - - stringBuilder.Append(Tokens.Generics.Start); - for (int i = 0; i < genericArgs.Length; i++) - { - if (i != 0) - { - stringBuilder.Append(Tokens.Generics.Separator); - } - - stringBuilder.Append(genericArgs[i].Name); - } - stringBuilder.Append(Tokens.Generics.End); - } - - private static void EmitFormatItem(StringBuilder stringBuilder, string name) - { - stringBuilder.Append('{'); - stringBuilder.Append(name); - stringBuilder.Append('}'); - } - } -} diff --git a/src/Tests/Microsoft.Diagnostics.Monitoring.HostingStartup.UnitTests/ParameterCapturing/MethodTemplateStringTests.cs b/src/Tests/Microsoft.Diagnostics.Monitoring.HostingStartup.UnitTests/ParameterCapturing/MethodTemplateStringTests.cs deleted file mode 100644 index ef38ab3c30c..00000000000 --- a/src/Tests/Microsoft.Diagnostics.Monitoring.HostingStartup.UnitTests/ParameterCapturing/MethodTemplateStringTests.cs +++ /dev/null @@ -1,43 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -using Microsoft.Diagnostics.Monitoring.HostingStartup.ParameterCapturing; -using Microsoft.Diagnostics.Monitoring.TestCommon; -using SampleMethods; -using System; -using System.Reflection; -using Xunit; - -namespace Microsoft.Diagnostics.Monitoring.HostingStartup.UnitTests.ParameterCapturing -{ - [TargetFrameworkMonikerTrait(TargetFrameworkMonikerExtensions.CurrentTargetFrameworkMoniker)] - public class MethodTemplateStringTests - { - [Theory] - [InlineData(typeof(TestMethodSignatures), nameof(TestMethodSignatures.ImplicitThis), "SampleMethods.TestMethodSignatures.ImplicitThis(this: {this})")] - [InlineData(typeof(StaticTestMethodSignatures), nameof(StaticTestMethodSignatures.Arrays), "SampleMethods.StaticTestMethodSignatures.Arrays(intArray: {intArray}, multidimensionalArray: {multidimensionalArray})")] - [InlineData(typeof(StaticTestMethodSignatures), nameof(StaticTestMethodSignatures.Delegate), "SampleMethods.StaticTestMethodSignatures.Delegate(func: {func})")] - [InlineData(typeof(StaticTestMethodSignatures), nameof(StaticTestMethodSignatures.InParam), "SampleMethods.StaticTestMethodSignatures.InParam(in i: {i})")] - [InlineData(typeof(StaticTestMethodSignatures), nameof(StaticTestMethodSignatures.OutParam), "SampleMethods.StaticTestMethodSignatures.OutParam(out i: {i})")] - [InlineData(typeof(StaticTestMethodSignatures), nameof(StaticTestMethodSignatures.RefParam), "SampleMethods.StaticTestMethodSignatures.RefParam(ref i: {i})")] - [InlineData(typeof(StaticTestMethodSignatures), nameof(StaticTestMethodSignatures.RefStruct), "SampleMethods.StaticTestMethodSignatures.RefStruct(ref myRefStruct: {myRefStruct})")] - [InlineData(typeof(StaticTestMethodSignatures), nameof(StaticTestMethodSignatures.GenericParameters), "SampleMethods.StaticTestMethodSignatures.GenericParameters(t: {t}, k: {k})")] - [InlineData(typeof(StaticTestMethodSignatures), nameof(StaticTestMethodSignatures.VarArgs), "SampleMethods.StaticTestMethodSignatures.VarArgs(b: {b}, myInts: {myInts})")] - [InlineData(typeof(StaticTestMethodSignatures), nameof(StaticTestMethodSignatures.Unicode_ΦΨ), "SampleMethods.StaticTestMethodSignatures.Unicode_ΦΨ(δ: {δ})")] - [InlineData(typeof(StaticTestMethodSignatures.SampleNestedStruct), nameof(StaticTestMethodSignatures.SampleNestedStruct.DoWork), "SampleMethods.StaticTestMethodSignatures+SampleNestedStruct.DoWork(this: {this}, i: {i})")] - public void MethodTemplateString(Type declaringType, string methodName, string templateString) - { - // Arrange - MethodInfo method = declaringType.GetMethod(methodName); - Assert.NotNull(method); - - // Act - string actualTemplateString = new MethodTemplateString(method).Template; - - // Assert - Assert.NotNull(actualTemplateString); - actualTemplateString = actualTemplateString.ReplaceLineEndings("").Replace("\t", ""); - Assert.Equal(templateString, actualTemplateString); - } - } -} From 8ec4643edaac1b7b733bce33777dfff90b5fd881 Mon Sep 17 00:00:00 2001 From: Claudiu Guiman Date: Wed, 15 May 2024 16:30:44 -0400 Subject: [PATCH 03/10] Trace probe faults through event source (#6644) * Trace probe faults through event source * ProbeFaulted should throw InvalidOperationException --- .../ParameterCapturingService.cs | 12 ++++- .../ParameterCapturingStrings.Designer.cs | 47 +------------------ .../ParameterCapturingStrings.resx | 20 ++------ .../ParameterCapturingEvents.cs | 3 +- 4 files changed, 17 insertions(+), 65 deletions(-) diff --git a/src/Microsoft.Diagnostics.Monitoring.HostingStartup/ParameterCapturing/ParameterCapturingService.cs b/src/Microsoft.Diagnostics.Monitoring.HostingStartup/ParameterCapturing/ParameterCapturingService.cs index 76b72dc9008..c2ac32665fa 100644 --- a/src/Microsoft.Diagnostics.Monitoring.HostingStartup/ParameterCapturing/ParameterCapturingService.cs +++ b/src/Microsoft.Diagnostics.Monitoring.HostingStartup/ParameterCapturing/ParameterCapturingService.cs @@ -12,6 +12,7 @@ using Microsoft.Extensions.Hosting; using System; using System.Collections.Generic; +using System.Globalization; using System.Reflection; using System.Threading; using System.Threading.Tasks; @@ -83,7 +84,16 @@ public void FailedToCapture(Guid requestId, ParameterCapturingEvents.CapturingFa public void ProbeFault(Guid requestId, InstrumentedMethod faultingMethod) { - // TODO: Report back this fault on ParameterCapturingEventSource. + _eventSource.FailedToCapture( + requestId, + ParameterCapturingEvents.CapturingFailedReason.ProbeFaulted, + string.Format( + CultureInfo.InvariantCulture, + ParameterCapturingStrings.StoppingParameterCapturingDueToProbeFault, + faultingMethod.MethodSignature.ModuleName, + faultingMethod.MethodSignature.TypeName, + faultingMethod.MethodSignature.MethodName + )); try { _pipeline?.RequestStop(requestId); diff --git a/src/Microsoft.Diagnostics.Monitoring.HostingStartup/ParameterCapturing/ParameterCapturingStrings.Designer.cs b/src/Microsoft.Diagnostics.Monitoring.HostingStartup/ParameterCapturing/ParameterCapturingStrings.Designer.cs index b92a947219a..f7a0b898498 100644 --- a/src/Microsoft.Diagnostics.Monitoring.HostingStartup/ParameterCapturing/ParameterCapturingStrings.Designer.cs +++ b/src/Microsoft.Diagnostics.Monitoring.HostingStartup/ParameterCapturing/ParameterCapturingStrings.Designer.cs @@ -61,15 +61,6 @@ internal ParameterCapturingStrings() { } } - /// - /// Looks up a localized string similar to Cancellation has been requested during probe installation. Cancellation tokens request state (Provided:{isProvidedTokenCancelled}, Disposal:{isDisposalTokenCancelled}).. - /// - internal static string CancellationRequestedDuringProbeInstallation { - get { - return ResourceManager.GetString("CancellationRequestedDuringProbeInstallation", resourceCulture); - } - } - /// /// Looks up a localized string similar to The following method descriptions are not allowed: {0}. /// @@ -107,43 +98,7 @@ internal static string ErrorMessage_SignatureIsNotForAMethod { } /// - /// Looks up a localized string similar to Unable to create an ILogger instance in the target process.. - /// - internal static string FeatureUnsupported_NoLogger { - get { - return ResourceManager.GetString("FeatureUnsupported_NoLogger", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to {callbackName}, hr={hr}. - /// - internal static string ProbeManagementCallback { - get { - return ResourceManager.GetString("ProbeManagementCallback", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Started parameter capturing for {duration} on {numberOfMethods} method(s).. - /// - internal static string StartParameterCapturingFormatString { - get { - return ResourceManager.GetString("StartParameterCapturingFormatString", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Stopped parameter capturing.. - /// - internal static string StopParameterCapturing { - get { - return ResourceManager.GetString("StopParameterCapturing", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Parameter capturing encountered an internal error when processing '{method}', stopping.. + /// Looks up a localized string similar to Parameter capturing encountered an internal error when processing '{0}!{1}.{2}', stopping.. /// internal static string StoppingParameterCapturingDueToProbeFault { get { diff --git a/src/Microsoft.Diagnostics.Monitoring.HostingStartup/ParameterCapturing/ParameterCapturingStrings.resx b/src/Microsoft.Diagnostics.Monitoring.HostingStartup/ParameterCapturing/ParameterCapturingStrings.resx index a40f1ee7666..be3c284e2a3 100644 --- a/src/Microsoft.Diagnostics.Monitoring.HostingStartup/ParameterCapturing/ParameterCapturingStrings.resx +++ b/src/Microsoft.Diagnostics.Monitoring.HostingStartup/ParameterCapturing/ParameterCapturingStrings.resx @@ -117,9 +117,6 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - Cancellation has been requested during probe installation. Cancellation tokens request state (Provided:{isProvidedTokenCancelled}, Disposal:{isDisposalTokenCancelled}). - The following method descriptions are not allowed: {0} @@ -132,20 +129,9 @@ The provided signature blob must be for a method. - - Unable to create an ILogger instance in the target process. - - - {callbackName}, hr={hr} - - - Started parameter capturing for {duration} on {numberOfMethods} method(s). - - - Stopped parameter capturing. - - Parameter capturing encountered an internal error when processing '{method}', stopping. + Parameter capturing encountered an internal error when processing '{0}!{1}.{2}', stopping. + 0 is the module name, 1 is the method type and 2 is the method name. Too many requests @@ -153,4 +139,4 @@ Unable to resolve one or more method descriptions: {0} - \ No newline at end of file + diff --git a/src/Tools/dotnet-monitor/ParameterCapturing/ParameterCapturingEvents.cs b/src/Tools/dotnet-monitor/ParameterCapturing/ParameterCapturingEvents.cs index f5deb7c7000..1975a8d085e 100644 --- a/src/Tools/dotnet-monitor/ParameterCapturing/ParameterCapturingEvents.cs +++ b/src/Tools/dotnet-monitor/ParameterCapturing/ParameterCapturingEvents.cs @@ -52,7 +52,8 @@ public enum CapturingFailedReason : uint UnresolvedMethods = 0, InvalidRequest, TooManyRequests, - InternalError + InternalError, + ProbeFaulted } public static class CapturingFailedPayloads From c215dc81eb9e879bbe68ecdff51013fec7b2ecb2 Mon Sep 17 00:00:00 2001 From: Claudiu Guiman Date: Thu, 16 May 2024 12:43:57 -0400 Subject: [PATCH 04/10] Remove leftover unused classes and file references (#6657) --- .../FunctionProbeCategories.cs | 25 ------------------- ...agnostics.Monitoring.HostingStartup.csproj | 2 -- 2 files changed, 27 deletions(-) delete mode 100644 src/Microsoft.Diagnostics.Monitoring.HostingStartup/FunctionProbeCategories.cs diff --git a/src/Microsoft.Diagnostics.Monitoring.HostingStartup/FunctionProbeCategories.cs b/src/Microsoft.Diagnostics.Monitoring.HostingStartup/FunctionProbeCategories.cs deleted file mode 100644 index c742134347d..00000000000 --- a/src/Microsoft.Diagnostics.Monitoring.HostingStartup/FunctionProbeCategories.cs +++ /dev/null @@ -1,25 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -namespace DotnetMonitor.ParameterCapture -{ - /// - /// Special namespace and class used for Parameter Capture logging. - /// This is to prevent log filtering that normally occurs for Microsoft categories. - /// We can also use this to classify different types of logs, such as user vs. library code. - /// - internal sealed class UserCode - { - } - - internal sealed class SystemCode - { - } - - internal sealed class Service - { - } -} - - - diff --git a/src/Microsoft.Diagnostics.Monitoring.HostingStartup/Microsoft.Diagnostics.Monitoring.HostingStartup.csproj b/src/Microsoft.Diagnostics.Monitoring.HostingStartup/Microsoft.Diagnostics.Monitoring.HostingStartup.csproj index 9c34122f9e8..904e8f90395 100644 --- a/src/Microsoft.Diagnostics.Monitoring.HostingStartup/Microsoft.Diagnostics.Monitoring.HostingStartup.csproj +++ b/src/Microsoft.Diagnostics.Monitoring.HostingStartup/Microsoft.Diagnostics.Monitoring.HostingStartup.csproj @@ -16,8 +16,6 @@ - - From edd8931a01b36fbd58c4fe264b2f571062659097 Mon Sep 17 00:00:00 2001 From: Claudiu Guiman Date: Mon, 20 May 2024 17:06:03 -0400 Subject: [PATCH 05/10] Enable nullable types in HostingStartup.UnitTests (#6682) --- ...Monitoring.HostingStartup.UnitTests.csproj | 1 + .../Boxing/BoxingInstructionsTests.cs | 20 ++++++++----- .../Boxing/MethodDefinitionExtensionsTests.cs | 6 ++-- .../ParameterCapturing/MethodResolverTests.cs | 2 +- .../MethodSignatureTests.cs | 14 ++++----- .../DebuggerDisplayFormatterTests.cs | 6 ++-- .../DebuggerDisplay/ExpressionBinderTests.cs | 2 +- .../Pipeline/CaptureLimitPolicyProbesTests.cs | 6 ++-- .../ParameterCapturingPipelineTests.cs | 30 +++++++++---------- .../Pipeline/TestFunctionProbes.cs | 6 ++-- .../ParameterCapturing/SampleMethods.cs | 2 +- 11 files changed, 51 insertions(+), 44 deletions(-) diff --git a/src/Tests/Microsoft.Diagnostics.Monitoring.HostingStartup.UnitTests/Microsoft.Diagnostics.Monitoring.HostingStartup.UnitTests.csproj b/src/Tests/Microsoft.Diagnostics.Monitoring.HostingStartup.UnitTests/Microsoft.Diagnostics.Monitoring.HostingStartup.UnitTests.csproj index b8488616b15..a20295d2c7d 100644 --- a/src/Tests/Microsoft.Diagnostics.Monitoring.HostingStartup.UnitTests/Microsoft.Diagnostics.Monitoring.HostingStartup.UnitTests.csproj +++ b/src/Tests/Microsoft.Diagnostics.Monitoring.HostingStartup.UnitTests/Microsoft.Diagnostics.Monitoring.HostingStartup.UnitTests.csproj @@ -3,6 +3,7 @@ $(TestTargetFrameworks) True + enable diff --git a/src/Tests/Microsoft.Diagnostics.Monitoring.HostingStartup.UnitTests/ParameterCapturing/Boxing/BoxingInstructionsTests.cs b/src/Tests/Microsoft.Diagnostics.Monitoring.HostingStartup.UnitTests/ParameterCapturing/Boxing/BoxingInstructionsTests.cs index 9526804f721..db2dcad85d4 100644 --- a/src/Tests/Microsoft.Diagnostics.Monitoring.HostingStartup.UnitTests/ParameterCapturing/Boxing/BoxingInstructionsTests.cs +++ b/src/Tests/Microsoft.Diagnostics.Monitoring.HostingStartup.UnitTests/ParameterCapturing/Boxing/BoxingInstructionsTests.cs @@ -49,7 +49,8 @@ public BoxingInstructionsTests(ITestOutputHelper outputHelper) public void GetBoxingInstructions_Detects_UnsupportedParameters(Type declaringType, string methodName, params bool[] supported) { // Arrange - MethodInfo method = declaringType.GetMethod(methodName); + MethodInfo? method = declaringType.GetMethod(methodName); + Assert.NotNull(method); // Act bool[] supportedParameters = BoxingInstructions.AreParametersSupported(BoxingInstructions.GetBoxingInstructions(method)); @@ -62,7 +63,8 @@ public void GetBoxingInstructions_Detects_UnsupportedParameters(Type declaringTy public void GetBoxingInstructions_Handles_GenericParameters() { // Arrange - MethodInfo method = Type.GetType($"{nameof(SampleMethods)}.GenericTestMethodSignatures`2").GetMethod("GenericParameters"); + MethodInfo? method = Type.GetType($"{nameof(SampleMethods)}.GenericTestMethodSignatures`2")?.GetMethod("GenericParameters"); + Assert.NotNull(method); bool[] supported = new bool[] { true, true, true, true }; // Act @@ -90,7 +92,8 @@ public void GetBoxingInstructions_Handles_Primitives() SpecialCaseBoxingTypes.Single, SpecialCaseBoxingTypes.Double, ]; - MethodInfo method = typeof(StaticTestMethodSignatures).GetMethod(nameof(StaticTestMethodSignatures.Primitives)); + MethodInfo? method = typeof(StaticTestMethodSignatures).GetMethod(nameof(StaticTestMethodSignatures.Primitives)); + Assert.NotNull(method); // Act ParameterBoxingInstructions[] actualInstructions = BoxingInstructions.GetBoxingInstructions(method); @@ -108,7 +111,8 @@ public void GetBoxingInstructions_Handles_BuiltInReferenceTypes() SpecialCaseBoxingTypes.Object, SpecialCaseBoxingTypes.Object, ]; - MethodInfo method = typeof(StaticTestMethodSignatures).GetMethod(nameof(StaticTestMethodSignatures.BuiltInReferenceTypes)); + MethodInfo? method = typeof(StaticTestMethodSignatures).GetMethod(nameof(StaticTestMethodSignatures.BuiltInReferenceTypes)); + Assert.NotNull(method); // Act ParameterBoxingInstructions[] actualInstructions = BoxingInstructions.GetBoxingInstructions(method); @@ -140,14 +144,14 @@ public void GetBoxingInstructions_Handles_BuiltInReferenceTypes() [InlineData(typeof(StaticTestMethodSignatures), nameof(StaticTestMethodSignatures.VarArgs))] public void ReflectionAndSignatureDecoder_Contract_InSync(Type declaringType, string methodName) { - MethodInfo method = declaringType.GetMethod(methodName); + MethodInfo? method = declaringType.GetMethod(methodName); ReflectionAndSignatureDecoder_Contract_InSyncCore(method); } [Fact] public void ReflectionAndSignatureDecoder_Contract_Generics_InSync() { - MethodInfo method = Type.GetType($"{nameof(SampleMethods)}.GenericTestMethodSignatures`2").GetMethod("GenericParameters"); + MethodInfo? method = Type.GetType($"{nameof(SampleMethods)}.GenericTestMethodSignatures`2")?.GetMethod("GenericParameters"); ReflectionAndSignatureDecoder_Contract_InSyncCore(method); } @@ -155,13 +159,13 @@ public void ReflectionAndSignatureDecoder_Contract_Generics_InSync() /// Tests if GetBoxingInstructionsFromReflection is in sync with the signature decoder support for a given method's parameters. /// /// The method whose parameters to test. - private static void ReflectionAndSignatureDecoder_Contract_InSyncCore(MethodInfo method) + private static void ReflectionAndSignatureDecoder_Contract_InSyncCore(MethodInfo? method) { Assert.NotNull(method); ParameterInfo[] parameters = method.GetParameters(); - ParameterBoxingInstructions[] signatureDecoderInstructions = BoxingInstructions.GetAncillaryBoxingInstructionsFromMethodSignature(method); ; + ParameterBoxingInstructions[]? signatureDecoderInstructions = BoxingInstructions.GetAncillaryBoxingInstructionsFromMethodSignature(method); Assert.NotNull(signatureDecoderInstructions); Assert.Equal(parameters.Length, signatureDecoderInstructions.Length); diff --git a/src/Tests/Microsoft.Diagnostics.Monitoring.HostingStartup.UnitTests/ParameterCapturing/Boxing/MethodDefinitionExtensionsTests.cs b/src/Tests/Microsoft.Diagnostics.Monitoring.HostingStartup.UnitTests/ParameterCapturing/Boxing/MethodDefinitionExtensionsTests.cs index 459405fb657..783b779e5a0 100644 --- a/src/Tests/Microsoft.Diagnostics.Monitoring.HostingStartup.UnitTests/ParameterCapturing/Boxing/MethodDefinitionExtensionsTests.cs +++ b/src/Tests/Microsoft.Diagnostics.Monitoring.HostingStartup.UnitTests/ParameterCapturing/Boxing/MethodDefinitionExtensionsTests.cs @@ -21,14 +21,16 @@ public class MethodDefinitionExtensionsTests [InlineData(typeof(StaticTestMethodSignatures), nameof(StaticTestMethodSignatures.ValueType_TypeSpec), 6, 17)] public void GetParameterBoxingInstructions_Captures_MemoryRegion_ForTypeSpecs(Type declaringType, string methodName, params int[] parameterSignatureLengths) { - MethodInfo method = declaringType.GetMethod(methodName); + MethodInfo? method = declaringType.GetMethod(methodName); + Assert.NotNull(method); TestCore(method, parameterSignatureLengths); } [Fact] public void GetParameterBoxingInstructions_Captures_MemoryRegion_ForTypeGenerics() { - MethodInfo method = Type.GetType($"{nameof(SampleMethods)}.GenericTestMethodSignatures`2").GetMethod("GenericParameters"); + MethodInfo? method = Type.GetType($"{nameof(SampleMethods)}.GenericTestMethodSignatures`2")?.GetMethod("GenericParameters"); + Assert.NotNull(method); int[] parameterSignatureLengths = [2, 2, 2]; TestCore(method, parameterSignatureLengths); } diff --git a/src/Tests/Microsoft.Diagnostics.Monitoring.HostingStartup.UnitTests/ParameterCapturing/MethodResolverTests.cs b/src/Tests/Microsoft.Diagnostics.Monitoring.HostingStartup.UnitTests/ParameterCapturing/MethodResolverTests.cs index a70ffdd0f75..ae642b93c10 100644 --- a/src/Tests/Microsoft.Diagnostics.Monitoring.HostingStartup.UnitTests/ParameterCapturing/MethodResolverTests.cs +++ b/src/Tests/Microsoft.Diagnostics.Monitoring.HostingStartup.UnitTests/ParameterCapturing/MethodResolverTests.cs @@ -162,7 +162,7 @@ private static MethodDescription GetMethodDescription(Type declaringType, string return new MethodDescription { ModuleName = declaringType.Module.Name, - TypeName = declaringType.FullName, + TypeName = declaringType.FullName ?? string.Empty, MethodName = methodName }; } diff --git a/src/Tests/Microsoft.Diagnostics.Monitoring.HostingStartup.UnitTests/ParameterCapturing/MethodSignatureTests.cs b/src/Tests/Microsoft.Diagnostics.Monitoring.HostingStartup.UnitTests/ParameterCapturing/MethodSignatureTests.cs index 7d5ce63f149..b8fa7693cb2 100644 --- a/src/Tests/Microsoft.Diagnostics.Monitoring.HostingStartup.UnitTests/ParameterCapturing/MethodSignatureTests.cs +++ b/src/Tests/Microsoft.Diagnostics.Monitoring.HostingStartup.UnitTests/ParameterCapturing/MethodSignatureTests.cs @@ -219,11 +219,11 @@ public void NestedStructs() => ]); private static void TestCore( - MethodInfo methodInfo, - string expectedMethodName, - string expectedDeclaringType, - string expectedDeclaringTypeModuleName, - ExpectedParameterSignature[] expectedParameters) + MethodInfo? methodInfo, + string expectedMethodName, + string expectedDeclaringType, + string expectedDeclaringTypeModuleName, + ExpectedParameterSignature[] expectedParameters) { // Arrange Assert.NotNull(methodInfo); @@ -249,9 +249,9 @@ private static void TestCore( private sealed record ExpectedParameterSignature(Type paramType) { - public string Name; + public string? Name; - public string Type; + public string? Type; public string TypeModuleName = paramType.Module.Name; diff --git a/src/Tests/Microsoft.Diagnostics.Monitoring.HostingStartup.UnitTests/ParameterCapturing/ObjectFormatting/Formatters/DebuggerDisplay/DebuggerDisplayFormatterTests.cs b/src/Tests/Microsoft.Diagnostics.Monitoring.HostingStartup.UnitTests/ParameterCapturing/ObjectFormatting/Formatters/DebuggerDisplay/DebuggerDisplayFormatterTests.cs index 3976c944bbc..554cb756442 100644 --- a/src/Tests/Microsoft.Diagnostics.Monitoring.HostingStartup.UnitTests/ParameterCapturing/ObjectFormatting/Formatters/DebuggerDisplay/DebuggerDisplayFormatterTests.cs +++ b/src/Tests/Microsoft.Diagnostics.Monitoring.HostingStartup.UnitTests/ParameterCapturing/ObjectFormatting/Formatters/DebuggerDisplay/DebuggerDisplayFormatterTests.cs @@ -28,7 +28,7 @@ private sealed class DebuggerDisplayClassWithNullField { public int Count { get; set; } - public static string NullField => null; + public static string? NullField => null; } [Theory] @@ -80,7 +80,7 @@ public void GetDebuggerDisplayFormatter_ReturnsWorkingFormatter() Count = 10 }; - FormatterFactoryResult factoryResult = DebuggerDisplayFormatter.GetDebuggerDisplayFormatter(testObj.GetType()); + FormatterFactoryResult? factoryResult = DebuggerDisplayFormatter.GetDebuggerDisplayFormatter(testObj.GetType()); Assert.NotNull(factoryResult); // Act @@ -100,7 +100,7 @@ public void GetDebuggerDisplayFormatter_FormatsNull() Count = 10 }; - FormatterFactoryResult factoryResult = DebuggerDisplayFormatter.GetDebuggerDisplayFormatter(testObj.GetType()); + FormatterFactoryResult? factoryResult = DebuggerDisplayFormatter.GetDebuggerDisplayFormatter(testObj.GetType()); Assert.NotNull(factoryResult); // Act diff --git a/src/Tests/Microsoft.Diagnostics.Monitoring.HostingStartup.UnitTests/ParameterCapturing/ObjectFormatting/Formatters/DebuggerDisplay/ExpressionBinderTests.cs b/src/Tests/Microsoft.Diagnostics.Monitoring.HostingStartup.UnitTests/ParameterCapturing/ObjectFormatting/Formatters/DebuggerDisplay/ExpressionBinderTests.cs index cdeb5ba459e..3713ade95e3 100644 --- a/src/Tests/Microsoft.Diagnostics.Monitoring.HostingStartup.UnitTests/ParameterCapturing/ObjectFormatting/Formatters/DebuggerDisplay/ExpressionBinderTests.cs +++ b/src/Tests/Microsoft.Diagnostics.Monitoring.HostingStartup.UnitTests/ParameterCapturing/ObjectFormatting/Formatters/DebuggerDisplay/ExpressionBinderTests.cs @@ -66,7 +66,7 @@ public void BindExpression(string expression, bool doesBind, object expected) } Assert.NotNull(evaluator); - object result = evaluator.Value.Evaluate(obj); + object? result = evaluator.Value.Evaluate(obj); // Assert Assert.Equal(expected, result); diff --git a/src/Tests/Microsoft.Diagnostics.Monitoring.HostingStartup.UnitTests/ParameterCapturing/Pipeline/CaptureLimitPolicyProbesTests.cs b/src/Tests/Microsoft.Diagnostics.Monitoring.HostingStartup.UnitTests/ParameterCapturing/Pipeline/CaptureLimitPolicyProbesTests.cs index 1e196a890f3..c6943a01480 100644 --- a/src/Tests/Microsoft.Diagnostics.Monitoring.HostingStartup.UnitTests/ParameterCapturing/Pipeline/CaptureLimitPolicyProbesTests.cs +++ b/src/Tests/Microsoft.Diagnostics.Monitoring.HostingStartup.UnitTests/ParameterCapturing/Pipeline/CaptureLimitPolicyProbesTests.cs @@ -88,8 +88,8 @@ public void EnterProbe_ShortCircuits_WhenLimitReached() public void CacheMethods_PassesThrough() { // Arrange - List expectedMethods = [(MethodInfo)MethodBase.GetCurrentMethod()]; - IList actualMethods = null; + List expectedMethods = [(MethodInfo)MethodBase.GetCurrentMethod()!]; + IList actualMethods = []; TaskCompletionSource requestStop = new(); CaptureLimitPolicyProbes probes = new(new TestFunctionProbes( @@ -113,7 +113,7 @@ public void EnterProbe_PassesThrough() object[] expectedArgs = [new Uri("https://www.example.com"), 10]; ulong? actualUniquifier = null; - object[] actualArgs = null; + object[] actualArgs = []; TaskCompletionSource requestStop = new(); CaptureLimitPolicyProbes probes = new(new TestFunctionProbes( diff --git a/src/Tests/Microsoft.Diagnostics.Monitoring.HostingStartup.UnitTests/ParameterCapturing/Pipeline/ParameterCapturingPipelineTests.cs b/src/Tests/Microsoft.Diagnostics.Monitoring.HostingStartup.UnitTests/ParameterCapturing/Pipeline/ParameterCapturingPipelineTests.cs index b703a9b8641..24817351bfd 100644 --- a/src/Tests/Microsoft.Diagnostics.Monitoring.HostingStartup.UnitTests/ParameterCapturing/Pipeline/ParameterCapturingPipelineTests.cs +++ b/src/Tests/Microsoft.Diagnostics.Monitoring.HostingStartup.UnitTests/ParameterCapturing/Pipeline/ParameterCapturingPipelineTests.cs @@ -21,12 +21,12 @@ namespace Microsoft.Diagnostics.Monitoring.HostingStartup.UnitTests.ParameterCap { internal sealed class TestFunctionProbesManager : IFunctionProbesManager { - private readonly Action, IFunctionProbes> _onStart; - private readonly Action _onStop; + private readonly Action, IFunctionProbes>? _onStart; + private readonly Action? _onStop; - public event EventHandler OnProbeFault; + public event EventHandler? OnProbeFault; - public TestFunctionProbesManager(Action, IFunctionProbes> onStart = null, Action onStop = null) + public TestFunctionProbesManager(Action, IFunctionProbes>? onStart = null, Action? onStop = null) { _onStart = onStart; _onStop = onStop; @@ -57,16 +57,16 @@ public void Dispose() internal sealed class TestParameterCapturingCallbacks : IParameterCapturingPipelineCallbacks { - private readonly Action> _onCapturingStart; - private readonly Action _onCapturingStop; - private readonly Action _onCapturingFailed; - private readonly Action _onProbeFault; + private readonly Action>? _onCapturingStart; + private readonly Action? _onCapturingStop; + private readonly Action? _onCapturingFailed; + private readonly Action? _onProbeFault; public TestParameterCapturingCallbacks( - Action> onCapturingStart = null, - Action onCapturingStop = null, - Action onCapturingFailed = null, - Action onProbeFault = null) + Action>? onCapturingStart = null, + Action? onCapturingStop = null, + Action? onCapturingFailed = null, + Action? onProbeFault = null) { _onCapturingStart = onCapturingStart; _onCapturingStop = onCapturingStop; @@ -97,8 +97,8 @@ public void ProbeFault(Guid requestId, InstrumentedMethod faultingMethod) internal sealed class TestMethodDescriptionValidator : IMethodDescriptionValidator { - private readonly Func _onValidateMethods; - public TestMethodDescriptionValidator(Func onValidateMethods = null) + private readonly Func? _onValidateMethods; + public TestMethodDescriptionValidator(Func? onValidateMethods = null) { _onValidateMethods = onValidateMethods; } @@ -476,7 +476,7 @@ private StartCapturingParametersPayload CreateStartCapturingPayload(TimeSpan dur string moduleName = typeof(ParameterCapturingPipelineTests).Module.Name; Assert.NotNull(moduleName); - string typeName = typeof(ParameterCapturingPipelineTests).FullName; + string? typeName = typeof(ParameterCapturingPipelineTests).FullName; Assert.NotNull(typeName); return new StartCapturingParametersPayload() diff --git a/src/Tests/Microsoft.Diagnostics.Monitoring.HostingStartup.UnitTests/ParameterCapturing/Pipeline/TestFunctionProbes.cs b/src/Tests/Microsoft.Diagnostics.Monitoring.HostingStartup.UnitTests/ParameterCapturing/Pipeline/TestFunctionProbes.cs index 664e6a84473..012b5b7f6dc 100644 --- a/src/Tests/Microsoft.Diagnostics.Monitoring.HostingStartup.UnitTests/ParameterCapturing/Pipeline/TestFunctionProbes.cs +++ b/src/Tests/Microsoft.Diagnostics.Monitoring.HostingStartup.UnitTests/ParameterCapturing/Pipeline/TestFunctionProbes.cs @@ -10,10 +10,10 @@ namespace Microsoft.Diagnostics.Monitoring.HostingStartup.UnitTests.ParameterCap { internal sealed class TestFunctionProbes : IFunctionProbes { - private readonly Func _onEnterProbe; - private readonly Action> _onCacheMethods; + private readonly Func? _onEnterProbe; + private readonly Action>? _onCacheMethods; - public TestFunctionProbes(Func onEnterProbe = null, Action> onCacheMethods = null) + public TestFunctionProbes(Func? onEnterProbe = null, Action>? onCacheMethods = null) { _onEnterProbe = onEnterProbe; _onCacheMethods = onCacheMethods; diff --git a/src/Tests/Microsoft.Diagnostics.Monitoring.HostingStartup.UnitTests/ParameterCapturing/SampleMethods.cs b/src/Tests/Microsoft.Diagnostics.Monitoring.HostingStartup.UnitTests/ParameterCapturing/SampleMethods.cs index e12eef7f172..f262658d303 100644 --- a/src/Tests/Microsoft.Diagnostics.Monitoring.HostingStartup.UnitTests/ParameterCapturing/SampleMethods.cs +++ b/src/Tests/Microsoft.Diagnostics.Monitoring.HostingStartup.UnitTests/ParameterCapturing/SampleMethods.cs @@ -79,7 +79,7 @@ public static string ExceptionRegionAtBeginningOfMethod(object myObject) { try { - return myObject.ToString(); + return myObject.ToString() ?? string.Empty; } catch { From 4e7f72655aea8f2829ec9e11d8ecbc62cd6a6a34 Mon Sep 17 00:00:00 2001 From: Claudiu Guiman Date: Wed, 22 May 2024 12:03:42 -0400 Subject: [PATCH 06/10] Introduce BackgroundService utility class in StartupHook (#6655) * Introduce BackgroundService utility class in StartupHook * Add ConfigureAwait(false) * Refactor BackgroundService to expose the executing task * Add SafeCancel * PR feedback * Rename tests --- .../ParameterCapturingService.cs | 2 +- .../BackgroundService.cs | 62 +++++++++ .../BackgroundServiceTests.cs | 129 ++++++++++++++++++ .../MockBackgroundService.cs | 38 ++++++ 4 files changed, 230 insertions(+), 1 deletion(-) create mode 100644 src/Microsoft.Diagnostics.Monitoring.StartupHook/BackgroundService.cs create mode 100644 src/Tests/Microsoft.Diagnostics.Monitoring.StartupHook.UnitTests/BackgroundService/BackgroundServiceTests.cs create mode 100644 src/Tests/Microsoft.Diagnostics.Monitoring.StartupHook.UnitTests/BackgroundService/MockBackgroundService.cs diff --git a/src/Microsoft.Diagnostics.Monitoring.HostingStartup/ParameterCapturing/ParameterCapturingService.cs b/src/Microsoft.Diagnostics.Monitoring.HostingStartup/ParameterCapturing/ParameterCapturingService.cs index c2ac32665fa..d8b1aadcb68 100644 --- a/src/Microsoft.Diagnostics.Monitoring.HostingStartup/ParameterCapturing/ParameterCapturingService.cs +++ b/src/Microsoft.Diagnostics.Monitoring.HostingStartup/ParameterCapturing/ParameterCapturingService.cs @@ -9,13 +9,13 @@ using Microsoft.Diagnostics.Tools.Monitor.ParameterCapturing; using Microsoft.Diagnostics.Tools.Monitor.Profiler; using Microsoft.Diagnostics.Tools.Monitor.StartupHook; -using Microsoft.Extensions.Hosting; using System; using System.Collections.Generic; using System.Globalization; using System.Reflection; using System.Threading; using System.Threading.Tasks; +using BackgroundService = Microsoft.Extensions.Hosting.BackgroundService; namespace Microsoft.Diagnostics.Monitoring.HostingStartup.ParameterCapturing { diff --git a/src/Microsoft.Diagnostics.Monitoring.StartupHook/BackgroundService.cs b/src/Microsoft.Diagnostics.Monitoring.StartupHook/BackgroundService.cs new file mode 100644 index 00000000000..9a2d43b8210 --- /dev/null +++ b/src/Microsoft.Diagnostics.Monitoring.StartupHook/BackgroundService.cs @@ -0,0 +1,62 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System; +using System.Threading; +using System.Threading.Tasks; + +namespace Microsoft.Diagnostics.Monitoring.StartupHook +{ + internal abstract class BackgroundService : IDisposable + { + private readonly CancellationTokenSource _cts = new(); + private long _disposedState; + + public Task? ExecutingTask { get; private set; } + + public void Start() + { + ExecutingTask = Task.Run(async () => + { + await ExecuteAsync(_cts.Token).ConfigureAwait(false); + }, _cts.Token); + } + + public void Stop() + { + SafeCancel(); + + try + { + ExecutingTask?.Wait(TimeSpan.FromSeconds(1)); + } + catch + { + // ignore + } + } + + public virtual void Dispose() + { + if (!DisposableHelper.CanDispose(ref _disposedState)) + return; + + SafeCancel(); + _cts.Dispose(); + } + + private void SafeCancel() + { + try + { + _cts.Cancel(); + } + catch (AggregateException) + { + // Ignore all exceptions thrown by registered callbacks on the associated CancellationToken. + } + } + + protected abstract Task ExecuteAsync(CancellationToken stoppingToken); + } +} diff --git a/src/Tests/Microsoft.Diagnostics.Monitoring.StartupHook.UnitTests/BackgroundService/BackgroundServiceTests.cs b/src/Tests/Microsoft.Diagnostics.Monitoring.StartupHook.UnitTests/BackgroundService/BackgroundServiceTests.cs new file mode 100644 index 00000000000..bd4be15f272 --- /dev/null +++ b/src/Tests/Microsoft.Diagnostics.Monitoring.StartupHook.UnitTests/BackgroundService/BackgroundServiceTests.cs @@ -0,0 +1,129 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using Microsoft.Diagnostics.Monitoring.TestCommon; +using System; +using System.Threading; +using System.Threading.Tasks; +using Xunit; + +namespace Microsoft.Diagnostics.Monitoring.StartupHook +{ + [TargetFrameworkMonikerTrait(TargetFrameworkMonikerExtensions.CurrentTargetFrameworkMoniker)] + public sealed class BackgroundServiceTests + { + [Fact] + public void ConstructionWorks() + { + using BackgroundService _ = new MockBackgroundService(); + } + + [Fact] + public async Task Start_RunsBackgroundTask() + { + // Arrange + using CancellationTokenSource cts = new(CommonTestTimeouts.GeneralTimeout); + using MockBackgroundService service = new MockBackgroundService(); + + // Act + service.Start(); + + // Assert + await service.BackgroundTaskStarted.Task.WaitAsync(cts.Token); + } + + [Fact] + public async Task Stop_TriggersCancellation() + { + // Arrange + using CancellationTokenSource cts = new(CommonTestTimeouts.GeneralTimeout); + using MockBackgroundService service = new MockBackgroundService(async (CancellationToken stoppingToken) => + { + await Task.Delay(Timeout.Infinite, stoppingToken); + }); + + // Act + service.Start(); + await service.BackgroundTaskStarted.Task.WaitAsync(cts.Token); + service.Stop(); + + // Assert + Assert.NotNull(service.ExecutingTask); + await Assert.ThrowsAnyAsync(() => service.ExecutingTask); + } + + [Fact] + public async Task Stop_WaitsForTheBackgroundTask() + { + // Arrange + using CancellationTokenSource cts = new(CommonTestTimeouts.GeneralTimeout); + object lockObj = new(); + bool stopCompleted = false; + bool taskCompleted = false; + TaskCompletionSource backgroundTaskCompletion = new(TaskCreationOptions.RunContinuationsAsynchronously); + TaskCompletionSource beforeStopCompletion = new(TaskCreationOptions.RunContinuationsAsynchronously); + + MockBackgroundService service = new MockBackgroundService(async _ => + { + await backgroundTaskCompletion.Task.WaitAsync(cts.Token); + lock (lockObj) + { + Assert.False(stopCompleted, "Stop completed before the background task."); + taskCompleted = true; + } + }); + + // Act + service.Start(); + await service.BackgroundTaskStarted.Task.WaitAsync(cts.Token); + + Task stopTask = Task.Run(async () => + { + await Task.Yield(); + beforeStopCompletion.SetResult(); + service.Stop(); + + lock (lockObj) + { + Assert.True(taskCompleted, "Stop completed before the background task."); + stopCompleted = true; + } + }); + + await beforeStopCompletion.Task.WaitAsync(cts.Token); + // Wait a bit to ensure Stop() is waiting for the background task to complete + await Task.Delay(TimeSpan.FromMilliseconds(100)); + + backgroundTaskCompletion.SetResult(); + + await stopTask.WaitAsync(cts.Token); + + // Assert + Assert.NotNull(service.ExecutingTask); + Assert.False(service.ExecutingTask.IsFaulted); + } + + [Fact] + public async Task WorkerThrows_TaskExceptionIsCaptured() + { + // Arrange + using CancellationTokenSource cts = new(CommonTestTimeouts.GeneralTimeout); + MockBackgroundService service = new MockBackgroundService(async _ => + { + await Task.Yield(); + throw new NotImplementedException(); + }); + + // Act + service.Start(); + await service.BackgroundTaskStarted.Task.WaitAsync(cts.Token); + + service.Stop(); + service.Dispose(); + + // Assert + Assert.NotNull(service.ExecutingTask); + await Assert.ThrowsAsync(() => service.ExecutingTask); + } + } +} diff --git a/src/Tests/Microsoft.Diagnostics.Monitoring.StartupHook.UnitTests/BackgroundService/MockBackgroundService.cs b/src/Tests/Microsoft.Diagnostics.Monitoring.StartupHook.UnitTests/BackgroundService/MockBackgroundService.cs new file mode 100644 index 00000000000..b750d6a4247 --- /dev/null +++ b/src/Tests/Microsoft.Diagnostics.Monitoring.StartupHook.UnitTests/BackgroundService/MockBackgroundService.cs @@ -0,0 +1,38 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System; +using System.Threading; +using System.Threading.Tasks; + +namespace Microsoft.Diagnostics.Monitoring.StartupHook +{ + internal sealed class MockBackgroundService : BackgroundService, IDisposable + { + private readonly Func _backgroundFunc; + + public MockBackgroundService() + { + _backgroundFunc = _ => Task.CompletedTask; + } + + public MockBackgroundService(Func backgroundFunc) + { + _backgroundFunc = backgroundFunc; + } + + protected override async Task ExecuteAsync(CancellationToken stoppingToken) + { + BackgroundTaskStarted.SetResult(); + + await _backgroundFunc(stoppingToken); + } + + public override void Dispose() + { + base.Dispose(); + } + + public TaskCompletionSource BackgroundTaskStarted { get; } = new(TaskCreationOptions.RunContinuationsAsynchronously); + } +} From e880a5faa368572fed54f3f31d080e1cbd345c39 Mon Sep 17 00:00:00 2001 From: Claudiu Guiman Date: Wed, 29 May 2024 17:49:41 -0400 Subject: [PATCH 07/10] Refactor FunctionProbesTests to use the AppRunner instead of ScenarioRunner in net7 or higher tests (#6744) --- .../FunctionProbesTests.cs | 50 ++++++++++++++++--- 1 file changed, 44 insertions(+), 6 deletions(-) diff --git a/src/Tests/Microsoft.Diagnostics.Monitoring.Tool.FunctionalTests/FunctionProbesTests.cs b/src/Tests/Microsoft.Diagnostics.Monitoring.Tool.FunctionalTests/FunctionProbesTests.cs index b087474d61a..df567693153 100644 --- a/src/Tests/Microsoft.Diagnostics.Monitoring.Tool.FunctionalTests/FunctionProbesTests.cs +++ b/src/Tests/Microsoft.Diagnostics.Monitoring.Tool.FunctionalTests/FunctionProbesTests.cs @@ -2,20 +2,26 @@ // The .NET Foundation licenses this file to you under the MIT license. using Microsoft.Diagnostics.Monitoring.TestCommon; -using Microsoft.Diagnostics.Monitoring.TestCommon.Options; +using Microsoft.Diagnostics.Monitoring.TestCommon.Runners; using Microsoft.Diagnostics.Monitoring.Tool.FunctionalTests.Fixtures; -using Microsoft.Diagnostics.Monitoring.Tool.FunctionalTests.Runners; -using Microsoft.Diagnostics.Monitoring.WebApi; +using Microsoft.Diagnostics.Tools.Monitor.HostingStartup; using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Logging; using System.Collections.Generic; using System.Linq; using System.Net.Http; +using System.Reflection; using System.Runtime.InteropServices; using System.Threading.Tasks; using Xunit; using Xunit.Abstractions; +#if !NET7_0_OR_GREATER +using Microsoft.Diagnostics.Monitoring.TestCommon.Options; +using Microsoft.Diagnostics.Monitoring.Tool.FunctionalTests.Runners; +using Microsoft.Diagnostics.Monitoring.WebApi; +using Microsoft.Extensions.Logging; +#endif + namespace Microsoft.Diagnostics.Monitoring.Tool.FunctionalTests { [TargetFrameworkMonikerTrait(TargetFrameworkMonikerExtensions.CurrentTargetFrameworkMoniker)] @@ -38,7 +44,6 @@ public FunctionProbesTests(ITestOutputHelper outputHelper, ServiceProviderFixtur public static IEnumerable GetAllTestScenarios() { List arguments = new(); - IEnumerable testArchitectures = ProfilerHelper.GetArchitecture(); List commands = typeof(TestAppScenarios.FunctionProbes.SubScenarios).GetFields(System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Static) .Select(p => p.Name) @@ -57,9 +62,41 @@ public static IEnumerable GetAllTestScenarios() return arguments; } +#if !NET7_0_OR_GREATER + [Theory(Skip ="This test installs the mutating profiler which is not enabled on net6 or lower.")] +#else [Theory] +#endif [MemberData(nameof(FunctionProbesTests.GetAllTestScenarios), MemberType = typeof(FunctionProbesTests))] public async Task RunTestScenario(Architecture targetArchitecture, string subScenario) + { + await using AppRunner appRunner = new(_outputHelper, Assembly.GetExecutingAssembly()) + { + Architecture = targetArchitecture, + ScenarioName = TestAppScenarios.FunctionProbes.Name, + SubScenarioName = subScenario + }; + + // Enable the mutating profiler + string profilerPath = NativeLibraryHelper.GetSharedLibraryPath(targetArchitecture, ProfilerIdentifiers.MutatingProfiler.LibraryRootFileName); + appRunner.Environment.Add(ProfilerHelper.ClrEnvVarEnableNotificationProfilers, ProfilerHelper.ClrEnvVarEnabledValue); + appRunner.Environment.Add(ProfilerHelper.ClrEnvVarEnableProfiling, ProfilerHelper.ClrEnvVarEnabledValue); + appRunner.Environment.Add(ProfilerHelper.ClrEnvVarProfiler, ProfilerIdentifiers.MutatingProfiler.Clsid.StringWithBraces); + appRunner.Environment.Add(ProfilerHelper.ClrEnvVarProfilerPath, profilerPath); + appRunner.Environment.Add(ProfilerIdentifiers.MutatingProfiler.EnvironmentVariables.ModulePath, profilerPath); + + // The profiler checks this env variable to enable parameter capturing features. + appRunner.Environment.Add(InProcessFeaturesIdentifiers.EnvironmentVariables.ParameterCapturing.Enable, "1"); + + await appRunner.ExecuteAsync(() => Task.CompletedTask); + + Assert.Equal(0, appRunner.ExitCode); + } + +#if !NET7_0_OR_GREATER + [Theory] + [MemberData(nameof(ProfilerHelper.GetArchitecture), MemberType = typeof(ProfilerHelper))] + public async Task ValidateProfilerIsNotInstalledOnNet6(Architecture targetArchitecture) { await ScenarioRunner.SingleTarget( _outputHelper, @@ -80,7 +117,8 @@ await ScenarioRunner.SingleTarget( }; }, profilerLogLevel: LogLevel.Trace, - subScenarioName: subScenario); + subScenarioName: TestAppScenarios.FunctionProbes.SubScenarios.ValidateNoMutatingProfiler); } +#endif // NET7_0_OR_GREATER } } From 2f5379b3774e8f9332553e06b986bb2d5e25fe00 Mon Sep 17 00:00:00 2001 From: Claudiu Guiman Date: Thu, 30 May 2024 12:37:57 -0400 Subject: [PATCH 08/10] Move the ParameterCapturing code in StartupHook (#6707) * Move the ParameterCapturing code in StartupHook * fix string resource --- .../HostingStartup.cs | 7 +----- .../DiagnosticsBootstrapper.cs | 10 ++++++++ ....Diagnostics.Monitoring.StartupHook.csproj | 16 +++++++++++++ .../Boxing/BoxingInstructions.cs | 4 ++-- .../Boxing/BoxingTokensSignatureProvider.cs | 4 ++-- .../Boxing/MethodDefinitionExtensions.cs | 4 ++-- .../DeniedMethodsException.cs | 2 +- .../AsyncParameterCapturingEventSource.cs | 3 +-- .../Eventing/ParameterCapturingEventSource.cs | 2 +- .../EventSourceEmittingProbes.cs | 6 ++--- .../FunctionProbes/FunctionProbesManager.cs | 9 ++++--- .../FunctionProbes/FunctionProbesState.cs | 2 +- .../FunctionProbes/FunctionProbesStub.cs | 3 +-- .../FunctionProbes/IFunctionProbes.cs | 2 +- .../FunctionProbes/IFunctionProbesManager.cs | 2 +- .../FunctionProbes/InstrumentedMethod.cs | 4 ++-- .../FunctionProbes/ProfilerAbi.cs | 2 +- .../IMethodDescriptionValidator.cs | 2 +- .../MethodDescriptionValidator.cs | 2 +- .../MethodInfoExtensions.cs | 2 +- .../ParameterCapturing/MethodResolver.cs | 2 +- .../ParameterCapturing/MethodSignature.cs | 2 +- .../DebuggerDisplayFormatter.cs | 4 ++-- .../DebuggerDisplay/DebuggerDisplayParser.cs | 2 +- .../DebuggerDisplay/ExpressionBinder.cs | 4 ++-- .../Formatters/RuntimeFormatters.cs | 2 +- .../ObjectFormatting/ObjectFormatter.cs | 2 +- .../ObjectFormatting/ObjectFormatterCache.cs | 2 +- .../ObjectFormatterFactory.cs | 4 ++-- .../ParameterCapturingService.cs | 10 ++++---- .../ParameterCapturingStrings.Designer.cs | 6 ++--- .../ParameterCapturingStrings.resx | 0 .../ParameterCapturing/ParameterSignature.cs | 2 +- .../Pipeline/CaptureLimitPolicyProbes.cs | 4 ++-- .../IParameterCapturingPipelineCallbacks.cs | 2 +- .../Pipeline/ParameterCapturingPipeline.cs | 4 ++-- .../Pipeline/TooManyRequestsException.cs | 2 +- .../ResolvedParameterInfo.cs | 4 ++-- .../ParameterCapturing/TypeUtils.cs | 2 +- .../UnresolvedMethodsException.cs | 2 +- .../Boxing/BoxingInstructionsTests.cs | 8 +++---- .../Boxing/MethodDefinitionExtensionsTests.cs | 6 ++--- .../FunctionProbes/ProfilerAbiTests.cs | 4 ++-- .../ParameterCapturing/MethodResolverTests.cs | 6 ++--- .../MethodSignatureTests.cs | 4 ++-- .../DebuggerDisplayFormatterTests.cs | 12 ++++++---- .../DebuggerDisplayParserTests.cs | 8 +++---- .../DebuggerDisplay/ExpressionBinderTests.cs | 6 ++--- .../Formatters/RuntimeFormattersTests.cs | 4 ++-- .../ObjectFormatterFactoryTests.cs | 4 ++-- .../ObjectFormatting/ObjectFormatterTests.cs | 4 ++-- .../Pipeline/CaptureLimitPolicyProbesTests.cs | 4 ++-- .../ParameterCapturingPipelineTests.cs | 10 ++++---- .../Pipeline/TestFunctionProbes.cs | 4 ++-- .../ParameterCapturing/SampleMethods.cs | 0 .../ParameterCapturing/TypeUtilsTests.cs | 4 ++-- .../ParameterCapturingTests.cs | 24 +++++-------------- ....Diagnostics.Monitoring.UnitTestApp.csproj | 3 ++- .../FunctionProbes/FunctionProbesScenario.cs | 4 ++-- .../FunctionProbes/PerFunctionProbeProxy.cs | 2 +- .../Scenarios/ParameterCapturingScenario.cs | 3 +++ .../CaptureParametersOperation.cs | 6 ++--- src/Tools/dotnet-monitor/Strings.Designer.cs | 18 +++++++------- src/Tools/dotnet-monitor/Strings.resx | 6 ++--- 64 files changed, 157 insertions(+), 147 deletions(-) rename src/{Microsoft.Diagnostics.Monitoring.HostingStartup => Microsoft.Diagnostics.Monitoring.StartupHook}/ParameterCapturing/Boxing/BoxingInstructions.cs (98%) rename src/{Microsoft.Diagnostics.Monitoring.HostingStartup => Microsoft.Diagnostics.Monitoring.StartupHook}/ParameterCapturing/Boxing/BoxingTokensSignatureProvider.cs (94%) rename src/{Microsoft.Diagnostics.Monitoring.HostingStartup => Microsoft.Diagnostics.Monitoring.StartupHook}/ParameterCapturing/Boxing/MethodDefinitionExtensions.cs (97%) rename src/{Microsoft.Diagnostics.Monitoring.HostingStartup => Microsoft.Diagnostics.Monitoring.StartupHook}/ParameterCapturing/DeniedMethodsException.cs (93%) rename src/{Microsoft.Diagnostics.Monitoring.HostingStartup => Microsoft.Diagnostics.Monitoring.StartupHook}/ParameterCapturing/Eventing/AsyncParameterCapturingEventSource.cs (96%) rename src/{Microsoft.Diagnostics.Monitoring.HostingStartup => Microsoft.Diagnostics.Monitoring.StartupHook}/ParameterCapturing/Eventing/ParameterCapturingEventSource.cs (98%) rename src/{Microsoft.Diagnostics.Monitoring.HostingStartup => Microsoft.Diagnostics.Monitoring.StartupHook}/ParameterCapturing/FunctionProbes/EventSourceEmittingProbes.cs (93%) rename src/{Microsoft.Diagnostics.Monitoring.HostingStartup => Microsoft.Diagnostics.Monitoring.StartupHook}/ParameterCapturing/FunctionProbes/FunctionProbesManager.cs (97%) rename src/{Microsoft.Diagnostics.Monitoring.HostingStartup => Microsoft.Diagnostics.Monitoring.StartupHook}/ParameterCapturing/FunctionProbes/FunctionProbesState.cs (86%) rename src/{Microsoft.Diagnostics.Monitoring.HostingStartup => Microsoft.Diagnostics.Monitoring.StartupHook}/ParameterCapturing/FunctionProbes/FunctionProbesStub.cs (89%) rename src/{Microsoft.Diagnostics.Monitoring.HostingStartup => Microsoft.Diagnostics.Monitoring.StartupHook}/ParameterCapturing/FunctionProbes/IFunctionProbes.cs (88%) rename src/{Microsoft.Diagnostics.Monitoring.HostingStartup => Microsoft.Diagnostics.Monitoring.StartupHook}/ParameterCapturing/FunctionProbes/IFunctionProbesManager.cs (86%) rename src/{Microsoft.Diagnostics.Monitoring.HostingStartup => Microsoft.Diagnostics.Monitoring.StartupHook}/ParameterCapturing/FunctionProbes/InstrumentedMethod.cs (93%) rename src/{Microsoft.Diagnostics.Monitoring.HostingStartup => Microsoft.Diagnostics.Monitoring.StartupHook}/ParameterCapturing/FunctionProbes/ProfilerAbi.cs (95%) rename src/{Microsoft.Diagnostics.Monitoring.HostingStartup => Microsoft.Diagnostics.Monitoring.StartupHook}/ParameterCapturing/IMethodDescriptionValidator.cs (83%) rename src/{Microsoft.Diagnostics.Monitoring.HostingStartup => Microsoft.Diagnostics.Monitoring.StartupHook}/ParameterCapturing/MethodDescriptionValidator.cs (93%) rename src/{Microsoft.Diagnostics.Monitoring.HostingStartup => Microsoft.Diagnostics.Monitoring.StartupHook}/ParameterCapturing/MethodInfoExtensions.cs (91%) rename src/{Microsoft.Diagnostics.Monitoring.HostingStartup => Microsoft.Diagnostics.Monitoring.StartupHook}/ParameterCapturing/MethodResolver.cs (98%) rename src/{Microsoft.Diagnostics.Monitoring.HostingStartup => Microsoft.Diagnostics.Monitoring.StartupHook}/ParameterCapturing/MethodSignature.cs (98%) rename src/{Microsoft.Diagnostics.Monitoring.HostingStartup => Microsoft.Diagnostics.Monitoring.StartupHook}/ParameterCapturing/ObjectFormatting/Formatters/DebuggerDisplay/DebuggerDisplayFormatter.cs (92%) rename src/{Microsoft.Diagnostics.Monitoring.HostingStartup => Microsoft.Diagnostics.Monitoring.StartupHook}/ParameterCapturing/ObjectFormatting/Formatters/DebuggerDisplay/DebuggerDisplayParser.cs (98%) rename src/{Microsoft.Diagnostics.Monitoring.HostingStartup => Microsoft.Diagnostics.Monitoring.StartupHook}/ParameterCapturing/ObjectFormatting/Formatters/DebuggerDisplay/ExpressionBinder.cs (97%) rename src/{Microsoft.Diagnostics.Monitoring.HostingStartup => Microsoft.Diagnostics.Monitoring.StartupHook}/ParameterCapturing/ObjectFormatting/Formatters/RuntimeFormatters.cs (93%) rename src/{Microsoft.Diagnostics.Monitoring.HostingStartup => Microsoft.Diagnostics.Monitoring.StartupHook}/ParameterCapturing/ObjectFormatting/ObjectFormatter.cs (97%) rename src/{Microsoft.Diagnostics.Monitoring.HostingStartup => Microsoft.Diagnostics.Monitoring.StartupHook}/ParameterCapturing/ObjectFormatting/ObjectFormatterCache.cs (95%) rename src/{Microsoft.Diagnostics.Monitoring.HostingStartup => Microsoft.Diagnostics.Monitoring.StartupHook}/ParameterCapturing/ObjectFormatting/ObjectFormatterFactory.cs (88%) rename src/{Microsoft.Diagnostics.Monitoring.HostingStartup => Microsoft.Diagnostics.Monitoring.StartupHook}/ParameterCapturing/ParameterCapturingService.cs (94%) rename src/{Microsoft.Diagnostics.Monitoring.HostingStartup => Microsoft.Diagnostics.Monitoring.StartupHook}/ParameterCapturing/ParameterCapturingStrings.Designer.cs (95%) rename src/{Microsoft.Diagnostics.Monitoring.HostingStartup => Microsoft.Diagnostics.Monitoring.StartupHook}/ParameterCapturing/ParameterCapturingStrings.resx (100%) rename src/{Microsoft.Diagnostics.Monitoring.HostingStartup => Microsoft.Diagnostics.Monitoring.StartupHook}/ParameterCapturing/ParameterSignature.cs (80%) rename src/{Microsoft.Diagnostics.Monitoring.HostingStartup => Microsoft.Diagnostics.Monitoring.StartupHook}/ParameterCapturing/Pipeline/CaptureLimitPolicyProbes.cs (90%) rename src/{Microsoft.Diagnostics.Monitoring.HostingStartup => Microsoft.Diagnostics.Monitoring.StartupHook}/ParameterCapturing/Pipeline/IParameterCapturingPipelineCallbacks.cs (89%) rename src/{Microsoft.Diagnostics.Monitoring.HostingStartup => Microsoft.Diagnostics.Monitoring.StartupHook}/ParameterCapturing/Pipeline/ParameterCapturingPipeline.cs (98%) rename src/{Microsoft.Diagnostics.Monitoring.HostingStartup => Microsoft.Diagnostics.Monitoring.StartupHook}/ParameterCapturing/Pipeline/TooManyRequestsException.cs (78%) rename src/{Microsoft.Diagnostics.Monitoring.HostingStartup => Microsoft.Diagnostics.Monitoring.StartupHook}/ParameterCapturing/ResolvedParameterInfo.cs (68%) rename src/{Microsoft.Diagnostics.Monitoring.HostingStartup => Microsoft.Diagnostics.Monitoring.StartupHook}/ParameterCapturing/TypeUtils.cs (93%) rename src/{Microsoft.Diagnostics.Monitoring.HostingStartup => Microsoft.Diagnostics.Monitoring.StartupHook}/ParameterCapturing/UnresolvedMethodsException.cs (93%) rename src/Tests/{Microsoft.Diagnostics.Monitoring.HostingStartup.UnitTests => Microsoft.Diagnostics.Monitoring.StartupHook.UnitTests}/ParameterCapturing/Boxing/BoxingInstructionsTests.cs (97%) rename src/Tests/{Microsoft.Diagnostics.Monitoring.HostingStartup.UnitTests => Microsoft.Diagnostics.Monitoring.StartupHook.UnitTests}/ParameterCapturing/Boxing/MethodDefinitionExtensionsTests.cs (91%) rename src/Tests/{Microsoft.Diagnostics.Monitoring.HostingStartup.UnitTests => Microsoft.Diagnostics.Monitoring.StartupHook.UnitTests}/ParameterCapturing/FunctionProbes/ProfilerAbiTests.cs (87%) rename src/Tests/{Microsoft.Diagnostics.Monitoring.HostingStartup.UnitTests => Microsoft.Diagnostics.Monitoring.StartupHook.UnitTests}/ParameterCapturing/MethodResolverTests.cs (96%) rename src/Tests/{Microsoft.Diagnostics.Monitoring.HostingStartup.UnitTests => Microsoft.Diagnostics.Monitoring.StartupHook.UnitTests}/ParameterCapturing/MethodSignatureTests.cs (98%) rename src/Tests/{Microsoft.Diagnostics.Monitoring.HostingStartup.UnitTests => Microsoft.Diagnostics.Monitoring.StartupHook.UnitTests}/ParameterCapturing/ObjectFormatting/Formatters/DebuggerDisplay/DebuggerDisplayFormatterTests.cs (85%) rename src/Tests/{Microsoft.Diagnostics.Monitoring.HostingStartup.UnitTests => Microsoft.Diagnostics.Monitoring.StartupHook.UnitTests}/ParameterCapturing/ObjectFormatting/Formatters/DebuggerDisplay/DebuggerDisplayParserTests.cs (89%) rename src/Tests/{Microsoft.Diagnostics.Monitoring.HostingStartup.UnitTests => Microsoft.Diagnostics.Monitoring.StartupHook.UnitTests}/ParameterCapturing/ObjectFormatting/Formatters/DebuggerDisplay/ExpressionBinderTests.cs (86%) rename src/Tests/{Microsoft.Diagnostics.Monitoring.HostingStartup.UnitTests => Microsoft.Diagnostics.Monitoring.StartupHook.UnitTests}/ParameterCapturing/ObjectFormatting/Formatters/RuntimeFormattersTests.cs (93%) rename src/Tests/{Microsoft.Diagnostics.Monitoring.HostingStartup.UnitTests => Microsoft.Diagnostics.Monitoring.StartupHook.UnitTests}/ParameterCapturing/ObjectFormatting/ObjectFormatterFactoryTests.cs (86%) rename src/Tests/{Microsoft.Diagnostics.Monitoring.HostingStartup.UnitTests => Microsoft.Diagnostics.Monitoring.StartupHook.UnitTests}/ParameterCapturing/ObjectFormatting/ObjectFormatterTests.cs (92%) rename src/Tests/{Microsoft.Diagnostics.Monitoring.HostingStartup.UnitTests => Microsoft.Diagnostics.Monitoring.StartupHook.UnitTests}/ParameterCapturing/Pipeline/CaptureLimitPolicyProbesTests.cs (95%) rename src/Tests/{Microsoft.Diagnostics.Monitoring.HostingStartup.UnitTests => Microsoft.Diagnostics.Monitoring.StartupHook.UnitTests}/ParameterCapturing/Pipeline/ParameterCapturingPipelineTests.cs (97%) rename src/Tests/{Microsoft.Diagnostics.Monitoring.HostingStartup.UnitTests => Microsoft.Diagnostics.Monitoring.StartupHook.UnitTests}/ParameterCapturing/Pipeline/TestFunctionProbes.cs (84%) rename src/Tests/{Microsoft.Diagnostics.Monitoring.HostingStartup.UnitTests => Microsoft.Diagnostics.Monitoring.StartupHook.UnitTests}/ParameterCapturing/SampleMethods.cs (100%) rename src/Tests/{Microsoft.Diagnostics.Monitoring.HostingStartup.UnitTests => Microsoft.Diagnostics.Monitoring.StartupHook.UnitTests}/ParameterCapturing/TypeUtilsTests.cs (86%) diff --git a/src/Microsoft.Diagnostics.Monitoring.HostingStartup/HostingStartup.cs b/src/Microsoft.Diagnostics.Monitoring.HostingStartup/HostingStartup.cs index 13fa379d089..91ea0e08644 100644 --- a/src/Microsoft.Diagnostics.Monitoring.HostingStartup/HostingStartup.cs +++ b/src/Microsoft.Diagnostics.Monitoring.HostingStartup/HostingStartup.cs @@ -3,10 +3,8 @@ using Microsoft.AspNetCore.Hosting; using Microsoft.Diagnostics.Monitoring.HostingStartup; -using Microsoft.Diagnostics.Monitoring.HostingStartup.ParameterCapturing; using Microsoft.Diagnostics.Tools.Monitor; using Microsoft.Diagnostics.Tools.Monitor.HostingStartup; -using Microsoft.Extensions.DependencyInjection; using System.Threading; [assembly: HostingStartup(typeof(HostingStartup))] @@ -24,10 +22,7 @@ public void Configure(IWebHostBuilder builder) // validation in tests. Interlocked.Increment(ref InvocationCount); - if (ToolIdentifiers.IsEnvVarEnabled(InProcessFeaturesIdentifiers.EnvironmentVariables.ParameterCapturing.Enable)) - { - services.AddHostedService(); - } + // TODO: remove the HostingStartup project. }); ToolIdentifiers.EnableEnvVar(InProcessFeaturesIdentifiers.EnvironmentVariables.AvailableInfrastructure.HostingStartup); diff --git a/src/Microsoft.Diagnostics.Monitoring.StartupHook/DiagnosticsBootstrapper.cs b/src/Microsoft.Diagnostics.Monitoring.StartupHook/DiagnosticsBootstrapper.cs index 414c677e5b3..66d06861518 100644 --- a/src/Microsoft.Diagnostics.Monitoring.StartupHook/DiagnosticsBootstrapper.cs +++ b/src/Microsoft.Diagnostics.Monitoring.StartupHook/DiagnosticsBootstrapper.cs @@ -3,6 +3,7 @@ using Microsoft.Diagnostics.Monitoring.StartupHook.Exceptions; using Microsoft.Diagnostics.Monitoring.StartupHook.Monitoring; +using Microsoft.Diagnostics.Monitoring.StartupHook.ParameterCapturing; using Microsoft.Diagnostics.Tools.Monitor; using Microsoft.Diagnostics.Tools.Monitor.HostingStartup; using Microsoft.Diagnostics.Tools.Monitor.Profiler; @@ -18,6 +19,7 @@ internal sealed class DiagnosticsBootstrapper : { private readonly CurrentAppDomainExceptionProcessor _exceptionProcessor; private readonly AspNetHostingStartupLoader? _hostingStartupLoader; + private readonly ParameterCapturingService? _parameterCapturingService; private long _disposedState; @@ -44,6 +46,12 @@ public DiagnosticsBootstrapper() new MessageDispatcher.ProfilerMessageSource(CommandSet.StartupHook)); ToolIdentifiers.EnableEnvVar(InProcessFeaturesIdentifiers.EnvironmentVariables.AvailableInfrastructure.ManagedMessaging); } + + if (ToolIdentifiers.IsEnvVarEnabled(InProcessFeaturesIdentifiers.EnvironmentVariables.ParameterCapturing.Enable)) + { + _parameterCapturingService = new(); + _parameterCapturingService.Start(); + } } catch { @@ -58,6 +66,8 @@ public void Dispose() return; _exceptionProcessor.Dispose(); + _parameterCapturingService?.Stop(); + _parameterCapturingService?.Dispose(); _hostingStartupLoader?.Dispose(); SharedInternals.MessageDispatcher?.Dispose(); } diff --git a/src/Microsoft.Diagnostics.Monitoring.StartupHook/Microsoft.Diagnostics.Monitoring.StartupHook.csproj b/src/Microsoft.Diagnostics.Monitoring.StartupHook/Microsoft.Diagnostics.Monitoring.StartupHook.csproj index 0311295165c..8459975bcf3 100644 --- a/src/Microsoft.Diagnostics.Monitoring.StartupHook/Microsoft.Diagnostics.Monitoring.StartupHook.csproj +++ b/src/Microsoft.Diagnostics.Monitoring.StartupHook/Microsoft.Diagnostics.Monitoring.StartupHook.csproj @@ -17,6 +17,7 @@ + @@ -32,4 +33,19 @@ + + + True + True + ParameterCapturingStrings.resx + + + + + + ResXFileCodeGenerator + ParameterCapturingStrings.Designer.cs + + + diff --git a/src/Microsoft.Diagnostics.Monitoring.HostingStartup/ParameterCapturing/Boxing/BoxingInstructions.cs b/src/Microsoft.Diagnostics.Monitoring.StartupHook/ParameterCapturing/Boxing/BoxingInstructions.cs similarity index 98% rename from src/Microsoft.Diagnostics.Monitoring.HostingStartup/ParameterCapturing/Boxing/BoxingInstructions.cs rename to src/Microsoft.Diagnostics.Monitoring.StartupHook/ParameterCapturing/Boxing/BoxingInstructions.cs index 6f4dfa23120..10c049d724b 100644 --- a/src/Microsoft.Diagnostics.Monitoring.HostingStartup/ParameterCapturing/Boxing/BoxingInstructions.cs +++ b/src/Microsoft.Diagnostics.Monitoring.StartupHook/ParameterCapturing/Boxing/BoxingInstructions.cs @@ -1,14 +1,14 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. -using Microsoft.Diagnostics.Monitoring.HostingStartup.ParameterCapturing.FunctionProbes; +using Microsoft.Diagnostics.Monitoring.StartupHook.ParameterCapturing.FunctionProbes; using System; using System.Diagnostics; using System.Reflection; using System.Reflection.Metadata; using System.Reflection.Metadata.Ecma335; -namespace Microsoft.Diagnostics.Monitoring.HostingStartup.ParameterCapturing.Boxing +namespace Microsoft.Diagnostics.Monitoring.StartupHook.ParameterCapturing.Boxing { internal static class BoxingInstructions { diff --git a/src/Microsoft.Diagnostics.Monitoring.HostingStartup/ParameterCapturing/Boxing/BoxingTokensSignatureProvider.cs b/src/Microsoft.Diagnostics.Monitoring.StartupHook/ParameterCapturing/Boxing/BoxingTokensSignatureProvider.cs similarity index 94% rename from src/Microsoft.Diagnostics.Monitoring.HostingStartup/ParameterCapturing/Boxing/BoxingTokensSignatureProvider.cs rename to src/Microsoft.Diagnostics.Monitoring.StartupHook/ParameterCapturing/Boxing/BoxingTokensSignatureProvider.cs index 010129a8756..11b8d0c4366 100644 --- a/src/Microsoft.Diagnostics.Monitoring.HostingStartup/ParameterCapturing/Boxing/BoxingTokensSignatureProvider.cs +++ b/src/Microsoft.Diagnostics.Monitoring.StartupHook/ParameterCapturing/Boxing/BoxingTokensSignatureProvider.cs @@ -1,12 +1,12 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. -using Microsoft.Diagnostics.Monitoring.HostingStartup.ParameterCapturing.FunctionProbes; +using Microsoft.Diagnostics.Monitoring.StartupHook.ParameterCapturing.FunctionProbes; using System.Collections.Immutable; using System.Reflection.Metadata; using System.Reflection.Metadata.Ecma335; -namespace Microsoft.Diagnostics.Monitoring.HostingStartup.ParameterCapturing.Boxing +namespace Microsoft.Diagnostics.Monitoring.StartupHook.ParameterCapturing.Boxing { /// /// This decoder is made specifically for parameters of the following types: diff --git a/src/Microsoft.Diagnostics.Monitoring.HostingStartup/ParameterCapturing/Boxing/MethodDefinitionExtensions.cs b/src/Microsoft.Diagnostics.Monitoring.StartupHook/ParameterCapturing/Boxing/MethodDefinitionExtensions.cs similarity index 97% rename from src/Microsoft.Diagnostics.Monitoring.HostingStartup/ParameterCapturing/Boxing/MethodDefinitionExtensions.cs rename to src/Microsoft.Diagnostics.Monitoring.StartupHook/ParameterCapturing/Boxing/MethodDefinitionExtensions.cs index 307bdac6629..9758230fdfd 100644 --- a/src/Microsoft.Diagnostics.Monitoring.HostingStartup/ParameterCapturing/Boxing/MethodDefinitionExtensions.cs +++ b/src/Microsoft.Diagnostics.Monitoring.StartupHook/ParameterCapturing/Boxing/MethodDefinitionExtensions.cs @@ -1,14 +1,14 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. -using Microsoft.Diagnostics.Monitoring.HostingStartup.ParameterCapturing.FunctionProbes; +using Microsoft.Diagnostics.Monitoring.StartupHook.ParameterCapturing.FunctionProbes; using System; using System.Collections.Immutable; using System.Diagnostics; using System.Reflection.Metadata; using System.Reflection.Metadata.Ecma335; -namespace Microsoft.Diagnostics.Monitoring.HostingStartup.ParameterCapturing.Boxing +namespace Microsoft.Diagnostics.Monitoring.StartupHook.ParameterCapturing.Boxing { internal static class MethodDefinitionExtensions { diff --git a/src/Microsoft.Diagnostics.Monitoring.HostingStartup/ParameterCapturing/DeniedMethodsException.cs b/src/Microsoft.Diagnostics.Monitoring.StartupHook/ParameterCapturing/DeniedMethodsException.cs similarity index 93% rename from src/Microsoft.Diagnostics.Monitoring.HostingStartup/ParameterCapturing/DeniedMethodsException.cs rename to src/Microsoft.Diagnostics.Monitoring.StartupHook/ParameterCapturing/DeniedMethodsException.cs index b8b3675945a..bb433ca9f7b 100644 --- a/src/Microsoft.Diagnostics.Monitoring.HostingStartup/ParameterCapturing/DeniedMethodsException.cs +++ b/src/Microsoft.Diagnostics.Monitoring.StartupHook/ParameterCapturing/DeniedMethodsException.cs @@ -7,7 +7,7 @@ using System.Globalization; using System.Text; -namespace Microsoft.Diagnostics.Monitoring.HostingStartup.ParameterCapturing +namespace Microsoft.Diagnostics.Monitoring.StartupHook.ParameterCapturing { internal sealed class DeniedMethodsException : ArgumentException { diff --git a/src/Microsoft.Diagnostics.Monitoring.HostingStartup/ParameterCapturing/Eventing/AsyncParameterCapturingEventSource.cs b/src/Microsoft.Diagnostics.Monitoring.StartupHook/ParameterCapturing/Eventing/AsyncParameterCapturingEventSource.cs similarity index 96% rename from src/Microsoft.Diagnostics.Monitoring.HostingStartup/ParameterCapturing/Eventing/AsyncParameterCapturingEventSource.cs rename to src/Microsoft.Diagnostics.Monitoring.StartupHook/ParameterCapturing/Eventing/AsyncParameterCapturingEventSource.cs index c034a77fa48..4dbcfdf9e86 100644 --- a/src/Microsoft.Diagnostics.Monitoring.HostingStartup/ParameterCapturing/Eventing/AsyncParameterCapturingEventSource.cs +++ b/src/Microsoft.Diagnostics.Monitoring.StartupHook/ParameterCapturing/Eventing/AsyncParameterCapturingEventSource.cs @@ -1,13 +1,12 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. -using Microsoft.Diagnostics.Monitoring.StartupHook; using System; using System.Collections.Concurrent; using System.Diagnostics; using System.Threading; -namespace Microsoft.Diagnostics.Monitoring.HostingStartup.ParameterCapturing.Eventing +namespace Microsoft.Diagnostics.Monitoring.StartupHook.ParameterCapturing.Eventing { internal sealed class AsyncParameterCapturingEventSource : IDisposable { diff --git a/src/Microsoft.Diagnostics.Monitoring.HostingStartup/ParameterCapturing/Eventing/ParameterCapturingEventSource.cs b/src/Microsoft.Diagnostics.Monitoring.StartupHook/ParameterCapturing/Eventing/ParameterCapturingEventSource.cs similarity index 98% rename from src/Microsoft.Diagnostics.Monitoring.HostingStartup/ParameterCapturing/Eventing/ParameterCapturingEventSource.cs rename to src/Microsoft.Diagnostics.Monitoring.StartupHook/ParameterCapturing/Eventing/ParameterCapturingEventSource.cs index 49460e11446..c1e81fbccd8 100644 --- a/src/Microsoft.Diagnostics.Monitoring.HostingStartup/ParameterCapturing/Eventing/ParameterCapturingEventSource.cs +++ b/src/Microsoft.Diagnostics.Monitoring.StartupHook/ParameterCapturing/Eventing/ParameterCapturingEventSource.cs @@ -9,7 +9,7 @@ using System.Reflection; using static Microsoft.Diagnostics.Tools.Monitor.ParameterCapturing.ParameterCapturingEvents; -namespace Microsoft.Diagnostics.Monitoring.HostingStartup.ParameterCapturing.Eventing +namespace Microsoft.Diagnostics.Monitoring.StartupHook.ParameterCapturing.Eventing { [EventSource(Name = ParameterCapturingEvents.SourceName)] internal sealed class ParameterCapturingEventSource : AbstractMonitorEventSource diff --git a/src/Microsoft.Diagnostics.Monitoring.HostingStartup/ParameterCapturing/FunctionProbes/EventSourceEmittingProbes.cs b/src/Microsoft.Diagnostics.Monitoring.StartupHook/ParameterCapturing/FunctionProbes/EventSourceEmittingProbes.cs similarity index 93% rename from src/Microsoft.Diagnostics.Monitoring.HostingStartup/ParameterCapturing/FunctionProbes/EventSourceEmittingProbes.cs rename to src/Microsoft.Diagnostics.Monitoring.StartupHook/ParameterCapturing/FunctionProbes/EventSourceEmittingProbes.cs index 08cbf44b053..b44a572d380 100644 --- a/src/Microsoft.Diagnostics.Monitoring.HostingStartup/ParameterCapturing/FunctionProbes/EventSourceEmittingProbes.cs +++ b/src/Microsoft.Diagnostics.Monitoring.StartupHook/ParameterCapturing/FunctionProbes/EventSourceEmittingProbes.cs @@ -1,13 +1,13 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. -using Microsoft.Diagnostics.Monitoring.HostingStartup.ParameterCapturing.Eventing; -using Microsoft.Diagnostics.Monitoring.HostingStartup.ParameterCapturing.ObjectFormatting; +using Microsoft.Diagnostics.Monitoring.StartupHook.ParameterCapturing.Eventing; +using Microsoft.Diagnostics.Monitoring.StartupHook.ParameterCapturing.ObjectFormatting; using System; using System.Collections.Generic; using System.Reflection; -namespace Microsoft.Diagnostics.Monitoring.HostingStartup.ParameterCapturing.FunctionProbes +namespace Microsoft.Diagnostics.Monitoring.StartupHook.ParameterCapturing.FunctionProbes { internal sealed class EventSourceEmittingProbes : IFunctionProbes { diff --git a/src/Microsoft.Diagnostics.Monitoring.HostingStartup/ParameterCapturing/FunctionProbes/FunctionProbesManager.cs b/src/Microsoft.Diagnostics.Monitoring.StartupHook/ParameterCapturing/FunctionProbes/FunctionProbesManager.cs similarity index 97% rename from src/Microsoft.Diagnostics.Monitoring.HostingStartup/ParameterCapturing/FunctionProbes/FunctionProbesManager.cs rename to src/Microsoft.Diagnostics.Monitoring.StartupHook/ParameterCapturing/FunctionProbes/FunctionProbesManager.cs index 2515e186653..ce1416e360f 100644 --- a/src/Microsoft.Diagnostics.Monitoring.HostingStartup/ParameterCapturing/FunctionProbes/FunctionProbesManager.cs +++ b/src/Microsoft.Diagnostics.Monitoring.StartupHook/ParameterCapturing/FunctionProbes/FunctionProbesManager.cs @@ -1,9 +1,8 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. -using Microsoft.Diagnostics.Monitoring.HostingStartup.ParameterCapturing.Boxing; -using Microsoft.Diagnostics.Monitoring.HostingStartup.ParameterCapturing.ObjectFormatting; -using Microsoft.Diagnostics.Monitoring.StartupHook; +using Microsoft.Diagnostics.Monitoring.StartupHook.ParameterCapturing.Boxing; +using Microsoft.Diagnostics.Monitoring.StartupHook.ParameterCapturing.ObjectFormatting; using Microsoft.Diagnostics.Tools.Monitor.Profiler; using System; using System.Collections.Generic; @@ -14,7 +13,7 @@ using System.Threading; using System.Threading.Tasks; -namespace Microsoft.Diagnostics.Monitoring.HostingStartup.ParameterCapturing.FunctionProbes +namespace Microsoft.Diagnostics.Monitoring.StartupHook.ParameterCapturing.FunctionProbes { internal sealed class FunctionProbesManager : IFunctionProbesManager { @@ -137,7 +136,7 @@ private void OnFault(ulong uniquifier) OnProbeFault?.Invoke(this, instrumentedMethod); } - + private void TransitionStateFromHr(TaskCompletionSource? taskCompletionSource, int hresult, long expectedState, long succeededState, long failedState) { Exception? ex = Marshal.GetExceptionForHR(hresult); diff --git a/src/Microsoft.Diagnostics.Monitoring.HostingStartup/ParameterCapturing/FunctionProbes/FunctionProbesState.cs b/src/Microsoft.Diagnostics.Monitoring.StartupHook/ParameterCapturing/FunctionProbes/FunctionProbesState.cs similarity index 86% rename from src/Microsoft.Diagnostics.Monitoring.HostingStartup/ParameterCapturing/FunctionProbes/FunctionProbesState.cs rename to src/Microsoft.Diagnostics.Monitoring.StartupHook/ParameterCapturing/FunctionProbes/FunctionProbesState.cs index 21bc960f331..6b05187affd 100644 --- a/src/Microsoft.Diagnostics.Monitoring.HostingStartup/ParameterCapturing/FunctionProbes/FunctionProbesState.cs +++ b/src/Microsoft.Diagnostics.Monitoring.StartupHook/ParameterCapturing/FunctionProbes/FunctionProbesState.cs @@ -3,7 +3,7 @@ using System.Collections.ObjectModel; -namespace Microsoft.Diagnostics.Monitoring.HostingStartup.ParameterCapturing.FunctionProbes +namespace Microsoft.Diagnostics.Monitoring.StartupHook.ParameterCapturing.FunctionProbes { internal sealed class FunctionProbesState { diff --git a/src/Microsoft.Diagnostics.Monitoring.HostingStartup/ParameterCapturing/FunctionProbes/FunctionProbesStub.cs b/src/Microsoft.Diagnostics.Monitoring.StartupHook/ParameterCapturing/FunctionProbes/FunctionProbesStub.cs similarity index 89% rename from src/Microsoft.Diagnostics.Monitoring.HostingStartup/ParameterCapturing/FunctionProbes/FunctionProbesStub.cs rename to src/Microsoft.Diagnostics.Monitoring.StartupHook/ParameterCapturing/FunctionProbes/FunctionProbesStub.cs index bd84b097f67..f0b4cdc51db 100644 --- a/src/Microsoft.Diagnostics.Monitoring.HostingStartup/ParameterCapturing/FunctionProbes/FunctionProbesStub.cs +++ b/src/Microsoft.Diagnostics.Monitoring.StartupHook/ParameterCapturing/FunctionProbes/FunctionProbesStub.cs @@ -1,10 +1,9 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. -using Microsoft.Diagnostics.Monitoring.StartupHook; using System; -namespace Microsoft.Diagnostics.Monitoring.HostingStartup.ParameterCapturing.FunctionProbes +namespace Microsoft.Diagnostics.Monitoring.StartupHook.ParameterCapturing.FunctionProbes { public static class FunctionProbesStub { diff --git a/src/Microsoft.Diagnostics.Monitoring.HostingStartup/ParameterCapturing/FunctionProbes/IFunctionProbes.cs b/src/Microsoft.Diagnostics.Monitoring.StartupHook/ParameterCapturing/FunctionProbes/IFunctionProbes.cs similarity index 88% rename from src/Microsoft.Diagnostics.Monitoring.HostingStartup/ParameterCapturing/FunctionProbes/IFunctionProbes.cs rename to src/Microsoft.Diagnostics.Monitoring.StartupHook/ParameterCapturing/FunctionProbes/IFunctionProbes.cs index b33985f23e9..87b78bd2e44 100644 --- a/src/Microsoft.Diagnostics.Monitoring.HostingStartup/ParameterCapturing/FunctionProbes/IFunctionProbes.cs +++ b/src/Microsoft.Diagnostics.Monitoring.StartupHook/ParameterCapturing/FunctionProbes/IFunctionProbes.cs @@ -5,7 +5,7 @@ using System.Collections.Generic; using System.Reflection; -namespace Microsoft.Diagnostics.Monitoring.HostingStartup.ParameterCapturing.FunctionProbes +namespace Microsoft.Diagnostics.Monitoring.StartupHook.ParameterCapturing.FunctionProbes { internal interface IFunctionProbes { diff --git a/src/Microsoft.Diagnostics.Monitoring.HostingStartup/ParameterCapturing/FunctionProbes/IFunctionProbesManager.cs b/src/Microsoft.Diagnostics.Monitoring.StartupHook/ParameterCapturing/FunctionProbes/IFunctionProbesManager.cs similarity index 86% rename from src/Microsoft.Diagnostics.Monitoring.HostingStartup/ParameterCapturing/FunctionProbes/IFunctionProbesManager.cs rename to src/Microsoft.Diagnostics.Monitoring.StartupHook/ParameterCapturing/FunctionProbes/IFunctionProbesManager.cs index 59edc813f34..e6918c7e0c6 100644 --- a/src/Microsoft.Diagnostics.Monitoring.HostingStartup/ParameterCapturing/FunctionProbes/IFunctionProbesManager.cs +++ b/src/Microsoft.Diagnostics.Monitoring.StartupHook/ParameterCapturing/FunctionProbes/IFunctionProbesManager.cs @@ -7,7 +7,7 @@ using System.Threading; using System.Threading.Tasks; -namespace Microsoft.Diagnostics.Monitoring.HostingStartup.ParameterCapturing.FunctionProbes +namespace Microsoft.Diagnostics.Monitoring.StartupHook.ParameterCapturing.FunctionProbes { internal interface IFunctionProbesManager : IDisposable { diff --git a/src/Microsoft.Diagnostics.Monitoring.HostingStartup/ParameterCapturing/FunctionProbes/InstrumentedMethod.cs b/src/Microsoft.Diagnostics.Monitoring.StartupHook/ParameterCapturing/FunctionProbes/InstrumentedMethod.cs similarity index 93% rename from src/Microsoft.Diagnostics.Monitoring.HostingStartup/ParameterCapturing/FunctionProbes/InstrumentedMethod.cs rename to src/Microsoft.Diagnostics.Monitoring.StartupHook/ParameterCapturing/FunctionProbes/InstrumentedMethod.cs index e1b65a2f497..38c0fd63a3d 100644 --- a/src/Microsoft.Diagnostics.Monitoring.HostingStartup/ParameterCapturing/FunctionProbes/InstrumentedMethod.cs +++ b/src/Microsoft.Diagnostics.Monitoring.StartupHook/ParameterCapturing/FunctionProbes/InstrumentedMethod.cs @@ -1,10 +1,10 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. -using Microsoft.Diagnostics.Monitoring.HostingStartup.ParameterCapturing.Boxing; +using Microsoft.Diagnostics.Monitoring.StartupHook.ParameterCapturing.Boxing; using System.Reflection; -namespace Microsoft.Diagnostics.Monitoring.HostingStartup.ParameterCapturing.FunctionProbes +namespace Microsoft.Diagnostics.Monitoring.StartupHook.ParameterCapturing.FunctionProbes { internal enum ParameterCaptureMode { diff --git a/src/Microsoft.Diagnostics.Monitoring.HostingStartup/ParameterCapturing/FunctionProbes/ProfilerAbi.cs b/src/Microsoft.Diagnostics.Monitoring.StartupHook/ParameterCapturing/FunctionProbes/ProfilerAbi.cs similarity index 95% rename from src/Microsoft.Diagnostics.Monitoring.HostingStartup/ParameterCapturing/FunctionProbes/ProfilerAbi.cs rename to src/Microsoft.Diagnostics.Monitoring.StartupHook/ParameterCapturing/FunctionProbes/ProfilerAbi.cs index fdc1a491d59..dd85a7690dc 100644 --- a/src/Microsoft.Diagnostics.Monitoring.HostingStartup/ParameterCapturing/FunctionProbes/ProfilerAbi.cs +++ b/src/Microsoft.Diagnostics.Monitoring.StartupHook/ParameterCapturing/FunctionProbes/ProfilerAbi.cs @@ -9,7 +9,7 @@ using System.Runtime.InteropServices; -namespace Microsoft.Diagnostics.Monitoring.HostingStartup.ParameterCapturing.FunctionProbes +namespace Microsoft.Diagnostics.Monitoring.StartupHook.ParameterCapturing.FunctionProbes { internal enum SpecialCaseBoxingTypes : uint { diff --git a/src/Microsoft.Diagnostics.Monitoring.HostingStartup/ParameterCapturing/IMethodDescriptionValidator.cs b/src/Microsoft.Diagnostics.Monitoring.StartupHook/ParameterCapturing/IMethodDescriptionValidator.cs similarity index 83% rename from src/Microsoft.Diagnostics.Monitoring.HostingStartup/ParameterCapturing/IMethodDescriptionValidator.cs rename to src/Microsoft.Diagnostics.Monitoring.StartupHook/ParameterCapturing/IMethodDescriptionValidator.cs index 5c2f367ff75..41668d3ddd0 100644 --- a/src/Microsoft.Diagnostics.Monitoring.HostingStartup/ParameterCapturing/IMethodDescriptionValidator.cs +++ b/src/Microsoft.Diagnostics.Monitoring.StartupHook/ParameterCapturing/IMethodDescriptionValidator.cs @@ -3,7 +3,7 @@ using Microsoft.Diagnostics.Monitoring.StartupHook.MonitorMessageDispatcher.Models; -namespace Microsoft.Diagnostics.Monitoring.HostingStartup.ParameterCapturing +namespace Microsoft.Diagnostics.Monitoring.StartupHook.ParameterCapturing { internal interface IMethodDescriptionValidator { diff --git a/src/Microsoft.Diagnostics.Monitoring.HostingStartup/ParameterCapturing/MethodDescriptionValidator.cs b/src/Microsoft.Diagnostics.Monitoring.StartupHook/ParameterCapturing/MethodDescriptionValidator.cs similarity index 93% rename from src/Microsoft.Diagnostics.Monitoring.HostingStartup/ParameterCapturing/MethodDescriptionValidator.cs rename to src/Microsoft.Diagnostics.Monitoring.StartupHook/ParameterCapturing/MethodDescriptionValidator.cs index bb624a4cdc2..7d09f5e072f 100644 --- a/src/Microsoft.Diagnostics.Monitoring.HostingStartup/ParameterCapturing/MethodDescriptionValidator.cs +++ b/src/Microsoft.Diagnostics.Monitoring.StartupHook/ParameterCapturing/MethodDescriptionValidator.cs @@ -3,7 +3,7 @@ using Microsoft.Diagnostics.Monitoring.StartupHook.MonitorMessageDispatcher.Models; -namespace Microsoft.Diagnostics.Monitoring.HostingStartup.ParameterCapturing +namespace Microsoft.Diagnostics.Monitoring.StartupHook.ParameterCapturing { internal class MethodDescriptionValidator : IMethodDescriptionValidator { diff --git a/src/Microsoft.Diagnostics.Monitoring.HostingStartup/ParameterCapturing/MethodInfoExtensions.cs b/src/Microsoft.Diagnostics.Monitoring.StartupHook/ParameterCapturing/MethodInfoExtensions.cs similarity index 91% rename from src/Microsoft.Diagnostics.Monitoring.HostingStartup/ParameterCapturing/MethodInfoExtensions.cs rename to src/Microsoft.Diagnostics.Monitoring.StartupHook/ParameterCapturing/MethodInfoExtensions.cs index 8f94594ca69..b580295aa72 100644 --- a/src/Microsoft.Diagnostics.Monitoring.HostingStartup/ParameterCapturing/MethodInfoExtensions.cs +++ b/src/Microsoft.Diagnostics.Monitoring.StartupHook/ParameterCapturing/MethodInfoExtensions.cs @@ -3,7 +3,7 @@ using System.Reflection; -namespace Microsoft.Diagnostics.Monitoring.HostingStartup.ParameterCapturing +namespace Microsoft.Diagnostics.Monitoring.StartupHook.ParameterCapturing { internal static class MethodInfoExtensions { diff --git a/src/Microsoft.Diagnostics.Monitoring.HostingStartup/ParameterCapturing/MethodResolver.cs b/src/Microsoft.Diagnostics.Monitoring.StartupHook/ParameterCapturing/MethodResolver.cs similarity index 98% rename from src/Microsoft.Diagnostics.Monitoring.HostingStartup/ParameterCapturing/MethodResolver.cs rename to src/Microsoft.Diagnostics.Monitoring.StartupHook/ParameterCapturing/MethodResolver.cs index 3399fab720f..4d0016e3dea 100644 --- a/src/Microsoft.Diagnostics.Monitoring.HostingStartup/ParameterCapturing/MethodResolver.cs +++ b/src/Microsoft.Diagnostics.Monitoring.StartupHook/ParameterCapturing/MethodResolver.cs @@ -7,7 +7,7 @@ using System.Linq; using System.Reflection; -namespace Microsoft.Diagnostics.Monitoring.HostingStartup.ParameterCapturing +namespace Microsoft.Diagnostics.Monitoring.StartupHook.ParameterCapturing { internal sealed class MethodResolver { diff --git a/src/Microsoft.Diagnostics.Monitoring.HostingStartup/ParameterCapturing/MethodSignature.cs b/src/Microsoft.Diagnostics.Monitoring.StartupHook/ParameterCapturing/MethodSignature.cs similarity index 98% rename from src/Microsoft.Diagnostics.Monitoring.HostingStartup/ParameterCapturing/MethodSignature.cs rename to src/Microsoft.Diagnostics.Monitoring.StartupHook/ParameterCapturing/MethodSignature.cs index 2cfc29b3de5..3bebdb796fe 100644 --- a/src/Microsoft.Diagnostics.Monitoring.HostingStartup/ParameterCapturing/MethodSignature.cs +++ b/src/Microsoft.Diagnostics.Monitoring.StartupHook/ParameterCapturing/MethodSignature.cs @@ -6,7 +6,7 @@ using System.Reflection; using System.Text; -namespace Microsoft.Diagnostics.Monitoring.HostingStartup.ParameterCapturing +namespace Microsoft.Diagnostics.Monitoring.StartupHook.ParameterCapturing { internal sealed class MethodSignature(MethodInfo method) { diff --git a/src/Microsoft.Diagnostics.Monitoring.HostingStartup/ParameterCapturing/ObjectFormatting/Formatters/DebuggerDisplay/DebuggerDisplayFormatter.cs b/src/Microsoft.Diagnostics.Monitoring.StartupHook/ParameterCapturing/ObjectFormatting/Formatters/DebuggerDisplay/DebuggerDisplayFormatter.cs similarity index 92% rename from src/Microsoft.Diagnostics.Monitoring.HostingStartup/ParameterCapturing/ObjectFormatting/Formatters/DebuggerDisplay/DebuggerDisplayFormatter.cs rename to src/Microsoft.Diagnostics.Monitoring.StartupHook/ParameterCapturing/ObjectFormatting/Formatters/DebuggerDisplay/DebuggerDisplayFormatter.cs index 3b7b4078814..ca7a4cc105a 100644 --- a/src/Microsoft.Diagnostics.Monitoring.HostingStartup/ParameterCapturing/ObjectFormatting/Formatters/DebuggerDisplay/DebuggerDisplayFormatter.cs +++ b/src/Microsoft.Diagnostics.Monitoring.StartupHook/ParameterCapturing/ObjectFormatting/Formatters/DebuggerDisplay/DebuggerDisplayFormatter.cs @@ -6,9 +6,9 @@ using System.Diagnostics; using System.Linq; using System.Reflection; -using static Microsoft.Diagnostics.Monitoring.HostingStartup.ParameterCapturing.ObjectFormatting.Formatters.DebuggerDisplay.DebuggerDisplayParser; +using static Microsoft.Diagnostics.Monitoring.StartupHook.ParameterCapturing.ObjectFormatting.Formatters.DebuggerDisplay.DebuggerDisplayParser; -namespace Microsoft.Diagnostics.Monitoring.HostingStartup.ParameterCapturing.ObjectFormatting.Formatters.DebuggerDisplay +namespace Microsoft.Diagnostics.Monitoring.StartupHook.ParameterCapturing.ObjectFormatting.Formatters.DebuggerDisplay { internal static class DebuggerDisplayFormatter { diff --git a/src/Microsoft.Diagnostics.Monitoring.HostingStartup/ParameterCapturing/ObjectFormatting/Formatters/DebuggerDisplay/DebuggerDisplayParser.cs b/src/Microsoft.Diagnostics.Monitoring.StartupHook/ParameterCapturing/ObjectFormatting/Formatters/DebuggerDisplay/DebuggerDisplayParser.cs similarity index 98% rename from src/Microsoft.Diagnostics.Monitoring.HostingStartup/ParameterCapturing/ObjectFormatting/Formatters/DebuggerDisplay/DebuggerDisplayParser.cs rename to src/Microsoft.Diagnostics.Monitoring.StartupHook/ParameterCapturing/ObjectFormatting/Formatters/DebuggerDisplay/DebuggerDisplayParser.cs index fd693269093..3ea670813d9 100644 --- a/src/Microsoft.Diagnostics.Monitoring.HostingStartup/ParameterCapturing/ObjectFormatting/Formatters/DebuggerDisplay/DebuggerDisplayParser.cs +++ b/src/Microsoft.Diagnostics.Monitoring.StartupHook/ParameterCapturing/ObjectFormatting/Formatters/DebuggerDisplay/DebuggerDisplayParser.cs @@ -5,7 +5,7 @@ using System.Collections.Generic; using System.Text; -namespace Microsoft.Diagnostics.Monitoring.HostingStartup.ParameterCapturing.ObjectFormatting.Formatters.DebuggerDisplay +namespace Microsoft.Diagnostics.Monitoring.StartupHook.ParameterCapturing.ObjectFormatting.Formatters.DebuggerDisplay { internal static class DebuggerDisplayParser { diff --git a/src/Microsoft.Diagnostics.Monitoring.HostingStartup/ParameterCapturing/ObjectFormatting/Formatters/DebuggerDisplay/ExpressionBinder.cs b/src/Microsoft.Diagnostics.Monitoring.StartupHook/ParameterCapturing/ObjectFormatting/Formatters/DebuggerDisplay/ExpressionBinder.cs similarity index 97% rename from src/Microsoft.Diagnostics.Monitoring.HostingStartup/ParameterCapturing/ObjectFormatting/Formatters/DebuggerDisplay/ExpressionBinder.cs rename to src/Microsoft.Diagnostics.Monitoring.StartupHook/ParameterCapturing/ObjectFormatting/Formatters/DebuggerDisplay/ExpressionBinder.cs index 478c74fd68b..ca51028df86 100644 --- a/src/Microsoft.Diagnostics.Monitoring.HostingStartup/ParameterCapturing/ObjectFormatting/Formatters/DebuggerDisplay/ExpressionBinder.cs +++ b/src/Microsoft.Diagnostics.Monitoring.StartupHook/ParameterCapturing/ObjectFormatting/Formatters/DebuggerDisplay/ExpressionBinder.cs @@ -4,9 +4,9 @@ using System; using System.Collections.Generic; using System.Reflection; -using static Microsoft.Diagnostics.Monitoring.HostingStartup.ParameterCapturing.ObjectFormatting.Formatters.DebuggerDisplay.DebuggerDisplayParser; +using static Microsoft.Diagnostics.Monitoring.StartupHook.ParameterCapturing.ObjectFormatting.Formatters.DebuggerDisplay.DebuggerDisplayParser; -namespace Microsoft.Diagnostics.Monitoring.HostingStartup.ParameterCapturing.ObjectFormatting.Formatters.DebuggerDisplay +namespace Microsoft.Diagnostics.Monitoring.StartupHook.ParameterCapturing.ObjectFormatting.Formatters.DebuggerDisplay { internal static class ExpressionBinder { diff --git a/src/Microsoft.Diagnostics.Monitoring.HostingStartup/ParameterCapturing/ObjectFormatting/Formatters/RuntimeFormatters.cs b/src/Microsoft.Diagnostics.Monitoring.StartupHook/ParameterCapturing/ObjectFormatting/Formatters/RuntimeFormatters.cs similarity index 93% rename from src/Microsoft.Diagnostics.Monitoring.HostingStartup/ParameterCapturing/ObjectFormatting/Formatters/RuntimeFormatters.cs rename to src/Microsoft.Diagnostics.Monitoring.StartupHook/ParameterCapturing/ObjectFormatting/Formatters/RuntimeFormatters.cs index 41cead7910f..645654e3ea8 100644 --- a/src/Microsoft.Diagnostics.Monitoring.HostingStartup/ParameterCapturing/ObjectFormatting/Formatters/RuntimeFormatters.cs +++ b/src/Microsoft.Diagnostics.Monitoring.StartupHook/ParameterCapturing/ObjectFormatting/Formatters/RuntimeFormatters.cs @@ -4,7 +4,7 @@ using System; using System.Globalization; -namespace Microsoft.Diagnostics.Monitoring.HostingStartup.ParameterCapturing.ObjectFormatting +namespace Microsoft.Diagnostics.Monitoring.StartupHook.ParameterCapturing.ObjectFormatting { internal static class RuntimeFormatters { diff --git a/src/Microsoft.Diagnostics.Monitoring.HostingStartup/ParameterCapturing/ObjectFormatting/ObjectFormatter.cs b/src/Microsoft.Diagnostics.Monitoring.StartupHook/ParameterCapturing/ObjectFormatting/ObjectFormatter.cs similarity index 97% rename from src/Microsoft.Diagnostics.Monitoring.HostingStartup/ParameterCapturing/ObjectFormatting/ObjectFormatter.cs rename to src/Microsoft.Diagnostics.Monitoring.StartupHook/ParameterCapturing/ObjectFormatting/ObjectFormatter.cs index d556b7a6822..0c8970d00c5 100644 --- a/src/Microsoft.Diagnostics.Monitoring.HostingStartup/ParameterCapturing/ObjectFormatting/ObjectFormatter.cs +++ b/src/Microsoft.Diagnostics.Monitoring.StartupHook/ParameterCapturing/ObjectFormatting/ObjectFormatter.cs @@ -4,7 +4,7 @@ using System; using static Microsoft.Diagnostics.Tools.Monitor.ParameterCapturing.ParameterCapturingEvents; -namespace Microsoft.Diagnostics.Monitoring.HostingStartup.ParameterCapturing.ObjectFormatting +namespace Microsoft.Diagnostics.Monitoring.StartupHook.ParameterCapturing.ObjectFormatting { internal delegate ObjectFormatterResult ObjectFormatterFunc(object obj, FormatSpecifier formatSpecifier = FormatSpecifier.None); diff --git a/src/Microsoft.Diagnostics.Monitoring.HostingStartup/ParameterCapturing/ObjectFormatting/ObjectFormatterCache.cs b/src/Microsoft.Diagnostics.Monitoring.StartupHook/ParameterCapturing/ObjectFormatting/ObjectFormatterCache.cs similarity index 95% rename from src/Microsoft.Diagnostics.Monitoring.HostingStartup/ParameterCapturing/ObjectFormatting/ObjectFormatterCache.cs rename to src/Microsoft.Diagnostics.Monitoring.StartupHook/ParameterCapturing/ObjectFormatting/ObjectFormatterCache.cs index f68cb2fbb3b..546b5d1a39b 100644 --- a/src/Microsoft.Diagnostics.Monitoring.HostingStartup/ParameterCapturing/ObjectFormatting/ObjectFormatterCache.cs +++ b/src/Microsoft.Diagnostics.Monitoring.StartupHook/ParameterCapturing/ObjectFormatting/ObjectFormatterCache.cs @@ -6,7 +6,7 @@ using System.Diagnostics; using System.Reflection; -namespace Microsoft.Diagnostics.Monitoring.HostingStartup.ParameterCapturing.ObjectFormatting +namespace Microsoft.Diagnostics.Monitoring.StartupHook.ParameterCapturing.ObjectFormatting { [DebuggerDisplay("Count = {_cache.Count}, UseDebuggerDisplayAttribute={_useDebuggerDisplayAttribute}")] internal sealed class ObjectFormatterCache diff --git a/src/Microsoft.Diagnostics.Monitoring.HostingStartup/ParameterCapturing/ObjectFormatting/ObjectFormatterFactory.cs b/src/Microsoft.Diagnostics.Monitoring.StartupHook/ParameterCapturing/ObjectFormatting/ObjectFormatterFactory.cs similarity index 88% rename from src/Microsoft.Diagnostics.Monitoring.HostingStartup/ParameterCapturing/ObjectFormatting/ObjectFormatterFactory.cs rename to src/Microsoft.Diagnostics.Monitoring.StartupHook/ParameterCapturing/ObjectFormatting/ObjectFormatterFactory.cs index 57cdb3a8c28..11cce22223a 100644 --- a/src/Microsoft.Diagnostics.Monitoring.HostingStartup/ParameterCapturing/ObjectFormatting/ObjectFormatterFactory.cs +++ b/src/Microsoft.Diagnostics.Monitoring.StartupHook/ParameterCapturing/ObjectFormatting/ObjectFormatterFactory.cs @@ -1,11 +1,11 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. -using Microsoft.Diagnostics.Monitoring.HostingStartup.ParameterCapturing.ObjectFormatting.Formatters.DebuggerDisplay; +using Microsoft.Diagnostics.Monitoring.StartupHook.ParameterCapturing.ObjectFormatting.Formatters.DebuggerDisplay; using System; using System.Collections.Generic; -namespace Microsoft.Diagnostics.Monitoring.HostingStartup.ParameterCapturing.ObjectFormatting +namespace Microsoft.Diagnostics.Monitoring.StartupHook.ParameterCapturing.ObjectFormatting { /// /// The results from GetFormatter. diff --git a/src/Microsoft.Diagnostics.Monitoring.HostingStartup/ParameterCapturing/ParameterCapturingService.cs b/src/Microsoft.Diagnostics.Monitoring.StartupHook/ParameterCapturing/ParameterCapturingService.cs similarity index 94% rename from src/Microsoft.Diagnostics.Monitoring.HostingStartup/ParameterCapturing/ParameterCapturingService.cs rename to src/Microsoft.Diagnostics.Monitoring.StartupHook/ParameterCapturing/ParameterCapturingService.cs index d8b1aadcb68..74371cc2603 100644 --- a/src/Microsoft.Diagnostics.Monitoring.HostingStartup/ParameterCapturing/ParameterCapturingService.cs +++ b/src/Microsoft.Diagnostics.Monitoring.StartupHook/ParameterCapturing/ParameterCapturingService.cs @@ -1,11 +1,10 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. -using Microsoft.Diagnostics.Monitoring.HostingStartup.ParameterCapturing.Eventing; -using Microsoft.Diagnostics.Monitoring.HostingStartup.ParameterCapturing.FunctionProbes; -using Microsoft.Diagnostics.Monitoring.HostingStartup.ParameterCapturing.Pipeline; -using Microsoft.Diagnostics.Monitoring.StartupHook; using Microsoft.Diagnostics.Monitoring.StartupHook.Monitoring; +using Microsoft.Diagnostics.Monitoring.StartupHook.ParameterCapturing.Eventing; +using Microsoft.Diagnostics.Monitoring.StartupHook.ParameterCapturing.FunctionProbes; +using Microsoft.Diagnostics.Monitoring.StartupHook.ParameterCapturing.Pipeline; using Microsoft.Diagnostics.Tools.Monitor.ParameterCapturing; using Microsoft.Diagnostics.Tools.Monitor.Profiler; using Microsoft.Diagnostics.Tools.Monitor.StartupHook; @@ -15,9 +14,8 @@ using System.Reflection; using System.Threading; using System.Threading.Tasks; -using BackgroundService = Microsoft.Extensions.Hosting.BackgroundService; -namespace Microsoft.Diagnostics.Monitoring.HostingStartup.ParameterCapturing +namespace Microsoft.Diagnostics.Monitoring.StartupHook.ParameterCapturing { internal sealed class ParameterCapturingService : BackgroundService, IParameterCapturingPipelineCallbacks, IDisposable { diff --git a/src/Microsoft.Diagnostics.Monitoring.HostingStartup/ParameterCapturing/ParameterCapturingStrings.Designer.cs b/src/Microsoft.Diagnostics.Monitoring.StartupHook/ParameterCapturing/ParameterCapturingStrings.Designer.cs similarity index 95% rename from src/Microsoft.Diagnostics.Monitoring.HostingStartup/ParameterCapturing/ParameterCapturingStrings.Designer.cs rename to src/Microsoft.Diagnostics.Monitoring.StartupHook/ParameterCapturing/ParameterCapturingStrings.Designer.cs index f7a0b898498..49469887ad2 100644 --- a/src/Microsoft.Diagnostics.Monitoring.HostingStartup/ParameterCapturing/ParameterCapturingStrings.Designer.cs +++ b/src/Microsoft.Diagnostics.Monitoring.StartupHook/ParameterCapturing/ParameterCapturingStrings.Designer.cs @@ -8,7 +8,7 @@ // //------------------------------------------------------------------------------ -namespace Microsoft.Diagnostics.Monitoring.HostingStartup.ParameterCapturing { +namespace Microsoft.Diagnostics.Monitoring.StartupHook.ParameterCapturing { using System; @@ -39,8 +39,8 @@ internal ParameterCapturingStrings() { internal static global::System.Resources.ResourceManager ResourceManager { get { if (object.ReferenceEquals(resourceMan, null)) { - global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Microsoft.Diagnostics.Monitoring.HostingStartup.ParameterCapturing.ParameterCaptu" + - "ringStrings", typeof(ParameterCapturingStrings).Assembly); + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Microsoft.Diagnostics.Monitoring.StartupHook.ParameterCapturing.ParameterCapturin" + + "gStrings", typeof(ParameterCapturingStrings).Assembly); resourceMan = temp; } return resourceMan; diff --git a/src/Microsoft.Diagnostics.Monitoring.HostingStartup/ParameterCapturing/ParameterCapturingStrings.resx b/src/Microsoft.Diagnostics.Monitoring.StartupHook/ParameterCapturing/ParameterCapturingStrings.resx similarity index 100% rename from src/Microsoft.Diagnostics.Monitoring.HostingStartup/ParameterCapturing/ParameterCapturingStrings.resx rename to src/Microsoft.Diagnostics.Monitoring.StartupHook/ParameterCapturing/ParameterCapturingStrings.resx diff --git a/src/Microsoft.Diagnostics.Monitoring.HostingStartup/ParameterCapturing/ParameterSignature.cs b/src/Microsoft.Diagnostics.Monitoring.StartupHook/ParameterCapturing/ParameterSignature.cs similarity index 80% rename from src/Microsoft.Diagnostics.Monitoring.HostingStartup/ParameterCapturing/ParameterSignature.cs rename to src/Microsoft.Diagnostics.Monitoring.StartupHook/ParameterCapturing/ParameterSignature.cs index abe151ac1ef..ffdc64d4d1e 100644 --- a/src/Microsoft.Diagnostics.Monitoring.HostingStartup/ParameterCapturing/ParameterSignature.cs +++ b/src/Microsoft.Diagnostics.Monitoring.StartupHook/ParameterCapturing/ParameterSignature.cs @@ -3,7 +3,7 @@ using System.Reflection; -namespace Microsoft.Diagnostics.Monitoring.HostingStartup.ParameterCapturing +namespace Microsoft.Diagnostics.Monitoring.StartupHook.ParameterCapturing { internal sealed record ParameterSignature(string? Name, string? Type, string? TypeModuleName, ParameterAttributes Attributes, bool IsByRef) { diff --git a/src/Microsoft.Diagnostics.Monitoring.HostingStartup/ParameterCapturing/Pipeline/CaptureLimitPolicyProbes.cs b/src/Microsoft.Diagnostics.Monitoring.StartupHook/ParameterCapturing/Pipeline/CaptureLimitPolicyProbes.cs similarity index 90% rename from src/Microsoft.Diagnostics.Monitoring.HostingStartup/ParameterCapturing/Pipeline/CaptureLimitPolicyProbes.cs rename to src/Microsoft.Diagnostics.Monitoring.StartupHook/ParameterCapturing/Pipeline/CaptureLimitPolicyProbes.cs index ea9815e121f..5b1f3b63461 100644 --- a/src/Microsoft.Diagnostics.Monitoring.HostingStartup/ParameterCapturing/Pipeline/CaptureLimitPolicyProbes.cs +++ b/src/Microsoft.Diagnostics.Monitoring.StartupHook/ParameterCapturing/Pipeline/CaptureLimitPolicyProbes.cs @@ -1,13 +1,13 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. -using Microsoft.Diagnostics.Monitoring.HostingStartup.ParameterCapturing.FunctionProbes; +using Microsoft.Diagnostics.Monitoring.StartupHook.ParameterCapturing.FunctionProbes; using System.Collections.Generic; using System.Reflection; using System.Threading; using System.Threading.Tasks; -namespace Microsoft.Diagnostics.Monitoring.HostingStartup.ParameterCapturing.Pipeline +namespace Microsoft.Diagnostics.Monitoring.StartupHook.ParameterCapturing.Pipeline { internal sealed class CaptureLimitPolicyProbes : IFunctionProbes { diff --git a/src/Microsoft.Diagnostics.Monitoring.HostingStartup/ParameterCapturing/Pipeline/IParameterCapturingPipelineCallbacks.cs b/src/Microsoft.Diagnostics.Monitoring.StartupHook/ParameterCapturing/Pipeline/IParameterCapturingPipelineCallbacks.cs similarity index 89% rename from src/Microsoft.Diagnostics.Monitoring.HostingStartup/ParameterCapturing/Pipeline/IParameterCapturingPipelineCallbacks.cs rename to src/Microsoft.Diagnostics.Monitoring.StartupHook/ParameterCapturing/Pipeline/IParameterCapturingPipelineCallbacks.cs index 5c90d6bd3a6..f2d47c4a813 100644 --- a/src/Microsoft.Diagnostics.Monitoring.HostingStartup/ParameterCapturing/Pipeline/IParameterCapturingPipelineCallbacks.cs +++ b/src/Microsoft.Diagnostics.Monitoring.StartupHook/ParameterCapturing/Pipeline/IParameterCapturingPipelineCallbacks.cs @@ -7,7 +7,7 @@ using System.Collections.Generic; using System.Reflection; -namespace Microsoft.Diagnostics.Monitoring.HostingStartup.ParameterCapturing.FunctionProbes +namespace Microsoft.Diagnostics.Monitoring.StartupHook.ParameterCapturing.FunctionProbes { internal interface IParameterCapturingPipelineCallbacks { diff --git a/src/Microsoft.Diagnostics.Monitoring.HostingStartup/ParameterCapturing/Pipeline/ParameterCapturingPipeline.cs b/src/Microsoft.Diagnostics.Monitoring.StartupHook/ParameterCapturing/Pipeline/ParameterCapturingPipeline.cs similarity index 98% rename from src/Microsoft.Diagnostics.Monitoring.HostingStartup/ParameterCapturing/Pipeline/ParameterCapturingPipeline.cs rename to src/Microsoft.Diagnostics.Monitoring.StartupHook/ParameterCapturing/Pipeline/ParameterCapturingPipeline.cs index d2df9465d73..1cd6eb69067 100644 --- a/src/Microsoft.Diagnostics.Monitoring.HostingStartup/ParameterCapturing/Pipeline/ParameterCapturingPipeline.cs +++ b/src/Microsoft.Diagnostics.Monitoring.StartupHook/ParameterCapturing/Pipeline/ParameterCapturingPipeline.cs @@ -1,7 +1,7 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. -using Microsoft.Diagnostics.Monitoring.HostingStartup.ParameterCapturing.FunctionProbes; +using Microsoft.Diagnostics.Monitoring.StartupHook.ParameterCapturing.FunctionProbes; using Microsoft.Diagnostics.Monitoring.StartupHook.MonitorMessageDispatcher.Models; using Microsoft.Diagnostics.Tools.Monitor.ParameterCapturing; using Microsoft.Diagnostics.Tools.Monitor.Profiler; @@ -13,7 +13,7 @@ using System.Threading.Channels; using System.Threading.Tasks; -namespace Microsoft.Diagnostics.Monitoring.HostingStartup.ParameterCapturing.Pipeline +namespace Microsoft.Diagnostics.Monitoring.StartupHook.ParameterCapturing.Pipeline { internal sealed class ParameterCapturingPipeline : IDisposable { diff --git a/src/Microsoft.Diagnostics.Monitoring.HostingStartup/ParameterCapturing/Pipeline/TooManyRequestsException.cs b/src/Microsoft.Diagnostics.Monitoring.StartupHook/ParameterCapturing/Pipeline/TooManyRequestsException.cs similarity index 78% rename from src/Microsoft.Diagnostics.Monitoring.HostingStartup/ParameterCapturing/Pipeline/TooManyRequestsException.cs rename to src/Microsoft.Diagnostics.Monitoring.StartupHook/ParameterCapturing/Pipeline/TooManyRequestsException.cs index 68c861ad746..ef629e047dd 100644 --- a/src/Microsoft.Diagnostics.Monitoring.HostingStartup/ParameterCapturing/Pipeline/TooManyRequestsException.cs +++ b/src/Microsoft.Diagnostics.Monitoring.StartupHook/ParameterCapturing/Pipeline/TooManyRequestsException.cs @@ -3,7 +3,7 @@ using System; -namespace Microsoft.Diagnostics.Monitoring.HostingStartup.ParameterCapturing.Pipeline +namespace Microsoft.Diagnostics.Monitoring.StartupHook.ParameterCapturing.Pipeline { internal sealed class TooManyRequestsException : Exception { diff --git a/src/Microsoft.Diagnostics.Monitoring.HostingStartup/ParameterCapturing/ResolvedParameterInfo.cs b/src/Microsoft.Diagnostics.Monitoring.StartupHook/ParameterCapturing/ResolvedParameterInfo.cs similarity index 68% rename from src/Microsoft.Diagnostics.Monitoring.HostingStartup/ParameterCapturing/ResolvedParameterInfo.cs rename to src/Microsoft.Diagnostics.Monitoring.StartupHook/ParameterCapturing/ResolvedParameterInfo.cs index 7ac627f9ab1..d59a46400aa 100644 --- a/src/Microsoft.Diagnostics.Monitoring.HostingStartup/ParameterCapturing/ResolvedParameterInfo.cs +++ b/src/Microsoft.Diagnostics.Monitoring.StartupHook/ParameterCapturing/ResolvedParameterInfo.cs @@ -1,10 +1,10 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. -using Microsoft.Diagnostics.Monitoring.HostingStartup.ParameterCapturing.ObjectFormatting; +using Microsoft.Diagnostics.Monitoring.StartupHook.ParameterCapturing.ObjectFormatting; using System.Reflection; -namespace Microsoft.Diagnostics.Monitoring.HostingStartup.ParameterCapturing +namespace Microsoft.Diagnostics.Monitoring.StartupHook.ParameterCapturing { internal sealed record ResolvedParameterInfo(string? Name, string? Type, string? TypeModuleName, ObjectFormatterResult Value, ParameterAttributes Attributes, bool IsByRef) { diff --git a/src/Microsoft.Diagnostics.Monitoring.HostingStartup/ParameterCapturing/TypeUtils.cs b/src/Microsoft.Diagnostics.Monitoring.StartupHook/ParameterCapturing/TypeUtils.cs similarity index 93% rename from src/Microsoft.Diagnostics.Monitoring.HostingStartup/ParameterCapturing/TypeUtils.cs rename to src/Microsoft.Diagnostics.Monitoring.StartupHook/ParameterCapturing/TypeUtils.cs index 547cd7a4ac4..d119bfa7b39 100644 --- a/src/Microsoft.Diagnostics.Monitoring.HostingStartup/ParameterCapturing/TypeUtils.cs +++ b/src/Microsoft.Diagnostics.Monitoring.StartupHook/ParameterCapturing/TypeUtils.cs @@ -3,7 +3,7 @@ using System; -namespace Microsoft.Diagnostics.Monitoring.HostingStartup.ParameterCapturing +namespace Microsoft.Diagnostics.Monitoring.StartupHook.ParameterCapturing { internal static class TypeUtils { diff --git a/src/Microsoft.Diagnostics.Monitoring.HostingStartup/ParameterCapturing/UnresolvedMethodsException.cs b/src/Microsoft.Diagnostics.Monitoring.StartupHook/ParameterCapturing/UnresolvedMethodsException.cs similarity index 93% rename from src/Microsoft.Diagnostics.Monitoring.HostingStartup/ParameterCapturing/UnresolvedMethodsException.cs rename to src/Microsoft.Diagnostics.Monitoring.StartupHook/ParameterCapturing/UnresolvedMethodsException.cs index ce23592b18e..31054a38e3a 100644 --- a/src/Microsoft.Diagnostics.Monitoring.HostingStartup/ParameterCapturing/UnresolvedMethodsException.cs +++ b/src/Microsoft.Diagnostics.Monitoring.StartupHook/ParameterCapturing/UnresolvedMethodsException.cs @@ -7,7 +7,7 @@ using System.Globalization; using System.Text; -namespace Microsoft.Diagnostics.Monitoring.HostingStartup.ParameterCapturing +namespace Microsoft.Diagnostics.Monitoring.StartupHook.ParameterCapturing { internal sealed class UnresolvedMethodsExceptions : Exception { diff --git a/src/Tests/Microsoft.Diagnostics.Monitoring.HostingStartup.UnitTests/ParameterCapturing/Boxing/BoxingInstructionsTests.cs b/src/Tests/Microsoft.Diagnostics.Monitoring.StartupHook.UnitTests/ParameterCapturing/Boxing/BoxingInstructionsTests.cs similarity index 97% rename from src/Tests/Microsoft.Diagnostics.Monitoring.HostingStartup.UnitTests/ParameterCapturing/Boxing/BoxingInstructionsTests.cs rename to src/Tests/Microsoft.Diagnostics.Monitoring.StartupHook.UnitTests/ParameterCapturing/Boxing/BoxingInstructionsTests.cs index db2dcad85d4..122337297a1 100644 --- a/src/Tests/Microsoft.Diagnostics.Monitoring.HostingStartup.UnitTests/ParameterCapturing/Boxing/BoxingInstructionsTests.cs +++ b/src/Tests/Microsoft.Diagnostics.Monitoring.StartupHook.UnitTests/ParameterCapturing/Boxing/BoxingInstructionsTests.cs @@ -1,8 +1,8 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. -using Microsoft.Diagnostics.Monitoring.HostingStartup.ParameterCapturing.Boxing; -using Microsoft.Diagnostics.Monitoring.HostingStartup.ParameterCapturing.FunctionProbes; +using Microsoft.Diagnostics.Monitoring.StartupHook.ParameterCapturing.Boxing; +using Microsoft.Diagnostics.Monitoring.StartupHook.ParameterCapturing.FunctionProbes; using Microsoft.Diagnostics.Monitoring.TestCommon; using SampleMethods; using System; @@ -10,7 +10,7 @@ using Xunit; using Xunit.Abstractions; -namespace Microsoft.Diagnostics.Monitoring.HostingStartup.UnitTests.ParameterCapturing.Boxing +namespace Microsoft.Diagnostics.Monitoring.StartupHook.UnitTests.ParameterCapturing.Boxing { [TargetFrameworkMonikerTrait(TargetFrameworkMonikerExtensions.CurrentTargetFrameworkMoniker)] public class BoxingInstructionsTests @@ -178,7 +178,7 @@ private static void ReflectionAndSignatureDecoder_Contract_InSyncCore(MethodInfo // // // NOTE: The signature decoder may produce a superset of boxing instructions compared to what GetBoxingInstructionsFromReflection needs. - // This is okay as GetBoxingInstructionsFromReflection determines when to leverage the signature decoder. + // This is okay as GetBoxingInstructionsFromReflection determines when to leverage the signature decoder. // ParameterBoxingInstructions reflectionInstructions = BoxingInstructions.GetBoxingInstructionsFromReflection(method, parameters[i].ParameterType, out bool canUseSignatureDecoder); if (canUseSignatureDecoder) diff --git a/src/Tests/Microsoft.Diagnostics.Monitoring.HostingStartup.UnitTests/ParameterCapturing/Boxing/MethodDefinitionExtensionsTests.cs b/src/Tests/Microsoft.Diagnostics.Monitoring.StartupHook.UnitTests/ParameterCapturing/Boxing/MethodDefinitionExtensionsTests.cs similarity index 91% rename from src/Tests/Microsoft.Diagnostics.Monitoring.HostingStartup.UnitTests/ParameterCapturing/Boxing/MethodDefinitionExtensionsTests.cs rename to src/Tests/Microsoft.Diagnostics.Monitoring.StartupHook.UnitTests/ParameterCapturing/Boxing/MethodDefinitionExtensionsTests.cs index 783b779e5a0..101c54c9f23 100644 --- a/src/Tests/Microsoft.Diagnostics.Monitoring.HostingStartup.UnitTests/ParameterCapturing/Boxing/MethodDefinitionExtensionsTests.cs +++ b/src/Tests/Microsoft.Diagnostics.Monitoring.StartupHook.UnitTests/ParameterCapturing/Boxing/MethodDefinitionExtensionsTests.cs @@ -1,8 +1,8 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. -using Microsoft.Diagnostics.Monitoring.HostingStartup.ParameterCapturing.Boxing; -using Microsoft.Diagnostics.Monitoring.HostingStartup.ParameterCapturing.FunctionProbes; +using Microsoft.Diagnostics.Monitoring.StartupHook.ParameterCapturing.Boxing; +using Microsoft.Diagnostics.Monitoring.StartupHook.ParameterCapturing.FunctionProbes; using Microsoft.Diagnostics.Monitoring.TestCommon; using SampleMethods; using System; @@ -11,7 +11,7 @@ using System.Reflection.Metadata; using Xunit; -namespace Microsoft.Diagnostics.Monitoring.HostingStartup.UnitTests.ParameterCapturing.Boxing +namespace Microsoft.Diagnostics.Monitoring.StartupHook.UnitTests.ParameterCapturing.Boxing { [TargetFrameworkMonikerTrait(TargetFrameworkMonikerExtensions.CurrentTargetFrameworkMoniker)] public class MethodDefinitionExtensionsTests diff --git a/src/Tests/Microsoft.Diagnostics.Monitoring.HostingStartup.UnitTests/ParameterCapturing/FunctionProbes/ProfilerAbiTests.cs b/src/Tests/Microsoft.Diagnostics.Monitoring.StartupHook.UnitTests/ParameterCapturing/FunctionProbes/ProfilerAbiTests.cs similarity index 87% rename from src/Tests/Microsoft.Diagnostics.Monitoring.HostingStartup.UnitTests/ParameterCapturing/FunctionProbes/ProfilerAbiTests.cs rename to src/Tests/Microsoft.Diagnostics.Monitoring.StartupHook.UnitTests/ParameterCapturing/FunctionProbes/ProfilerAbiTests.cs index d9d2beb694e..8e9971ec35e 100644 --- a/src/Tests/Microsoft.Diagnostics.Monitoring.HostingStartup.UnitTests/ParameterCapturing/FunctionProbes/ProfilerAbiTests.cs +++ b/src/Tests/Microsoft.Diagnostics.Monitoring.StartupHook.UnitTests/ParameterCapturing/FunctionProbes/ProfilerAbiTests.cs @@ -1,12 +1,12 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. -using Microsoft.Diagnostics.Monitoring.HostingStartup.ParameterCapturing.FunctionProbes; +using Microsoft.Diagnostics.Monitoring.StartupHook.ParameterCapturing.FunctionProbes; using Microsoft.Diagnostics.Monitoring.TestCommon; using System.Reflection; using Xunit; -namespace Microsoft.Diagnostics.Monitoring.HostingStartup.UnitTests.ParameterCapturing.FunctionProbes +namespace Microsoft.Diagnostics.Monitoring.StartupHook.UnitTests.ParameterCapturing.FunctionProbes { [TargetFrameworkMonikerTrait(TargetFrameworkMonikerExtensions.CurrentTargetFrameworkMoniker)] public class ProfilerAbiTests diff --git a/src/Tests/Microsoft.Diagnostics.Monitoring.HostingStartup.UnitTests/ParameterCapturing/MethodResolverTests.cs b/src/Tests/Microsoft.Diagnostics.Monitoring.StartupHook.UnitTests/ParameterCapturing/MethodResolverTests.cs similarity index 96% rename from src/Tests/Microsoft.Diagnostics.Monitoring.HostingStartup.UnitTests/ParameterCapturing/MethodResolverTests.cs rename to src/Tests/Microsoft.Diagnostics.Monitoring.StartupHook.UnitTests/ParameterCapturing/MethodResolverTests.cs index ae642b93c10..8dfc044d78e 100644 --- a/src/Tests/Microsoft.Diagnostics.Monitoring.HostingStartup.UnitTests/ParameterCapturing/MethodResolverTests.cs +++ b/src/Tests/Microsoft.Diagnostics.Monitoring.StartupHook.UnitTests/ParameterCapturing/MethodResolverTests.cs @@ -1,8 +1,8 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. -using Microsoft.Diagnostics.Monitoring.HostingStartup.ParameterCapturing; -using Microsoft.Diagnostics.Monitoring.HostingStartup.ParameterCapturing.Boxing; +using Microsoft.Diagnostics.Monitoring.StartupHook.ParameterCapturing; +using Microsoft.Diagnostics.Monitoring.StartupHook.ParameterCapturing.Boxing; using Microsoft.Diagnostics.Monitoring.StartupHook.MonitorMessageDispatcher.Models; using Microsoft.Diagnostics.Monitoring.TestCommon; using SampleMethods; @@ -13,7 +13,7 @@ using Xunit; using Xunit.Abstractions; -namespace Microsoft.Diagnostics.Monitoring.HostingStartup.UnitTests.ParameterCapturing +namespace Microsoft.Diagnostics.Monitoring.StartupHook.UnitTests.ParameterCapturing { [TargetFrameworkMonikerTrait(TargetFrameworkMonikerExtensions.CurrentTargetFrameworkMoniker)] public class MethodResolverTests diff --git a/src/Tests/Microsoft.Diagnostics.Monitoring.HostingStartup.UnitTests/ParameterCapturing/MethodSignatureTests.cs b/src/Tests/Microsoft.Diagnostics.Monitoring.StartupHook.UnitTests/ParameterCapturing/MethodSignatureTests.cs similarity index 98% rename from src/Tests/Microsoft.Diagnostics.Monitoring.HostingStartup.UnitTests/ParameterCapturing/MethodSignatureTests.cs rename to src/Tests/Microsoft.Diagnostics.Monitoring.StartupHook.UnitTests/ParameterCapturing/MethodSignatureTests.cs index b8fa7693cb2..6f650262492 100644 --- a/src/Tests/Microsoft.Diagnostics.Monitoring.HostingStartup.UnitTests/ParameterCapturing/MethodSignatureTests.cs +++ b/src/Tests/Microsoft.Diagnostics.Monitoring.StartupHook.UnitTests/ParameterCapturing/MethodSignatureTests.cs @@ -1,14 +1,14 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. -using Microsoft.Diagnostics.Monitoring.HostingStartup.ParameterCapturing; +using Microsoft.Diagnostics.Monitoring.StartupHook.ParameterCapturing; using Microsoft.Diagnostics.Monitoring.TestCommon; using SampleMethods; using System; using System.Reflection; using Xunit; -namespace Microsoft.Diagnostics.Monitoring.HostingStartup.UnitTests.ParameterCapturing +namespace Microsoft.Diagnostics.Monitoring.StartupHook.UnitTests.ParameterCapturing { [TargetFrameworkMonikerTrait(TargetFrameworkMonikerExtensions.CurrentTargetFrameworkMoniker)] public class MethodSignatureTests diff --git a/src/Tests/Microsoft.Diagnostics.Monitoring.HostingStartup.UnitTests/ParameterCapturing/ObjectFormatting/Formatters/DebuggerDisplay/DebuggerDisplayFormatterTests.cs b/src/Tests/Microsoft.Diagnostics.Monitoring.StartupHook.UnitTests/ParameterCapturing/ObjectFormatting/Formatters/DebuggerDisplay/DebuggerDisplayFormatterTests.cs similarity index 85% rename from src/Tests/Microsoft.Diagnostics.Monitoring.HostingStartup.UnitTests/ParameterCapturing/ObjectFormatting/Formatters/DebuggerDisplay/DebuggerDisplayFormatterTests.cs rename to src/Tests/Microsoft.Diagnostics.Monitoring.StartupHook.UnitTests/ParameterCapturing/ObjectFormatting/Formatters/DebuggerDisplay/DebuggerDisplayFormatterTests.cs index 554cb756442..203c87e1f13 100644 --- a/src/Tests/Microsoft.Diagnostics.Monitoring.HostingStartup.UnitTests/ParameterCapturing/ObjectFormatting/Formatters/DebuggerDisplay/DebuggerDisplayFormatterTests.cs +++ b/src/Tests/Microsoft.Diagnostics.Monitoring.StartupHook.UnitTests/ParameterCapturing/ObjectFormatting/Formatters/DebuggerDisplay/DebuggerDisplayFormatterTests.cs @@ -1,16 +1,16 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. -using Microsoft.Diagnostics.Monitoring.HostingStartup.ParameterCapturing.ObjectFormatting; -using Microsoft.Diagnostics.Monitoring.HostingStartup.ParameterCapturing.ObjectFormatting.Formatters.DebuggerDisplay; +using Microsoft.Diagnostics.Monitoring.StartupHook.ParameterCapturing.ObjectFormatting; +using Microsoft.Diagnostics.Monitoring.StartupHook.ParameterCapturing.ObjectFormatting.Formatters.DebuggerDisplay; using Microsoft.Diagnostics.Monitoring.TestCommon; using System; using System.Diagnostics; using Xunit; -using static Microsoft.Diagnostics.Monitoring.HostingStartup.ParameterCapturing.ObjectFormatting.Formatters.DebuggerDisplay.DebuggerDisplayFormatter; +using static Microsoft.Diagnostics.Monitoring.StartupHook.ParameterCapturing.ObjectFormatting.Formatters.DebuggerDisplay.DebuggerDisplayFormatter; using static Microsoft.Diagnostics.Tools.Monitor.ParameterCapturing.ParameterCapturingEvents; -namespace Microsoft.Diagnostics.Monitoring.HostingStartup.UnitTests.ParameterCapturing.ObjectFormatting.Formatters.DebuggerDisplay +namespace Microsoft.Diagnostics.Monitoring.StartupHook.UnitTests.ParameterCapturing.ObjectFormatting.Formatters.DebuggerDisplay { [TargetFrameworkMonikerTrait(TargetFrameworkMonikerExtensions.CurrentTargetFrameworkMoniker)] public class DebuggerDisplayFormatterTests @@ -28,7 +28,9 @@ private sealed class DebuggerDisplayClassWithNullField { public int Count { get; set; } - public static string? NullField => null; +#pragma warning disable CS8603 // Possible null reference return. + public static string NullField => null; +#pragma warning restore CS8603 // Possible null reference return. } [Theory] diff --git a/src/Tests/Microsoft.Diagnostics.Monitoring.HostingStartup.UnitTests/ParameterCapturing/ObjectFormatting/Formatters/DebuggerDisplay/DebuggerDisplayParserTests.cs b/src/Tests/Microsoft.Diagnostics.Monitoring.StartupHook.UnitTests/ParameterCapturing/ObjectFormatting/Formatters/DebuggerDisplay/DebuggerDisplayParserTests.cs similarity index 89% rename from src/Tests/Microsoft.Diagnostics.Monitoring.HostingStartup.UnitTests/ParameterCapturing/ObjectFormatting/Formatters/DebuggerDisplay/DebuggerDisplayParserTests.cs rename to src/Tests/Microsoft.Diagnostics.Monitoring.StartupHook.UnitTests/ParameterCapturing/ObjectFormatting/Formatters/DebuggerDisplay/DebuggerDisplayParserTests.cs index e8a27df110d..718f5386011 100644 --- a/src/Tests/Microsoft.Diagnostics.Monitoring.HostingStartup.UnitTests/ParameterCapturing/ObjectFormatting/Formatters/DebuggerDisplay/DebuggerDisplayParserTests.cs +++ b/src/Tests/Microsoft.Diagnostics.Monitoring.StartupHook.UnitTests/ParameterCapturing/ObjectFormatting/Formatters/DebuggerDisplay/DebuggerDisplayParserTests.cs @@ -1,15 +1,15 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. -using Microsoft.Diagnostics.Monitoring.HostingStartup.ParameterCapturing.ObjectFormatting; -using Microsoft.Diagnostics.Monitoring.HostingStartup.ParameterCapturing.ObjectFormatting.Formatters.DebuggerDisplay; +using Microsoft.Diagnostics.Monitoring.StartupHook.ParameterCapturing.ObjectFormatting; +using Microsoft.Diagnostics.Monitoring.StartupHook.ParameterCapturing.ObjectFormatting.Formatters.DebuggerDisplay; using Microsoft.Diagnostics.Monitoring.TestCommon; using System; using System.Linq; using Xunit; -using static Microsoft.Diagnostics.Monitoring.HostingStartup.ParameterCapturing.ObjectFormatting.Formatters.DebuggerDisplay.DebuggerDisplayParser; +using static Microsoft.Diagnostics.Monitoring.StartupHook.ParameterCapturing.ObjectFormatting.Formatters.DebuggerDisplay.DebuggerDisplayParser; -namespace Microsoft.Diagnostics.Monitoring.HostingStartup.UnitTests.ParameterCapturing.ObjectFormatting.Formatters.DebuggerDisplay +namespace Microsoft.Diagnostics.Monitoring.StartupHook.UnitTests.ParameterCapturing.ObjectFormatting.Formatters.DebuggerDisplay { [TargetFrameworkMonikerTrait(TargetFrameworkMonikerExtensions.CurrentTargetFrameworkMoniker)] public class DebuggerDisplayParserTests diff --git a/src/Tests/Microsoft.Diagnostics.Monitoring.HostingStartup.UnitTests/ParameterCapturing/ObjectFormatting/Formatters/DebuggerDisplay/ExpressionBinderTests.cs b/src/Tests/Microsoft.Diagnostics.Monitoring.StartupHook.UnitTests/ParameterCapturing/ObjectFormatting/Formatters/DebuggerDisplay/ExpressionBinderTests.cs similarity index 86% rename from src/Tests/Microsoft.Diagnostics.Monitoring.HostingStartup.UnitTests/ParameterCapturing/ObjectFormatting/Formatters/DebuggerDisplay/ExpressionBinderTests.cs rename to src/Tests/Microsoft.Diagnostics.Monitoring.StartupHook.UnitTests/ParameterCapturing/ObjectFormatting/Formatters/DebuggerDisplay/ExpressionBinderTests.cs index 3713ade95e3..08175177585 100644 --- a/src/Tests/Microsoft.Diagnostics.Monitoring.HostingStartup.UnitTests/ParameterCapturing/ObjectFormatting/Formatters/DebuggerDisplay/ExpressionBinderTests.cs +++ b/src/Tests/Microsoft.Diagnostics.Monitoring.StartupHook.UnitTests/ParameterCapturing/ObjectFormatting/Formatters/DebuggerDisplay/ExpressionBinderTests.cs @@ -1,13 +1,13 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. -using Microsoft.Diagnostics.Monitoring.HostingStartup.ParameterCapturing.ObjectFormatting.Formatters.DebuggerDisplay; +using Microsoft.Diagnostics.Monitoring.StartupHook.ParameterCapturing.ObjectFormatting.Formatters.DebuggerDisplay; using Microsoft.Diagnostics.Monitoring.TestCommon; using System; using Xunit; -using static Microsoft.Diagnostics.Monitoring.HostingStartup.ParameterCapturing.ObjectFormatting.Formatters.DebuggerDisplay.ExpressionBinder; +using static Microsoft.Diagnostics.Monitoring.StartupHook.ParameterCapturing.ObjectFormatting.Formatters.DebuggerDisplay.ExpressionBinder; -namespace Microsoft.Diagnostics.Monitoring.HostingStartup.UnitTests.ParameterCapturing.ObjectFormatting.Formatters.DebuggerDisplay +namespace Microsoft.Diagnostics.Monitoring.StartupHook.UnitTests.ParameterCapturing.ObjectFormatting.Formatters.DebuggerDisplay { [TargetFrameworkMonikerTrait(TargetFrameworkMonikerExtensions.CurrentTargetFrameworkMoniker)] public class ExpressionBinderTests diff --git a/src/Tests/Microsoft.Diagnostics.Monitoring.HostingStartup.UnitTests/ParameterCapturing/ObjectFormatting/Formatters/RuntimeFormattersTests.cs b/src/Tests/Microsoft.Diagnostics.Monitoring.StartupHook.UnitTests/ParameterCapturing/ObjectFormatting/Formatters/RuntimeFormattersTests.cs similarity index 93% rename from src/Tests/Microsoft.Diagnostics.Monitoring.HostingStartup.UnitTests/ParameterCapturing/ObjectFormatting/Formatters/RuntimeFormattersTests.cs rename to src/Tests/Microsoft.Diagnostics.Monitoring.StartupHook.UnitTests/ParameterCapturing/ObjectFormatting/Formatters/RuntimeFormattersTests.cs index 6644d5d7991..3a8be64ba5b 100644 --- a/src/Tests/Microsoft.Diagnostics.Monitoring.HostingStartup.UnitTests/ParameterCapturing/ObjectFormatting/Formatters/RuntimeFormattersTests.cs +++ b/src/Tests/Microsoft.Diagnostics.Monitoring.StartupHook.UnitTests/ParameterCapturing/ObjectFormatting/Formatters/RuntimeFormattersTests.cs @@ -1,14 +1,14 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. -using Microsoft.Diagnostics.Monitoring.HostingStartup.ParameterCapturing.ObjectFormatting; +using Microsoft.Diagnostics.Monitoring.StartupHook.ParameterCapturing.ObjectFormatting; using Microsoft.Diagnostics.Monitoring.TestCommon; using SampleMethods; using System; using Xunit; using static Microsoft.Diagnostics.Tools.Monitor.ParameterCapturing.ParameterCapturingEvents; -namespace Microsoft.Diagnostics.Monitoring.HostingStartup.UnitTests.ParameterCapturing.ObjectFormatting.Formatters +namespace Microsoft.Diagnostics.Monitoring.StartupHook.UnitTests.ParameterCapturing.ObjectFormatting.Formatters { [TargetFrameworkMonikerTrait(TargetFrameworkMonikerExtensions.CurrentTargetFrameworkMoniker)] public class RuntimeFormattersTests diff --git a/src/Tests/Microsoft.Diagnostics.Monitoring.HostingStartup.UnitTests/ParameterCapturing/ObjectFormatting/ObjectFormatterFactoryTests.cs b/src/Tests/Microsoft.Diagnostics.Monitoring.StartupHook.UnitTests/ParameterCapturing/ObjectFormatting/ObjectFormatterFactoryTests.cs similarity index 86% rename from src/Tests/Microsoft.Diagnostics.Monitoring.HostingStartup.UnitTests/ParameterCapturing/ObjectFormatting/ObjectFormatterFactoryTests.cs rename to src/Tests/Microsoft.Diagnostics.Monitoring.StartupHook.UnitTests/ParameterCapturing/ObjectFormatting/ObjectFormatterFactoryTests.cs index 11aa53b0e02..eac1a1e6592 100644 --- a/src/Tests/Microsoft.Diagnostics.Monitoring.HostingStartup.UnitTests/ParameterCapturing/ObjectFormatting/ObjectFormatterFactoryTests.cs +++ b/src/Tests/Microsoft.Diagnostics.Monitoring.StartupHook.UnitTests/ParameterCapturing/ObjectFormatting/ObjectFormatterFactoryTests.cs @@ -1,14 +1,14 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. -using Microsoft.Diagnostics.Monitoring.HostingStartup.ParameterCapturing.ObjectFormatting; +using Microsoft.Diagnostics.Monitoring.StartupHook.ParameterCapturing.ObjectFormatting; using Microsoft.Diagnostics.Monitoring.TestCommon; using SampleMethods; using System; using System.Reflection; using Xunit; -namespace Microsoft.Diagnostics.Monitoring.HostingStartup.UnitTests.ParameterCapturing +namespace Microsoft.Diagnostics.Monitoring.StartupHook.UnitTests.ParameterCapturing { [TargetFrameworkMonikerTrait(TargetFrameworkMonikerExtensions.CurrentTargetFrameworkMoniker)] public class ObjectFormatterFactoryTests diff --git a/src/Tests/Microsoft.Diagnostics.Monitoring.HostingStartup.UnitTests/ParameterCapturing/ObjectFormatting/ObjectFormatterTests.cs b/src/Tests/Microsoft.Diagnostics.Monitoring.StartupHook.UnitTests/ParameterCapturing/ObjectFormatting/ObjectFormatterTests.cs similarity index 92% rename from src/Tests/Microsoft.Diagnostics.Monitoring.HostingStartup.UnitTests/ParameterCapturing/ObjectFormatting/ObjectFormatterTests.cs rename to src/Tests/Microsoft.Diagnostics.Monitoring.StartupHook.UnitTests/ParameterCapturing/ObjectFormatting/ObjectFormatterTests.cs index dc1a447414e..607088b7541 100644 --- a/src/Tests/Microsoft.Diagnostics.Monitoring.HostingStartup.UnitTests/ParameterCapturing/ObjectFormatting/ObjectFormatterTests.cs +++ b/src/Tests/Microsoft.Diagnostics.Monitoring.StartupHook.UnitTests/ParameterCapturing/ObjectFormatting/ObjectFormatterTests.cs @@ -1,13 +1,13 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. -using Microsoft.Diagnostics.Monitoring.HostingStartup.ParameterCapturing.ObjectFormatting; +using Microsoft.Diagnostics.Monitoring.StartupHook.ParameterCapturing.ObjectFormatting; using Microsoft.Diagnostics.Monitoring.TestCommon; using System; using Xunit; using static Microsoft.Diagnostics.Tools.Monitor.ParameterCapturing.ParameterCapturingEvents; -namespace Microsoft.Diagnostics.Monitoring.HostingStartup.UnitTests.ParameterCapturing +namespace Microsoft.Diagnostics.Monitoring.StartupHook.UnitTests.ParameterCapturing { [TargetFrameworkMonikerTrait(TargetFrameworkMonikerExtensions.CurrentTargetFrameworkMoniker)] public class ObjectFormatterTests diff --git a/src/Tests/Microsoft.Diagnostics.Monitoring.HostingStartup.UnitTests/ParameterCapturing/Pipeline/CaptureLimitPolicyProbesTests.cs b/src/Tests/Microsoft.Diagnostics.Monitoring.StartupHook.UnitTests/ParameterCapturing/Pipeline/CaptureLimitPolicyProbesTests.cs similarity index 95% rename from src/Tests/Microsoft.Diagnostics.Monitoring.HostingStartup.UnitTests/ParameterCapturing/Pipeline/CaptureLimitPolicyProbesTests.cs rename to src/Tests/Microsoft.Diagnostics.Monitoring.StartupHook.UnitTests/ParameterCapturing/Pipeline/CaptureLimitPolicyProbesTests.cs index c6943a01480..5852757efac 100644 --- a/src/Tests/Microsoft.Diagnostics.Monitoring.HostingStartup.UnitTests/ParameterCapturing/Pipeline/CaptureLimitPolicyProbesTests.cs +++ b/src/Tests/Microsoft.Diagnostics.Monitoring.StartupHook.UnitTests/ParameterCapturing/Pipeline/CaptureLimitPolicyProbesTests.cs @@ -1,7 +1,7 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. -using Microsoft.Diagnostics.Monitoring.HostingStartup.ParameterCapturing.Pipeline; +using Microsoft.Diagnostics.Monitoring.StartupHook.ParameterCapturing.Pipeline; using Microsoft.Diagnostics.Monitoring.TestCommon; using System; using System.Collections.Generic; @@ -10,7 +10,7 @@ using System.Threading.Tasks; using Xunit; -namespace Microsoft.Diagnostics.Monitoring.HostingStartup.UnitTests.ParameterCapturing.Pipeline +namespace Microsoft.Diagnostics.Monitoring.StartupHook.UnitTests.ParameterCapturing.Pipeline { [TargetFrameworkMonikerTrait(TargetFrameworkMonikerExtensions.CurrentTargetFrameworkMoniker)] public class CaptureLimitPolicyProbesTests diff --git a/src/Tests/Microsoft.Diagnostics.Monitoring.HostingStartup.UnitTests/ParameterCapturing/Pipeline/ParameterCapturingPipelineTests.cs b/src/Tests/Microsoft.Diagnostics.Monitoring.StartupHook.UnitTests/ParameterCapturing/Pipeline/ParameterCapturingPipelineTests.cs similarity index 97% rename from src/Tests/Microsoft.Diagnostics.Monitoring.HostingStartup.UnitTests/ParameterCapturing/Pipeline/ParameterCapturingPipelineTests.cs rename to src/Tests/Microsoft.Diagnostics.Monitoring.StartupHook.UnitTests/ParameterCapturing/Pipeline/ParameterCapturingPipelineTests.cs index 24817351bfd..9fcc5192107 100644 --- a/src/Tests/Microsoft.Diagnostics.Monitoring.HostingStartup.UnitTests/ParameterCapturing/Pipeline/ParameterCapturingPipelineTests.cs +++ b/src/Tests/Microsoft.Diagnostics.Monitoring.StartupHook.UnitTests/ParameterCapturing/Pipeline/ParameterCapturingPipelineTests.cs @@ -1,10 +1,10 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. -using Microsoft.Diagnostics.Monitoring.HostingStartup.ParameterCapturing; -using Microsoft.Diagnostics.Monitoring.HostingStartup.ParameterCapturing.Boxing; -using Microsoft.Diagnostics.Monitoring.HostingStartup.ParameterCapturing.FunctionProbes; -using Microsoft.Diagnostics.Monitoring.HostingStartup.ParameterCapturing.Pipeline; +using Microsoft.Diagnostics.Monitoring.StartupHook.ParameterCapturing; +using Microsoft.Diagnostics.Monitoring.StartupHook.ParameterCapturing.Boxing; +using Microsoft.Diagnostics.Monitoring.StartupHook.ParameterCapturing.FunctionProbes; +using Microsoft.Diagnostics.Monitoring.StartupHook.ParameterCapturing.Pipeline; using Microsoft.Diagnostics.Monitoring.StartupHook.MonitorMessageDispatcher.Models; using Microsoft.Diagnostics.Monitoring.TestCommon; using Microsoft.Diagnostics.Tools.Monitor.ParameterCapturing; @@ -17,7 +17,7 @@ using Xunit; using Xunit.Abstractions; -namespace Microsoft.Diagnostics.Monitoring.HostingStartup.UnitTests.ParameterCapturing.Pipeline +namespace Microsoft.Diagnostics.Monitoring.StartupHook.UnitTests.ParameterCapturing.Pipeline { internal sealed class TestFunctionProbesManager : IFunctionProbesManager { diff --git a/src/Tests/Microsoft.Diagnostics.Monitoring.HostingStartup.UnitTests/ParameterCapturing/Pipeline/TestFunctionProbes.cs b/src/Tests/Microsoft.Diagnostics.Monitoring.StartupHook.UnitTests/ParameterCapturing/Pipeline/TestFunctionProbes.cs similarity index 84% rename from src/Tests/Microsoft.Diagnostics.Monitoring.HostingStartup.UnitTests/ParameterCapturing/Pipeline/TestFunctionProbes.cs rename to src/Tests/Microsoft.Diagnostics.Monitoring.StartupHook.UnitTests/ParameterCapturing/Pipeline/TestFunctionProbes.cs index 012b5b7f6dc..af79d704560 100644 --- a/src/Tests/Microsoft.Diagnostics.Monitoring.HostingStartup.UnitTests/ParameterCapturing/Pipeline/TestFunctionProbes.cs +++ b/src/Tests/Microsoft.Diagnostics.Monitoring.StartupHook.UnitTests/ParameterCapturing/Pipeline/TestFunctionProbes.cs @@ -1,12 +1,12 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. -using Microsoft.Diagnostics.Monitoring.HostingStartup.ParameterCapturing.FunctionProbes; +using Microsoft.Diagnostics.Monitoring.StartupHook.ParameterCapturing.FunctionProbes; using System; using System.Collections.Generic; using System.Reflection; -namespace Microsoft.Diagnostics.Monitoring.HostingStartup.UnitTests.ParameterCapturing.Pipeline +namespace Microsoft.Diagnostics.Monitoring.StartupHook.UnitTests.ParameterCapturing.Pipeline { internal sealed class TestFunctionProbes : IFunctionProbes { diff --git a/src/Tests/Microsoft.Diagnostics.Monitoring.HostingStartup.UnitTests/ParameterCapturing/SampleMethods.cs b/src/Tests/Microsoft.Diagnostics.Monitoring.StartupHook.UnitTests/ParameterCapturing/SampleMethods.cs similarity index 100% rename from src/Tests/Microsoft.Diagnostics.Monitoring.HostingStartup.UnitTests/ParameterCapturing/SampleMethods.cs rename to src/Tests/Microsoft.Diagnostics.Monitoring.StartupHook.UnitTests/ParameterCapturing/SampleMethods.cs diff --git a/src/Tests/Microsoft.Diagnostics.Monitoring.HostingStartup.UnitTests/ParameterCapturing/TypeUtilsTests.cs b/src/Tests/Microsoft.Diagnostics.Monitoring.StartupHook.UnitTests/ParameterCapturing/TypeUtilsTests.cs similarity index 86% rename from src/Tests/Microsoft.Diagnostics.Monitoring.HostingStartup.UnitTests/ParameterCapturing/TypeUtilsTests.cs rename to src/Tests/Microsoft.Diagnostics.Monitoring.StartupHook.UnitTests/ParameterCapturing/TypeUtilsTests.cs index 8f9ea43b4d8..bde6433d900 100644 --- a/src/Tests/Microsoft.Diagnostics.Monitoring.HostingStartup.UnitTests/ParameterCapturing/TypeUtilsTests.cs +++ b/src/Tests/Microsoft.Diagnostics.Monitoring.StartupHook.UnitTests/ParameterCapturing/TypeUtilsTests.cs @@ -1,11 +1,11 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. -using Microsoft.Diagnostics.Monitoring.HostingStartup.ParameterCapturing; +using Microsoft.Diagnostics.Monitoring.StartupHook.ParameterCapturing; using Microsoft.Diagnostics.Monitoring.TestCommon; using Xunit; -namespace Microsoft.Diagnostics.Monitoring.HostingStartup.UnitTests.ParameterCapturing +namespace Microsoft.Diagnostics.Monitoring.StartupHook.UnitTests.ParameterCapturing { [TargetFrameworkMonikerTrait(TargetFrameworkMonikerExtensions.CurrentTargetFrameworkMoniker)] public class TypeUtilsTests diff --git a/src/Tests/Microsoft.Diagnostics.Monitoring.Tool.FunctionalTests/ParameterCapturingTests.cs b/src/Tests/Microsoft.Diagnostics.Monitoring.Tool.FunctionalTests/ParameterCapturingTests.cs index 0d91d93bc7c..3705fc373cb 100644 --- a/src/Tests/Microsoft.Diagnostics.Monitoring.Tool.FunctionalTests/ParameterCapturingTests.cs +++ b/src/Tests/Microsoft.Diagnostics.Monitoring.Tool.FunctionalTests/ParameterCapturingTests.cs @@ -78,30 +78,18 @@ await RunTestCaseCore(TestAppScenarios.ParameterCapturing.SubScenarios.AspNetApp [Theory] [MemberData(nameof(ProfilerHelper.GetArchitecture), MemberType = typeof(ProfilerHelper))] - public async Task NonAspNetAppFailsOperation(Architecture targetArchitecture) - { - await RunTestCaseCore(TestAppScenarios.ParameterCapturing.SubScenarios.NonAspNetApp, targetArchitecture, async (appRunner, apiClient) => - { - int processId = await appRunner.ProcessIdTask; - - CaptureParametersConfiguration config = GetValidConfiguration(); - - ValidationProblemDetailsException validationException = await Assert.ThrowsAsync(() => apiClient.CaptureParametersAsync(processId, Timeout.InfiniteTimeSpan, config)); - Assert.Equal(HttpStatusCode.BadRequest, validationException.StatusCode); - - await appRunner.SendCommandAsync(TestAppScenarios.ParameterCapturing.Commands.Continue); - }); - } + public Task CapturesParametersInNonAspNetApps(Architecture targetArchitecture) => + CapturesParametersCore(TestAppScenarios.ParameterCapturing.SubScenarios.NonAspNetApp, targetArchitecture, CapturedParameterFormat.JsonSequence); [Theory] [MemberData(nameof(ProfilerHelper.GetArchitecture), MemberType = typeof(ProfilerHelper))] public Task CapturesParametersAndOutputJsonSequence(Architecture targetArchitecture) => - CapturesParametersCore(targetArchitecture, CapturedParameterFormat.JsonSequence); + CapturesParametersCore(TestAppScenarios.ParameterCapturing.SubScenarios.AspNetApp, targetArchitecture, CapturedParameterFormat.JsonSequence); [Theory] [MemberData(nameof(ProfilerHelper.GetArchitecture), MemberType = typeof(ProfilerHelper))] public Task CapturesParametersAndOutputNewlineDelimitedJson(Architecture targetArchitecture) => - CapturesParametersCore(targetArchitecture, CapturedParameterFormat.NewlineDelimitedJson); + CapturesParametersCore(TestAppScenarios.ParameterCapturing.SubScenarios.AspNetApp, targetArchitecture, CapturedParameterFormat.NewlineDelimitedJson); #else // NET7_0_OR_GREATER [Theory] @@ -122,9 +110,9 @@ await RunTestCaseCore(TestAppScenarios.ParameterCapturing.SubScenarios.AspNetApp } #endif // NET7_0_OR_GREATER - private async Task CapturesParametersCore(Architecture targetArchitecture, CapturedParameterFormat format) + private async Task CapturesParametersCore(string subScenarioName,Architecture targetArchitecture, CapturedParameterFormat format) { - await RunTestCaseCore(TestAppScenarios.ParameterCapturing.SubScenarios.AspNetApp, targetArchitecture, async (appRunner, apiClient) => + await RunTestCaseCore(subScenarioName, targetArchitecture, async (appRunner, apiClient) => { int processId = await appRunner.ProcessIdTask; diff --git a/src/Tests/Microsoft.Diagnostics.Monitoring.UnitTestApp/Microsoft.Diagnostics.Monitoring.UnitTestApp.csproj b/src/Tests/Microsoft.Diagnostics.Monitoring.UnitTestApp/Microsoft.Diagnostics.Monitoring.UnitTestApp.csproj index 417ff0bf4b0..dee00113162 100644 --- a/src/Tests/Microsoft.Diagnostics.Monitoring.UnitTestApp/Microsoft.Diagnostics.Monitoring.UnitTestApp.csproj +++ b/src/Tests/Microsoft.Diagnostics.Monitoring.UnitTestApp/Microsoft.Diagnostics.Monitoring.UnitTestApp.csproj @@ -13,11 +13,12 @@ + - + diff --git a/src/Tests/Microsoft.Diagnostics.Monitoring.UnitTestApp/Scenarios/FunctionProbes/FunctionProbesScenario.cs b/src/Tests/Microsoft.Diagnostics.Monitoring.UnitTestApp/Scenarios/FunctionProbes/FunctionProbesScenario.cs index a4889756faf..f4962615ad5 100644 --- a/src/Tests/Microsoft.Diagnostics.Monitoring.UnitTestApp/Scenarios/FunctionProbes/FunctionProbesScenario.cs +++ b/src/Tests/Microsoft.Diagnostics.Monitoring.UnitTestApp/Scenarios/FunctionProbes/FunctionProbesScenario.cs @@ -1,8 +1,8 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. -using Microsoft.Diagnostics.Monitoring.HostingStartup.ParameterCapturing; -using Microsoft.Diagnostics.Monitoring.HostingStartup.ParameterCapturing.FunctionProbes; +using Microsoft.Diagnostics.Monitoring.StartupHook.ParameterCapturing; +using Microsoft.Diagnostics.Monitoring.StartupHook.ParameterCapturing.FunctionProbes; using Microsoft.Diagnostics.Monitoring.StartupHook; using Microsoft.Diagnostics.Monitoring.TestCommon; using SampleMethods; diff --git a/src/Tests/Microsoft.Diagnostics.Monitoring.UnitTestApp/Scenarios/FunctionProbes/PerFunctionProbeProxy.cs b/src/Tests/Microsoft.Diagnostics.Monitoring.UnitTestApp/Scenarios/FunctionProbes/PerFunctionProbeProxy.cs index 64fd7b69f5e..275d7c4491a 100644 --- a/src/Tests/Microsoft.Diagnostics.Monitoring.UnitTestApp/Scenarios/FunctionProbes/PerFunctionProbeProxy.cs +++ b/src/Tests/Microsoft.Diagnostics.Monitoring.UnitTestApp/Scenarios/FunctionProbes/PerFunctionProbeProxy.cs @@ -8,7 +8,7 @@ using System.Threading; using Xunit.Sdk; -namespace Microsoft.Diagnostics.Monitoring.HostingStartup.ParameterCapturing.FunctionProbes +namespace Microsoft.Diagnostics.Monitoring.StartupHook.ParameterCapturing.FunctionProbes { internal sealed class PerFunctionProbeWrapper { diff --git a/src/Tests/Microsoft.Diagnostics.Monitoring.UnitTestApp/Scenarios/ParameterCapturingScenario.cs b/src/Tests/Microsoft.Diagnostics.Monitoring.UnitTestApp/Scenarios/ParameterCapturingScenario.cs index c4030d4f1f6..ae9a0973382 100644 --- a/src/Tests/Microsoft.Diagnostics.Monitoring.UnitTestApp/Scenarios/ParameterCapturingScenario.cs +++ b/src/Tests/Microsoft.Diagnostics.Monitoring.UnitTestApp/Scenarios/ParameterCapturingScenario.cs @@ -48,6 +48,9 @@ public static Task NonAspNetAppAsync(ParseResult result, CancellationToken func: async logger => { await ScenarioHelpers.WaitForCommandAsync(TestAppScenarios.ParameterCapturing.Commands.Continue, logger); + + SampleMethods.StaticTestMethodSignatures.NoArgs(); + return 0; }, token); } diff --git a/src/Tools/dotnet-monitor/ParameterCapturing/CaptureParametersOperation.cs b/src/Tools/dotnet-monitor/ParameterCapturing/CaptureParametersOperation.cs index e1d4c74388a..f8c9dcc1214 100644 --- a/src/Tools/dotnet-monitor/ParameterCapturing/CaptureParametersOperation.cs +++ b/src/Tools/dotnet-monitor/ParameterCapturing/CaptureParametersOperation.cs @@ -107,10 +107,10 @@ static Exception getNotAvailableException(string reason) throw getNotAvailableException(Strings.ParameterCapturingNotAvailable_Reason_ManagedMessagingDidNotLoad); } - if (!env.TryGetValue(InProcessFeaturesIdentifiers.EnvironmentVariables.AvailableInfrastructure.HostingStartup, out string isHostingStartupAvailable) || - !ToolIdentifiers.IsEnvVarValueEnabled(isHostingStartupAvailable)) + if (!env.TryGetValue(InProcessFeaturesIdentifiers.EnvironmentVariables.AvailableInfrastructure.StartupHook, out string isStartupHookAvailable) || + !ToolIdentifiers.IsEnvVarValueEnabled(isStartupHookAvailable)) { - throw getNotAvailableException(Strings.ParameterCapturingNotAvailable_Reason_HostingStartupDidNotLoad); + throw getNotAvailableException(Strings.ParameterCapturingNotAvailable_Reason_StartupHookDidNotLoad); } const string EditAndContinueEnvName = "COMPLUS_ForceEnc"; diff --git a/src/Tools/dotnet-monitor/Strings.Designer.cs b/src/Tools/dotnet-monitor/Strings.Designer.cs index e6468279b8f..af49d4f19b9 100644 --- a/src/Tools/dotnet-monitor/Strings.Designer.cs +++ b/src/Tools/dotnet-monitor/Strings.Designer.cs @@ -1654,15 +1654,6 @@ internal static string Message_ShowSources { } } - /// - /// Looks up a localized string similar to This feature is only available on processes using ASP.NET Core. If the process is using ASP.NET Core and has successfully started, ensure that it has not been configured to prevent hosting startup assemblies from loading.. - /// - internal static string ParameterCapturingNotAvailable_Reason_HostingStartupDidNotLoad { - get { - return ResourceManager.GetString("ParameterCapturingNotAvailable_Reason_HostingStartupDidNotLoad", resourceCulture); - } - } - /// /// Looks up a localized string similar to The process has Hot Reload enabled.. /// @@ -1690,6 +1681,15 @@ internal static string ParameterCapturingNotAvailable_Reason_PreventedHostingSta } } + /// + /// Looks up a localized string similar to This feature requires the startup hook to be loaded in the target process.. + /// + internal static string ParameterCapturingNotAvailable_Reason_StartupHookDidNotLoad { + get { + return ResourceManager.GetString("ParameterCapturingNotAvailable_Reason_StartupHookDidNotLoad", resourceCulture); + } + } + /// /// Looks up a localized string similar to The process needs to be using .NET 7 or newer.. /// diff --git a/src/Tools/dotnet-monitor/Strings.resx b/src/Tools/dotnet-monitor/Strings.resx index 8616e168143..a63ac31d441 100644 --- a/src/Tools/dotnet-monitor/Strings.resx +++ b/src/Tools/dotnet-monitor/Strings.resx @@ -930,8 +930,8 @@ The process has prevented hosting startup assemblies from loading using the ASPNETCORE_PREVENTHOSTINGSTARTUP environment variable. - - This feature is only available on processes using ASP.NET Core. If the process is using ASP.NET Core and has successfully started, ensure that it has not been configured to prevent hosting startup assemblies from loading. + + This feature requires the startup hook to be loaded in the target process. An internal error occurred that has prevented communication with the process. @@ -949,4 +949,4 @@ The expiration time on or after the generated key will no longer be accepted. This is a time span offset (e.g. "7.00:00:00" for 7 days) that will be added to the current date time to create the expiration date time. Gets the string to display in help that explains what the '--expiration' option does. - \ No newline at end of file + From 3bd2c0f9d17060eff09eb36861f25a7b5fcfe768 Mon Sep 17 00:00:00 2001 From: Claudiu Guiman Date: Fri, 31 May 2024 13:47:41 -0400 Subject: [PATCH 09/10] Remove HostingStartup (#6751) --- documentation/api/parameters.md | 2 - dotnet-monitor.sln | 14 --- eng/AfterSolutionBuild.targets | 1 - .../HostingStartup.cs | 31 ------- ...agnostics.Monitoring.HostingStartup.csproj | 45 --------- .../ProjectsToPublish.props | 15 --- .../IMethodDescription.cs | 2 +- .../AspNetHostingStartupLoader.cs | 69 -------------- .../DiagnosticsBootstrapper.cs | 11 --- ....Diagnostics.Monitoring.StartupHook.csproj | 3 - .../IInProcessFeatures.cs | 2 - .../KeyValueLogScope.cs | 4 - .../KeyValueLogScopeExtensions.cs | 8 +- .../Models/CaptureParametersConfiguration.cs | 2 +- .../Models/MethodDescription.cs | 2 +- .../ProfilerMessage.cs | 5 +- ...Monitoring.HostingStartup.UnitTests.csproj | 13 --- ...t.Diagnostics.Monitoring.TestCommon.csproj | 1 - .../TestAppScenarios.cs | 12 --- .../FunctionProbesTests.cs | 2 +- .../HostingStartupTests.cs | 62 ------------- ...ics.Monitoring.Tool.FunctionalTests.csproj | 1 - .../StartupHookTests.cs | 2 +- ....Diagnostics.Monitoring.UnitTestApp.csproj | 1 - .../Program.cs | 1 - .../Scenarios/HostingStartupScenario.cs | 81 ----------------- .../Commands/CollectCommandHandler.cs | 1 - .../HostingStartup/HostingStartupService.cs | 91 ------------------- .../InProcessFeatures/InProcessFeatures.cs | 6 +- ...cessFeaturesEndpointInfoSourceCallbacks.cs | 2 +- .../InProcessFeaturesIdentifiers.cs | 3 +- .../InProcessFeaturesService.cs | 2 +- src/Tools/dotnet-monitor/LoggingExtensions.cs | 11 --- .../CaptureParametersOperation.cs | 9 +- .../Profiler/ProfilerMessagePayloads.cs | 2 +- .../ServiceCollectionExtensions.cs | 8 -- .../StartupHook/StartupHookIdentifiers.cs | 16 ---- src/Tools/dotnet-monitor/Strings.Designer.cs | 27 ------ src/Tools/dotnet-monitor/Strings.resx | 63 ++++++------- .../dotnet-monitor/dotnet-monitor.csproj | 8 -- .../dotnet-monitor-base/Package.props | 1 - 41 files changed, 41 insertions(+), 601 deletions(-) delete mode 100644 src/Microsoft.Diagnostics.Monitoring.HostingStartup/HostingStartup.cs delete mode 100644 src/Microsoft.Diagnostics.Monitoring.HostingStartup/Microsoft.Diagnostics.Monitoring.HostingStartup.csproj delete mode 100644 src/Microsoft.Diagnostics.Monitoring.HostingStartup/ProjectsToPublish.props delete mode 100644 src/Microsoft.Diagnostics.Monitoring.StartupHook/AspNetHostingStartupLoader.cs delete mode 100644 src/Tests/Microsoft.Diagnostics.Monitoring.HostingStartup.UnitTests/Microsoft.Diagnostics.Monitoring.HostingStartup.UnitTests.csproj delete mode 100644 src/Tests/Microsoft.Diagnostics.Monitoring.Tool.FunctionalTests/HostingStartupTests.cs delete mode 100644 src/Tests/Microsoft.Diagnostics.Monitoring.UnitTestApp/Scenarios/HostingStartupScenario.cs delete mode 100644 src/Tools/dotnet-monitor/HostingStartup/HostingStartupService.cs delete mode 100644 src/Tools/dotnet-monitor/StartupHook/StartupHookIdentifiers.cs diff --git a/documentation/api/parameters.md b/documentation/api/parameters.md index 2bf5c886da3..d20f5431334 100644 --- a/documentation/api/parameters.md +++ b/documentation/api/parameters.md @@ -131,8 +131,6 @@ Content-Type: application/x-ndjson - The target application must use ASP.NET Core. - The target application cannot have [Hot Reload](https://learn.microsoft.com/visualstudio/debugger/hot-reload) enabled. - `dotnet-monitor` must be set to `Listen` mode, and the target application must start suspended. See [diagnostic port configuration](../configuration/diagnostic-port-configuration.md) for information on how to do this. -- The target application must have [`ILogger`](https://learn.microsoft.com/dotnet/api/microsoft.extensions.logging.ilogger) available via [ASP.NET Core's dependency injection](https://learn.microsoft.com/aspnet/core/fundamentals/dependency-injection). -- This feature relies on a hosting startup assembly. If the target application [disabled automatic loading](https://learn.microsoft.com/aspnet/core/fundamentals/host/platform-specific-configuration#disable-automatic-loading-of-hosting-startup-assemblies) of these, this feature will not be available. - This feature relies on a [ICorProfilerCallback](https://docs.microsoft.com/dotnet/framework/unmanaged-api/profiling/icorprofilercallback-interface) implementation. If the target application is already using an `ICorProfiler` that isn't notify-only, this feature will not be available. - If a target application is using .NET 7 then the `dotnet-monitor` startup hook must be configured. This is automatically done in .NET 8+. diff --git a/dotnet-monitor.sln b/dotnet-monitor.sln index a44a392a57e..338f5bdc028 100644 --- a/dotnet-monitor.sln +++ b/dotnet-monitor.sln @@ -70,10 +70,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Diagnostics.Monit EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Extensions", "Extensions", "{D3FEE1C0-E1E7-4796-A217-B46E3B6CCCCD}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Diagnostics.Monitoring.HostingStartup", "src\Microsoft.Diagnostics.Monitoring.HostingStartup\Microsoft.Diagnostics.Monitoring.HostingStartup.csproj", "{86BDA5CD-6A18-4EC2-9F13-F1A2723DD864}" -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Diagnostics.Monitoring.HostingStartup.UnitTests", "src\Tests\Microsoft.Diagnostics.Monitoring.HostingStartup.UnitTests\Microsoft.Diagnostics.Monitoring.HostingStartup.UnitTests.csproj", "{B9216DD7-F216-490A-A388-BBE0EC946EF2}" -EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -188,14 +184,6 @@ Global {E7EA323B-0CFE-4D42-9844-4C322A3BC54A}.Debug|Any CPU.Build.0 = Debug|Any CPU {E7EA323B-0CFE-4D42-9844-4C322A3BC54A}.Release|Any CPU.ActiveCfg = Release|Any CPU {E7EA323B-0CFE-4D42-9844-4C322A3BC54A}.Release|Any CPU.Build.0 = Release|Any CPU - {86BDA5CD-6A18-4EC2-9F13-F1A2723DD864}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {86BDA5CD-6A18-4EC2-9F13-F1A2723DD864}.Debug|Any CPU.Build.0 = Debug|Any CPU - {86BDA5CD-6A18-4EC2-9F13-F1A2723DD864}.Release|Any CPU.ActiveCfg = Release|Any CPU - {86BDA5CD-6A18-4EC2-9F13-F1A2723DD864}.Release|Any CPU.Build.0 = Release|Any CPU - {B9216DD7-F216-490A-A388-BBE0EC946EF2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {B9216DD7-F216-490A-A388-BBE0EC946EF2}.Debug|Any CPU.Build.0 = Debug|Any CPU - {B9216DD7-F216-490A-A388-BBE0EC946EF2}.Release|Any CPU.ActiveCfg = Release|Any CPU - {B9216DD7-F216-490A-A388-BBE0EC946EF2}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -231,8 +219,6 @@ Global {72EC615C-E1BE-4D27-A0FC-C0FEE483D3D2} = {19FAB78C-3351-4911-8F0C-8C6056401740} {E7EA323B-0CFE-4D42-9844-4C322A3BC54A} = {C7568468-1C79-4944-8136-18812A7F9EA7} {D3FEE1C0-E1E7-4796-A217-B46E3B6CCCCD} = {19FAB78C-3351-4911-8F0C-8C6056401740} - {86BDA5CD-6A18-4EC2-9F13-F1A2723DD864} = {19FAB78C-3351-4911-8F0C-8C6056401740} - {B9216DD7-F216-490A-A388-BBE0EC946EF2} = {C7568468-1C79-4944-8136-18812A7F9EA7} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {46465737-C938-44FC-BE1A-4CE139EBB5E0} diff --git a/eng/AfterSolutionBuild.targets b/eng/AfterSolutionBuild.targets index af7ca5f7f55..809cbd183bc 100644 --- a/eng/AfterSolutionBuild.targets +++ b/eng/AfterSolutionBuild.targets @@ -3,7 +3,6 @@ - diff --git a/src/Microsoft.Diagnostics.Monitoring.HostingStartup/HostingStartup.cs b/src/Microsoft.Diagnostics.Monitoring.HostingStartup/HostingStartup.cs deleted file mode 100644 index 91ea0e08644..00000000000 --- a/src/Microsoft.Diagnostics.Monitoring.HostingStartup/HostingStartup.cs +++ /dev/null @@ -1,31 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -using Microsoft.AspNetCore.Hosting; -using Microsoft.Diagnostics.Monitoring.HostingStartup; -using Microsoft.Diagnostics.Tools.Monitor; -using Microsoft.Diagnostics.Tools.Monitor.HostingStartup; -using System.Threading; - -[assembly: HostingStartup(typeof(HostingStartup))] -namespace Microsoft.Diagnostics.Monitoring.HostingStartup -{ - internal sealed class HostingStartup : IHostingStartup - { - public static int InvocationCount; - - public void Configure(IWebHostBuilder builder) - { - builder.ConfigureServices(services => - { - // Keep track of how many times this hosting startup has been invoked for easy - // validation in tests. - Interlocked.Increment(ref InvocationCount); - - // TODO: remove the HostingStartup project. - }); - - ToolIdentifiers.EnableEnvVar(InProcessFeaturesIdentifiers.EnvironmentVariables.AvailableInfrastructure.HostingStartup); - } - } -} diff --git a/src/Microsoft.Diagnostics.Monitoring.HostingStartup/Microsoft.Diagnostics.Monitoring.HostingStartup.csproj b/src/Microsoft.Diagnostics.Monitoring.HostingStartup/Microsoft.Diagnostics.Monitoring.HostingStartup.csproj deleted file mode 100644 index 904e8f90395..00000000000 --- a/src/Microsoft.Diagnostics.Monitoring.HostingStartup/Microsoft.Diagnostics.Monitoring.HostingStartup.csproj +++ /dev/null @@ -1,45 +0,0 @@ - - - - - net6.0 - true - Library - $(DefineConstants);HOSTINGSTARTUP - enable - True - - - - - - - - - - - - - - - - - - - - - - True - True - ParameterCapturingStrings.resx - - - - - - ResXFileCodeGenerator - ParameterCapturingStrings.Designer.cs - - - - diff --git a/src/Microsoft.Diagnostics.Monitoring.HostingStartup/ProjectsToPublish.props b/src/Microsoft.Diagnostics.Monitoring.HostingStartup/ProjectsToPublish.props deleted file mode 100644 index 958e293fe26..00000000000 --- a/src/Microsoft.Diagnostics.Monitoring.HostingStartup/ProjectsToPublish.props +++ /dev/null @@ -1,15 +0,0 @@ - - - net6.0 - Microsoft.Diagnostics.Monitoring.HostingStartup - $(ArtifactsDir)pub\$(HostingStartupLibraryName)\$(Configuration)\$(HostingStartupTargetFramework)\ - $(HostingStartupPublishPath)$(HostingStartupLibraryName).dll - $(HostingStartupPublishPath)$(HostingStartupLibraryName).pdb - - - - - TargetFramework=$(HostingStartupTargetFramework);RuntimeIdentifier=;PublishDir=$(HostingStartupPublishPath) - - - diff --git a/src/Microsoft.Diagnostics.Monitoring.Options/IMethodDescription.cs b/src/Microsoft.Diagnostics.Monitoring.Options/IMethodDescription.cs index a2c5c1b1173..7191e1f9931 100644 --- a/src/Microsoft.Diagnostics.Monitoring.Options/IMethodDescription.cs +++ b/src/Microsoft.Diagnostics.Monitoring.Options/IMethodDescription.cs @@ -3,7 +3,7 @@ using System.Text.Json.Serialization; -#if STARTUPHOOK || HOSTINGSTARTUP +#if STARTUPHOOK namespace Microsoft.Diagnostics.Monitoring.StartupHook.MonitorMessageDispatcher.Models #else namespace Microsoft.Diagnostics.Monitoring.Options diff --git a/src/Microsoft.Diagnostics.Monitoring.StartupHook/AspNetHostingStartupLoader.cs b/src/Microsoft.Diagnostics.Monitoring.StartupHook/AspNetHostingStartupLoader.cs deleted file mode 100644 index 158a17fe3ee..00000000000 --- a/src/Microsoft.Diagnostics.Monitoring.StartupHook/AspNetHostingStartupLoader.cs +++ /dev/null @@ -1,69 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -using System; -using System.IO; -using System.Reflection; -using System.Runtime.Loader; - -namespace Microsoft.Diagnostics.Monitoring.StartupHook -{ - internal sealed class AspNetHostingStartupLoader : IDisposable - { - private readonly string _filePath; - private readonly string _simpleAssemblyName; - - private long _disposedState; - - public AspNetHostingStartupLoader(string filePath) - { - _filePath = filePath; - _simpleAssemblyName = CalculateSimpleAssemblyName(filePath); - - RegisterHostingStartupAssembly(_simpleAssemblyName); - AssemblyLoadContext.Default.Resolving += AssemblyResolver; - } - - private Assembly? AssemblyResolver(AssemblyLoadContext context, AssemblyName assemblyName) - { - if (_simpleAssemblyName.Equals(assemblyName.Name, StringComparison.OrdinalIgnoreCase)) - { - return AssemblyLoadContext.Default.LoadFromAssemblyPath(_filePath); - } - - return null; - } - - private static string CalculateSimpleAssemblyName(string filePath) - { - string fileName = Path.GetFileName(filePath); - const string dllExtension = ".dll"; - if (dllExtension.Equals(Path.GetExtension(fileName), StringComparison.OrdinalIgnoreCase)) - { - return fileName[..^dllExtension.Length]; - } - - return fileName; - } - - private static void RegisterHostingStartupAssembly(string simpleAssemblyName) - { - const string HostingStartupEnvVariable = "ASPNETCORE_HOSTINGSTARTUPASSEMBLIES"; - // aspnetcore explicitly uses ; as the delimiter for the above environment variable. - // ref: https://github.com/dotnet/aspnetcore/blob/898c164a1f537a8210a26eaf388bdc92531f6b09/src/Hosting/Hosting/src/Internal/WebHostOptions.cs#L79 - const char Delimiter = ';'; - - string? curValue = Environment.GetEnvironmentVariable(HostingStartupEnvVariable); - string newValue = string.IsNullOrWhiteSpace(curValue) ? simpleAssemblyName : string.Concat(curValue, Delimiter, simpleAssemblyName); - Environment.SetEnvironmentVariable(HostingStartupEnvVariable, newValue); - } - - public void Dispose() - { - if (!DisposableHelper.CanDispose(ref _disposedState)) - return; - - AssemblyLoadContext.Default.Resolving -= AssemblyResolver; - } - } -} diff --git a/src/Microsoft.Diagnostics.Monitoring.StartupHook/DiagnosticsBootstrapper.cs b/src/Microsoft.Diagnostics.Monitoring.StartupHook/DiagnosticsBootstrapper.cs index 66d06861518..080201c31e5 100644 --- a/src/Microsoft.Diagnostics.Monitoring.StartupHook/DiagnosticsBootstrapper.cs +++ b/src/Microsoft.Diagnostics.Monitoring.StartupHook/DiagnosticsBootstrapper.cs @@ -5,11 +5,9 @@ using Microsoft.Diagnostics.Monitoring.StartupHook.Monitoring; using Microsoft.Diagnostics.Monitoring.StartupHook.ParameterCapturing; using Microsoft.Diagnostics.Tools.Monitor; -using Microsoft.Diagnostics.Tools.Monitor.HostingStartup; using Microsoft.Diagnostics.Tools.Monitor.Profiler; using Microsoft.Diagnostics.Tools.Monitor.StartupHook; using System; -using System.IO; using MessageDispatcher = Microsoft.Diagnostics.Monitoring.StartupHook.MonitorMessageDispatcher; namespace Microsoft.Diagnostics.Monitoring.StartupHook @@ -18,7 +16,6 @@ internal sealed class DiagnosticsBootstrapper : IDisposable { private readonly CurrentAppDomainExceptionProcessor _exceptionProcessor; - private readonly AspNetHostingStartupLoader? _hostingStartupLoader; private readonly ParameterCapturingService? _parameterCapturingService; private long _disposedState; @@ -30,13 +27,6 @@ public DiagnosticsBootstrapper() using IDisposable _ = MonitorExecutionContextTracker.MonitorScope(); - string? hostingStartupPath = Environment.GetEnvironmentVariable(StartupHookIdentifiers.EnvironmentVariables.HostingStartupPath); - // TODO: Log if specified hosting startup assembly doesn't exist - if (File.Exists(hostingStartupPath)) - { - _hostingStartupLoader = new AspNetHostingStartupLoader(hostingStartupPath); - } - try { // Check that the profiler is loaded before establishing the dispatcher, which has a dependency on the existence of the profiler @@ -68,7 +58,6 @@ public void Dispose() _exceptionProcessor.Dispose(); _parameterCapturingService?.Stop(); _parameterCapturingService?.Dispose(); - _hostingStartupLoader?.Dispose(); SharedInternals.MessageDispatcher?.Dispose(); } } diff --git a/src/Microsoft.Diagnostics.Monitoring.StartupHook/Microsoft.Diagnostics.Monitoring.StartupHook.csproj b/src/Microsoft.Diagnostics.Monitoring.StartupHook/Microsoft.Diagnostics.Monitoring.StartupHook.csproj index 8459975bcf3..353f6c571e0 100644 --- a/src/Microsoft.Diagnostics.Monitoring.StartupHook/Microsoft.Diagnostics.Monitoring.StartupHook.csproj +++ b/src/Microsoft.Diagnostics.Monitoring.StartupHook/Microsoft.Diagnostics.Monitoring.StartupHook.csproj @@ -14,7 +14,6 @@ - @@ -27,9 +26,7 @@ - - diff --git a/src/Microsoft.Diagnostics.Monitoring.WebApi/IInProcessFeatures.cs b/src/Microsoft.Diagnostics.Monitoring.WebApi/IInProcessFeatures.cs index e0c7b2123d5..3ce243d9c73 100644 --- a/src/Microsoft.Diagnostics.Monitoring.WebApi/IInProcessFeatures.cs +++ b/src/Microsoft.Diagnostics.Monitoring.WebApi/IInProcessFeatures.cs @@ -10,8 +10,6 @@ public interface IInProcessFeatures bool IsStartupHookRequired { get; } - bool IsHostingStartupRequired { get; } - bool IsLibrarySharingRequired { get; } } } diff --git a/src/Microsoft.Diagnostics.Monitoring.WebApi/KeyValueLogScope.cs b/src/Microsoft.Diagnostics.Monitoring.WebApi/KeyValueLogScope.cs index 76f62de6635..8039539695f 100644 --- a/src/Microsoft.Diagnostics.Monitoring.WebApi/KeyValueLogScope.cs +++ b/src/Microsoft.Diagnostics.Monitoring.WebApi/KeyValueLogScope.cs @@ -5,11 +5,7 @@ using System.Collections.Generic; using System.Text; -#if HOSTINGSTARTUP -namespace Microsoft.Diagnostics.Monitoring.HostingStartup -#else namespace Microsoft.Diagnostics.Monitoring.WebApi -#endif { // Logger implementations have different ways of serializing log scopes. This class helps those loggers // serialize the scope information in the best way possible for each of the implementations. diff --git a/src/Microsoft.Diagnostics.Monitoring.WebApi/KeyValueLogScopeExtensions.cs b/src/Microsoft.Diagnostics.Monitoring.WebApi/KeyValueLogScopeExtensions.cs index b94b3e0972a..43f0f238c17 100644 --- a/src/Microsoft.Diagnostics.Monitoring.WebApi/KeyValueLogScopeExtensions.cs +++ b/src/Microsoft.Diagnostics.Monitoring.WebApi/KeyValueLogScopeExtensions.cs @@ -2,14 +2,9 @@ // The .NET Foundation licenses this file to you under the MIT license. using System.Collections.Generic; - -#if HOSTINGSTARTUP -namespace Microsoft.Diagnostics.Monitoring.HostingStartup -#else using System.Globalization; namespace Microsoft.Diagnostics.Monitoring.WebApi -#endif { internal static class KeyValueLogScopeExtensions { @@ -17,7 +12,7 @@ public static void Add(this List> values, string ke { values.Add(new KeyValuePair(key, value)); } -#if !HOSTINGSTARTUP + public static void AddArtifactType(this KeyValueLogScope scope, string artifactType) { scope.Values.Add("ArtifactType", artifactType); @@ -32,6 +27,5 @@ public static void AddArtifactEndpointInfo(this KeyValueLogScope scope, IEndpoin ArtifactMetadataNames.ArtifactSource.RuntimeInstanceCookie, endpointInfo.RuntimeInstanceCookie.ToString("N")); } -#endif } } diff --git a/src/Microsoft.Diagnostics.Monitoring.WebApi/Models/CaptureParametersConfiguration.cs b/src/Microsoft.Diagnostics.Monitoring.WebApi/Models/CaptureParametersConfiguration.cs index e967a080b30..e0c4a7181b2 100644 --- a/src/Microsoft.Diagnostics.Monitoring.WebApi/Models/CaptureParametersConfiguration.cs +++ b/src/Microsoft.Diagnostics.Monitoring.WebApi/Models/CaptureParametersConfiguration.cs @@ -5,7 +5,7 @@ using System.ComponentModel.DataAnnotations; using System.Text.Json.Serialization; -#if STARTUPHOOK || HOSTINGSTARTUP +#if STARTUPHOOK namespace Microsoft.Diagnostics.Monitoring.StartupHook.MonitorMessageDispatcher.Models #else namespace Microsoft.Diagnostics.Monitoring.WebApi.Models diff --git a/src/Microsoft.Diagnostics.Monitoring.WebApi/Models/MethodDescription.cs b/src/Microsoft.Diagnostics.Monitoring.WebApi/Models/MethodDescription.cs index 62aea680ec6..8a7b18afca0 100644 --- a/src/Microsoft.Diagnostics.Monitoring.WebApi/Models/MethodDescription.cs +++ b/src/Microsoft.Diagnostics.Monitoring.WebApi/Models/MethodDescription.cs @@ -4,7 +4,7 @@ using System; using System.ComponentModel.DataAnnotations; -#if STARTUPHOOK || HOSTINGSTARTUP +#if STARTUPHOOK namespace Microsoft.Diagnostics.Monitoring.StartupHook.MonitorMessageDispatcher.Models #else using Microsoft.Diagnostics.Monitoring.Options; diff --git a/src/Microsoft.Diagnostics.Monitoring.WebApi/ProfilerMessage.cs b/src/Microsoft.Diagnostics.Monitoring.WebApi/ProfilerMessage.cs index 6255ace92af..f40475a9489 100644 --- a/src/Microsoft.Diagnostics.Monitoring.WebApi/ProfilerMessage.cs +++ b/src/Microsoft.Diagnostics.Monitoring.WebApi/ProfilerMessage.cs @@ -6,7 +6,7 @@ using System.Text.Json; -#if STARTUPHOOK || HOSTINGSTARTUP +#if STARTUPHOOK namespace Microsoft.Diagnostics.Monitoring.StartupHook.Monitoring #else namespace Microsoft.Diagnostics.Monitoring @@ -29,9 +29,6 @@ public enum ProfilerCommand : ushort Callstack }; - /// - /// Shared between the StartupHook and HostingStartup assembly. - /// public enum StartupHookCommand : ushort { StartCapturingParameters, diff --git a/src/Tests/Microsoft.Diagnostics.Monitoring.HostingStartup.UnitTests/Microsoft.Diagnostics.Monitoring.HostingStartup.UnitTests.csproj b/src/Tests/Microsoft.Diagnostics.Monitoring.HostingStartup.UnitTests/Microsoft.Diagnostics.Monitoring.HostingStartup.UnitTests.csproj deleted file mode 100644 index a20295d2c7d..00000000000 --- a/src/Tests/Microsoft.Diagnostics.Monitoring.HostingStartup.UnitTests/Microsoft.Diagnostics.Monitoring.HostingStartup.UnitTests.csproj +++ /dev/null @@ -1,13 +0,0 @@ - - - - $(TestTargetFrameworks) - True - enable - - - - - - - diff --git a/src/Tests/Microsoft.Diagnostics.Monitoring.TestCommon/Microsoft.Diagnostics.Monitoring.TestCommon.csproj b/src/Tests/Microsoft.Diagnostics.Monitoring.TestCommon/Microsoft.Diagnostics.Monitoring.TestCommon.csproj index a8410dac814..3544d5bfdd2 100644 --- a/src/Tests/Microsoft.Diagnostics.Monitoring.TestCommon/Microsoft.Diagnostics.Monitoring.TestCommon.csproj +++ b/src/Tests/Microsoft.Diagnostics.Monitoring.TestCommon/Microsoft.Diagnostics.Monitoring.TestCommon.csproj @@ -33,7 +33,6 @@ - diff --git a/src/Tests/Microsoft.Diagnostics.Monitoring.TestCommon/TestAppScenarios.cs b/src/Tests/Microsoft.Diagnostics.Monitoring.TestCommon/TestAppScenarios.cs index f73606f941e..fe4766ef238 100644 --- a/src/Tests/Microsoft.Diagnostics.Monitoring.TestCommon/TestAppScenarios.cs +++ b/src/Tests/Microsoft.Diagnostics.Monitoring.TestCommon/TestAppScenarios.cs @@ -120,18 +120,6 @@ public static class SubScenarios } } - public static class HostingStartup - { - public const string Name = nameof(HostingStartup); - - public static class SubScenarios - { - public const string VerifyAspNetAppWithoutHostingStartup = nameof(VerifyAspNetAppWithoutHostingStartup); - public const string VerifyAspNetApp = nameof(VerifyAspNetApp); - public const string VerifyNonAspNetAppNotImpacted = nameof(VerifyNonAspNetAppNotImpacted); - } - } - public static class Stacks { public const string Name = nameof(Stacks); diff --git a/src/Tests/Microsoft.Diagnostics.Monitoring.Tool.FunctionalTests/FunctionProbesTests.cs b/src/Tests/Microsoft.Diagnostics.Monitoring.Tool.FunctionalTests/FunctionProbesTests.cs index df567693153..cea57664c78 100644 --- a/src/Tests/Microsoft.Diagnostics.Monitoring.Tool.FunctionalTests/FunctionProbesTests.cs +++ b/src/Tests/Microsoft.Diagnostics.Monitoring.Tool.FunctionalTests/FunctionProbesTests.cs @@ -4,7 +4,7 @@ using Microsoft.Diagnostics.Monitoring.TestCommon; using Microsoft.Diagnostics.Monitoring.TestCommon.Runners; using Microsoft.Diagnostics.Monitoring.Tool.FunctionalTests.Fixtures; -using Microsoft.Diagnostics.Tools.Monitor.HostingStartup; +using Microsoft.Diagnostics.Tools.Monitor.StartupHook; using Microsoft.Extensions.DependencyInjection; using System.Collections.Generic; using System.Linq; diff --git a/src/Tests/Microsoft.Diagnostics.Monitoring.Tool.FunctionalTests/HostingStartupTests.cs b/src/Tests/Microsoft.Diagnostics.Monitoring.Tool.FunctionalTests/HostingStartupTests.cs deleted file mode 100644 index fee42ee1bfd..00000000000 --- a/src/Tests/Microsoft.Diagnostics.Monitoring.Tool.FunctionalTests/HostingStartupTests.cs +++ /dev/null @@ -1,62 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -using Microsoft.Diagnostics.Monitoring.TestCommon; -using Microsoft.Diagnostics.Monitoring.TestCommon.Options; -using Microsoft.Diagnostics.Monitoring.Tool.FunctionalTests.Fixtures; -using Microsoft.Diagnostics.Monitoring.Tool.FunctionalTests.Runners; -using Microsoft.Diagnostics.Monitoring.WebApi; -using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Logging; -using System.Net.Http; -using System.Threading.Tasks; -using Xunit; -using Xunit.Abstractions; - -namespace Microsoft.Diagnostics.Monitoring.Tool.FunctionalTests -{ - [TargetFrameworkMonikerTrait(TargetFrameworkMonikerExtensions.CurrentTargetFrameworkMoniker)] - [Collection(DefaultCollectionFixture.Name)] - public class HostingStartupTests - { - private readonly IHttpClientFactory _httpClientFactory; - private readonly ITestOutputHelper _outputHelper; - - public HostingStartupTests(ITestOutputHelper outputHelper, ServiceProviderFixture serviceProviderFixture) - { - _httpClientFactory = serviceProviderFixture.ServiceProvider.GetService(); - _outputHelper = outputHelper; - } - - - [Theory] - [InlineData(TestAppScenarios.HostingStartup.SubScenarios.VerifyAspNetApp, true)] - [InlineData(TestAppScenarios.HostingStartup.SubScenarios.VerifyAspNetAppWithoutHostingStartup, false)] - [InlineData(TestAppScenarios.HostingStartup.SubScenarios.VerifyNonAspNetAppNotImpacted, true)] - - public async Task HostingStartupLoadTests(string subScenario, bool tryLoadHostingStartup) - { - await ScenarioRunner.SingleTarget( - _outputHelper, - _httpClientFactory, - DiagnosticPortConnectionMode.Listen, - TestAppScenarios.HostingStartup.Name, - appValidate: (runner, client) => { return Task.CompletedTask; }, - configureApp: runner => - { - runner.EnableMonitorStartupHook = true; - }, - configureTool: runner => - { - runner.ConfigurationFromEnvironment.EnableInProcessFeatures(); - // Enable a feature that requires the hosting startup assembly. - runner.ConfigurationFromEnvironment.InProcessFeatures.ParameterCapturing = new() - { - Enabled = tryLoadHostingStartup - }; - }, - profilerLogLevel: LogLevel.Trace, - subScenarioName: subScenario); - } - } -} diff --git a/src/Tests/Microsoft.Diagnostics.Monitoring.Tool.FunctionalTests/Microsoft.Diagnostics.Monitoring.Tool.FunctionalTests.csproj b/src/Tests/Microsoft.Diagnostics.Monitoring.Tool.FunctionalTests/Microsoft.Diagnostics.Monitoring.Tool.FunctionalTests.csproj index 3b632639638..c2373b90b27 100644 --- a/src/Tests/Microsoft.Diagnostics.Monitoring.Tool.FunctionalTests/Microsoft.Diagnostics.Monitoring.Tool.FunctionalTests.csproj +++ b/src/Tests/Microsoft.Diagnostics.Monitoring.Tool.FunctionalTests/Microsoft.Diagnostics.Monitoring.Tool.FunctionalTests.csproj @@ -85,7 +85,6 @@ - diff --git a/src/Tests/Microsoft.Diagnostics.Monitoring.Tool.UnitTests/StartupHookTests.cs b/src/Tests/Microsoft.Diagnostics.Monitoring.Tool.UnitTests/StartupHookTests.cs index 25358ee9d2e..d9cf19c2681 100644 --- a/src/Tests/Microsoft.Diagnostics.Monitoring.Tool.UnitTests/StartupHookTests.cs +++ b/src/Tests/Microsoft.Diagnostics.Monitoring.Tool.UnitTests/StartupHookTests.cs @@ -4,7 +4,7 @@ using Microsoft.Diagnostics.Monitoring.TestCommon; using Microsoft.Diagnostics.Monitoring.TestCommon.Runners; using Microsoft.Diagnostics.NETCore.Client; -using Microsoft.Diagnostics.Tools.Monitor.HostingStartup; +using Microsoft.Diagnostics.Tools.Monitor.StartupHook; using Microsoft.Extensions.Logging; using System; using System.Collections.Generic; diff --git a/src/Tests/Microsoft.Diagnostics.Monitoring.UnitTestApp/Microsoft.Diagnostics.Monitoring.UnitTestApp.csproj b/src/Tests/Microsoft.Diagnostics.Monitoring.UnitTestApp/Microsoft.Diagnostics.Monitoring.UnitTestApp.csproj index dee00113162..cd3ab6d95da 100644 --- a/src/Tests/Microsoft.Diagnostics.Monitoring.UnitTestApp/Microsoft.Diagnostics.Monitoring.UnitTestApp.csproj +++ b/src/Tests/Microsoft.Diagnostics.Monitoring.UnitTestApp/Microsoft.Diagnostics.Monitoring.UnitTestApp.csproj @@ -12,7 +12,6 @@ - diff --git a/src/Tests/Microsoft.Diagnostics.Monitoring.UnitTestApp/Program.cs b/src/Tests/Microsoft.Diagnostics.Monitoring.UnitTestApp/Program.cs index 256bdd5cf47..f5cfd0d8d36 100644 --- a/src/Tests/Microsoft.Diagnostics.Monitoring.UnitTestApp/Program.cs +++ b/src/Tests/Microsoft.Diagnostics.Monitoring.UnitTestApp/Program.cs @@ -22,7 +22,6 @@ public static Task Main(string[] args) FunctionProbesScenario.Command(), LoggerScenario.Command(), ParameterCapturingScenario.Command(), - HostingStartupScenario.Command(), SpinWaitScenario.Command(), EnvironmentVariablesScenario.Command(), StacksScenario.Command(), diff --git a/src/Tests/Microsoft.Diagnostics.Monitoring.UnitTestApp/Scenarios/HostingStartupScenario.cs b/src/Tests/Microsoft.Diagnostics.Monitoring.UnitTestApp/Scenarios/HostingStartupScenario.cs deleted file mode 100644 index 582aeab617d..00000000000 --- a/src/Tests/Microsoft.Diagnostics.Monitoring.UnitTestApp/Scenarios/HostingStartupScenario.cs +++ /dev/null @@ -1,81 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -using Microsoft.AspNetCore.Builder; -using Microsoft.AspNetCore.Hosting; -using Microsoft.AspNetCore.Http; -using Microsoft.Diagnostics.Monitoring.TestCommon; -using Microsoft.Extensions.DependencyInjection; -using System.CommandLine; -using System.Threading; -using System.Threading.Tasks; -using Xunit; - -namespace Microsoft.Diagnostics.Monitoring.UnitTestApp.Scenarios -{ - internal sealed class HostingStartupScenario - { - public static CliCommand Command() - { - CliCommand aspnetAppNoHostingStartupCommand = new(TestAppScenarios.HostingStartup.SubScenarios.VerifyAspNetAppWithoutHostingStartup); - aspnetAppNoHostingStartupCommand.SetAction(VerifyAspNetAppWithoutHostingStartupAsync); - - CliCommand aspnetAppCommand = new(TestAppScenarios.HostingStartup.SubScenarios.VerifyAspNetApp); - aspnetAppCommand.SetAction(VerifyAspNetAppAsync); - - CliCommand nonAspNetAppCommand = new(TestAppScenarios.HostingStartup.SubScenarios.VerifyNonAspNetAppNotImpacted); - nonAspNetAppCommand.SetAction(VerifyNonAspNetAppNotImpactedAsync); - - CliCommand scenarioCommand = new(TestAppScenarios.HostingStartup.Name); - scenarioCommand.Subcommands.Add(aspnetAppNoHostingStartupCommand); - scenarioCommand.Subcommands.Add(aspnetAppCommand); - scenarioCommand.Subcommands.Add(nonAspNetAppCommand); - return scenarioCommand; - } - - public static Task VerifyNonAspNetAppNotImpactedAsync(ParseResult result, CancellationToken token) - { - return ScenarioHelpers.RunScenarioAsync(logger => - { - Assert.Equal(0, HostingStartup.HostingStartup.InvocationCount); - return Task.FromResult(0); - }, token); - } - - public static Task VerifyAspNetAppWithoutHostingStartupAsync(ParseResult result, CancellationToken token) - { - return ScenarioHelpers.RunWebScenarioAsync(logger => - { - Assert.Equal(0, HostingStartup.HostingStartup.InvocationCount); - return Task.FromResult(0); - }, token); - } - - public static Task VerifyAspNetAppAsync(ParseResult result, CancellationToken token) - { - return ScenarioHelpers.RunWebScenarioAsync(logger => - { - Assert.Equal(1, HostingStartup.HostingStartup.InvocationCount); - return Task.FromResult(0); - }, token); - } - - private sealed class Startup - { - public static void ConfigureServices(IServiceCollection services) - { - services.AddControllers(); - } - - public static void Configure(IApplicationBuilder app, IWebHostEnvironment env) - { - app.UseRouting(); - - app.UseEndpoints(endpoints => - { - endpoints.MapGet("/", () => Results.Ok()); - }); - } - } - } -} diff --git a/src/Tools/dotnet-monitor/Commands/CollectCommandHandler.cs b/src/Tools/dotnet-monitor/Commands/CollectCommandHandler.cs index 799ff74c852..32b2f930c9e 100644 --- a/src/Tools/dotnet-monitor/Commands/CollectCommandHandler.cs +++ b/src/Tools/dotnet-monitor/Commands/CollectCommandHandler.cs @@ -133,7 +133,6 @@ private static IHostBuilder Configure(this IHostBuilder builder, StartupAuthenti services.ConfigureLibrarySharing(); services.ConfigureProfiler(); services.ConfigureStartupHook(); - services.ConfigureHostingStartup(); services.ConfigureExceptions(); services.ConfigureStartupLoggers(authConfigurator); services.ConfigureInProcessFeatures(context.Configuration); diff --git a/src/Tools/dotnet-monitor/HostingStartup/HostingStartupService.cs b/src/Tools/dotnet-monitor/HostingStartup/HostingStartupService.cs deleted file mode 100644 index 9836d4b2fba..00000000000 --- a/src/Tools/dotnet-monitor/HostingStartup/HostingStartupService.cs +++ /dev/null @@ -1,91 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -using Microsoft.Diagnostics.Monitoring.WebApi; -using Microsoft.Diagnostics.NETCore.Client; -using Microsoft.Diagnostics.Tools.Monitor.LibrarySharing; -using Microsoft.Diagnostics.Tools.Monitor.StartupHook; -using Microsoft.Extensions.FileProviders; -using Microsoft.Extensions.Logging; -using System; -using System.IO; -using System.Threading; -using System.Threading.Tasks; - -namespace Microsoft.Diagnostics.Tools.Monitor.HostingStartup -{ - internal sealed class HostingStartupService - : IDiagnosticLifetimeService - { - // Intent is to ship a single TFM of the hosting startup, which should be the lowest supported version. - private const string HostingStartupFileName = "Microsoft.Diagnostics.Monitoring.HostingStartup.dll"; - private const string HostingStartupTargetFramework = "net6.0"; - - private readonly IEndpointInfo _endpointInfo; - private readonly StartupHookService _startupHookService; - private readonly IInProcessFeatures _inProcessFeatures; - private readonly ISharedLibraryService _sharedLibraryService; - private readonly ILogger _logger; - - public HostingStartupService( - IEndpointInfo endpointInfo, - StartupHookService startupHookService, - ISharedLibraryService sharedLibraryService, - IInProcessFeatures inProcessFeatures, - ILogger logger) - { - _endpointInfo = endpointInfo; - _startupHookService = startupHookService; - _inProcessFeatures = inProcessFeatures; - _sharedLibraryService = sharedLibraryService; - _logger = logger; - } - - public async ValueTask StartAsync(CancellationToken cancellationToken) - { - if (!_inProcessFeatures.IsHostingStartupRequired) - { - return; - } - - // Hosting startup is only supported on .NET 6+ - if (_endpointInfo.RuntimeVersion == null || _endpointInfo.RuntimeVersion.Major < 6) - { - return; - } - - try - { - // Hosting startup requires the startup hook - if (!await _startupHookService.Applied.WaitAsync(cancellationToken)) - { - return; - } - - IFileProviderFactory fileProviderFactory = await _sharedLibraryService.GetFactoryAsync(cancellationToken); - IFileProvider managedFileProvider = fileProviderFactory.CreateManaged(HostingStartupTargetFramework); - - IFileInfo hostingStartupLibraryFileInfo = managedFileProvider.GetFileInfo(HostingStartupFileName); - if (!hostingStartupLibraryFileInfo.Exists) - { - throw new FileNotFoundException(Strings.ErrorMessage_UnableToFindHostingStartupAssembly, hostingStartupLibraryFileInfo.Name); - } - - DiagnosticsClient client = new DiagnosticsClient(_endpointInfo.Endpoint); - await client.SetEnvironmentVariableAsync( - StartupHookIdentifiers.EnvironmentVariables.HostingStartupPath, - hostingStartupLibraryFileInfo.PhysicalPath, - cancellationToken); - } - catch (Exception ex) - { - _logger.UnableToApplyHostingStartup(ex); - } - } - - public ValueTask StopAsync(CancellationToken cancellationToken) - { - return ValueTask.CompletedTask; - } - } -} diff --git a/src/Tools/dotnet-monitor/InProcessFeatures/InProcessFeatures.cs b/src/Tools/dotnet-monitor/InProcessFeatures/InProcessFeatures.cs index 55f99c6d780..8d48f0313a2 100644 --- a/src/Tools/dotnet-monitor/InProcessFeatures/InProcessFeatures.cs +++ b/src/Tools/dotnet-monitor/InProcessFeatures/InProcessFeatures.cs @@ -32,10 +32,8 @@ public InProcessFeatures( public bool IsMutatingProfilerRequired => IsParameterCapturingEnabled; - public bool IsStartupHookRequired => IsHostingStartupRequired || IsExceptionsEnabled; + public bool IsStartupHookRequired => IsParameterCapturingEnabled || IsExceptionsEnabled; - public bool IsHostingStartupRequired => IsParameterCapturingEnabled; - - public bool IsLibrarySharingRequired => IsProfilerRequired || IsStartupHookRequired || IsHostingStartupRequired; + public bool IsLibrarySharingRequired => IsProfilerRequired || IsStartupHookRequired; } } diff --git a/src/Tools/dotnet-monitor/InProcessFeatures/InProcessFeaturesEndpointInfoSourceCallbacks.cs b/src/Tools/dotnet-monitor/InProcessFeatures/InProcessFeaturesEndpointInfoSourceCallbacks.cs index f194c6bf7fe..0c3aa44491c 100644 --- a/src/Tools/dotnet-monitor/InProcessFeatures/InProcessFeaturesEndpointInfoSourceCallbacks.cs +++ b/src/Tools/dotnet-monitor/InProcessFeatures/InProcessFeaturesEndpointInfoSourceCallbacks.cs @@ -5,7 +5,7 @@ using System.Threading; using System.Threading.Tasks; -namespace Microsoft.Diagnostics.Tools.Monitor.HostingStartup +namespace Microsoft.Diagnostics.Tools.Monitor.StartupHook { internal sealed class InProcessFeaturesEndpointInfoSourceCallbacks : IEndpointInfoSourceCallbacks { diff --git a/src/Tools/dotnet-monitor/InProcessFeatures/InProcessFeaturesIdentifiers.cs b/src/Tools/dotnet-monitor/InProcessFeatures/InProcessFeaturesIdentifiers.cs index 3e2606a040a..c4e2118d210 100644 --- a/src/Tools/dotnet-monitor/InProcessFeatures/InProcessFeaturesIdentifiers.cs +++ b/src/Tools/dotnet-monitor/InProcessFeatures/InProcessFeaturesIdentifiers.cs @@ -1,7 +1,7 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. -namespace Microsoft.Diagnostics.Tools.Monitor.HostingStartup +namespace Microsoft.Diagnostics.Tools.Monitor.StartupHook { public static class InProcessFeaturesIdentifiers { @@ -26,7 +26,6 @@ public static class AvailableInfrastructure private const string AvailableInfrastructurePrefix = InProcessFeaturesPrefix + "AvailableInfrastructure_"; public const string ManagedMessaging = AvailableInfrastructurePrefix + nameof(ManagedMessaging); public const string StartupHook = AvailableInfrastructurePrefix + nameof(StartupHook); - public const string HostingStartup = AvailableInfrastructurePrefix + nameof(HostingStartup); } } } diff --git a/src/Tools/dotnet-monitor/InProcessFeatures/InProcessFeaturesService.cs b/src/Tools/dotnet-monitor/InProcessFeatures/InProcessFeaturesService.cs index bd5d37b83e5..4311f8a5b7f 100644 --- a/src/Tools/dotnet-monitor/InProcessFeatures/InProcessFeaturesService.cs +++ b/src/Tools/dotnet-monitor/InProcessFeatures/InProcessFeaturesService.cs @@ -11,7 +11,7 @@ using System.Threading; using System.Threading.Tasks; -namespace Microsoft.Diagnostics.Tools.Monitor.HostingStartup +namespace Microsoft.Diagnostics.Tools.Monitor.StartupHook { internal sealed class InProcessFeaturesService { diff --git a/src/Tools/dotnet-monitor/LoggingExtensions.cs b/src/Tools/dotnet-monitor/LoggingExtensions.cs index 0a44b655669..5578be3cee7 100644 --- a/src/Tools/dotnet-monitor/LoggingExtensions.cs +++ b/src/Tools/dotnet-monitor/LoggingExtensions.cs @@ -512,12 +512,6 @@ internal static class LoggingExtensions logLevel: LogLevel.Debug, formatString: Strings.LogFormatString_EndpointRemovalFailed); - private static readonly Action _unableToApplyHostingStartup = - LoggerMessage.Define( - eventId: LoggingEventIds.UnableToApplyHostingStartup.EventId(), - logLevel: LogLevel.Error, - formatString: Strings.LogFormatString_UnableToApplyHostingStartup); - private static readonly Action _unableToApplyInProcessFeatureFlags = LoggerMessage.Define( eventId: LoggingEventIds.UnableToApplyInProcessFeatureFlags.EventId(), @@ -954,11 +948,6 @@ public static void EndpointRemovalFailed(this ILogger logger, int processId, Exc _endpointRemovalFailed(logger, processId, ex); } - public static void UnableToApplyHostingStartup(this ILogger logger, Exception ex) - { - _unableToApplyHostingStartup(logger, ex); - } - public static void UnableToApplyInProcessFeatureFlags(this ILogger logger, Exception ex) { _unableToApplyInProcessFeatureFlags(logger, ex); diff --git a/src/Tools/dotnet-monitor/ParameterCapturing/CaptureParametersOperation.cs b/src/Tools/dotnet-monitor/ParameterCapturing/CaptureParametersOperation.cs index f8c9dcc1214..12c32830bf8 100644 --- a/src/Tools/dotnet-monitor/ParameterCapturing/CaptureParametersOperation.cs +++ b/src/Tools/dotnet-monitor/ParameterCapturing/CaptureParametersOperation.cs @@ -6,8 +6,8 @@ using Microsoft.Diagnostics.Monitoring.WebApi; using Microsoft.Diagnostics.Monitoring.WebApi.Models; using Microsoft.Diagnostics.NETCore.Client; -using Microsoft.Diagnostics.Tools.Monitor.HostingStartup; using Microsoft.Diagnostics.Tools.Monitor.Profiler; +using Microsoft.Diagnostics.Tools.Monitor.StartupHook; using Microsoft.Extensions.Logging; using System; using System.Collections.Generic; @@ -94,13 +94,6 @@ static Exception getNotAvailableException(string reason) IDictionary env = await client.GetProcessEnvironmentAsync(token); - const string PreventHostingStartupEnvName = "ASPNETCORE_PREVENTHOSTINGSTARTUP"; - if (env.TryGetValue(PreventHostingStartupEnvName, out string preventHostingStartupEnvValue) && - ToolIdentifiers.IsEnvVarValueEnabled(preventHostingStartupEnvValue)) - { - throw getNotAvailableException(Strings.ParameterCapturingNotAvailable_Reason_PreventedHostingStartup); - } - if (!env.TryGetValue(InProcessFeaturesIdentifiers.EnvironmentVariables.AvailableInfrastructure.ManagedMessaging, out string isManagedMessagingAvailable) || !ToolIdentifiers.IsEnvVarValueEnabled(isManagedMessagingAvailable)) { diff --git a/src/Tools/dotnet-monitor/Profiler/ProfilerMessagePayloads.cs b/src/Tools/dotnet-monitor/Profiler/ProfilerMessagePayloads.cs index ded6c17f014..ed648f8ad8d 100644 --- a/src/Tools/dotnet-monitor/Profiler/ProfilerMessagePayloads.cs +++ b/src/Tools/dotnet-monitor/Profiler/ProfilerMessagePayloads.cs @@ -1,7 +1,7 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. -#if STARTUPHOOK || HOSTINGSTARTUP +#if STARTUPHOOK using Microsoft.Diagnostics.Monitoring.StartupHook.MonitorMessageDispatcher.Models; #else using Microsoft.Diagnostics.Monitoring.WebApi.Models; diff --git a/src/Tools/dotnet-monitor/ServiceCollectionExtensions.cs b/src/Tools/dotnet-monitor/ServiceCollectionExtensions.cs index 159ad6037e8..0844ce7aaea 100644 --- a/src/Tools/dotnet-monitor/ServiceCollectionExtensions.cs +++ b/src/Tools/dotnet-monitor/ServiceCollectionExtensions.cs @@ -26,7 +26,6 @@ using Microsoft.Diagnostics.Tools.Monitor.Egress.FileSystem; using Microsoft.Diagnostics.Tools.Monitor.Exceptions; using Microsoft.Diagnostics.Tools.Monitor.Extensibility; -using Microsoft.Diagnostics.Tools.Monitor.HostingStartup; using Microsoft.Diagnostics.Tools.Monitor.LibrarySharing; using Microsoft.Diagnostics.Tools.Monitor.ParameterCapturing; using Microsoft.Diagnostics.Tools.Monitor.Profiler; @@ -358,13 +357,6 @@ public static IServiceCollection ConfigureExceptions(this IServiceCollection ser return services; } - public static IServiceCollection ConfigureHostingStartup(this IServiceCollection services) - { - services.AddScoped(); - services.AddScopedForwarder(); - return services; - } - public static IServiceCollection ConfigureStartupHook(this IServiceCollection services) { services.AddScoped(); diff --git a/src/Tools/dotnet-monitor/StartupHook/StartupHookIdentifiers.cs b/src/Tools/dotnet-monitor/StartupHook/StartupHookIdentifiers.cs deleted file mode 100644 index 5c581892070..00000000000 --- a/src/Tools/dotnet-monitor/StartupHook/StartupHookIdentifiers.cs +++ /dev/null @@ -1,16 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -namespace Microsoft.Diagnostics.Tools.Monitor.StartupHook -{ - public static class StartupHookIdentifiers - { - public static class EnvironmentVariables - { - private const string StartupHookPrefix = ToolIdentifiers.StandardPrefix + "StartupHook_"; - - // The full path of a HostingStartup assembly to load into a target process. - public const string HostingStartupPath = StartupHookPrefix + nameof(HostingStartupPath); - } - } -} diff --git a/src/Tools/dotnet-monitor/Strings.Designer.cs b/src/Tools/dotnet-monitor/Strings.Designer.cs index af49d4f19b9..bf9c5d8a90a 100644 --- a/src/Tools/dotnet-monitor/Strings.Designer.cs +++ b/src/Tools/dotnet-monitor/Strings.Designer.cs @@ -538,15 +538,6 @@ internal static string ErrorMessage_UnableToDetermineTargetPlatform { } } - /// - /// Looks up a localized string similar to Unable to find hosting startup assembly at determined path.. - /// - internal static string ErrorMessage_UnableToFindHostingStartupAssembly { - get { - return ResourceManager.GetString("ErrorMessage_UnableToFindHostingStartupAssembly", resourceCulture); - } - } - /// /// Looks up a localized string similar to Unable to find profiler assembly at determined path.. /// @@ -1519,15 +1510,6 @@ internal static string LogFormatString_StartupHookInstructions { } } - /// - /// Looks up a localized string similar to Unable to apply hosting startup.. - /// - internal static string LogFormatString_UnableToApplyHostingStartup { - get { - return ResourceManager.GetString("LogFormatString_UnableToApplyHostingStartup", resourceCulture); - } - } - /// /// Looks up a localized string similar to Unable to apply in process feature flags.. /// @@ -1672,15 +1654,6 @@ internal static string ParameterCapturingNotAvailable_Reason_ManagedMessagingDid } } - /// - /// Looks up a localized string similar to The process has prevented hosting startup assemblies from loading using the ASPNETCORE_PREVENTHOSTINGSTARTUP environment variable.. - /// - internal static string ParameterCapturingNotAvailable_Reason_PreventedHostingStartup { - get { - return ResourceManager.GetString("ParameterCapturingNotAvailable_Reason_PreventedHostingStartup", resourceCulture); - } - } - /// /// Looks up a localized string similar to This feature requires the startup hook to be loaded in the target process.. /// diff --git a/src/Tools/dotnet-monitor/Strings.resx b/src/Tools/dotnet-monitor/Strings.resx index a63ac31d441..149fd3abebe 100644 --- a/src/Tools/dotnet-monitor/Strings.resx +++ b/src/Tools/dotnet-monitor/Strings.resx @@ -1,17 +1,17 @@  - @@ -897,12 +897,6 @@ 0. providerName: The name of the provider that failed validation. 1. errorMessage: The validation failure message - - Unable to find hosting startup assembly at determined path. - - - Unable to apply hosting startup. - Unable to apply in process feature flags. @@ -927,9 +921,6 @@ 1 Format Parameters: 0. reason: The reason why the feature is unavailable. - - The process has prevented hosting startup assemblies from loading using the ASPNETCORE_PREVENTHOSTINGSTARTUP environment variable. - This feature requires the startup hook to be loaded in the target process. diff --git a/src/Tools/dotnet-monitor/dotnet-monitor.csproj b/src/Tools/dotnet-monitor/dotnet-monitor.csproj index de82ee8efdc..241ee397586 100644 --- a/src/Tools/dotnet-monitor/dotnet-monitor.csproj +++ b/src/Tools/dotnet-monitor/dotnet-monitor.csproj @@ -73,7 +73,6 @@ - @@ -118,13 +117,6 @@ tools/$(TargetFramework)/any/shared/any/$(StartupHookTargetFramework) - - - tools/$(TargetFramework)/any/shared/any/$(HostingStartupTargetFramework) - - - tools/$(TargetFramework)/any/shared/any/$(HostingStartupTargetFramework) - diff --git a/src/archives/dotnet-monitor-base/Package.props b/src/archives/dotnet-monitor-base/Package.props index 6a317e71722..b82800d81e1 100644 --- a/src/archives/dotnet-monitor-base/Package.props +++ b/src/archives/dotnet-monitor-base/Package.props @@ -1,7 +1,6 @@ - dotnet-monitor From a2c9bfaa2aa0896f220ec039e4770e33c7527106 Mon Sep 17 00:00:00 2001 From: Claudiu Guiman Date: Thu, 6 Jun 2024 17:41:37 -0400 Subject: [PATCH 10/10] Enable parameter capturing in no suspend mode. (#6778) * Enable parameter capturing in no suspend mode. * Change the suspension mode in the configureApp callback * Update ScenarioRunner.SingleTarget to support starting the app before the tool and add a test to verify the feature doesn't work if the startup hook is manually configured. * docs update --- documentation/api/parameters.md | 5 +- .../ParameterCapturingTests.cs | 90 ++++++++++++++----- .../Runners/ScenarioRunner.cs | 76 +++++++++++----- .../Commands/CollectCommandHandler.cs | 6 +- 4 files changed, 129 insertions(+), 48 deletions(-) diff --git a/documentation/api/parameters.md b/documentation/api/parameters.md index d20f5431334..93891024716 100644 --- a/documentation/api/parameters.md +++ b/documentation/api/parameters.md @@ -128,11 +128,10 @@ Content-Type: application/x-ndjson ## Additional Requirements -- The target application must use ASP.NET Core. - The target application cannot have [Hot Reload](https://learn.microsoft.com/visualstudio/debugger/hot-reload) enabled. -- `dotnet-monitor` must be set to `Listen` mode, and the target application must start suspended. See [diagnostic port configuration](../configuration/diagnostic-port-configuration.md) for information on how to do this. +- `dotnet-monitor` must be set to `Listen` mode. See [diagnostic port configuration](../configuration/diagnostic-port-configuration.md) for information on how to do this. +- If the target application is using .NET 7 then the dotnet-monitor startup hook must be manually configured and the target application must start suspended. In .NET 8+ this is not a requirement. - This feature relies on a [ICorProfilerCallback](https://docs.microsoft.com/dotnet/framework/unmanaged-api/profiling/icorprofilercallback-interface) implementation. If the target application is already using an `ICorProfiler` that isn't notify-only, this feature will not be available. -- If a target application is using .NET 7 then the `dotnet-monitor` startup hook must be configured. This is automatically done in .NET 8+. ## Additional Notes diff --git a/src/Tests/Microsoft.Diagnostics.Monitoring.Tool.FunctionalTests/ParameterCapturingTests.cs b/src/Tests/Microsoft.Diagnostics.Monitoring.Tool.FunctionalTests/ParameterCapturingTests.cs index e155b0788d4..55da1356767 100644 --- a/src/Tests/Microsoft.Diagnostics.Monitoring.Tool.FunctionalTests/ParameterCapturingTests.cs +++ b/src/Tests/Microsoft.Diagnostics.Monitoring.Tool.FunctionalTests/ParameterCapturingTests.cs @@ -51,7 +51,12 @@ public ParameterCapturingTests(ITestOutputHelper outputHelper, ServiceProviderFi [MemberData(nameof(ProfilerHelper.GetArchitecture), MemberType = typeof(ProfilerHelper))] public async Task UnresolvableMethodsFailsOperation(Architecture targetArchitecture) { - await RunTestCaseCore(TestAppScenarios.ParameterCapturing.SubScenarios.AspNetApp, targetArchitecture, async (appRunner, apiClient) => + await RunTestCaseCore( + TestAppScenarios.ParameterCapturing.SubScenarios.AspNetApp, + targetArchitecture, + shouldSuspendTargetApp: true, + enableStartupHook: true, + async (appRunner, apiClient) => { int processId = await appRunner.ProcessIdTask; @@ -78,40 +83,52 @@ await RunTestCaseCore(TestAppScenarios.ParameterCapturing.SubScenarios.AspNetApp [Theory] [MemberData(nameof(ProfilerHelper.GetArchitecture), MemberType = typeof(ProfilerHelper))] public Task CapturesParametersInNonAspNetApps(Architecture targetArchitecture) => - CapturesParametersCore(TestAppScenarios.ParameterCapturing.SubScenarios.NonAspNetApp, targetArchitecture, CapturedParameterFormat.JsonSequence); + CapturesParametersCore(TestAppScenarios.ParameterCapturing.SubScenarios.NonAspNetApp, targetArchitecture, CapturedParameterFormat.JsonSequence, shouldSuspendTargetApp: true, enableStartupHook: true); [Theory] [MemberData(nameof(ProfilerHelper.GetArchitecture), MemberType = typeof(ProfilerHelper))] public Task CapturesParametersAndOutputJsonSequence(Architecture targetArchitecture) => - CapturesParametersCore(TestAppScenarios.ParameterCapturing.SubScenarios.AspNetApp, targetArchitecture, CapturedParameterFormat.JsonSequence); + CapturesParametersCore(TestAppScenarios.ParameterCapturing.SubScenarios.AspNetApp, targetArchitecture, CapturedParameterFormat.JsonSequence, shouldSuspendTargetApp: true, enableStartupHook: true); [Theory] [MemberData(nameof(ProfilerHelper.GetArchitecture), MemberType = typeof(ProfilerHelper))] public Task CapturesParametersAndOutputNewlineDelimitedJson(Architecture targetArchitecture) => - CapturesParametersCore(TestAppScenarios.ParameterCapturing.SubScenarios.AspNetApp, targetArchitecture, CapturedParameterFormat.NewlineDelimitedJson); + CapturesParametersCore(TestAppScenarios.ParameterCapturing.SubScenarios.AspNetApp, targetArchitecture, CapturedParameterFormat.NewlineDelimitedJson, shouldSuspendTargetApp: true, enableStartupHook: true); -#else // NET7_0_OR_GREATER +#if NET8_0_OR_GREATER [Theory] [MemberData(nameof(ProfilerHelper.GetArchitecture), MemberType = typeof(ProfilerHelper))] - public async Task Net6AppFailsOperation(Architecture targetArchitecture) - { - await RunTestCaseCore(TestAppScenarios.ParameterCapturing.SubScenarios.AspNetApp, targetArchitecture, async (appRunner, apiClient) => - { - int processId = await appRunner.ProcessIdTask; + public Task CapturesParametersNoSuspend(Architecture targetArchitecture) => + CapturesParametersCore(TestAppScenarios.ParameterCapturing.SubScenarios.AspNetApp, targetArchitecture, CapturedParameterFormat.JsonSequence, shouldSuspendTargetApp: false, enableStartupHook: false); - CaptureParametersConfiguration config = GetValidConfiguration(); +#endif // NET8_0_OR_GREATER - ValidationProblemDetailsException validationException = await Assert.ThrowsAsync(() => apiClient.CaptureParametersAsync(processId, Timeout.InfiniteTimeSpan, config)); - Assert.Equal(HttpStatusCode.BadRequest, validationException.StatusCode); + [Theory] + [MemberData(nameof(ProfilerHelper.GetArchitecture), MemberType = typeof(ProfilerHelper))] + public Task AppWithStartupHookFailsInNoSuspend(Architecture targetArchitecture) => + ValidateBadRequestFailure(TestAppScenarios.ParameterCapturing.SubScenarios.AspNetApp, targetArchitecture, shouldSuspendTargetApp: false, enableStartupHook: true); + +#else // NET7_0_OR_GREATER + [Theory] + [MemberData(nameof(ProfilerHelper.GetArchitecture), MemberType = typeof(ProfilerHelper))] + public Task Net6AppFailsOperation(Architecture targetArchitecture) => + ValidateBadRequestFailure(TestAppScenarios.ParameterCapturing.SubScenarios.AspNetApp, targetArchitecture, shouldSuspendTargetApp: true, enableStartupHook: true); - await appRunner.SendCommandAsync(TestAppScenarios.ParameterCapturing.Commands.Continue); - }); - } #endif // NET7_0_OR_GREATER - private async Task CapturesParametersCore(string subScenarioName,Architecture targetArchitecture, CapturedParameterFormat format) + private async Task CapturesParametersCore( + string subScenarioName, + Architecture targetArchitecture, + CapturedParameterFormat format, + bool shouldSuspendTargetApp, + bool enableStartupHook) { - await RunTestCaseCore(subScenarioName, targetArchitecture, async (appRunner, apiClient) => + await RunTestCaseCore( + subScenarioName, + targetArchitecture, + shouldSuspendTargetApp: shouldSuspendTargetApp, + enableStartupHook: enableStartupHook, + async (appRunner, apiClient) => { int processId = await appRunner.ProcessIdTask; @@ -143,7 +160,36 @@ await RunTestCaseCore(subScenarioName, targetArchitecture, async (appRunner, api }); } - private async Task RunTestCaseCore(string subScenarioName, Architecture targetArchitecture, Func appValidate) + private async Task ValidateBadRequestFailure( + string subScenarioName, + Architecture targetArchitecture, + bool shouldSuspendTargetApp, + bool enableStartupHook) + { + await RunTestCaseCore( + subScenarioName, + targetArchitecture, + shouldSuspendTargetApp: shouldSuspendTargetApp, + enableStartupHook: enableStartupHook, + async (appRunner, apiClient) => + { + int processId = await appRunner.ProcessIdTask; + + CaptureParametersConfiguration config = GetValidConfiguration(); + + ValidationProblemDetailsException validationException = await Assert.ThrowsAsync(() => apiClient.CaptureParametersAsync(processId, Timeout.InfiniteTimeSpan, config)); + Assert.Equal(HttpStatusCode.BadRequest, validationException.StatusCode); + + await appRunner.SendCommandAsync(TestAppScenarios.ParameterCapturing.Commands.Continue); + }); + } + + private async Task RunTestCaseCore( + string subScenarioName, + Architecture targetArchitecture, + bool shouldSuspendTargetApp, + bool enableStartupHook, + Func appValidate) { await ScenarioRunner.SingleTarget( _outputHelper, @@ -153,8 +199,9 @@ await ScenarioRunner.SingleTarget( appValidate: appValidate, configureApp: runner => { - runner.EnableMonitorStartupHook = true; + runner.EnableMonitorStartupHook = enableStartupHook; runner.Architecture = targetArchitecture; + runner.DiagnosticPortSuspend = shouldSuspendTargetApp; }, configureTool: (toolRunner) => { @@ -166,7 +213,8 @@ await ScenarioRunner.SingleTarget( toolRunner.WriteKeyPerValueConfiguration(new RootOptions().AddFileSystemEgress(FileProviderName, _tempDirectory.FullName)); }, profilerLogLevel: LogLevel.Trace, - subScenarioName: subScenarioName); + subScenarioName: subScenarioName, + startAppBeforeTool: !shouldSuspendTargetApp); } private static CaptureParametersConfiguration GetValidConfiguration() diff --git a/src/Tests/Microsoft.Diagnostics.Monitoring.Tool.FunctionalTests/Runners/ScenarioRunner.cs b/src/Tests/Microsoft.Diagnostics.Monitoring.Tool.FunctionalTests/Runners/ScenarioRunner.cs index 341e3ad526a..ce60896f26b 100644 --- a/src/Tests/Microsoft.Diagnostics.Monitoring.Tool.FunctionalTests/Runners/ScenarioRunner.cs +++ b/src/Tests/Microsoft.Diagnostics.Monitoring.Tool.FunctionalTests/Runners/ScenarioRunner.cs @@ -28,7 +28,8 @@ public static async Task SingleTarget( Action configureTool = null, bool disableHttpEgress = false, LogLevel profilerLogLevel = LogLevel.Error, - string subScenarioName = null) + string subScenarioName = null, + bool startAppBeforeTool = false) { DiagnosticPortHelper.Generate( mode, @@ -43,37 +44,66 @@ public static async Task SingleTarget( configureTool?.Invoke(toolRunner); - await toolRunner.StartAsync(); - - using HttpClient httpClient = await toolRunner.CreateHttpClientDefaultAddressAsync(httpClientFactory); - ApiClient apiClient = new(outputHelper, httpClient); - - await using AppRunner appRunner = new(outputHelper, Assembly.GetExecutingAssembly()); - if (profilerLogLevel != LogLevel.None) + if (!startAppBeforeTool) { - appRunner.ProfilerLogLevel = profilerLogLevel.ToString("G"); + await toolRunner.StartAsync(); } - appRunner.ConnectionMode = appConnectionMode; - appRunner.DiagnosticPortPath = diagnosticPortPath; - appRunner.ScenarioName = scenarioName; - appRunner.SubScenarioName = subScenarioName; - configureApp?.Invoke(appRunner); +#nullable enable + HttpClient? httpClient = null; + ApiClient? apiClient = null; - await appRunner.ExecuteAsync(async () => + try { - // Wait for the process to be discovered. - int processId = await appRunner.ProcessIdTask; - _ = await apiClient.GetProcessWithRetryAsync(outputHelper, pid: processId); + if (!startAppBeforeTool) + { + httpClient = await toolRunner.CreateHttpClientDefaultAddressAsync(httpClientFactory); + apiClient = new(outputHelper, httpClient); + } + + await using AppRunner appRunner = new(outputHelper, Assembly.GetExecutingAssembly()); + if (profilerLogLevel != LogLevel.None) + { + appRunner.ProfilerLogLevel = profilerLogLevel.ToString("G"); + } + appRunner.ConnectionMode = appConnectionMode; + appRunner.DiagnosticPortPath = diagnosticPortPath; + appRunner.ScenarioName = scenarioName; + appRunner.SubScenarioName = subScenarioName; + + configureApp?.Invoke(appRunner); + + await appRunner.ExecuteAsync(async () => + { + if (startAppBeforeTool) + { + await toolRunner.StartAsync(); + httpClient = await toolRunner.CreateHttpClientDefaultAddressAsync(httpClientFactory); + apiClient = new(outputHelper, httpClient); + } - await appValidate(appRunner, apiClient); - }); - Assert.Equal(0, appRunner.ExitCode); + // Wait for the process to be discovered. + int processId = await appRunner.ProcessIdTask; + _ = await apiClient.GetProcessWithRetryAsync(outputHelper, pid: processId); - if (null != postAppValidate) + Assert.NotNull(apiClient); + + await appValidate(appRunner, apiClient); + }); + Assert.Equal(0, appRunner.ExitCode); + + Assert.NotNull(apiClient); + + if (null != postAppValidate) + { + await postAppValidate(apiClient, await appRunner.ProcessIdTask); + } + } + finally { - await postAppValidate(apiClient, await appRunner.ProcessIdTask); + httpClient?.Dispose(); } +#nullable disable } } } diff --git a/src/Tools/dotnet-monitor/Commands/CollectCommandHandler.cs b/src/Tools/dotnet-monitor/Commands/CollectCommandHandler.cs index b14fd48fa18..20134f09fab 100644 --- a/src/Tools/dotnet-monitor/Commands/CollectCommandHandler.cs +++ b/src/Tools/dotnet-monitor/Commands/CollectCommandHandler.cs @@ -131,11 +131,15 @@ private static IHostBuilder Configure(this IHostBuilder builder, StartupAuthenti services.AddSingleton(); services.ConfigureCollectionRules(); services.ConfigureLibrarySharing(); + /* + * ConfigureInProcessFeatures needs to be called before ConfigureProfiler + * because the profiler needs to have access to environment variables set by in process features. + */ + services.ConfigureInProcessFeatures(context.Configuration); services.ConfigureProfiler(); services.ConfigureStartupHook(); services.ConfigureExceptions(); services.ConfigureStartupLoggers(authConfigurator); - services.ConfigureInProcessFeatures(context.Configuration); services.AddSingleton(); services.AddSingleton(); services.AddSingleton();