Invalid JSON logs produced for function apps.

Martin Milesich 166 Reputation points
2022-09-10T11:16:18.907+00:00

I have a function app on a consumption plan with custom runtime written in Go. The app writes a valid JSON to a console output.

I am using diagnostic settings to send Function Application Logs to a Log Analytics workspace and a partner solution (elastic cloud).

The problem is that Azure replace all double quotes to single quotes on all logs generated by the app before it is send to log analytics or partner solution. This makes it unusable since it is not a valid JSON.

{  
	"time": "2022-09-10T10:27:45Z",  
	"resourceId": "/SUBSCRIPTIONS/xxx/RESOURCEGROUPS/xxx/PROVIDERS/MICROSOFT.WEB/SITES/xxx",  
	"category": "FunctionAppLogs",   
	"operationName": "Microsoft.Web/sites/functions/log",   
	"level": "Error",   
	"location": "West Europe",   
	"properties": {'appName':'xxx','roleInstance':'xxx','message':'{\'level\':\'info\',\'time\':\'2022-09-10T10:27:45.818077054Z\',\'message\':\'init config\'}','category':'Host.Function.Console','hostVersion':'4.10.4.4','hostInstanceId':'xxx','level':'Error','levelId':4,'processId':60}  
}  
  

As you can see everything in properties has single quotes and what my app generates is in the message field.

239733-screenshot-2022-09-10-at-125155e.png

Same in the log analytics workspace.

Note: I am not using Application Insights.

Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
5,909 questions
{count} votes

Accepted answer
  1. MughundhanRaveendran-MSFT 12,506 Reputation points
    2022-09-16T08:45:32.96+00:00

    @Martin Milesich ,

    It appears to be a "by design" behavior of the diagnostic setting. I would suggest you to replace the single quotes with double quotes using the golang
    https://www.geeksforgeeks.org/strings-replace-function-in-golang-with-examples/


1 additional answer

Sort by: Most helpful
  1. Deleted

    This answer has been deleted due to a violation of our Code of Conduct. The answer was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.


    Comments have been turned off. Learn more

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.