diff --git a/src/Hosting/Hosting/src/Internal/HostingApplicationDiagnostics.cs b/src/Hosting/Hosting/src/Internal/HostingApplicationDiagnostics.cs index 4c51043c9eefa29700a2eee9422cc0b706e82674..d2a3e9365728182f5253f8ab8d75072ac279fb8f 100644 --- a/src/Hosting/Hosting/src/Internal/HostingApplicationDiagnostics.cs +++ b/src/Hosting/Hosting/src/Internal/HostingApplicationDiagnostics.cs @@ -224,7 +224,7 @@ internal sealed class HostingApplicationDiagnostics [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026", Justification = "The values being passed into Write have the commonly used properties being preserved with DynamicDependency.")] - private static void WriteDiagnosticEvent<TValue>( + private static void WriteDiagnosticEvent<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicProperties)] TValue>( DiagnosticSource diagnosticSource, string name, TValue value) { diagnosticSource.Write(name, value); @@ -413,6 +413,19 @@ internal sealed class HostingApplicationDiagnostics } // These are versions of DiagnosticSource.Start/StopActivity that don't allocate strings per call (see https://github.com/dotnet/corefx/issues/37055) + // DynamicDependency matches the properties selected in: + // https://github.com/dotnet/diagnostics/blob/7cc6fbef613cdfe5ff64393120d59d7a15e98bd6/src/Microsoft.Diagnostics.Monitoring.EventPipe/Configuration/HttpRequestSourceConfiguration.cs#L20-L33 + [DynamicDependency(nameof(HttpContext.Request), typeof(HttpContext))] + [DynamicDependency(nameof(HttpRequest.Scheme), typeof(HttpRequest))] + [DynamicDependency(nameof(HttpRequest.Host), typeof(HttpRequest))] + [DynamicDependency(nameof(HttpRequest.PathBase), typeof(HttpRequest))] + [DynamicDependency(nameof(HttpRequest.QueryString), typeof(HttpRequest))] + [DynamicDependency(nameof(HttpRequest.Path), typeof(HttpRequest))] + [DynamicDependency(nameof(HttpRequest.Method), typeof(HttpRequest))] + [DynamicDependency(nameof(HttpRequest.Headers), typeof(HttpRequest))] + [DynamicDependency(DynamicallyAccessedMemberTypes.All, typeof(QueryString))] + [DynamicDependency(DynamicallyAccessedMemberTypes.All, typeof(HostString))] + [DynamicDependency(DynamicallyAccessedMemberTypes.All, typeof(PathString))] private Activity StartActivity(Activity activity, HttpContext httpContext) { activity.Start(); @@ -420,6 +433,11 @@ internal sealed class HostingApplicationDiagnostics return activity; } + // DynamicDependency matches the properties selected in: + // https://github.com/dotnet/diagnostics/blob/7cc6fbef613cdfe5ff64393120d59d7a15e98bd6/src/Microsoft.Diagnostics.Monitoring.EventPipe/Configuration/HttpRequestSourceConfiguration.cs#L35-L38 + [DynamicDependency(nameof(HttpContext.Response), typeof(HttpContext))] + [DynamicDependency(nameof(HttpResponse.StatusCode), typeof(HttpResponse))] + [DynamicDependency(nameof(HttpResponse.Headers), typeof(HttpResponse))] private void StopActivity(Activity activity, HttpContext httpContext) { // Stop sets the end time if it was unset, but we want it set before we issue the write