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

If extra keys has property "name", the logger name in the output is overwritten #229

Open
bjhogan opened this issue Apr 3, 2023 · 1 comment · May be fixed by #244
Open

If extra keys has property "name", the logger name in the output is overwritten #229

bjhogan opened this issue Apr 3, 2023 · 1 comment · May be fixed by #244
Assignees
Labels
area/logging Core logging utility need-rfc
Milestone

Comments

@bjhogan
Copy link

bjhogan commented Apr 3, 2023

Expected Behaviour

Logger name should not be lost when object logged has a property called "name".

This is lost - "name": "AWS.Lambda.Powertools.Logging.Logger", and replaced with "name": "Alan Adams", .

If the object being logged has a TimeStamp property, the Lambda timestamp will also be lost.

This problem relates to another bug.

Current Behaviour

The logger name is lost

{
    "coldStart": true,
    "xrayTraceId": "1-642af849-5a28de55210c2acf73933301",
    "functionName": "ThreeSimpleWaysToLog",
    "functionVersion": "$LATEST",
    "functionMemorySize": 256,
    "functionArn": "arn:aws:lambda:us-east-1:694977046108:function:ThreeSimpleWaysToLog",
    "functionRequestId": "e882f2c8-24af-406a-ac5a-90c1031c3b65",
    "name": "Alan Adams",
    "age": 11,
    "timestamp": "2023-04-03T16:01:14.3304021Z",
    "level": "Information",
    "service": "ThreeSimpleWaysToLog",
    "message": "Alan Adams and is 11 years old"
}

Code snippet

using Amazon.Lambda.Core;
using AWS.Lambda.Powertools.Logging;

// Assembly attribute to enable the Lambda function's JSON input to be converted into a .NET class.
[assembly: LambdaSerializer(typeof(Amazon.Lambda.Serialization.SystemTextJson.DefaultLambdaJsonSerializer))]

namespace ThreeSimpleWaysToLog;

public class Function

{
    [Logging(LogEvent = true, LoggerOutputCase = LoggerOutputCase.CamelCase)]
    public void FunctionHandler(string input, ILambdaContext context)
    {
        Person person = new Person { Name ="Alan Adams", Age = 11 };
        Logger.LogInformation<Person>(person, "{Name} and is {Age} years old", new object[]{person.Name, person.Age});
    }
}


public class Person 
{
    public string Name {get ; set;} 
    public int Age { get; set; }
}

Possible Solution

The Person should be have be represented in the JSON under a Person property.

"person": {
    "name": "Alan Adams",
    "age": 11
}

### Steps to Reproduce

Deploy the code above and invoke

### AWS Lambda Powertools for .NET version

latest

### AWS Lambda function runtime

dotnet6

### Debugging logs

_No response_
@bjhogan bjhogan added bug Unexpected, reproducible and unintended software behaviour triage Pending triage from maintainers labels Apr 3, 2023
@hjgraca
Copy link
Contributor

hjgraca commented Apr 12, 2023

@bjhogan thanks for reporting. Having a look

@hjgraca hjgraca self-assigned this Apr 12, 2023
@sliedig sliedig added need-rfc area/logging Core logging utility and removed triage Pending triage from maintainers bug Unexpected, reproducible and unintended software behaviour labels Apr 14, 2023
@hjgraca hjgraca linked a pull request May 30, 2023 that will close this issue
7 tasks
@hjgraca hjgraca added this to the Logging V2 milestone Dec 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/logging Core logging utility need-rfc
Projects
Status: 📋 Backlog
Development

Successfully merging a pull request may close this issue.

4 participants