Skip to content

Commit

Permalink
Merge pull request wso2#4040 from wso2/revert-4031-revert-4028-correl…
Browse files Browse the repository at this point in the history
…ation-logs

Revert "Revert "Include Correlation ID, LDAP, and JDBC logs when correlation logs are enabled with management API""
  • Loading branch information
DedunuKarunarathne authored Feb 19, 2025
2 parents 2e8a7f8 + 9e0ff48 commit 844bd06
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,14 @@
import org.apache.commons.logging.LogFactory;
import org.apache.synapse.MessageContext;
import org.apache.synapse.commons.json.JsonUtil;
import org.apache.synapse.commons.logger.ContextAwareLogger;
import org.apache.synapse.config.SynapseConfiguration;
import org.apache.synapse.transport.passthru.config.PassThroughCorrelationConfigDataHolder;
import org.json.JSONObject;
import org.wso2.micro.integrator.management.apis.security.handler.SecurityUtils;
import org.wso2.micro.integrator.ndatasource.rdbms.CorrelationLogInterceptor;
import org.wso2.micro.integrator.security.user.api.UserStoreException;
import org.wso2.micro.integrator.security.user.core.ldap.LDAPConnectionContext;

import java.io.IOException;
import java.util.HashSet;
Expand Down Expand Up @@ -127,6 +130,10 @@ private JSONObject handlePut(org.apache.axis2.context.MessageContext axis2Messag
}
boolean enabled = Boolean.parseBoolean(configs.get(ENABLED).getAsString());
PassThroughCorrelationConfigDataHolder.setEnable(enabled);
ContextAwareLogger.setCorrelationLoggingEnabled(enabled);
LDAPConnectionContext.setCorrelationLoggingEnabled(enabled);
CorrelationLogInterceptor.setCorrelationLoggingEnabled(enabled);

JSONObject response = new JSONObject();
response.put(Constants.MESSAGE, "Successfully Updated Correlation Logs Status");
return response;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ public class CorrelationLogInterceptor extends AbstractQueryReport {
private static final String BLACKLISTED_THREADS_SYSTEM_PROPERTY =
"org.wso2.CorrelationLogInterceptor.BlacklistedThreads";
private static final String DEFAULT_BLACKLISTED_THREAD = "MessageDeliveryTaskThreadPool";
private static boolean correlationLoggingEnabled = false;
private List<String> blacklistedThreadList = new ArrayList<>();

public CorrelationLogInterceptor() {
Expand Down Expand Up @@ -124,7 +125,7 @@ protected void prepareCall(String s, long l) {
public Object createStatement(Object proxy, Method method, Object[] args, Object statement, long time) {

try {
if (Boolean.parseBoolean(System.getProperty(CORRELATION_LOG_SYSTEM_PROPERTY))) {
if (Boolean.parseBoolean(System.getProperty(CORRELATION_LOG_SYSTEM_PROPERTY)) || correlationLoggingEnabled) {
return invokeProxy(method, args, statement, time);
} else {
return statement;
Expand Down Expand Up @@ -284,4 +285,8 @@ private String createFormattedLog(List<String> logPropertiesList) {
return sb.toString();
}
}
public static void setCorrelationLoggingEnabled(boolean correlationLoggingEnabled) {

CorrelationLogInterceptor.correlationLoggingEnabled = correlationLoggingEnabled;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ public class LDAPConnectionContext {
private static final int CORRELATION_LOG_INITIALIZATION_ARGS_LENGTH = 0;
private static final String CORRELATION_LOG_SEPARATOR = "|";
private static final String CORRELATION_LOG_SYSTEM_PROPERTY = "enableCorrelationLogs";
private static boolean correlationLoggingEnabled = false;
public static final String CIRCUIT_STATE_OPEN = "open";
public static final String CIRCUIT_STATE_CLOSE = "close";

Expand Down Expand Up @@ -625,7 +626,7 @@ private LdapContext getContextForEnvironmentVariables(Hashtable<?, ?> environmen
*/
private DirContext getDirContext(Hashtable<?, ?> environment) throws NamingException {

if (Boolean.parseBoolean(System.getProperty(CORRELATION_LOG_SYSTEM_PROPERTY))) {
if (Boolean.parseBoolean(System.getProperty(CORRELATION_LOG_SYSTEM_PROPERTY)) || correlationLoggingEnabled) {
final Class[] proxyInterfaces = new Class[]{DirContext.class};
long start = System.currentTimeMillis();

Expand Down Expand Up @@ -662,7 +663,7 @@ private DirContext getDirContext(Hashtable<?, ?> environment) throws NamingExcep
private LdapContext getLdapContext(Hashtable<?, ?> environment, Control[] connectionControls)
throws NamingException, UserStoreException {

if (Boolean.parseBoolean(System.getProperty(CORRELATION_LOG_SYSTEM_PROPERTY))) {
if (Boolean.parseBoolean(System.getProperty(CORRELATION_LOG_SYSTEM_PROPERTY)) || correlationLoggingEnabled) {
final Class[] proxyInterfaces = new Class[]{LdapContext.class};
long start = System.currentTimeMillis();

Expand Down Expand Up @@ -840,4 +841,8 @@ private long getThresholdTimeoutInMilliseconds(String retryWaitingTime) throws U
+ UserStoreConfigConstants.CONNECTION_RETRY_DELAY);
}
}
public static void setCorrelationLoggingEnabled(boolean correlationLoggingEnabled) {

LDAPConnectionContext.correlationLoggingEnabled = correlationLoggingEnabled;
}
}
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1627,7 +1627,7 @@
<version.jaxb.api>2.4.0-b180830.0359</version.jaxb.api>
<com.sun.jaxb.version>2.3.0</com.sun.jaxb.version>
<com.sun.jaxb.impl.version>2.3.1</com.sun.jaxb.impl.version>
<synapse.version>4.0.0-wso2v215</synapse.version>
<synapse.version>4.0.0-wso2v216</synapse.version>
<imp.pkg.version.synapse>[4.0.0, 4.0.1)</imp.pkg.version.synapse>
<carbon.mediation.version>4.7.244</carbon.mediation.version>
<carbon.crypto.version>1.1.3</carbon.crypto.version>
Expand Down

0 comments on commit 844bd06

Please sign in to comment.