microsoft / ApplicationInsights-dotnet

ApplicationInsights-dotnet
MIT License
565 stars 287 forks source link

Populate required field Message with n/a if it is empty #2857

Closed NeilMountford closed 8 months ago

NeilMountford commented 8 months ago

Fix Issue #1066.

Changes

Application Insights rejects exceptions that have empty messages. This means that some exceptions are lost, making investigation of runtime issues difficult. I noticed this when investigating an issue in a .NET 8 API, where a CosmosException for a conflict occurred, was logged on the console but wasn't logged in App Insights.

There was previously a PR #2697 that never got merged due to lack of tests.

Original example from the other PR:

var configuration = TelemetryConfiguration.CreateDefault();
configuration.ConnectionString = "InstrumentationKey=...";
var telemetryClient = new TelemetryClient(configuration);
telemetryClient.TrackException(new Exception("")); // ignored
telemetryClient.TrackException(new Exception("foo")); // logged
telemetryClient.Flush();

Original response from the other PR:

{
    "itemsReceived": 1,
    "itemsAccepted": 0,
    "errors":
    [
        {
            "index": 0,
            "statusCode": 400,
            "message": "109: Field 'message' on type 'ExceptionDetails' is required but missing or empty. Expected: string, Actual: undefined"
        }
    ]
}

Checklist

For significant contributions please make sure you have completed the following items:

The PR will trigger build, unit tests, and functional tests automatically. Please follow these instructions to build and test locally.

Notes for authors:

NeilMountford commented 8 months ago

@microsoft-github-policy-service agree

NeilMountford commented 8 months ago

Thanks @cijothomas, I've pushed a further change to move using Microsoft.ApplicationInsights.DataContracts; into the namespace block to make the build happy for the net4* builds - apologies for not catching this locally, I don't have access to a Windows machine currently. Could you approve the workflows again please? 🙂

NeilMountford commented 8 months ago

@TimothyMothra What are the next steps to get this merged/released? Let me know if you need anything from me 🙂

cijothomas commented 8 months ago

@TimothyMothra What are the next steps to get this merged/released? Let me know if you need anything from me 🙂

Merged! We don't have a planned date for the next release.

jiilaa commented 2 months ago

So, half a year since this fix was merged (and even longer since the latest release for this library), maybe a good time for a release? :)

asos-AdamCox commented 1 month ago

@TimothyMothra / @cijothomas any chance of a release? We've just spent an entire day chasing this bug down only to find it was found in 2019, fixed 7 months ago and still not released...