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

Parameter types are not respected in LogContextPipe #6748

Open
Tracked by #6802
Laurens-makel opened this issue May 1, 2024 · 3 comments
Open
Tracked by #6802

Parameter types are not respected in LogContextPipe #6748

Laurens-makel opened this issue May 1, 2024 · 3 comments
Assignees
Labels
Milestone

Comments

@Laurens-makel
Copy link
Contributor

Laurens-makel commented May 1, 2024

❗ please do not add sensitive information in issues, you can provide extra information via email using issue number as reference ❗

Describe the issue
The LogContextPipe will put the value of each parameter in the ThreadContext. The values of the ThreadContext will be logged to -messages.json|log log files and can be used by tools such as Splunk or Grafana to search on these attributes.

In our OTEL experiment we've noticed that these values are always added to the ThreadContext as string values. The ThreadContext values are added to our traces as tags, however we cannot use numeric operators to find traces, i,e: mails.received > 0 because the values are always added as strings.

When looking at the underlying code, the problem becomes obvious. The parameter types are not checked....

I'd expect that when I specify a parameter with type="INTEGER" or type="BOOLEAN" that these are respected and are added to the ThreadContext with their corresponding java types..

@evandongen
Copy link
Contributor

@Laurens-makel , the ThreadContext is based on a Map<String, String> (that means that the key and the value are a String). That's why we use pv.asStringVAlue() to conform to this. I don't see how we can change this for your needs because the ThreadContext is a class in the log4j library.

@Laurens-makel
Copy link
Contributor Author

@Laurens-makel , the ThreadContext is based on a Map<String, String> (that means that the key and the value are a String). That's why we use pv.asStringVAlue() to conform to this. I don't see how we can change this for your needs because the ThreadContext is a class in the log4j library.

I'd like to include @nielsm5.

Hmm, I was quite sure that I investigated that this would be possible but I probably made a mistake. The current implementation of ThreadContext is indeed String based.

However... I'd like to refer to these links:
https://issues.apache.org/jira/browse/LOG4J2-1648
https://stackoverflow.com/questions/77876650/how-to-produce-json-logs-with-numeric-values-in-java-web-application

It seems that this is a known issue and will be implemented in an upcoming release:
image

Seems they are about to release soon?
image

@evandongen
Copy link
Contributor

@Laurens-makel , I'll move this ticket to the backlog. We can investigate this again when Log4j 2.24.0 is released. Thanks for the heads up!

@nielsm5 nielsm5 added Feature and removed Bug labels May 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: On Hold
Development

No branches or pull requests

3 participants