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

feat: support customization for MDC serializer #293

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

aliaksandr-lavishak-tde

No description provided.

Copy link

cla-checker-service bot commented Nov 29, 2024

💚 CLA has been signed

@github-actions github-actions bot added agent-java community Issues and PRs created by the community triage Issues and PRs that need to be triaged labels Nov 29, 2024
Copy link
Contributor

@JonasKunz JonasKunz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your contribution @aliaksandr-lavishak-tde ! I think this feature request is reasonable, I just have some objections on how we structure the extension mechanism.

Copy link
Contributor

@JonasKunz JonasKunz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Forgot to publish my second comment

@aliaksandr-lavishak-tde aliaksandr-lavishak-tde force-pushed the custom-mdc-serializer branch 2 times, most recently from 851e620 to 7ee13d8 Compare December 13, 2024 15:55
Copy link
Contributor

@JonasKunz JonasKunz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, just some small changes

return (MdcSerializer) clazz.getDeclaredConstructor().newInstance();
} catch (ClassNotFoundException | InstantiationException | IllegalAccessException
| NoSuchMethodException | InvocationTargetException e) {
return resolveDefault();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would silently hide the misconfiguration, leaving users scratching their head why thinks don't work.

I think it is better to throw an exception which will usually abort the application start to show the problem to the user:

Suggested change
return resolveDefault();
throw new IllegalArgumentException("Could not create MdcSerializer " + mdcSerializerFullClassName, e);

* Implementations must have a public no-argument constructor to allow dynamic instantiation.
* </p>
*/
public interface MdcSerializer {
void serializeMdc(LogEvent event, StringBuilder builder);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add the following javadoc to the method:

/**
 * Add MDC data for the give log event to the provided output string builder.
 * The output written to the string builder must be a valid JSON-object without the surrounding curly braces
 * and with a trailing comma. If this MDC serializer does not append any content, no comma shall be added.
 * For example, the serializer could output the following content: "foo":"bar","key":"value",
 * 
 * @param event the log event to write the MDC content for
 * @param builder the output JSON string builder
 */

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
agent-java community Issues and PRs created by the community triage Issues and PRs that need to be triaged
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants