Closed SergeyKanzhelev closed 2 years ago
Looking at code I think the most probable root cause is that IHttpContextAccessor
is null. I binged and saw couple links with the same problem.
@pakrym what may be the cause? If this is expected behavior - we'd need to remove the check and fail more gracefully.
Hm, it seems I jumped into conclusion too fast. It probably has http accessor since it fails in Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetService[T](IServiceProvider provider)
, not in telemetry initializer itself.
Failed here
So httpContext.RequestServices
was null in this code:
var telemetry = httpContext.RequestServices.GetService<RequestTelemetry>();
In version 2.X the call was replaced to:
var telemetry = httpContext.Features.Get<RequestTelemetry>();
Now the question is what might be a condition when httpContext.RequestServices
became null
and whether the same condition may apply to httpContext.Features
The only reason I know httpContext.RequestServices
to be set to null is when request is completed and HttpContext
disposed. I think it might happen to httpContext.Features
too, but request code should be done executing at this time.
@pakrym can dispose happen for some reason while in Microsoft.AspNetCore.Mvc.Internal.MvcCoreDiagnosticSourceExtensions.BeforeAction
? Looking at stack I do not have any explanation how it can happen, but clearly customer experienced this. Any ideas?
This issue is stale because it has been open 300 days with no activity. Remove stale label or comment or this will be closed in 7 days.
Customer reported:
Problem Desc: on 2017-02-21T17:16:16.109Z we encountered a runtime exception in the Application Insights integration module.
Application is an aspnet core application built in .Net461 full framework. Application insights has been applied through Microsoft.ApplicationInsights.AspNetCore 1.0.2 – Now upgraded to 2.0.0 We have enabled it from the app service “Application Insights” setting as well. The application is published though “Continous Delivery”. It happened only once. The application communicates to Redis “as a service”, sql “as a service”, Azure tables. We have configured application logging to send data to azure storage.