elastic / elastic/ecs-logging-java

Add support for custom MdcSerializer in EcsLayout

Open
#291 1 comment 0 reactions 0 assignees View on GitHub
agent-java community triage
Dominant language
Java
Stars
148
Forks
82
Avg merge
2d 17h
Merged PRs (30d)
3

Description

### Summary
`EcsLayout` from `log4j2-ecs-layout` currently uses a hardcoded implementation of `MdcSerializer` for MDC serialization. While this works well for most cases, it lacks flexibility for users with custom MDC serialization requirements.

I propose adding support for configuring or overriding the `MdcSerializer` implementation to accommodate specific use cases, such as:

- Custom JSON structure for MDC fields.
- Enhanced MDC sanitization or transformation logic.
- Integrating additional logging contexts.

### Problem Statement
The current implementation of `MdcSerializer` is resolved dynamically using `MdcSerializer.Resolver`. However, it does not allow users to provide their own `MdcSerializer` implementation.

### Proposed Solution
Introduce a mechanism to customize the `MdcSerializer`, such as already implemented for `ObjectMessageJacksonSerializer`

Contributor guide

Open the contributing guide

Research direction

Start with EcsLayout and trace how MdcSerializer.Resolver currently selects the serializer. Compare that path with the existing customization for ObjectMessageJacksonSerializer, then define how a user-provided MdcSerializer would be configured or overridden. Done means EcsLayout uses the custom serializer for MDC output while retaining the current default behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
backend, observability-sre
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.