sentry-python: Azure Function doesn't capture exceptions on Azure
I 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?
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Comments: 36 (16 by maintainers)
@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