Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

logging.exception does not create entry in exceptions table

Open
#866 9 comments 2 reactions 1 assignee View on GitHub

Nobody has claimed this yet.

Assessment

This issue has not been assessed yet.

Description

area:python-functions needs-investigation

When logging.exception("Simple Exception") then it should show up in the exceptions table in App Insights. It only shows up when it is explicitly raised.

If we want to show 403,404 as an "exception from the app's point of view" and correlate with requests etc currently the app insights will only show failures that explicitly raised an exception. If a valid HttpResponse is sent with 403, it will be shown as successful request because the function executed successfully. But from the app's point of view, if it needs a simple correlation between requests/traces and exceptions, the workaround is to use logging.exception and assign it a error for ease of querying.

But the logging.exception when used outside of a try/catch context in Python functions does not log the exception inside exceptions table in app insights.

Here is a sample code that can be used to test this:

def main(req: func.HttpRequest, context: func.Context) -> func.HttpResponse: logging.exception("Before exception logging") try: raise ValueError("Oops. something went wrong") except ValueError as err: logger.exception("Simple exception logging:" + str(err)) #raise #HTTP 500 kill -> failed.

In this sample "Before exception logging" statement does not show up in the exceptions table
traces
| where message contains "Before"

exceptions
| where message contains "Before"

Overall this would have been an easier stopgap method to correlate exceptions in Python as it does not have a provision to override the custom telemetry model offered by App Insights.

Dominant language
Python
Stars
357
Forks
117
Avg merge
13d 12h
Merged PRs (30d)
2

Getting set up

Open in Codespaces

Starts the project's dev container in your browser, under your own GitHub account.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from Azure/azure-functions-python-worker

All issues in Azure/azure-functions-python-worker

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.