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

Amazon.Lambda.Logging.AspNetCore should support structural json logging #1144

Open
1 of 2 tasks
Dreamescaper opened this issue Apr 15, 2022 · 7 comments
Open
1 of 2 tasks
Labels
feature-request A feature should be added or improved. module/aspnetcore-support p2 This is a standard priority issue queued

Comments

@Dreamescaper
Copy link
Contributor

Dreamescaper commented Apr 15, 2022

Describe the feature

I should be able to use structural logging with lambda logger.

Use Case

I'd like to use structural logging either with CloudWatch Insights, or with third party system (e.g. DataDog).

Proposed Solution

Add Json lambda logger to DI via smth like this:

serviceCollection.AddLogging(logging =>
        {
            var loggerOptions = new LambdaJsonLoggerOptions
            {
                 ...
            };

            // Configure Lambda logging
            logging.AddLambdaJsonLogger(loggerOptions);
        });

This logger should support logging "state" object:
logger.LogInformation("Saving entity {entityId} by user {userId}.", entityId, userId);

"message": "Saving entity 123456ab-29c5-4912-aa3b-65bf845ae68b for user 1234567890.",
"state": {
	"{OriginalFormat}": "Saving transaction {transactionId} for tenant {userId}.",
	"entityId": "123456ab-29c5-4912-aa3b-65bf845ae68b",
	"userId": "1234567890"
},

This logger should support logging "scopes" object:

        using var scope = logger.BeginScope(new Dictionary<string, object>
        {
            ["requestId"] = input.RequestContext?.RequestId,
            ["userId"] = "testUser"
        });
        logger.LogInformation("Info");
"message": "Info",
"scopes": {
	"requestId": "QnU_ABCDFiAEJ9Q=",
	"userId": "testUser"
},

Ideally, if I use json logger, it shouldn't be needed to set 'AWS_LAMBDA_HANDLER_LOG_FORMAT' environment variable.

Other Information

No response

Acknowledgements

  • I may be able to implement this feature request
  • This feature might incur a breaking change

AWS .NET SDK and/or Package version used

Amazon.Lambda.Logging.AspNetCore Version="3.1.0"

Targeted .NET Platform

.NET6

Operating System and version

AmazonLinux

@Dreamescaper Dreamescaper added feature-request A feature should be added or improved. needs-triage This issue or PR still needs to be triaged. labels Apr 15, 2022
@ashishdhingra
Copy link
Contributor

@Dreamescaper Thanks for submitting feature request. Please advise on how you came up with the JSON format of the log output. Did you use Serilog structured logging as reference?

@ashishdhingra ashishdhingra added response-requested Waiting on additional info and feedback. Will move to close soon in 7 days. and removed needs-triage This issue or PR still needs to be triaged. labels Jun 23, 2022
@Dreamescaper
Copy link
Contributor Author

@github-actions github-actions bot removed the response-requested Waiting on additional info and feedback. Will move to close soon in 7 days. label Jun 24, 2022
@petarrepac
Copy link

@Dreamescaper
can you setup your logging using MS Json logging and direct it to the console (std out) ?

that way you can use whatever MS supports including structured logging and not have any dependency on AWS .NET assemblies

@Dreamescaper
Copy link
Contributor Author

@petarrepac
MS console logging uses a background thread for logging, and it's not a great idea for lambdas, according to this info
https://github.com/aws/aws-logging-dotnet#aws-lambda

@ashishdhingra
Copy link
Contributor

Needs review with the team.

@ashishdhingra ashishdhingra added needs-review p2 This is a standard priority issue labels Dec 28, 2022
@ashishdhingra
Copy link
Contributor

@Dreamescaper Good afternoon. Structured logging support was added as part of PR #1803. Please refer to #1747 for details. Kindly confirm if it covers your scenario.

Thanks,
Ashish

@ashishdhingra ashishdhingra added the response-requested Waiting on additional info and feedback. Will move to close soon in 7 days. label Sep 19, 2024
@Dreamescaper
Copy link
Contributor Author

@ashishdhingra

Not sure. Per my understanding, in order to use it with AspNetCore, it would have to implement Microsoft.Extensions.Logging.ILogger, right?

@github-actions github-actions bot removed the response-requested Waiting on additional info and feedback. Will move to close soon in 7 days. label Sep 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature-request A feature should be added or improved. module/aspnetcore-support p2 This is a standard priority issue queued
Projects
None yet
Development

No branches or pull requests

3 participants