Skip to content

Add a Log4j Core filter activated by trace_flags #13804

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

Open
ppkarwasz opened this issue Apr 30, 2025 · 0 comments
Open

Add a Log4j Core filter activated by trace_flags #13804

ppkarwasz opened this issue Apr 30, 2025 · 0 comments
Labels
enhancement New feature or request needs triage New issue that requires triage

Comments

@ppkarwasz
Copy link

Is your feature request related to a problem? Please describe.

A possible application of the W3C Sampled Flag is to enable more detailed logging if the flag is set to true.

To dynamically switch the log level, based on context data, Log4j Core requires a Filter implementation that matches the log events for which the sampled flag is true.

Describe the solution you'd like

In Log4j Core filters can be applied in one of four phases. The most efficient ones are the global filters, because they are evaluated before a log event is created and therefore before the OpenTelemetryContextDataProvider can fill the event with context data.

It might useful to develop a Log4j Core filter that uses the OpenTelemetry API directly to determine whether the sampled flag is set for the context. The most obvious place to host such a filter is this repo (e.g. the opentelemetry-log4j-context-data-2.17-autoconfigure artifact).

Describe alternatives you've considered

It is currently possible to decrease threshold level for log events by using a ContextMapFilter that checks if the trace_flags key in the context data of a log event has a value of 01.

This is not ideal since:

  • It can not be used before a log event is created.
  • The configuration will break if trace_flags has a value different from 00 or 01.

Additional context

No response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request needs triage New issue that requires triage
Projects
None yet
Development

No branches or pull requests

1 participant