Azure / Azure/azure-functions-host
Custom Handler Logs not appearing for Timer Triggers with 500 status-code
- Dominant language
- C#
- Stars
- 2k
- Forks
- 482
- Avg merge
- 2d 12h
- Merged PRs (30d)
- 38
Description
I have a Function App running Go, using a timer-triggered custom-handler.
On trigger, a new string-slice is created to collect Logs for the current invocation, which are later embedded in the response-body, described below:
```
type InvokeResponse struct {
Outputs map[string]interface{}
Logs []string
ReturnValue interface{}
}
```
When I send a response with a status-code 500, the only logs I can find in Application Insights and Log Analytics are:
```
Executing 'Functions.config' (Reason='This function was programmatically called via the host APIs.', Id=)
Response status code does not indicate success: 500 (Internal Server Error).
Executed 'Functions.config' (Failed, Id=, Duration=7680ms)
Response status code does not indicate success: 500 (Internal Server Error).
```
Whereas a status-code of 200 results in my error-logs appearing:
```
Executing 'Functions.config' (Reason='This function was programmatically called via the host APIs.', Id=)
{"level":"error","ts":"2025-05-26T07:57:25.198Z","msg":"failed to generate JWKS","error":"fetched key is not valid"}
Executed 'Functions.config' (Succeeded, Id=, Duration=6726ms)
```
#### Investigative information
Please provide the following:
- Timestamp: 26/05/2025, 09:41:30
- Invocation ID: 59dd08e1-b8ec-4bb2-a676-6a278e6ab8bb
- Region: West Europe
#### Repro steps
Provide the steps required to reproduce the problem:
1. Create a Go Function App with a Timer Trigger Function (Application Insights Enabled).
2. Log some data to an in-memory string-slice.
3. Embed the logs in the response-body's `Logs` attribute.
4. Return an HTTP-response with status-code 500.
5. Invoke Function
6. Observe logs not appearing in Log Analytics, nor Application Insights.
7. Adjust Function App to respond with status code 200, don't change the logs in any way.
8. Invoke Function
9. Observe logs appearing in Log Analytics and Application Insights.
#### Expected behavior
Independent of the status-code of the custom-handler response, entries in the `Logs` response body attribute should be visible in Log Analytics and Application Insights when the Function App is configured to use Log Analytics, Application Insights.
#### Actual behavior
Only a 200 status-code results in Logs shown in Application Insights and Log Analytics.
#### Known workarounds
Always set the status-code to 200, even when the Function execution fails
#### Related information
https://learn.microsoft.com/en-us/azure/azure-functions/functions-custom-handlers
Contributor guide
Research direction
Start by reproducing the issue with a Go timer-triggered custom handler using the response body's Logs attribute, first returning 200 and then 500. Trace how the Azure Functions host processes that custom-handler response and compare Application Insights and Log Analytics output; done means Logs entries remain visible for both status codes.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- azure, csharp, go
- Domain
- backend, cloud, observability
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100