Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request: Add InnerException to Exceptions' structured log #680

Open
2 tasks done
joaope opened this issue Dec 6, 2024 · 2 comments
Open
2 tasks done

Feature request: Add InnerException to Exceptions' structured log #680

joaope opened this issue Dec 6, 2024 · 2 comments
Assignees
Labels
feature-request New or enhancements to existing features logging Logging utility triage Pending triage from maintainers

Comments

@joaope
Copy link

joaope commented Dec 6, 2024

Use case

Hi!

Current implementation leads to logged exceptions to loose valuable information, in particular their inner exceptions. Only Message, Source and StackTrace are being added to the final structured log.

For the following:

Logger.LogError(
    new InvalidOperationException("Parent exception message",
        new ArgumentNullException(nameof(input), "Very important inner exception message")), 
    "Something went wrong and we logged an exception itself with an inner exception. This is a param {arg}",
    12345);

We will see this, with the very important inner exception being lost forever:

{
    "...",
    "timestamp": "2024-12-05T13:29:34.9150895Z",
    "level": "Error",
    "service": "DotnetAotFunction",
    "name": "DotnetAotFunction",
    "message": "Something went wrong and we logged an exception itself with an inner exception. This is a param 12345",
    "exception": {
        "type": "System.InvalidOperationException",
        "message": "parent exception message"
    }
}

Solution/User Experience

Given InnerException is itself a property of the base Exception class, adding support to also structure log it seems pretty trivial.

For the above I would expect this instead:

{
    "...",
    "timestamp": "2024-12-05T13:29:34.9150895Z",
    "level": "Error",
    "service": "DotnetAotFunction",
    "name": "DotnetAotFunctionr",
    "message": "Something went wrong and we logged an exception itself with an inner exception. This is a param 12345",
    "exception": {
        "type": "System.InvalidOperationException",
        "message": "Parent exception message",
        "inner_exception": {
            "type": "System.ArgumentNullException",
            "message": "Very important inner exception message"
        }
    }
}

Obviously the example is for a single child inner exception but, given the serialization is recursive, this would be also be working for inner exceptions within inner exceptions, until the end of the exceptions' tree branch.

Happy to contribute a PR for this, if accepted.

Thanks!

Alternative solutions

N/A

Acknowledgment

@joaope joaope added feature-request New or enhancements to existing features triage Pending triage from maintainers labels Dec 6, 2024
Copy link

boring-cyborg bot commented Dec 6, 2024

Thanks for opening your first issue here! We'll come back to you as soon as we can.
In the meantime, check out the #dotnet channel on our Powertools for AWS Lambda Discord: Invite link

@hjgraca
Copy link
Contributor

hjgraca commented Dec 12, 2024

Hi @joaope thanks for opening the issue. You are correct that should be part of the exception. I need a couple of days to understand why is not available in the first place, hopefully is a simple addition to the logs. Will keep you posted.
Thanks again

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature-request New or enhancements to existing features logging Logging utility triage Pending triage from maintainers
Projects
Status: No status
Development

No branches or pull requests

2 participants