Azure / Azure/azure-functions-dotnet-worker

Duplicate exception telemetry items

Open
#2,055 0 comments 4 reactions 0 assignees View on GitHub
Dominant language
C#
Stars
466
Forks
215
Avg merge
3d 10h
Merged PRs (30d)
7

Description

I configured my isolated Function to [emit logs directly to Application Insights](https://learn.microsoft.com/en-us/azure/azure-functions/dotnet-isolated-process-guide#application-insights),

I referenced `Microsoft.ApplicationInsights.WorkerService` version `2.21.0` and `Microsoft.Azure.Functions.Worker.ApplicationInsights` version `1.0.0`.

`Program.cs`:

```csharp
var host = new HostBuilder()
.ConfigureFunctionsWorkerDefaults()
.ConfigureServices(services =>
{
services
.AddApplicationInsightsTelemetryWorkerService()
.ConfigureFunctionsApplicationInsights();
})
.Build();
```

## HTTP trigger

For an HTTP trigger, the exception is recorded twice by the host:

![isolated-v4-default-http-binding-exception-logged-twice-host](https://github.com/Azure/azure-functions-dotnet-worker/assets/2101647/8004a0b8-a8ed-418c-bdf8-5ff04fc7445f)

Function code:

```csharp
public static class HttpExceptionThrowingFunction
{
[Function(nameof(HttpExceptionThrowingFunction))]
public static HttpResponseData RunGetException(
[HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "http-exception")]
HttpRequestData request)
{
throw new InvalidOperationException("The only goal of this function is to throw an Exception.");
}
}
```

## Service Bus trigger

For a Service Bus trigger, the exception is recorded three times by the host:

![image](https://github.com/Azure/azure-functions-dotnet-worker/assets/2101647/d262c2ac-62e9-4ffe-8f40-bd9d21f87f8e)

Function code:

```csharp
public static class ServiceBusExceptionThrowingFunction
{
[Function(nameof(ServiceBusExceptionThrowingFunction))]
public static void Run(
[ServiceBusTrigger("defaultv4isolated-exception-queue", Connection = "ServiceBusConnection")]
string myQueueItem)
{
throw new InvalidOperationException("The only goal of this function is to throw an Exception.");
}
}
```

## Disable RpcException

When enabling user code exceptions, the duplicate exceptions are still recorded but they have a different problem Id and they're not associated with the operation:

![image](https://github.com/Azure/azure-functions-dotnet-worker/assets/2101647/c77423bd-ae78-4319-b53c-a2613c4b7fcc)

`Program.cs`:

```csharp
var host = new HostBuilder()
.ConfigureFunctionsWorkerDefaults(builder => { }, options =>
{
options.EnableUserCodeException = true;
})
.ConfigureServices(services =>
{
services
.AddApplicationInsightsTelemetryWorkerService()
.ConfigureFunctionsApplicationInsights();
})
.Build();
```

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with the Program.cs configurations shown in the report and reproduce the exception telemetry for both the HTTP and Service Bus triggers. Compare the duplicate records with and without EnableUserCodeException; done means each exception is recorded once and remains associated with the operation.

Written by the indexing model from the issue text.

Assessment

Tech stack
azure, csharp
Domain
observability
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.