slow sql long string trim (#3318)

*  slow sql long string trim

*  fix slow sql has long string
This commit is contained in:
webb2019 2019-08-25 21:21:48 +08:00 committed by 吴晟 Wu Sheng
parent dbab6977c8
commit f0acf9b61f
2 changed files with 12 additions and 1 deletions

View File

@ -47,4 +47,8 @@ public class TraceServiceModuleConfig extends ModuleConfig {
* 2. NO means, only save trace, but metrics come other places, such as service mesh.
*/
@Setter @Getter private boolean traceAnalysis = true;
/**
* Slow Sql string length can't beyond this limit
*/
@Setter @Getter private int maxSlowSQLLength = 2000;
}

View File

@ -21,6 +21,7 @@ package org.apache.skywalking.oap.server.receiver.trace.provider.parser.listener
import java.util.*;
import org.apache.skywalking.apm.network.common.KeyStringValuePair;
import org.apache.skywalking.apm.network.language.agent.*;
import org.apache.skywalking.apm.util.StringUtil;
import org.apache.skywalking.oap.server.core.*;
import org.apache.skywalking.oap.server.core.cache.*;
import org.apache.skywalking.oap.server.core.source.*;
@ -161,7 +162,13 @@ public class MultiScopesSpanListener implements EntrySpanListener, ExitSpanListe
statement.setTraceId(traceId);
for (KeyStringValuePair tag : spanDecorator.getAllTags()) {
if (SpanTags.DB_STATEMENT.equals(tag.getKey())) {
statement.setStatement(tag.getValue());
String sqlStatement = tag.getValue();
if (!StringUtil.isEmpty(sqlStatement) && sqlStatement.length() > config.getMaxSlowSQLLength()) {
statement.setStatement(sqlStatement.substring(0,config.getMaxSlowSQLLength()));
}
else {
statement.setStatement(sqlStatement);
}
} else if (SpanTags.DB_TYPE.equals(tag.getKey())) {
String dbType = tag.getValue();