Azure Function doesn't capture exceptions on Azure
See original GitHub issueI have a Queue Trigger Azure Function in Python with the following code:
import logging
import os
import azure.functions as func
import sentry_sdk
from sentry_sdk.api import capture_exception, flush, push_scope
from sentry_sdk.integrations.serverless import serverless_function
# Sentry configuration
sentry_dsn = "my-dsn"
environment = "DEV"
logger = logging.getLogger(__name__)
sentry_sdk.init(
sentry_dsn,
environment=environment,
send_default_pii=True,
request_bodies="always",
with_locals=True,
)
sentry_sdk.utils.MAX_STRING_LENGTH = 2048
@serverless_function
def main(msg: func.QueueMessage) -> None:
with push_scope() as scope:
scope.set_tag("function.name", "ProcessHeadersFile")
scope.set_context(
"Queue Message",
{
"id": msg.id,
"dequeue_count": msg.dequeue_count,
"insertion_time": msg.insertion_time,
"expiration_time": msg.expiration_time,
"pop_receipt": msg.pop_receipt,
},
)
try:
# code that might raise exceptions here
function_that_raise()
except Exception as ex:
print(ex)
# Rethrow to fail the execution
raise
def function_that_raise():
return 5 / 0
Works locally, but not on Azure. I run multiple invocations, I get all the failures, but then nothing shows on Sentry.
I have also try manually capturing and flushing, but doesn’t work either:
try:
# code that might raise exceptions here
function_that_raise()
except Exception as ex:
capture_exception(ex)
flush(2)
raise
Using sentry-sdk==0.19.5
.
How can I troubleshoot what’s happening? What can be the causes that it works when running the function locally, but not when running on Azure?
Issue Analytics
- State:
- Created 3 years ago
- Comments:36 (16 by maintainers)
Top Results From Across the Web
Azure Function - Not throwing right exception - Microsoft Learn
I have a ADF Azure Function activity which calls an Azure Function. In the Azure Function, this is my exception block. catch (Exception...
Read more >azure function not logging exceptions to application insight
I've found that when logging a message or excpeption to Application Insights with null or string.Empty the exception is not saved in Application ......
Read more >A comprehensive guide to Azure Functions error monitoring
Monitor errors in your Azure Function Apps with Raygun. ... would normally connect some kind of global logger to catch and log exceptions....
Read more >Error Handling with Durable Functions - Mark Heath
I wrote recently about why you should use Azure Durable Functions to ... if the orchestrator function doesn't catch these exceptions itself, ...
Read more >Building resilient azure functions with retry policies - Medium
A special kind of exception is timeout, which can happen on the client, server, or proxy. Client can decide to terminate waiting for...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@empz fyi we’re going to have somebody look into this next week for real. Past weeks we were strapped for resources. Sorry again for slow responses and thanks for the patience so far.
This should be ok, right? We dedupe by exception identity