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 ability to extract arbitrary fields from the request and store in log keys #816

Open
2 tasks done
gregsinclair42 opened this issue Mar 12, 2025 · 1 comment · May be fixed by #817
Open
2 tasks done
Assignees
Labels
area/logging Core logging utility feature-request New or enhancements to existing features

Comments

@gregsinclair42
Copy link
Contributor

gregsinclair42 commented Mar 12, 2025

Use case

We already have the ability to do this with the CorrelationId, I'd like to be able to use it as well for arbitrary fields in the request, like a deviceId or userId. This would be a new parameter in the Logging attribute called ExtractedKeyPaths. The name could be improved :)

Solution/User Experience

To add these fields (deviceId and userId), assuming they are stored in a header, we would add them to the attribute like this:

[Logging(ExtractedKeyPaths = [("Header/Device-Id", "DeviceId"), ("Header/User-Id", "UserId")]
void MyHandler(APIGatewayProxyRequest request, ILambdaContext context)
{
///
}

Here is an example PR with this change: #817

Acknowledgment

@gregsinclair42 gregsinclair42 added feature-request New or enhancements to existing features triage Pending triage from maintainers labels Mar 12, 2025
@gregsinclair42 gregsinclair42 changed the title Feature request: Add ability to extract arbitrary fields from the request and store in keys Feature request: Add ability to extract arbitrary fields from the request and store in log keys Mar 12, 2025
@hjgraca hjgraca added area/logging Core logging utility and removed triage Pending triage from maintainers labels Mar 13, 2025
@hjgraca hjgraca moved this to 👀 In review in Powertools for AWS Lambda (.NET) Mar 13, 2025
@hjgraca hjgraca linked a pull request Mar 13, 2025 that will close this issue
7 tasks
@hjgraca
Copy link
Contributor

hjgraca commented Mar 13, 2025

HI @gregsinclair42 thank you so much for opening the issue and creating the pull request.
We have a Powertools maintainers sync meeting next Monday so we will be discussing this feature.

Let me share with you my first impressions, while I do believe the use cases makes sense we are trying to move away from doing stuff in the decorator and doing more outside of it.
For this use case this could be solved doing an AppendKey inside the handler which would be a bit cleaner than json pointer expressions in the decorator.

But again thank you for the issue, I will give you an update on Monday

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/logging Core logging utility feature-request New or enhancements to existing features
Projects
Status: 👀 In review
2 participants