Azure / azure-sdk-for-python

This repository is for active development of the Azure SDK for Python. For consumers of the SDK we recommend visiting our public developer docs at https://learn.microsoft.com/python/azure/ or our versioned developer docs at https://azure.github.io/azure-sdk-for-python.
MIT License
4.64k stars 2.84k forks source link

Exceptions are reported twice in Application Insights using Azure Functions #37919

Open viktor-morin opened 1 month ago

viktor-morin commented 1 month ago

Describe the bug Running an Azure Function, which listen to an eventhub (not sure if it's relevant), causing exception to be logged twice.

To Reproduce function_app.py

import azure.functions as func
import json
import os
from typing import Iterable
from azure.monitor.opentelemetry import configure_azure_monitor

counter = 0
app = func.FunctionApp()

@app.blob_input(
    arg_name="eventconfig",
    connection="AzureWebJobsStorage",
    path="config/event_config.json",
    data_type=func.DataType.BINARY,
)
@app.event_hub_message_trigger(
    arg_name="events",
    data_type=func.DataType.BINARY,
    event_hub_name="EVENT_HUB_NAME",
    connection="EVENT_HUB_CONNECTION_STRING",
    consumer_group=os.environ["EVENT_HUB_CONSUMER_GROUP"],
    cardinality=func.Cardinality.MANY,
)
def eventhub_trigger(events: Iterable[func.EventHubEvent], eventconfig: bytes):
    configure_azure_monitor()
    global counter
    counter = counter + 1
    raise Exception(f"Counter: {counter}")

requirements.txt

azure-functions
azure-data-tables==12.*
azure-identity==1.*
azure-keyvault-secrets==4.*
tzdata

local.settings.json

{
  "IsEncrypted": false,
  "Values": {
    "APPLICATIONINSIGHTS_CONNECTION_STRING": "InstrumentationKey=xxxxx"
  }
}

Expected behavior We expect the exception to only be logged once in Application Insights

Screenshots Same exception is shown twice Image

Additional context NA

github-actions[bot] commented 1 month ago

Thank you for your feedback. Tagging and routing to the team member best able to assist.