2

I have an Azure C# Http triggered function which is an API call that returns a Json payload. The function is run in an Isolated Worker Model and contains several separate async tasks that run concurrently to produce different sections of the said Json payload.

Sometimes these tasks can take longer than expected and because of this consumers of this API call occasionally cancel the request. These API calls will then show up in Application Insights as a request that ends in error (HTTP 499).

The question is how can I have this event logged but not necessarily as an error in Application Insights?

I have tried catching TaskCancelledException on the individual async tasks and the orchestrating trigger function method. I do always catch the exception successfully, log it as information and then return a 200 status code but the request is still showing as an error in Application Insights.

Thanks for any pointers you can give.

1
  • Please provide enough code so others can better understand or reproduce the problem. Commented Mar 5 at 20:10

1 Answer 1

1

HTTP 499 is the that client has closed the connection. Its likely the client has timeout out the operation. So sounds like you would just need to increase the timeout threshold of the consuming client.

I have found using a backgroundservice helps particularly with long running operations, you can off load to that as well.

Also if this is an azure function I would also check these limits.

Default timeout The default timeout for the consumption plan is five minutes, with a maximum of 10 minutes The default timeout for the premium plan is 30 minutes, with an unlimited maximum

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks. Unfortunately, I have no control over the clients cancelling their request. What I am trying to do given this scenario of cancelling the request is to gracefully handle it. So, logging the cancelled request as information and not an error / failure.
You might be able to create a task which only completes at the end of the block of your function, then if it is cancelled at any point it should raise the cancellation token, you could call your logging mechanism from there. Other options are to extend the logging to a per method basis with the likes of Serilog.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.