Unable to receive Trace Logs in Application Insights from the worker
hajekj opened this issue · 3 comments
Hello,
I am currently investigating some cost optimizations for our Azure Functions which use PowerShell (storage account related) and I was trying to collect the trace logs which I can collect locally, for example from the Managed Dependencies. When running the function locally, it works just fine:
Example logs
[2024-12-11T09:58:03.934Z] System Log: { Log-Level: Information; Log-Message: Last installed dependency snapshot found: 'C:\Users\hajek\AppData\Local\AzureFunctions\functionsPoweShell\ManagedDependencies\2412101600497890807.r'. }
[2024-12-11T09:58:03.935Z] System Log: { Log-Level: Information; Log-Message: Dependency snapshot 'C:\Users\hajek\AppData\Local\AzureFunctions\functionsPoweShell\ManagedDependencies\2412101600497890807.r' manifest is equivalent to the current manifest. }
[2024-12-11T09:58:03.937Z] System Log: { Log-Level: Trace; Log-Message: Updating dependencies folder heartbeat for 'C:\Users\hajek\AppData\Local\AzureFunctions\functionsPoweShell\ManagedDependencies\2412101600497890807.r''. }
[2024-12-11T09:58:03.948Z] System Log: { Log-Level: Trace; Log-Message: First function load request completed in 37 ms. }
[2024-12-11T09:58:03.949Z] System Log: { Log-Level: Trace; Log-Message: The function app has existing dependencies installed. Updating the dependencies to the latest versions will be performed in the background. New function app instances will pick up any new dependencies. }
[2024-12-11T09:58:03.950Z] System Log: { Log-Level: Trace; Log-Message: Number of dependency snapshots installed: '0'. Dependency snapshots to keep: '1'. }
However when running in Azure (Linux Consumption plan), I am unable to collect these logs. Locally, I just modified the host.json like this:
host.json
{
"version": "2.0",
"logging": {
"LogLevel": {
"Default": "Trace"
}
},
"extensionBundle": {
"id": "Microsoft.Azure.Functions.ExtensionBundle",
"version": "[4.*, 5.0.0)"
},
"managedDependency": {
"enabled": true
}
}However, when in Azure, this doesn't pass the logs to neither Application Insights nor Log Analytics when configured via Diagnostic settings directly. I am able to reproduce this in a new Functions app (so unrelated to the one I am troubleshooting).
Is this a bug? Or am I missing something in the configuration?
The example is here: /subscriptions/63dd3a98-6ad8-47ae-ae7f-568e9b3104a8/resourceGroups/pwshManagedDependenciesTest/providers/Microsoft.Web/sites/hajekj-pwsh-managed-dependencies-test
@hajekj This doesn't seem to be related to the PowerShell worker, there is probably something wrong with the logging configuration. Please consider creating an Azure support ticket here: https://azure.microsoft.com/support/create-ticket/
Alright. I went ahead and created a ticket. The number is: 2412120050000899
Let's keep this issue open please, I will post back the findings, so in case anyone else hits this can easily find it.
Alright, I found why the logs are missing.
When running in Azure, the runner is using completely different bootstrap than the local tooling.
In Azure, the WebJobs has additional filters - https://github.com/Azure/azure-functions-host/blob/dev/src/WebJobs.Script/Extensions/ScriptLoggingBuilderExtensions.cs#L35 which permanently filters out these prefixes https://github.com/Azure/azure-functions-host/blob/dev/src/WebJobs.Script/ScriptConstants.cs#L241 so it is not possible to get these logs ever.