0

I have a function that gets a PDF file from the blob storage and returns it. Once in a while, I get a socket-exhausted exception. This is probably an issue with another function that reads a lot of data from a Storage Table. I'm in to process of mitigating that exception but when it occurs the first function returns the stack trace to the user which I do not want.

How can I prevent the function from returning the stack trace?

I've searched using Google and found mostly questions from people that want the stack trace, which is very hard in Azure Function. But I want to opposite. Don't show the stack trace, just return a 500 or something.

Paul Meems
  • 3,002
  • 4
  • 35
  • 66

1 Answers1

0

How can I prevent the function from returning the stack trace?

By default, Function will produce the Functions Runtime or host logs during every execution in the console and that can be sent to Azure Application Insights Instance if integrated.

Those logs include the Function Runtime Level Logs, Host Level logs, Dependencies Level Logs and those logs comprises from Information to Error.

I know that information logs such as Host lock lease, lease renewal logs, Function Starting the worker process logs, etc.

You can set the filters on the log level categories in host.json configuration code for preventing the Stack trace produced by Azure Functions in every executions to get the required logs such as any error or warnings or successful result.

Example:

 "logLevel": {
      "Function": "Error",
    }

Check this SO solution where I have the collection of approaches recommended by Microsoft and a practical to get the specific logs with host.json configuration that also shows the Cost Optimization techniques.