Issue
- I am using brave (https://github.com/openzipkin/brave) to create a correlation across all logs events from Liferay, portlets and backends. After upgrading from Liferay 7.2 to 2024.Q3.12, which now internally uses log4j2 v2.17.1, I am missing the information taceId and spanId in most of our logs from Liferay portlets. To insert the information into all log outputs, %X{traceId} and %X{spanId} are placeholders that log4j resolves at runtime and retrieves the corresponding values from the org.apache.logging.log4j.ThreadContext.
Brave provides a special library (io.zipkin.brave:brave-context-log4j2) that writes the current taceId and spanId to the ThreadContext of log4j. This works in principle, as some of their logs also contain this information. But in most cases they are missing.
After some research, the customer found the class com.liferay.portal.log.Log4jLogContextLogWrapper in the Liferay code, which also uses the org.apache.logging.log4j.ThreadContext. This class hooks into all log events of Liferay in order to also place information in the ThreadContext. But after logging, the context is unfortunately deleted completely (method _cleanThreadContext()). This means that their traceId and spanId are also lost with the first internal Liferay log
Environment
- Liferay Quarterly Release 2024.q3.12
Resolution
- The case is resolved by LPD-18800. Please request a hotfix.