question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Azure Function doesn't capture exceptions on Azure

See original GitHub issue

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?

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:36 (16 by maintainers)

github_iconTop GitHub Comments

1reaction
untitakercommented, Jan 22, 2021

@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.

1reaction
untitakercommented, Jan 15, 2021

And yes, I’m only getting one event because the second one (the serverless_function one) get’s filtered by the DedupeIntegration.

This should be ok, right? We dedupe by exception identity

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found