spring-projects / spring-projects/spring-boot

Allow structured logging include stack trace hashes to be added to separate structured field

Open
#49,639 6 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

status: team-only type: enhancement
Dominant language
Java
Stars
81.5k
Forks
42.7k
Avg merge
2d 4h
Merged PRs (30d)
65

Description

Background

I am currently using Spring Boot Structured Logging and it has been working great, I have been using this on 3.5.11 and 4.0.3. Also for context I am using logstash formatting.

One feature that I noticed was provided was logging.structured.json.stacktrace.include-hashes as detailed here.

My configuration looks like:

logging:
  level.root: INFO
  structured:
    format.console: logstash
    json.stacktrace.include-hashes: true
  threshold.console: INFO

What I see with this is that when a stack trace is added with a log message, the hash is prefixed to the stack_trace entry. For example:

<#351b6441> jakarta.validation.ConstraintViolationException: myEndpointPOST.fieldId: must match \"^[0-9a-f]{2}$\"
    at org.springframework.validation.beanvalidation.MethodValidationInterceptor.invoke(MethodValidationInterceptor.java:168)
...
Enhancement

So hashes are getting added, but the enhancement I would like to suggest is allowing the adding of the stack trace hash to a dedicated structured field (as an example stack_hash or stack_trace_hash, but not picky on the naming, or even this could be configurable).

Reason being, stack hashes are very useful for grouping common exceptions, so the ability to filter these out in logs easily adds great value when analysing common failures. Having a dedicated structured log field makes this very easy.

Workaround

To achieve this functionality without updates to Spring Boot, it is possible to create a StructuredLoggingJsonMembersCustomizer<ILoggingEvent> and re-implementing the internal spring boot hashing algorithm (or adding a custom implementation).

This works, but could be valuable to have this available out the box.

Thanks

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with Spring Boot's structured logging documentation on stack-trace customization and the StructuredLoggingJsonMembersCustomizer entry point mentioned in the issue. Trace how logstash formatting currently adds the hash to stack_trace and identify the existing hashing implementation. Done should mean the hash is available in a separate structured field, with behavior verified for structured log output.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, spring-boot
Domain
observability
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.