I have an ASP.Net Core 2 web api project.
I have added the following to the Configure method in my Startup.cs file
app.UseExceptionHandler();
I noticed in my Postman tests that I was getting an "Unable to get response" result.
Server-side logging shows that the error has to do with Tables being missing from my Database. Which is fine, I can resolve that. But my question is why would the server not be returning a 500 Internal Server Error? Why is it dying, and returning no response at all to Postman?
So, in my Controller, I purposely throw an Exception to test the handler, and call the URL from Postman, and indeed, I get back a 500 Internal server error response, as expected.
Why are the "deeper down" errors being thrown from EFCore not being handled by the ExceptionHandler middleware, and crashing my app? Am I missing something?
In your startup.cs, move the UseMvc() tag to the bottom of the pipeline i.e.
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
...
app.UseExceptionHandler();
app.UseMvcWithDefaultRoute();
}
In my case, the request pipeline faulted on startup when the route launched by the browser did not exist. In that scenario, my app.UseExceptionHandler() before the app.UseMvc() was not executed.
Related
So we have a simple .net core 5.0 service that only serves some simple pages with mvc. We are starting to get 400 Errors (details below) on some of the requests. Our frontend is embedded in an iframe which forces us to use our own domain for our api-calls. The 400 errors disappears when we use the azure internal-urls. (*.azurewebsites.net instead of *.ourdomain.net). When I get to the "diagnose and solve problems" -> "availability and performance" -> HTTP 4XX ERRORS i can se below errors. Any ideas on what can cause this error?
Bad Request. The request could not be understood by the server due to malformed syntax. The client should not repeat the request without modifications.
So, the biggest problem above is that we do not get the correct errormessage. After a lot of experimentation we activated the ConnectionLogging for Kestrel.
WebHost.CreateDefaultBuilder(args)
.UseKestrel(options =>
{
options.ConfigureEndpointDefaults(listenOptions =>
{
listenOptions.UseConnectionLogging();
});
})
And after that we found some more intressting logs. One that said:
Connection id "0HMFSA73IA4LS" bad request data: "Malformed request: invalid headers."
Microsoft.AspNetCore.Server.Kestrel.Core.BadHttpRequestException: Malformed request: invalid headers.
After some more investigation we could diff a succesful request from a failing request. And the problem was related to the certificate of *.ourdomain.se. In a part of the certificate we hade a string thats named "Stockholms län" in the cases where it failed the string decoded to l�n and when it succeeded the string decoded to l%C3%A4n. We are now investigating if this is a load balancer problem. But this app is running hostingmodel outofprocess. By changing this to inprocess and wrap our Kestrel in IIS the errors disapears.
I am deploying react-search-refiner with LUIS and Azure Functions https://github.com/SharePoint/sp-dev-fx-webparts/tree/master/samples/react-search-refiners/functions
Now, I passed through various problems and finally confirmed the communication from SPFx to Function App.
My problem is when searching after deploying according to the procedure, an internal Sever error occurs after Status Code 200. And nothing error message returns.
POST https://.azurewebsites.net/api/enhanceQuery 500
(Internal Server Error) Message: [NlpService.enhanceSearchQuery()]:
Error: '{"error":{"type":"function_error","message":"Error"}}' for url
'https://.azurewebsites.net/api/enhanceQuery'
On the application log, Function App is executed and succeeded return code 0. So, it doesn't return error code.
My checking is below that does not contains in README. Would someone help me?
Set local.settings.json to environment variable.
Change authlevel "function" to "anonymous" for simplization.
Local debug is succeeded.
POSTMAN didn't check because rawQuery from HttpRequest might be
included large keys and values.
i am encountering a problem i'm not familiar with.
So i'm trying to log exceptions from a test Azure Function but when i throw an exception and return a 400 bad request, application insight registers the log as a successful request.
As i understand it it is probably register the function's successful run but what i don't understand is how i then should log the exception.
So what i have done so far is this.
(I Will be referring to Application Insights as AI from here on out)
I started by created an AI-Resource.
Then i took the instrument key and applied it to the app settings of my function.
After that i installed the AI NUGET to my function bu creating a Projet.json file and then pasting something like this which installed the necessary assemblies and such.
{
"frameworks": {
"net46":{
"dependencies": {
"Microsoft.ApplicationInsights": "2.4.0"
}
}
}
}
after this i initialize the TelemetryClient in the function and try to log and exception in a catch:
Initiation:
string key = TelemetryConfiguration.Active.InstrumentationKey = System.Environment.GetEnvironmentVariable("APPINSIGHTS_INSTRUMENTATIONKEY", EnvironmentVariableTarget.Process);
TelemetryClient telemetry = new TelemetryClient() {
InstrumentationKey = key
};
Catch:
catch (Exception e)
{
Dictionary<string,string> properties = new Dictionary<string,string>();
properties.Add("Function Payload", data.ToString());
properties.Add("Function Exception", e.ToString());
telemetry.TrackException(e, properties);
return req.CreateResponse(HttpStatusCode.BadRequest, e);
}
Test running the function i get:
2018-03-07T14:24:36.171 [Info] Function started (Id=0292b455-314d-4c4c-872a-2b8137a72305)
2018-03-07T14:24:37.092 [Info] Function completed (Success, Id=0292b455-314d-4c4c-872a-2b8137a72305, Duration=931ms)
In Application insights i can can only see bad requests for StatusCode: 500
but 400 Bad requests gets logged as Successful requests.
And also the TrackException functionality doesn't log any of the custom properties...
So what am i missing?
MORE DETAILS ABOUT EXCEPTION LOGGING:
#Mikhail is right that we treat this as a success because the function is a success. We didn't want to use status codes to guess whether there was a successful operation or not, so we look for whether the function threw an exception.
Your exception isn't appearing in that screen because it hasn't been property correlated with this function execution. If you go to App Insights Analytics and query for that ExceptionTelemetry, you should see it.
In order to correlate it with a specific function, you'd need to set the OperationId, which is the same as the function's InvocationId. There is a sample that shows how to do this with Events, Metrics, and Dependencies, but doing it for Exceptions is the same (you can ignore the User.Id assignment): https://learn.microsoft.com/en-us/azure/azure-functions/functions-monitoring#custom-telemetry-in-c-functions
Update: From what you've shown of your function above, you may be able to get away with doing something like:
catch (Exception e)
{
log.Error("Function Payload " + data.ToString());
throw;
}
That would return a 500 (rather than a 400), and Functions would log the trace to Application Insights, and then log the exception as well as the Request failure. If you're not using your TelemetryClient anywhere else, you could remove that from your code.
The server (Azure Function) processed the request without errors, you returned a result from it, so from the point of view of Function App runtime the request was processed successfully. You can see that from the log too:
... Function completed (Success, ...
So, it makes sense that the Function App registers the call as success in Application Insights too. At least, that's how they chose to implement it.
the "for this operation" not showing exceptions implies that the exception that you sent does not have the same operationId as the azure function. operation
id is how application insights "links" related telemetry together.
your "exeption logging" screenshot is not an exception, but a request, so the custom properties logged on your exception won't be there.
if you want your azure function to fail, and show as a failed request, and log an exception, why are you catching the exception and logging it yourself? doesn't catching the exception then cause the azure function to succeed? why not just let the exception trickle out and let the function runtime do that part for you? (doesn't it?)
After a deploy to our Azure Web App, we are getting 500 timeouts on any request to the service:
500 - The request timed out.
The web server failed to respond within the specified time.
This has come out of the blue and we cannot determine what's causing it. It seems to take around 230s consistently to time out.
I've enabled all the diagnostic logs in the portal:
But I honestly don't quite know what to look for in the logs. I've scoured through all the files in the following folders but nothing jumps out.
How can I troubleshoot this problem?
The trick to get debug messages is to set stdoutLogFile="D:\home\LogFiles\stdout.log" in your config, instead of the ..\logs path that you had. After changing that, you get an error file under D:\home\LogFiles. Here is the error you get:
Application startup exception: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.ArgumentNullException: SMTP server password cannot be null or empty.
Parameter name: smtpPassword
at TransitApi.Infrastructure.Modules.Logging.EmailOutput.EmailLogger..ctor(String recipient, String sender, String smtpUsername, String smtpPassword, String smtpHost, Int32 smtpPort, String environmentName, LogLevel minimumLevel)
at TransitApi.Infrastructure.Modules.Logging.EmailOutput.EmailLoggerProvider.CreateLogger(String name)
at Microsoft.Extensions.Logging.Logger.AddProvider(ILoggerProvider provider)
at Microsoft.Extensions.Logging.LoggerFactory.AddProvider(ILoggerProvider provider)
at TransitApi.Api.Startup.Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
So some kind of issue setting up the mail server. That causes the process to crash, and that it behaves poorly.
But I highly suggest that you upgrade to Core RC2, as RC1 is quite obsolete.
I have a Yesod web application, that calls a web service on another server. I reuse the Http Manager from yesod for my Requests to that web service.
On some calls, I'm getting a Yesod error, and I'm not sure why the Yesod error handler is kicking in, since the error handling is not part of the Manager.
My code does its own status handling on the HTTP response (I do let req' = req { H.checkStatus = \_ _ _ -> Nothing } on the request).
The error I'm getting:
07/Jun/2013:14:05:15 +0200 [Error#yesod-core] ParseError {errorContexts = [], errorMessage = "Failed reading: satisfy", errorPosition = 1:1} #(yesod-core-1.2.0.4:Yesod.Core.Class.Yesod ./Yesod/Core/Class/Yesod.hs:471:5)
I have the distinct impression that the web service returns an error, and Yesod is handling it instead of my code. My web service client code throws exception that are caught to be redirected to an error page, and this works well when I do errors in the invocation of the service, I just don't understand why I'm getting this ParseError on some requests.
I'm dumping the request and the response that I get from the web service, and I never see the response in my log, which seems to indicate that yesod is intercepting the response.
Any idea?
OK, sorry for the stupid question, I've figured it out. The http-conduit code is throwing the ParseError, and my code was not catching it, so Yesod was barfing. If I catch the ParseError, I get my error page. Now, is it normal that http-conduit fails with such an abrupt message, I don't know, but I do think the web service is misbehaving anyway.