Skip to content

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

@davidjlynn

Description

@davidjlynn

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

Metadata

Metadata

Labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions