Skip to content

ECS structure logging is not removing the nested keys #45545

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

Closed
durgaprasad-akshinthala opened this issue May 14, 2025 · 1 comment
Closed

ECS structure logging is not removing the nested keys #45545

durgaprasad-akshinthala opened this issue May 14, 2025 · 1 comment

Comments

@durgaprasad-akshinthala
Copy link

durgaprasad-akshinthala commented May 14, 2025

It is nice that spring boot introduced the nested logging with 3.5.0.
Ref : #45063

We actually started going for custom implementation of structured logging to have nested format; but since it is going to be introduced in 3.5.0; we can rely on default implementation.

I tested the nested logging with below format and works with out any issues.

MDC.put("error_details.error_type", "MethodArgumentNotValidException");
MDC.put("error_details.error_code", "10200");
MDC.put("error_details.error_message", "Test error");
MDC.put("error_details.error_description", "Error occurred due to field violation");

How ever; if I do not want "error_details" for further logs in the same request; I need to remove the individual keys separately like below.

MDC.remove("error_details.error_type");
MDC.remove("error_details.error_code");
MDC.remove("error_details.error_message");
MDC.remove("error_details.error_description");

Imagine if I have more than 10 keys(or may be more); it is cumbersome to remove all those keys from MDC separately.
It would be nice; to have some thing like below; which will delete all sub keys under "error_details"

MDC.remove("error_details");

Can you please check this.

Tested with Spring Boot 3.5.0-RC1.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label May 14, 2025
@philwebb
Copy link
Member

We don't have a way to do this out of the box. The MVC class isn't part of Spring Boot, so we can't change that API. The best suggestion I have for you is to develop your own JsonWriterStructuredLogFormatter implementation based on ours and update the way that contextPairs are written. Perhaps you could do MDC.put("filter_error_details", true) and use that signal to filter all error_details.

@philwebb philwebb closed this as not planned Won't fix, can't repro, duplicate, stale May 14, 2025
@philwebb philwebb removed the status: waiting-for-triage An issue we've not yet triaged label May 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants