mirror of
https://github.com/wahyd4/pinpoint.git
synced 2026-08-17 08:46:22 +10:00
[강운덕] [LUCYSUS-1744] sql trace정보를 서버로 던질때 개별 파라미터로 던지는게 아니고, 한번에 뭉쳐서 던지도록 수정함.
git-svn-id: http://svn.bds.nhncorp.com/pe/hippo-tomcat-profiler/trunk@2516 84d0f5b1-2673-498c-a247-62c4ff18d310
This commit is contained in:
@@ -3,6 +3,7 @@ package com.nhn.pinpoint.profiler.context;
|
||||
import com.nhn.pinpoint.profiler.util.AnnotationValueMapper;
|
||||
import com.nhn.pinpoint.thrift.dto.TAnnotation;
|
||||
import com.nhn.pinpoint.thrift.dto.TAnnotationValue;
|
||||
import com.nhn.pinpoint.thrift.dto.TIntStringStringValue;
|
||||
import com.nhn.pinpoint.thrift.dto.TIntStringValue;
|
||||
|
||||
/**
|
||||
@@ -24,6 +25,11 @@ public class Annotation extends TAnnotation {
|
||||
this.setValue(TAnnotationValue.intStringValue(value));
|
||||
}
|
||||
|
||||
public Annotation(int key, TIntStringStringValue value) {
|
||||
super(key);
|
||||
this.setValue(TAnnotationValue.intStringStringValue(value));
|
||||
}
|
||||
|
||||
public Annotation(int key, String value) {
|
||||
super(key);
|
||||
this.setValue(TAnnotationValue.stringValue(value));
|
||||
|
||||
@@ -5,6 +5,7 @@ import com.nhn.pinpoint.common.ServiceType;
|
||||
import com.nhn.pinpoint.common.util.ParsingResult;
|
||||
import com.nhn.pinpoint.profiler.interceptor.MethodDescriptor;
|
||||
import com.nhn.pinpoint.profiler.util.StringUtils;
|
||||
import com.nhn.pinpoint.thrift.dto.TIntStringStringValue;
|
||||
import com.nhn.pinpoint.thrift.dto.TIntStringValue;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
@@ -231,7 +232,7 @@ public final class DefaultTrace implements Trace {
|
||||
recordAttribute(AnnotationKey.EXCEPTION_CLASS, th.getClass().getName());
|
||||
|
||||
final Span span = getCallStack().getSpan();
|
||||
if (span.getErrCode() == 0) {
|
||||
if (!span.isSetErrCode()) {
|
||||
span.setErrCode(1);
|
||||
}
|
||||
}
|
||||
@@ -308,27 +309,33 @@ public final class DefaultTrace implements Trace {
|
||||
|
||||
@Override
|
||||
public void recordSqlParsingResult(ParsingResult parsingResult) {
|
||||
recordSqlParsingResult(parsingResult, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void recordSqlParsingResult(ParsingResult parsingResult, String bindValue) {
|
||||
if (parsingResult == null) {
|
||||
return;
|
||||
}
|
||||
String sql = parsingResult.getSql();
|
||||
recordAttribute(AnnotationKey.SQL_ID, sql.hashCode());
|
||||
String output = parsingResult.getOutput();
|
||||
if (output != null && output.length() != 0) {
|
||||
recordAttribute(AnnotationKey.SQL_PARAM, output);
|
||||
final String sql = parsingResult.getSql();
|
||||
final TIntStringStringValue tSqlValue = new TIntStringStringValue(sql.hashCode());
|
||||
final String output = parsingResult.getOutput();
|
||||
if (isNotEmpty(output)) {
|
||||
tSqlValue.setStringValue1(output);
|
||||
}
|
||||
// final String sql = parsingResult.getSql();
|
||||
// final TIntStringValue tSqlValue = new TIntStringValue(sql.hashCode());
|
||||
// final String output = parsingResult.getOutput();
|
||||
// if (output != null && output.length() != 0) {
|
||||
// tSqlValue.setBindValue(output);
|
||||
// }
|
||||
// recordSqlParam(tSqlValue);
|
||||
if (isNotEmpty(bindValue)) {
|
||||
tSqlValue.setStringValue2(bindValue);
|
||||
}
|
||||
recordSqlParam(tSqlValue);
|
||||
}
|
||||
|
||||
private void recordSqlParam(TIntStringValue tIntStringValue) {
|
||||
private static boolean isNotEmpty(final String bindValue) {
|
||||
return bindValue != null && bindValue.length() != 0;
|
||||
}
|
||||
|
||||
private void recordSqlParam(TIntStringStringValue tIntStringStringValue) {
|
||||
final StackFrame currentStackFrame = this.currentStackFrame;
|
||||
currentStackFrame.addAnnotation(new Annotation(AnnotationKey.SQL_ID.getCode(), tIntStringValue));
|
||||
currentStackFrame.addAnnotation(new Annotation(AnnotationKey.SQL_ID.getCode(), tIntStringStringValue));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -113,6 +113,10 @@ public class DisableTrace implements Trace {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
public void recordSqlParsingResult(ParsingResult parsingResult, String bindValue) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void recordAttribute(AnnotationKey key, String value) {
|
||||
throw new UnsupportedOperationException();
|
||||
|
||||
@@ -68,6 +68,10 @@ public class Span extends TSpan implements Thriftable {
|
||||
return super.getExceptionId();
|
||||
}
|
||||
|
||||
public boolean isSetErrCode() {
|
||||
return isSetErr();
|
||||
}
|
||||
|
||||
public int getErrCode() {
|
||||
return getErr();
|
||||
}
|
||||
|
||||
+5
-10
@@ -55,18 +55,13 @@ public class PreparedStatementExecuteQueryInterceptor implements SimpleAroundInt
|
||||
trace.recordDestinationId(databaseInfo.getDatabaseId());
|
||||
|
||||
|
||||
ParsingResult parsingResult = (ParsingResult) getSql.invoke(target);
|
||||
|
||||
trace.recordSqlParsingResult(parsingResult);
|
||||
|
||||
final ParsingResult parsingResult = (ParsingResult) getSql.invoke(target);
|
||||
Map<Integer, String> bindValue = getBindValue.invoke(target);
|
||||
if (bindValue != null) {
|
||||
String bindString = toBindVariable(bindValue);
|
||||
if (bindString != null && bindString.length() != 0) {
|
||||
trace.recordAttribute(AnnotationKey.SQL_BINDVALUE, bindString);
|
||||
}
|
||||
trace.recordSqlParsingResult(parsingResult, bindString);
|
||||
} else {
|
||||
logger.warn("bindValue not found.");
|
||||
trace.recordSqlParsingResult(parsingResult);
|
||||
}
|
||||
|
||||
trace.recordApi(descriptor);
|
||||
@@ -90,7 +85,7 @@ public class PreparedStatementExecuteQueryInterceptor implements SimpleAroundInt
|
||||
}
|
||||
|
||||
private String toBindVariable(Map<Integer, String> bindValue) {
|
||||
String[] temp = new String[bindValue.size()];
|
||||
final String[] temp = new String[bindValue.size()];
|
||||
for (Map.Entry<Integer, String> entry : bindValue.entrySet()) {
|
||||
Integer key = entry.getKey() - 1;
|
||||
if (temp.length < key) {
|
||||
@@ -107,7 +102,7 @@ public class PreparedStatementExecuteQueryInterceptor implements SimpleAroundInt
|
||||
if (temp == null) {
|
||||
return "";
|
||||
}
|
||||
StringBuilder sb = new StringBuilder();
|
||||
final StringBuilder sb = new StringBuilder(32);
|
||||
int end = temp.length - 1;
|
||||
for (int i = 0; i < temp.length; i++) {
|
||||
sb.append(temp[i]);
|
||||
|
||||
@@ -2,6 +2,7 @@ package com.nhn.pinpoint.profiler.util;
|
||||
|
||||
|
||||
import com.nhn.pinpoint.thrift.dto.*;
|
||||
import org.apache.thrift.TBase;
|
||||
|
||||
public class AnnotationValueMapper {
|
||||
|
||||
@@ -37,6 +38,8 @@ public class AnnotationValueMapper {
|
||||
} else if (value instanceof Short) {
|
||||
annotation.setValue(TAnnotationValue.shortValue((Short) value));
|
||||
return;
|
||||
} else if(value instanceof TBase) {
|
||||
throw new IllegalArgumentException("TBase not supported. Class:" + value.getClass());
|
||||
}
|
||||
String str = StringUtils.drop(value.toString());
|
||||
annotation.setValue(TAnnotationValue.stringValue(str));
|
||||
|
||||
Reference in New Issue
Block a user