From ff58b3950bec55755cd7298986a1dbe6c2389158 Mon Sep 17 00:00:00 2001 From: Minwoo Jung Date: Thu, 22 Jan 2015 14:30:36 +0900 Subject: [PATCH 1/4] [#76] statuscode profiling method for containing HttpMethod, HttpRequest parameter --- .../bootstrap/context/RecordableTrace.java | 2 + .../interceptor/http/HttpCallContext.java | 31 ++++++ .../bootstrap/interceptor/MockTrace.java | 5 + .../profiler/context/DefaultTrace.java | 5 + .../profiler/context/DisableTrace.java | 5 + .../profiler/context/MetricTrace.java | 5 + .../profiler/context/RootStackFrame.java | 7 ++ .../profiler/context/SpanEventStackFrame.java | 7 ++ .../pinpoint/profiler/context/StackFrame.java | 4 + .../ClosableHttpClientModifier.java | 67 ++++++------ .../HttpRequestExecuteInterceptor.java | 101 ++++++++++++++++-- 11 files changed, 203 insertions(+), 36 deletions(-) create mode 100644 bootstrap/src/main/java/com/navercorp/pinpoint/bootstrap/interceptor/http/HttpCallContext.java diff --git a/bootstrap/src/main/java/com/navercorp/pinpoint/bootstrap/context/RecordableTrace.java b/bootstrap/src/main/java/com/navercorp/pinpoint/bootstrap/context/RecordableTrace.java index 51e68c98e..598b139f8 100644 --- a/bootstrap/src/main/java/com/navercorp/pinpoint/bootstrap/context/RecordableTrace.java +++ b/bootstrap/src/main/java/com/navercorp/pinpoint/bootstrap/context/RecordableTrace.java @@ -39,6 +39,8 @@ public interface RecordableTrace { boolean canSampled(); boolean isRoot(); + + ServiceType getServiceType(); void recordException(Throwable throwable); diff --git a/bootstrap/src/main/java/com/navercorp/pinpoint/bootstrap/interceptor/http/HttpCallContext.java b/bootstrap/src/main/java/com/navercorp/pinpoint/bootstrap/interceptor/http/HttpCallContext.java new file mode 100644 index 000000000..79d9584ba --- /dev/null +++ b/bootstrap/src/main/java/com/navercorp/pinpoint/bootstrap/interceptor/http/HttpCallContext.java @@ -0,0 +1,31 @@ +/* + * Copyright 2014 NAVER Corp. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.navercorp.pinpoint.bootstrap.interceptor.http; + +public class HttpCallContext { + private int statusCode; + + public int getStatusCode() { + return statusCode; + } + + public void setStatusCode(int statusCode) { + this.statusCode = statusCode; + } + + +} diff --git a/bootstrap/src/test/java/com/navercorp/pinpoint/bootstrap/interceptor/MockTrace.java b/bootstrap/src/test/java/com/navercorp/pinpoint/bootstrap/interceptor/MockTrace.java index 754e845b1..410ef1174 100644 --- a/bootstrap/src/test/java/com/navercorp/pinpoint/bootstrap/interceptor/MockTrace.java +++ b/bootstrap/src/test/java/com/navercorp/pinpoint/bootstrap/interceptor/MockTrace.java @@ -209,4 +209,9 @@ public class MockTrace implements Trace { public void traceBlockEnd(int stackId) { } + + @Override + public ServiceType getServiceType() { + return null; + } } diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/DefaultTrace.java b/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/DefaultTrace.java index 62edfe94a..74a69b021 100644 --- a/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/DefaultTrace.java +++ b/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/DefaultTrace.java @@ -532,4 +532,9 @@ public final class DefaultTrace implements Trace { return this.getCurrentStackFrame().getStackFrameId(); } + + @Override + public ServiceType getServiceType() { + return currentStackFrame.getServiceType(); + } } diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/DisableTrace.java b/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/DisableTrace.java index 5c454ca88..43d49aefc 100644 --- a/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/DisableTrace.java +++ b/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/DisableTrace.java @@ -199,4 +199,9 @@ public class DisableTrace implements Trace { public int getStackFrameId() { throw new UnsupportedOperationException(); } + + @Override + public ServiceType getServiceType() { + throw new UnsupportedOperationException(); + } } diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/MetricTrace.java b/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/MetricTrace.java index f7ac74430..813942dcf 100644 --- a/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/MetricTrace.java +++ b/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/MetricTrace.java @@ -364,4 +364,9 @@ public class MetricTrace implements Trace { public int getStackFrameId() { return this.getCurrentStackFrame().getStackFrameId(); } + + @Override + public ServiceType getServiceType() { + return currentStackFrame.getServiceType(); + } } diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/RootStackFrame.java b/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/RootStackFrame.java index 9c46b8c2f..32ca868af 100644 --- a/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/RootStackFrame.java +++ b/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/RootStackFrame.java @@ -16,6 +16,8 @@ package com.navercorp.pinpoint.profiler.context; +import com.navercorp.pinpoint.common.ServiceType; + /** * @author emeroad */ @@ -124,4 +126,9 @@ public class RootStackFrame implements StackFrame { this.frameObject = null; return copy; } + + @Override + public ServiceType getServiceType() { + return ServiceType.findServiceType(this.span.getServiceType()); + } } diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/SpanEventStackFrame.java b/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/SpanEventStackFrame.java index ac0dc6104..f839ca71b 100644 --- a/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/SpanEventStackFrame.java +++ b/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/SpanEventStackFrame.java @@ -16,6 +16,8 @@ package com.navercorp.pinpoint.profiler.context; +import com.navercorp.pinpoint.common.ServiceType; + /** * @author emeroad */ @@ -128,6 +130,11 @@ public class SpanEventStackFrame implements StackFrame { this.frameObject = null; return copy; } + + @Override + public ServiceType getServiceType() { + return ServiceType.findServiceType(spanEvent.getServiceType()); + } } diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/StackFrame.java b/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/StackFrame.java index ad617e8ab..1d679b1fc 100644 --- a/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/StackFrame.java +++ b/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/StackFrame.java @@ -16,6 +16,8 @@ package com.navercorp.pinpoint.profiler.context; +import com.navercorp.pinpoint.common.ServiceType; + /** * @author emeroad */ @@ -46,6 +48,8 @@ public interface StackFrame { void setServiceType(short serviceType); void addAnnotation(Annotation annotation); + + ServiceType getServiceType(); void attachFrameObject(Object frameObject); diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/modifier/connector/httpclient4/ClosableHttpClientModifier.java b/profiler/src/main/java/com/navercorp/pinpoint/profiler/modifier/connector/httpclient4/ClosableHttpClientModifier.java index 34f4c9b42..a1e319b18 100644 --- a/profiler/src/main/java/com/navercorp/pinpoint/profiler/modifier/connector/httpclient4/ClosableHttpClientModifier.java +++ b/profiler/src/main/java/com/navercorp/pinpoint/profiler/modifier/connector/httpclient4/ClosableHttpClientModifier.java @@ -19,9 +19,13 @@ package com.navercorp.pinpoint.profiler.modifier.connector.httpclient4; import java.security.ProtectionDomain; import com.navercorp.pinpoint.bootstrap.Agent; +import com.navercorp.pinpoint.bootstrap.instrument.AttachmentScope; import com.navercorp.pinpoint.bootstrap.instrument.ByteCodeInstrumentor; +import com.navercorp.pinpoint.bootstrap.instrument.DefaultScopeDefinition; import com.navercorp.pinpoint.bootstrap.instrument.InstrumentClass; import com.navercorp.pinpoint.bootstrap.instrument.InstrumentException; +import com.navercorp.pinpoint.bootstrap.instrument.Scope; +import com.navercorp.pinpoint.bootstrap.instrument.ScopeDefinition; import com.navercorp.pinpoint.bootstrap.interceptor.Interceptor; import com.navercorp.pinpoint.profiler.modifier.AbstractModifier; import com.navercorp.pinpoint.profiler.modifier.connector.httpclient4.interceptor.HttpClient4Scope; @@ -59,10 +63,12 @@ public class ClosableHttpClientModifier extends AbstractModifier { try { InstrumentClass aClass = byteCodeInstrumentor.getClass(classLoader, javassistClassName, classFileBuffer); + ScopeDefinition scopeDefinition = new DefaultScopeDefinition(HttpClient4Scope.SCOPE, ScopeDefinition.Type.ATTACHMENT); + Scope scope = byteCodeInstrumentor.getScope(scopeDefinition); - addHttpRequestApi(classLoader, protectedDomain, aClass); + addHttpRequestApi(classLoader, protectedDomain, aClass, scope); - addHttpUriRequestApi(classLoader, protectedDomain, aClass); + addHttpUriRequestApi(classLoader, protectedDomain, aClass, scope); return aClass.toBytecode(); } catch (Throwable e) { @@ -70,40 +76,41 @@ public class ClosableHttpClientModifier extends AbstractModifier { return null; } } + + private void addHttpRequestApi(ClassLoader classLoader, ProtectionDomain protectedDomain, InstrumentClass aClass, Scope scope) throws InstrumentException { + Interceptor httpRequestApi1= newHttpRequestInterceptor(classLoader, protectedDomain ,false, scope); + aClass.addInterceptor("execute", new String[]{"org.apache.http.HttpHost", "org.apache.http.HttpRequest"}, httpRequestApi1); - private void addHttpRequestApi(ClassLoader classLoader, ProtectionDomain protectedDomain, InstrumentClass aClass) throws InstrumentException { - Interceptor httpRequestApi1= newHttpRequestInterceptor(classLoader, protectedDomain); - aClass.addScopeInterceptorIfDeclared("execute", new String[]{"org.apache.http.HttpHost", "org.apache.http.HttpRequest"}, httpRequestApi1, HttpClient4Scope.SCOPE); + Interceptor httpRequestApi2 = newHttpRequestInterceptor(classLoader, protectedDomain, false, scope); + aClass.addInterceptor("execute", new String[]{"org.apache.http.HttpHost", "org.apache.http.HttpRequest", "org.apache.http.protocol.HttpContext"}, httpRequestApi2); - Interceptor httpRequestApi2 = newHttpRequestInterceptor(classLoader, protectedDomain); - aClass.addScopeInterceptorIfDeclared("execute", new String[]{"org.apache.http.HttpHost", "org.apache.http.HttpRequest", "org.apache.http.protocol.HttpContext"}, httpRequestApi2, HttpClient4Scope.SCOPE); + Interceptor httpRequestApi3 = newHttpRequestInterceptor(classLoader, protectedDomain, true, scope); + aClass.addInterceptor("execute", new String[]{"org.apache.http.HttpHost", "org.apache.http.HttpRequest", "org.apache.http.client.ResponseHandler"}, httpRequestApi3); - Interceptor httpRequestApi3 = newHttpRequestInterceptor(classLoader, protectedDomain); - aClass.addScopeInterceptorIfDeclared("execute", new String[]{"org.apache.http.HttpHost", "org.apache.http.HttpRequest", "org.apache.http.client.ResponseHandler"}, httpRequestApi3, HttpClient4Scope.SCOPE); - - Interceptor httpRequestApi4 = newHttpRequestInterceptor(classLoader, protectedDomain); - aClass.addScopeInterceptorIfDeclared("execute", new String[]{"org.apache.http.HttpHost", "org.apache.http.HttpRequest", "org.apache.http.client.ResponseHandler", "org.apache.http.protocol.HttpContext"}, httpRequestApi4, HttpClient4Scope.SCOPE); + Interceptor httpRequestApi4 = newHttpRequestInterceptor(classLoader, protectedDomain, true, scope); + aClass.addInterceptor("execute", new String[]{"org.apache.http.HttpHost", "org.apache.http.HttpRequest", "org.apache.http.client.ResponseHandler", "org.apache.http.protocol.HttpContext"}, httpRequestApi4); + } - private Interceptor newHttpRequestInterceptor(ClassLoader classLoader, ProtectionDomain protectedDomain) throws InstrumentException { - return byteCodeInstrumentor.newInterceptor(classLoader, protectedDomain, "com.navercorp.pinpoint.profiler.modifier.connector.httpclient4.interceptor.HttpRequestExecuteInterceptor"); + private Interceptor newHttpRequestInterceptor(ClassLoader classLoader, ProtectionDomain protectedDomain, boolean isHasCallbackParam, Scope scope) throws InstrumentException { + return byteCodeInstrumentor.newInterceptor(classLoader, protectedDomain, "com.navercorp.pinpoint.profiler.modifier.connector.httpclient4.interceptor.HttpRequestExecuteInterceptor", new Object[] {isHasCallbackParam, scope}, new Class[] {boolean.class, Scope.class}); + } + + private void addHttpUriRequestApi(ClassLoader classLoader, ProtectionDomain protectedDomain, InstrumentClass aClass, Scope scope) throws InstrumentException { + Interceptor httpUriRequestInterceptor1 = newHttpUriRequestInterceptor(classLoader, protectedDomain, false, scope); + aClass.addInterceptor("execute", new String[]{"org.apache.http.client.methods.HttpUriRequest"}, httpUriRequestInterceptor1); + + Interceptor httpUriRequestInterceptor2 = newHttpUriRequestInterceptor(classLoader, protectedDomain, false, scope); + aClass.addInterceptor("execute", new String[]{"org.apache.http.client.methods.HttpUriRequest", "org.apache.http.protocol.HttpContext"}, httpUriRequestInterceptor2); + + Interceptor httpUriRequestInterceptor3 = newHttpUriRequestInterceptor(classLoader, protectedDomain, true, scope); + aClass.addInterceptor("execute", new String[]{"org.apache.http.client.methods.HttpUriRequest", "org.apache.http.client.ResponseHandler"}, httpUriRequestInterceptor3); + + Interceptor httpUriRequestInterceptor4 = newHttpUriRequestInterceptor(classLoader, protectedDomain, true, scope); + aClass.addInterceptor("execute", new String[]{"org.apache.http.client.methods.HttpUriRequest", "org.apache.http.client.ResponseHandler", "org.apache.http.protocol.HttpContext"}, httpUriRequestInterceptor4); } - private void addHttpUriRequestApi(ClassLoader classLoader, ProtectionDomain protectedDomain, InstrumentClass aClass) throws InstrumentException { - Interceptor httpUriRequestInterceptor1 = newHttpUriRequestInterceptor(classLoader, protectedDomain); - aClass.addScopeInterceptorIfDeclared("execute", new String[]{"org.apache.http.client.methods.HttpUriRequest"}, httpUriRequestInterceptor1, HttpClient4Scope.SCOPE); - - Interceptor httpUriRequestInterceptor2 = newHttpUriRequestInterceptor(classLoader, protectedDomain); - aClass.addScopeInterceptorIfDeclared("execute", new String[]{"org.apache.http.client.methods.HttpUriRequest", "org.apache.http.protocol.HttpContext"}, httpUriRequestInterceptor2, HttpClient4Scope.SCOPE); - - Interceptor httpUriRequestInterceptor3 = newHttpUriRequestInterceptor(classLoader, protectedDomain); - aClass.addScopeInterceptorIfDeclared("execute", new String[]{"org.apache.http.client.methods.HttpUriRequest", "org.apache.http.client.ResponseHandler"}, httpUriRequestInterceptor3, HttpClient4Scope.SCOPE); - - Interceptor httpUriRequestInterceptor4 = newHttpUriRequestInterceptor(classLoader, protectedDomain); - aClass.addScopeInterceptorIfDeclared("execute", new String[]{"org.apache.http.client.methods.HttpUriRequest", "org.apache.http.client.ResponseHandler", "org.apache.http.protocol.HttpContext"}, httpUriRequestInterceptor4, HttpClient4Scope.SCOPE); - } - - private Interceptor newHttpUriRequestInterceptor(ClassLoader classLoader, ProtectionDomain protectedDomain) throws InstrumentException { - return byteCodeInstrumentor.newInterceptor(classLoader, protectedDomain, "com.navercorp.pinpoint.profiler.modifier.connector.httpclient4.interceptor.HttpUriRequestExecuteInterceptor"); + private Interceptor newHttpUriRequestInterceptor(ClassLoader classLoader, ProtectionDomain protectedDomain, boolean isHasCallbackParam, Scope scope) throws InstrumentException { + return byteCodeInstrumentor.newInterceptor(classLoader, protectedDomain, "com.navercorp.pinpoint.profiler.modifier.connector.httpclient4.interceptor.HttpUriRequestExecuteInterceptor", new Object[] {isHasCallbackParam, scope}, new Class[] {boolean.class, Scope.class}); } } \ No newline at end of file diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/modifier/connector/httpclient4/interceptor/HttpRequestExecuteInterceptor.java b/profiler/src/main/java/com/navercorp/pinpoint/profiler/modifier/connector/httpclient4/interceptor/HttpRequestExecuteInterceptor.java index c80708e10..b9eb2e941 100644 --- a/profiler/src/main/java/com/navercorp/pinpoint/profiler/modifier/connector/httpclient4/interceptor/HttpRequestExecuteInterceptor.java +++ b/profiler/src/main/java/com/navercorp/pinpoint/profiler/modifier/connector/httpclient4/interceptor/HttpRequestExecuteInterceptor.java @@ -16,13 +16,18 @@ package com.navercorp.pinpoint.profiler.modifier.connector.httpclient4.interceptor; -import com.navercorp.pinpoint.bootstrap.interceptor.TargetClassLoader; -import com.navercorp.pinpoint.bootstrap.pair.NameIntValuePair; - import org.apache.http.HttpHost; import org.apache.http.HttpRequest; import org.apache.http.HttpResponse; +import com.navercorp.pinpoint.bootstrap.context.Trace; +import com.navercorp.pinpoint.bootstrap.instrument.AttachmentScope; +import com.navercorp.pinpoint.bootstrap.instrument.Scope; +import com.navercorp.pinpoint.bootstrap.interceptor.TargetClassLoader; +import com.navercorp.pinpoint.bootstrap.interceptor.http.HttpCallContext; +import com.navercorp.pinpoint.bootstrap.pair.NameIntValuePair; +import com.navercorp.pinpoint.common.ServiceType; + /** * MethodInfo interceptor *

@@ -42,10 +47,92 @@ public class HttpRequestExecuteInterceptor extends AbstractHttpRequestExecute im private static final int HTTP_HOST_INDEX = 0; private static final int HTTP_REQUEST_INDEX = 1; - public HttpRequestExecuteInterceptor() { + private boolean isHasCallbackParam; + private AttachmentScope scope; + + public HttpRequestExecuteInterceptor(boolean isHasCallbackParam, Scope scope) { super(HttpRequestExecuteInterceptor.class); + this.isHasCallbackParam = isHasCallbackParam; + this.scope = (AttachmentScope)scope; } + +// public HttpRequestExecuteInterceptor() { +// super(HttpRequestExecuteInterceptor.class); +// } + @Override + public void before(Object target, Object[] args) { + if (!isPassibleBeforeProcess()) { + return; + } + + super.before(target, args); + } + + @Override + public void after(Object target, Object[] args, Object result, Throwable throwable) { + if (!isPassibleAfterProcess()) { + addStatusCode(result); + scope.pop(); + return; + } + + super.after(target, args, result, throwable); + scope.pop(); + }; + + private boolean isPassibleBeforeProcess() { + if (scope.push() == Scope.ZERO) { + return true; + } + + return false; + } + + private boolean isPassibleAfterProcess() { + final int depth = scope.depth(); + + if (depth - 1 == Scope.ZERO) { + return true; + } + + return false; + } + + private void addStatusCode(Object result) { + if(!needGetStatusCode()) { + return; + } + + if (result instanceof HttpResponse) { + HttpResponse response = (HttpResponse)result; + + if (response.getStatusLine() != null) { + HttpCallContext context = new HttpCallContext(); + context.setStatusCode(response.getStatusLine().getStatusCode()); + scope.setAttachment(context); + } + } + } + + private boolean needGetStatusCode() { + if (isHasCallbackParam) { + return false; + } + + final Trace trace = traceContext.currentRawTraceObject(); + + if (trace == null || trace.getServiceType() != ServiceType.HTTP_CLIENT) { + return false; + } + + if(scope.getAttachment() != null) { + return false; + } + + return true; + } + @Override protected NameIntValuePair getHost(Object[] args) { final Object arg = args[HTTP_HOST_INDEX]; @@ -75,8 +162,10 @@ public class HttpRequestExecuteInterceptor extends AbstractHttpRequestExecute im } } + if (scope.getAttachment() != null && scope.getAttachment() instanceof HttpCallContext) { + return ((HttpCallContext)scope.getAttachment()).getStatusCode(); + } + return null; } - - } \ No newline at end of file From 9a44512c473c1dfc5064b8c32e54180b2eebdbb2 Mon Sep 17 00:00:00 2001 From: Minwoo Jung Date: Thu, 22 Jan 2015 16:41:34 +0900 Subject: [PATCH 2/4] [#76] profiing for method containing ResponseHandler parameter --- .../ClosableHttpClientModifier.java | 2 +- .../DivergeForAddingStatusCode.java | 112 ++++++++++++++++++ .../HttpRequestExecuteInterceptor.java | 102 +--------------- .../HttpUriRequestExecuteInterceptor.java | 21 +--- 4 files changed, 119 insertions(+), 118 deletions(-) create mode 100644 profiler/src/main/java/com/navercorp/pinpoint/profiler/modifier/connector/httpclient4/interceptor/DivergeForAddingStatusCode.java diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/modifier/connector/httpclient4/ClosableHttpClientModifier.java b/profiler/src/main/java/com/navercorp/pinpoint/profiler/modifier/connector/httpclient4/ClosableHttpClientModifier.java index a1e319b18..4a027b046 100644 --- a/profiler/src/main/java/com/navercorp/pinpoint/profiler/modifier/connector/httpclient4/ClosableHttpClientModifier.java +++ b/profiler/src/main/java/com/navercorp/pinpoint/profiler/modifier/connector/httpclient4/ClosableHttpClientModifier.java @@ -78,7 +78,7 @@ public class ClosableHttpClientModifier extends AbstractModifier { } private void addHttpRequestApi(ClassLoader classLoader, ProtectionDomain protectedDomain, InstrumentClass aClass, Scope scope) throws InstrumentException { - Interceptor httpRequestApi1= newHttpRequestInterceptor(classLoader, protectedDomain ,false, scope); + Interceptor httpRequestApi1 = newHttpRequestInterceptor(classLoader, protectedDomain ,false, scope); aClass.addInterceptor("execute", new String[]{"org.apache.http.HttpHost", "org.apache.http.HttpRequest"}, httpRequestApi1); Interceptor httpRequestApi2 = newHttpRequestInterceptor(classLoader, protectedDomain, false, scope); diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/modifier/connector/httpclient4/interceptor/DivergeForAddingStatusCode.java b/profiler/src/main/java/com/navercorp/pinpoint/profiler/modifier/connector/httpclient4/interceptor/DivergeForAddingStatusCode.java new file mode 100644 index 000000000..fdd9e3523 --- /dev/null +++ b/profiler/src/main/java/com/navercorp/pinpoint/profiler/modifier/connector/httpclient4/interceptor/DivergeForAddingStatusCode.java @@ -0,0 +1,112 @@ +package com.navercorp.pinpoint.profiler.modifier.connector.httpclient4.interceptor; + +import org.apache.http.HttpResponse; + +import com.navercorp.pinpoint.bootstrap.context.Trace; +import com.navercorp.pinpoint.bootstrap.instrument.AttachmentScope; +import com.navercorp.pinpoint.bootstrap.instrument.Scope; +import com.navercorp.pinpoint.bootstrap.interceptor.http.HttpCallContext; +import com.navercorp.pinpoint.common.ServiceType; + +public abstract class DivergeForAddingStatusCode extends AbstractHttpRequestExecute { + + private boolean isHasCallbackParam; + private AttachmentScope scope; + + public DivergeForAddingStatusCode(Class childClazz, boolean isHasCallbackParam, Scope scope) { + super(childClazz); + this.isHasCallbackParam = isHasCallbackParam; + this.scope = (AttachmentScope)scope; + } + + @Override + public void before(Object target, Object[] args) { + if (!isPassibleBeforeProcess()) { + return; + } + + super.before(target, args); + } + + @Override + public void after(Object target, Object[] args, Object result, Throwable throwable) { + if (!isPassibleAfterProcess()) { + addStatusCode(result); + scope.pop(); + return; + } + + super.after(target, args, result, throwable); + scope.pop(); + }; + + private boolean isPassibleBeforeProcess() { + if (scope.push() == Scope.ZERO) { + return true; + } + + return false; + } + + private boolean isPassibleAfterProcess() { + final int depth = scope.depth(); + + if (depth - 1 == Scope.ZERO) { + return true; + } + + return false; + } + + private void addStatusCode(Object result) { + if(!needGetStatusCode()) { + return; + } + + if (result instanceof HttpResponse) { + HttpResponse response = (HttpResponse)result; + + if (response.getStatusLine() != null) { + HttpCallContext context = new HttpCallContext(); + context.setStatusCode(response.getStatusLine().getStatusCode()); + scope.setAttachment(context); + } + } + } + + private boolean needGetStatusCode() { + if (isHasCallbackParam) { + return false; + } + + final Trace trace = traceContext.currentRawTraceObject(); + + if (trace == null || trace.getServiceType() != ServiceType.HTTP_CLIENT) { + return false; + } + + if(scope.getAttachment() != null) { + return false; + } + + return true; + } + + @Override + Integer getStatusCode(Object result) { + if (result instanceof HttpResponse) { + HttpResponse response = (HttpResponse)result; + + if (response.getStatusLine() != null) { + return response.getStatusLine().getStatusCode(); + } + } + + if (scope.getAttachment() != null && scope.getAttachment() instanceof HttpCallContext) { + return ((HttpCallContext)scope.getAttachment()).getStatusCode(); + } + + return null; + } + +} diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/modifier/connector/httpclient4/interceptor/HttpRequestExecuteInterceptor.java b/profiler/src/main/java/com/navercorp/pinpoint/profiler/modifier/connector/httpclient4/interceptor/HttpRequestExecuteInterceptor.java index b9eb2e941..700b95665 100644 --- a/profiler/src/main/java/com/navercorp/pinpoint/profiler/modifier/connector/httpclient4/interceptor/HttpRequestExecuteInterceptor.java +++ b/profiler/src/main/java/com/navercorp/pinpoint/profiler/modifier/connector/httpclient4/interceptor/HttpRequestExecuteInterceptor.java @@ -42,95 +42,14 @@ import com.navercorp.pinpoint.common.ServiceType; * * @author emeroad */ -public class HttpRequestExecuteInterceptor extends AbstractHttpRequestExecute implements TargetClassLoader { +public class HttpRequestExecuteInterceptor extends DivergeForAddingStatusCode implements TargetClassLoader { private static final int HTTP_HOST_INDEX = 0; private static final int HTTP_REQUEST_INDEX = 1; - private boolean isHasCallbackParam; - private AttachmentScope scope; public HttpRequestExecuteInterceptor(boolean isHasCallbackParam, Scope scope) { - super(HttpRequestExecuteInterceptor.class); - this.isHasCallbackParam = isHasCallbackParam; - this.scope = (AttachmentScope)scope; - } - -// public HttpRequestExecuteInterceptor() { -// super(HttpRequestExecuteInterceptor.class); -// } - - @Override - public void before(Object target, Object[] args) { - if (!isPassibleBeforeProcess()) { - return; - } - - super.before(target, args); - } - - @Override - public void after(Object target, Object[] args, Object result, Throwable throwable) { - if (!isPassibleAfterProcess()) { - addStatusCode(result); - scope.pop(); - return; - } - - super.after(target, args, result, throwable); - scope.pop(); - }; - - private boolean isPassibleBeforeProcess() { - if (scope.push() == Scope.ZERO) { - return true; - } - - return false; - } - - private boolean isPassibleAfterProcess() { - final int depth = scope.depth(); - - if (depth - 1 == Scope.ZERO) { - return true; - } - - return false; - } - - private void addStatusCode(Object result) { - if(!needGetStatusCode()) { - return; - } - - if (result instanceof HttpResponse) { - HttpResponse response = (HttpResponse)result; - - if (response.getStatusLine() != null) { - HttpCallContext context = new HttpCallContext(); - context.setStatusCode(response.getStatusLine().getStatusCode()); - scope.setAttachment(context); - } - } - } - - private boolean needGetStatusCode() { - if (isHasCallbackParam) { - return false; - } - - final Trace trace = traceContext.currentRawTraceObject(); - - if (trace == null || trace.getServiceType() != ServiceType.HTTP_CLIENT) { - return false; - } - - if(scope.getAttachment() != null) { - return false; - } - - return true; + super(HttpRequestExecuteInterceptor.class, isHasCallbackParam, scope); } @Override @@ -151,21 +70,4 @@ public class HttpRequestExecuteInterceptor extends AbstractHttpRequestExecute im } return null; } - - @Override - Integer getStatusCode(Object result) { - if (result instanceof HttpResponse) { - HttpResponse response = (HttpResponse)result; - - if (response.getStatusLine() != null) { - return response.getStatusLine().getStatusCode(); - } - } - - if (scope.getAttachment() != null && scope.getAttachment() instanceof HttpCallContext) { - return ((HttpCallContext)scope.getAttachment()).getStatusCode(); - } - - return null; - } } \ No newline at end of file diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/modifier/connector/httpclient4/interceptor/HttpUriRequestExecuteInterceptor.java b/profiler/src/main/java/com/navercorp/pinpoint/profiler/modifier/connector/httpclient4/interceptor/HttpUriRequestExecuteInterceptor.java index c936982cb..83df774fb 100644 --- a/profiler/src/main/java/com/navercorp/pinpoint/profiler/modifier/connector/httpclient4/interceptor/HttpUriRequestExecuteInterceptor.java +++ b/profiler/src/main/java/com/navercorp/pinpoint/profiler/modifier/connector/httpclient4/interceptor/HttpUriRequestExecuteInterceptor.java @@ -18,6 +18,7 @@ package com.navercorp.pinpoint.profiler.modifier.connector.httpclient4.intercept import java.net.URI; +import com.navercorp.pinpoint.bootstrap.instrument.Scope; import com.navercorp.pinpoint.bootstrap.interceptor.TargetClassLoader; import com.navercorp.pinpoint.bootstrap.pair.NameIntValuePair; @@ -36,12 +37,12 @@ import org.apache.http.client.methods.HttpUriRequest; * * @author emeroad */ -public class HttpUriRequestExecuteInterceptor extends AbstractHttpRequestExecute implements TargetClassLoader { +public class HttpUriRequestExecuteInterceptor extends DivergeForAddingStatusCode implements TargetClassLoader { private static final int HTTP_URI_REQUEST_INDEX = 0; - public HttpUriRequestExecuteInterceptor() { - super(HttpUriRequestExecuteInterceptor.class); + public HttpUriRequestExecuteInterceptor(boolean isHasCallbackParam, Scope scope) { + super(HttpUriRequestExecuteInterceptor.class, isHasCallbackParam, scope); } @Override @@ -126,18 +127,4 @@ public class HttpUriRequestExecuteInterceptor extends AbstractHttpRequestExecute } return target; } - - @Override - Integer getStatusCode(Object result) { - if (result instanceof HttpResponse) { - HttpResponse response = (HttpResponse)result; - - if (response.getStatusLine() != null) { - return response.getStatusLine().getStatusCode(); - } - } - - return null; - } - } \ No newline at end of file From ea031c603f19a412967fbff942c01e7f12423eac Mon Sep 17 00:00:00 2001 From: Minwoo Jung Date: Thu, 22 Jan 2015 19:22:54 +0900 Subject: [PATCH 3/4] [#76] common logic changed to abstract class --- .../interceptor/http/HttpCallContext.java | 3 ++ .../ClosableHttpClientModifier.java | 9 ++-- .../httpclient4/HttpClient4Modifier.java | 53 ++++++++++--------- .../DivergeForAddingStatusCode.java | 19 +++++++ .../HttpRequestExecuteInterceptor.java | 6 +-- .../HttpUriRequestExecuteInterceptor.java | 8 +-- 6 files changed, 60 insertions(+), 38 deletions(-) diff --git a/bootstrap/src/main/java/com/navercorp/pinpoint/bootstrap/interceptor/http/HttpCallContext.java b/bootstrap/src/main/java/com/navercorp/pinpoint/bootstrap/interceptor/http/HttpCallContext.java index 79d9584ba..d8ff08b8b 100644 --- a/bootstrap/src/main/java/com/navercorp/pinpoint/bootstrap/interceptor/http/HttpCallContext.java +++ b/bootstrap/src/main/java/com/navercorp/pinpoint/bootstrap/interceptor/http/HttpCallContext.java @@ -16,6 +16,9 @@ package com.navercorp.pinpoint.bootstrap.interceptor.http; +/** + * @author minwoo.jung + */ public class HttpCallContext { private int statusCode; diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/modifier/connector/httpclient4/ClosableHttpClientModifier.java b/profiler/src/main/java/com/navercorp/pinpoint/profiler/modifier/connector/httpclient4/ClosableHttpClientModifier.java index 4a027b046..ea946ae3b 100644 --- a/profiler/src/main/java/com/navercorp/pinpoint/profiler/modifier/connector/httpclient4/ClosableHttpClientModifier.java +++ b/profiler/src/main/java/com/navercorp/pinpoint/profiler/modifier/connector/httpclient4/ClosableHttpClientModifier.java @@ -18,8 +18,10 @@ package com.navercorp.pinpoint.profiler.modifier.connector.httpclient4; import java.security.ProtectionDomain; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + import com.navercorp.pinpoint.bootstrap.Agent; -import com.navercorp.pinpoint.bootstrap.instrument.AttachmentScope; import com.navercorp.pinpoint.bootstrap.instrument.ByteCodeInstrumentor; import com.navercorp.pinpoint.bootstrap.instrument.DefaultScopeDefinition; import com.navercorp.pinpoint.bootstrap.instrument.InstrumentClass; @@ -30,9 +32,6 @@ import com.navercorp.pinpoint.bootstrap.interceptor.Interceptor; import com.navercorp.pinpoint.profiler.modifier.AbstractModifier; import com.navercorp.pinpoint.profiler.modifier.connector.httpclient4.interceptor.HttpClient4Scope; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - /** * Apache httpclient 4.3 CloseableHttpClient modifier * @@ -43,6 +42,7 @@ import org.slf4j.LoggerFactory; * * * @author netspider + * @author minwoo.jung */ public class ClosableHttpClientModifier extends AbstractModifier { @@ -89,7 +89,6 @@ public class ClosableHttpClientModifier extends AbstractModifier { Interceptor httpRequestApi4 = newHttpRequestInterceptor(classLoader, protectedDomain, true, scope); aClass.addInterceptor("execute", new String[]{"org.apache.http.HttpHost", "org.apache.http.HttpRequest", "org.apache.http.client.ResponseHandler", "org.apache.http.protocol.HttpContext"}, httpRequestApi4); - } private Interceptor newHttpRequestInterceptor(ClassLoader classLoader, ProtectionDomain protectedDomain, boolean isHasCallbackParam, Scope scope) throws InstrumentException { diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/modifier/connector/httpclient4/HttpClient4Modifier.java b/profiler/src/main/java/com/navercorp/pinpoint/profiler/modifier/connector/httpclient4/HttpClient4Modifier.java index dbc03a600..42345a7a0 100644 --- a/profiler/src/main/java/com/navercorp/pinpoint/profiler/modifier/connector/httpclient4/HttpClient4Modifier.java +++ b/profiler/src/main/java/com/navercorp/pinpoint/profiler/modifier/connector/httpclient4/HttpClient4Modifier.java @@ -20,8 +20,11 @@ import java.security.ProtectionDomain; import com.navercorp.pinpoint.bootstrap.Agent; import com.navercorp.pinpoint.bootstrap.instrument.ByteCodeInstrumentor; +import com.navercorp.pinpoint.bootstrap.instrument.DefaultScopeDefinition; import com.navercorp.pinpoint.bootstrap.instrument.InstrumentClass; import com.navercorp.pinpoint.bootstrap.instrument.InstrumentException; +import com.navercorp.pinpoint.bootstrap.instrument.Scope; +import com.navercorp.pinpoint.bootstrap.instrument.ScopeDefinition; import com.navercorp.pinpoint.bootstrap.interceptor.Interceptor; import com.navercorp.pinpoint.profiler.modifier.AbstractModifier; import com.navercorp.pinpoint.profiler.modifier.connector.httpclient4.interceptor.HttpClient4Scope; @@ -68,10 +71,12 @@ public class HttpClient4Modifier extends AbstractModifier { try { InstrumentClass aClass = byteCodeInstrumentor.getClass(classLoader, javassistClassName, classFileBuffer); + ScopeDefinition scopeDefinition = new DefaultScopeDefinition(HttpClient4Scope.SCOPE, ScopeDefinition.Type.ATTACHMENT); + Scope scope = byteCodeInstrumentor.getScope(scopeDefinition); - addHttpRequestApi(classLoader, protectedDomain, aClass); + addHttpRequestApi(classLoader, protectedDomain, aClass, scope); - addHttpUriRequestApi(classLoader, protectedDomain, aClass); + addHttpUriRequestApi(classLoader, protectedDomain, aClass, scope); return aClass.toBytecode(); } catch (Throwable e) { @@ -80,39 +85,39 @@ public class HttpClient4Modifier extends AbstractModifier { } } - private void addHttpRequestApi(ClassLoader classLoader, ProtectionDomain protectedDomain, InstrumentClass aClass) throws InstrumentException { - Interceptor httpRequestApi1= newHttpRequestInterceptor(classLoader, protectedDomain); - aClass.addScopeInterceptorIfDeclared("execute", new String[]{"org.apache.http.HttpHost", "org.apache.http.HttpRequest"}, httpRequestApi1, HttpClient4Scope.SCOPE); + private void addHttpRequestApi(ClassLoader classLoader, ProtectionDomain protectedDomain, InstrumentClass aClass, Scope scope) throws InstrumentException { + Interceptor httpRequestApi1 = newHttpRequestInterceptor(classLoader, protectedDomain ,false, scope); + aClass.addInterceptor("execute", new String[]{"org.apache.http.HttpHost", "org.apache.http.HttpRequest"}, httpRequestApi1); - Interceptor httpRequestApi2 = newHttpRequestInterceptor(classLoader, protectedDomain); - aClass.addScopeInterceptorIfDeclared("execute", new String[]{"org.apache.http.HttpHost", "org.apache.http.HttpRequest", "org.apache.http.protocol.HttpContext"}, httpRequestApi2, HttpClient4Scope.SCOPE); + Interceptor httpRequestApi2 = newHttpRequestInterceptor(classLoader, protectedDomain, false, scope); + aClass.addInterceptor("execute", new String[]{"org.apache.http.HttpHost", "org.apache.http.HttpRequest", "org.apache.http.protocol.HttpContext"}, httpRequestApi2); - Interceptor httpRequestApi3 = newHttpRequestInterceptor(classLoader, protectedDomain); - aClass.addScopeInterceptorIfDeclared("execute", new String[]{"org.apache.http.HttpHost", "org.apache.http.HttpRequest", "org.apache.http.client.ResponseHandler"}, httpRequestApi3, HttpClient4Scope.SCOPE); + Interceptor httpRequestApi3 = newHttpRequestInterceptor(classLoader, protectedDomain, true, scope); + aClass.addInterceptor("execute", new String[]{"org.apache.http.HttpHost", "org.apache.http.HttpRequest", "org.apache.http.client.ResponseHandler"}, httpRequestApi3); - Interceptor httpRequestApi4 = newHttpRequestInterceptor(classLoader, protectedDomain); - aClass.addScopeInterceptorIfDeclared("execute", new String[]{"org.apache.http.HttpHost", "org.apache.http.HttpRequest", "org.apache.http.client.ResponseHandler", "org.apache.http.protocol.HttpContext"}, httpRequestApi4, HttpClient4Scope.SCOPE); + Interceptor httpRequestApi4 = newHttpRequestInterceptor(classLoader, protectedDomain, true, scope); + aClass.addInterceptor("execute", new String[]{"org.apache.http.HttpHost", "org.apache.http.HttpRequest", "org.apache.http.client.ResponseHandler", "org.apache.http.protocol.HttpContext"}, httpRequestApi4); } - private Interceptor newHttpRequestInterceptor(ClassLoader classLoader, ProtectionDomain protectedDomain) throws InstrumentException { - return byteCodeInstrumentor.newInterceptor(classLoader, protectedDomain, "com.navercorp.pinpoint.profiler.modifier.connector.httpclient4.interceptor.HttpRequestExecuteInterceptor"); + private Interceptor newHttpRequestInterceptor(ClassLoader classLoader, ProtectionDomain protectedDomain, boolean isHasCallbackParam, Scope scope) throws InstrumentException { + return byteCodeInstrumentor.newInterceptor(classLoader, protectedDomain, "com.navercorp.pinpoint.profiler.modifier.connector.httpclient4.interceptor.HttpRequestExecuteInterceptor", new Object[] {isHasCallbackParam, scope}, new Class[] {boolean.class, Scope.class}); } - private void addHttpUriRequestApi(ClassLoader classLoader, ProtectionDomain protectedDomain, InstrumentClass aClass) throws InstrumentException { - Interceptor httpUriRequestInterceptor1 = newHttpUriRequestInterceptor(classLoader, protectedDomain); - aClass.addScopeInterceptorIfDeclared("execute", new String[]{"org.apache.http.client.methods.HttpUriRequest"}, httpUriRequestInterceptor1, HttpClient4Scope.SCOPE); + private void addHttpUriRequestApi(ClassLoader classLoader, ProtectionDomain protectedDomain, InstrumentClass aClass, Scope scope) throws InstrumentException { + Interceptor httpUriRequestInterceptor1 = newHttpUriRequestInterceptor(classLoader, protectedDomain, false, scope); + aClass.addInterceptor("execute", new String[]{"org.apache.http.client.methods.HttpUriRequest"}, httpUriRequestInterceptor1); - Interceptor httpUriRequestInterceptor2 = newHttpUriRequestInterceptor(classLoader, protectedDomain); - aClass.addScopeInterceptorIfDeclared("execute", new String[]{"org.apache.http.client.methods.HttpUriRequest", "org.apache.http.protocol.HttpContext"}, httpUriRequestInterceptor2, HttpClient4Scope.SCOPE); + Interceptor httpUriRequestInterceptor2 = newHttpUriRequestInterceptor(classLoader, protectedDomain, false, scope); + aClass.addInterceptor("execute", new String[]{"org.apache.http.client.methods.HttpUriRequest", "org.apache.http.protocol.HttpContext"}, httpUriRequestInterceptor2); - Interceptor httpUriRequestInterceptor3 = newHttpUriRequestInterceptor(classLoader, protectedDomain); - aClass.addScopeInterceptorIfDeclared("execute", new String[]{"org.apache.http.client.methods.HttpUriRequest", "org.apache.http.client.ResponseHandler"}, httpUriRequestInterceptor3, HttpClient4Scope.SCOPE); + Interceptor httpUriRequestInterceptor3 = newHttpUriRequestInterceptor(classLoader, protectedDomain, true, scope); + aClass.addInterceptor("execute", new String[]{"org.apache.http.client.methods.HttpUriRequest", "org.apache.http.client.ResponseHandler"}, httpUriRequestInterceptor3); - Interceptor httpUriRequestInterceptor4 = newHttpUriRequestInterceptor(classLoader, protectedDomain); - aClass.addScopeInterceptorIfDeclared("execute", new String[]{"org.apache.http.client.methods.HttpUriRequest", "org.apache.http.client.ResponseHandler", "org.apache.http.protocol.HttpContext"}, httpUriRequestInterceptor4, HttpClient4Scope.SCOPE); + Interceptor httpUriRequestInterceptor4 = newHttpUriRequestInterceptor(classLoader, protectedDomain, true, scope); + aClass.addInterceptor("execute", new String[]{"org.apache.http.client.methods.HttpUriRequest", "org.apache.http.client.ResponseHandler", "org.apache.http.protocol.HttpContext"}, httpUriRequestInterceptor4); } - private Interceptor newHttpUriRequestInterceptor(ClassLoader classLoader, ProtectionDomain protectedDomain) throws InstrumentException { - return byteCodeInstrumentor.newInterceptor(classLoader, protectedDomain, "com.navercorp.pinpoint.profiler.modifier.connector.httpclient4.interceptor.HttpUriRequestExecuteInterceptor"); + private Interceptor newHttpUriRequestInterceptor(ClassLoader classLoader, ProtectionDomain protectedDomain, boolean isHasCallbackParam, Scope scope) throws InstrumentException { + return byteCodeInstrumentor.newInterceptor(classLoader, protectedDomain, "com.navercorp.pinpoint.profiler.modifier.connector.httpclient4.interceptor.HttpUriRequestExecuteInterceptor", new Object[] {isHasCallbackParam, scope}, new Class[] {boolean.class, Scope.class}); } } \ No newline at end of file diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/modifier/connector/httpclient4/interceptor/DivergeForAddingStatusCode.java b/profiler/src/main/java/com/navercorp/pinpoint/profiler/modifier/connector/httpclient4/interceptor/DivergeForAddingStatusCode.java index fdd9e3523..a5ea79ec1 100644 --- a/profiler/src/main/java/com/navercorp/pinpoint/profiler/modifier/connector/httpclient4/interceptor/DivergeForAddingStatusCode.java +++ b/profiler/src/main/java/com/navercorp/pinpoint/profiler/modifier/connector/httpclient4/interceptor/DivergeForAddingStatusCode.java @@ -1,3 +1,19 @@ +/* + * Copyright 2014 NAVER Corp. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package com.navercorp.pinpoint.profiler.modifier.connector.httpclient4.interceptor; import org.apache.http.HttpResponse; @@ -8,6 +24,9 @@ import com.navercorp.pinpoint.bootstrap.instrument.Scope; import com.navercorp.pinpoint.bootstrap.interceptor.http.HttpCallContext; import com.navercorp.pinpoint.common.ServiceType; +/** + * @author minwoo.jung + */ public abstract class DivergeForAddingStatusCode extends AbstractHttpRequestExecute { private boolean isHasCallbackParam; diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/modifier/connector/httpclient4/interceptor/HttpRequestExecuteInterceptor.java b/profiler/src/main/java/com/navercorp/pinpoint/profiler/modifier/connector/httpclient4/interceptor/HttpRequestExecuteInterceptor.java index 700b95665..cdd43c525 100644 --- a/profiler/src/main/java/com/navercorp/pinpoint/profiler/modifier/connector/httpclient4/interceptor/HttpRequestExecuteInterceptor.java +++ b/profiler/src/main/java/com/navercorp/pinpoint/profiler/modifier/connector/httpclient4/interceptor/HttpRequestExecuteInterceptor.java @@ -18,15 +18,10 @@ package com.navercorp.pinpoint.profiler.modifier.connector.httpclient4.intercept import org.apache.http.HttpHost; import org.apache.http.HttpRequest; -import org.apache.http.HttpResponse; -import com.navercorp.pinpoint.bootstrap.context.Trace; -import com.navercorp.pinpoint.bootstrap.instrument.AttachmentScope; import com.navercorp.pinpoint.bootstrap.instrument.Scope; import com.navercorp.pinpoint.bootstrap.interceptor.TargetClassLoader; -import com.navercorp.pinpoint.bootstrap.interceptor.http.HttpCallContext; import com.navercorp.pinpoint.bootstrap.pair.NameIntValuePair; -import com.navercorp.pinpoint.common.ServiceType; /** * MethodInfo interceptor @@ -41,6 +36,7 @@ import com.navercorp.pinpoint.common.ServiceType; * throws IOException, ClientProtocolException { * * @author emeroad + * @author minwoo.jung */ public class HttpRequestExecuteInterceptor extends DivergeForAddingStatusCode implements TargetClassLoader { diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/modifier/connector/httpclient4/interceptor/HttpUriRequestExecuteInterceptor.java b/profiler/src/main/java/com/navercorp/pinpoint/profiler/modifier/connector/httpclient4/interceptor/HttpUriRequestExecuteInterceptor.java index 83df774fb..a58d22fb1 100644 --- a/profiler/src/main/java/com/navercorp/pinpoint/profiler/modifier/connector/httpclient4/interceptor/HttpUriRequestExecuteInterceptor.java +++ b/profiler/src/main/java/com/navercorp/pinpoint/profiler/modifier/connector/httpclient4/interceptor/HttpUriRequestExecuteInterceptor.java @@ -18,14 +18,13 @@ package com.navercorp.pinpoint.profiler.modifier.connector.httpclient4.intercept import java.net.URI; +import org.apache.http.HttpRequest; +import org.apache.http.client.methods.HttpUriRequest; + import com.navercorp.pinpoint.bootstrap.instrument.Scope; import com.navercorp.pinpoint.bootstrap.interceptor.TargetClassLoader; import com.navercorp.pinpoint.bootstrap.pair.NameIntValuePair; -import org.apache.http.HttpRequest; -import org.apache.http.HttpResponse; -import org.apache.http.client.methods.HttpUriRequest; - /** * MethodInfo interceptor *

@@ -36,6 +35,7 @@ import org.apache.http.client.methods.HttpUriRequest; * public final HttpResponse execute(HttpUriRequest request) throws IOException, ClientProtocolException * * @author emeroad + * @author minwoo.jung */ public class HttpUriRequestExecuteInterceptor extends DivergeForAddingStatusCode implements TargetClassLoader { From 60f8cd1cd7ac2be6b1e285dda2135001627c6660 Mon Sep 17 00:00:00 2001 From: Minwoo Jung Date: Thu, 22 Jan 2015 20:29:35 +0900 Subject: [PATCH 4/4] [#73] delete relesctionship of abstract classes. Because Pinpoint check direct super class only. [#76] edit config --- agent/src/main/resources/pinpoint.config | 3 + .../bootstrap/config/ProfilerConfig.java | 6 + .../httpclient4/HttpClient4Modifier.java | 1 + .../AbstractHttpRequestExecute.java | 13 +- ...tractHttpRequestExecuteWithDivergence.java | 433 ++++++++++++++++++ .../DivergeForAddingStatusCode.java | 131 ------ .../HttpRequestExecuteInterceptor.java | 2 +- .../HttpUriRequestExecuteInterceptor.java | 2 +- profiler/src/test/resources/pinpoint.config | 394 ++++++++-------- .../agent/src/main/resources/pinpoint.config | 391 ++++++++-------- quickstart/conf/pinpoint.config | 392 ++++++++-------- 11 files changed, 1048 insertions(+), 720 deletions(-) create mode 100644 profiler/src/main/java/com/navercorp/pinpoint/profiler/modifier/connector/httpclient4/interceptor/AbstractHttpRequestExecuteWithDivergence.java delete mode 100644 profiler/src/main/java/com/navercorp/pinpoint/profiler/modifier/connector/httpclient4/interceptor/DivergeForAddingStatusCode.java diff --git a/agent/src/main/resources/pinpoint.config b/agent/src/main/resources/pinpoint.config index ebe4765b0..d20eb895f 100644 --- a/agent/src/main/resources/pinpoint.config +++ b/agent/src/main/resources/pinpoint.config @@ -149,6 +149,9 @@ profiler.apache.httpclient4.entity=true profiler.apache.httpclient4.entity.dumptype=ALWAYS profiler.apache.httpclient4.entity.sampling.rate=1 +# Can profile status code value +profiler.apache.httpclient4.entity.statuscode=true + # Not supported yet #profiler.apache.nio.httpclient4=true diff --git a/bootstrap/src/main/java/com/navercorp/pinpoint/bootstrap/config/ProfilerConfig.java b/bootstrap/src/main/java/com/navercorp/pinpoint/bootstrap/config/ProfilerConfig.java index bfa497626..d26a0648d 100644 --- a/bootstrap/src/main/java/com/navercorp/pinpoint/bootstrap/config/ProfilerConfig.java +++ b/bootstrap/src/main/java/com/navercorp/pinpoint/bootstrap/config/ProfilerConfig.java @@ -164,6 +164,7 @@ public class ProfilerConfig { private boolean apacheHttpClient4ProfileEntity = false; private DumpType apacheHttpClient4ProfileEntityDumpType = DumpType.EXCEPTION; private int apacheHttpClient4ProfileEntitySamplingRate = 1; + private boolean apacheHttpClient4ProfileStatusCode = true; /** * apache nio http client @@ -486,6 +487,10 @@ public class ProfilerConfig { public int getApacheHttpClient4ProfileEntitySamplingRate() { return apacheHttpClient4ProfileEntitySamplingRate; } + + public boolean isApacheHttpClient4ProfileStatusCode() { + return apacheHttpClient4ProfileStatusCode; + } //----------------------------------------- // org/apache/http/impl/nio/* @@ -689,6 +694,7 @@ public class ProfilerConfig { this.apacheHttpClient4ProfileEntityDumpType = readDumpType("profiler.apache.httpclient4.entity.dumptype", DumpType.EXCEPTION); this.apacheHttpClient4ProfileEntitySamplingRate = readInt("profiler.apache.httpclient4.entity.sampling.rate", 1); + this.apacheHttpClient4ProfileStatusCode = readBoolean("profiler.apache.httpclient4.entity.statuscode", true); /** * apache nio http client */ diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/modifier/connector/httpclient4/HttpClient4Modifier.java b/profiler/src/main/java/com/navercorp/pinpoint/profiler/modifier/connector/httpclient4/HttpClient4Modifier.java index 42345a7a0..d6a72d8a4 100644 --- a/profiler/src/main/java/com/navercorp/pinpoint/profiler/modifier/connector/httpclient4/HttpClient4Modifier.java +++ b/profiler/src/main/java/com/navercorp/pinpoint/profiler/modifier/connector/httpclient4/HttpClient4Modifier.java @@ -51,6 +51,7 @@ import org.slf4j.LoggerFactory; * * @author netspider * @author emeroad + * @author minwoo.jung */ public class HttpClient4Modifier extends AbstractModifier { diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/modifier/connector/httpclient4/interceptor/AbstractHttpRequestExecute.java b/profiler/src/main/java/com/navercorp/pinpoint/profiler/modifier/connector/httpclient4/interceptor/AbstractHttpRequestExecute.java index 14e548cd8..16f80b74e 100644 --- a/profiler/src/main/java/com/navercorp/pinpoint/profiler/modifier/connector/httpclient4/interceptor/AbstractHttpRequestExecute.java +++ b/profiler/src/main/java/com/navercorp/pinpoint/profiler/modifier/connector/httpclient4/interceptor/AbstractHttpRequestExecute.java @@ -63,6 +63,8 @@ public abstract class AbstractHttpRequestExecute implements TraceContextSupport, protected boolean entity; protected DumpType entityDumpType; protected SimpleSampler entitySampler; + + protected boolean statusCode; public AbstractHttpRequestExecute(Class childClazz) { this.logger = PLoggerFactory.getLogger(childClazz); @@ -159,10 +161,12 @@ public abstract class AbstractHttpRequestExecute implements TraceContextSupport, recordHttpRequest(trace, httpRequest, throwable); } - Integer statusCode = getStatusCode(result); - - if (statusCode != null) { - trace.recordAttribute(AnnotationKey.HTTP_STATUS_CODE, statusCode); + if (statusCode) { + Integer statusCodeValue = getStatusCode(result); + + if (statusCodeValue != null) { + trace.recordAttribute(AnnotationKey.HTTP_STATUS_CODE, statusCodeValue); + } } trace.recordApi(descriptor); @@ -316,6 +320,7 @@ public abstract class AbstractHttpRequestExecute implements TraceContextSupport, if (entity) { this.entitySampler = SimpleSamplerFactory.createSampler(entity, profilerConfig.getApacheHttpClient4ProfileEntitySamplingRate()); } + this.statusCode = profilerConfig.isApacheHttpClient4ProfileStatusCode(); } @Override diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/modifier/connector/httpclient4/interceptor/AbstractHttpRequestExecuteWithDivergence.java b/profiler/src/main/java/com/navercorp/pinpoint/profiler/modifier/connector/httpclient4/interceptor/AbstractHttpRequestExecuteWithDivergence.java new file mode 100644 index 000000000..683aa871a --- /dev/null +++ b/profiler/src/main/java/com/navercorp/pinpoint/profiler/modifier/connector/httpclient4/interceptor/AbstractHttpRequestExecuteWithDivergence.java @@ -0,0 +1,433 @@ +/* + * Copyright 2014 NAVER Corp. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.navercorp.pinpoint.profiler.modifier.connector.httpclient4.interceptor; + +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.Reader; + +import org.apache.http.HeaderElement; +import org.apache.http.HttpEntity; +import org.apache.http.HttpEntityEnclosingRequest; +import org.apache.http.HttpMessage; +import org.apache.http.HttpRequest; +import org.apache.http.HttpResponse; +import org.apache.http.NameValuePair; +import org.apache.http.ParseException; +import org.apache.http.protocol.HTTP; + +import com.navercorp.pinpoint.bootstrap.config.DumpType; +import com.navercorp.pinpoint.bootstrap.config.ProfilerConfig; +import com.navercorp.pinpoint.bootstrap.context.Header; +import com.navercorp.pinpoint.bootstrap.context.Trace; +import com.navercorp.pinpoint.bootstrap.context.TraceContext; +import com.navercorp.pinpoint.bootstrap.context.TraceId; +import com.navercorp.pinpoint.bootstrap.instrument.AttachmentScope; +import com.navercorp.pinpoint.bootstrap.instrument.Scope; +import com.navercorp.pinpoint.bootstrap.interceptor.ByteCodeMethodDescriptorSupport; +import com.navercorp.pinpoint.bootstrap.interceptor.MethodDescriptor; +import com.navercorp.pinpoint.bootstrap.interceptor.SimpleAroundInterceptor; +import com.navercorp.pinpoint.bootstrap.interceptor.TraceContextSupport; +import com.navercorp.pinpoint.bootstrap.interceptor.http.HttpCallContext; +import com.navercorp.pinpoint.bootstrap.logging.PLogger; +import com.navercorp.pinpoint.bootstrap.logging.PLoggerFactory; +import com.navercorp.pinpoint.bootstrap.pair.NameIntValuePair; +import com.navercorp.pinpoint.bootstrap.sampler.SamplingFlagUtils; +import com.navercorp.pinpoint.bootstrap.util.InterceptorUtils; +import com.navercorp.pinpoint.bootstrap.util.SimpleSampler; +import com.navercorp.pinpoint.bootstrap.util.SimpleSamplerFactory; +import com.navercorp.pinpoint.bootstrap.util.StringUtils; +import com.navercorp.pinpoint.common.AnnotationKey; +import com.navercorp.pinpoint.common.ServiceType; + +/** + * @author minwoo.jung + */ +public abstract class AbstractHttpRequestExecuteWithDivergence implements TraceContextSupport, ByteCodeMethodDescriptorSupport, SimpleAroundInterceptor { + + private boolean isHasCallbackParam; + private AttachmentScope scope; + + protected final PLogger logger; + protected final boolean isDebug; + + protected TraceContext traceContext; + protected MethodDescriptor descriptor; + + protected boolean cookie; + protected DumpType cookieDumpType; + protected SimpleSampler cookieSampler; + + protected boolean entity; + protected DumpType entityDumpType; + protected SimpleSampler entitySampler; + + protected boolean statusCode; + + public AbstractHttpRequestExecuteWithDivergence(Class childClazz, boolean isHasCallbackParam, Scope scope) { + this.logger = PLoggerFactory.getLogger(childClazz); + this.isDebug = logger.isDebugEnabled(); + + this.isHasCallbackParam = isHasCallbackParam; + this.scope = (AttachmentScope)scope; + } + + abstract NameIntValuePair getHost(Object[] args); + + abstract HttpRequest getHttpRequest(Object[] args); + + @Override + public void before(Object target, Object[] args) { + if (!isPassibleBeforeProcess()) { + return; + } + + before2(target, args); + } + + @Override + public void after(Object target, Object[] args, Object result, Throwable throwable) { + if (!isPassibleAfterProcess()) { + addStatusCode(result); + scope.pop(); + return; + } + + after2(target, args, result, throwable); + scope.pop(); + }; + + private boolean isPassibleBeforeProcess() { + if (scope.push() == Scope.ZERO) { + return true; + } + + return false; + } + + private boolean isPassibleAfterProcess() { + final int depth = scope.depth(); + + if (depth - 1 == Scope.ZERO) { + return true; + } + + return false; + } + + private void addStatusCode(Object result) { + if(!needGetStatusCode()) { + return; + } + + if (result instanceof HttpResponse) { + HttpResponse response = (HttpResponse)result; + + if (response.getStatusLine() != null) { + HttpCallContext context = new HttpCallContext(); + context.setStatusCode(response.getStatusLine().getStatusCode()); + scope.setAttachment(context); + } + } + } + + private boolean needGetStatusCode() { + if (isHasCallbackParam) { + return false; + } + + final Trace trace = traceContext.currentRawTraceObject(); + + if (trace == null || trace.getServiceType() != ServiceType.HTTP_CLIENT) { + return false; + } + + if(scope.getAttachment() != null) { + return false; + } + + return true; + } + + Integer getStatusCode(Object result) { + if (result instanceof HttpResponse) { + HttpResponse response = (HttpResponse)result; + + if (response.getStatusLine() != null) { + return response.getStatusLine().getStatusCode(); + } + } + + if (scope.getAttachment() != null && scope.getAttachment() instanceof HttpCallContext) { + return ((HttpCallContext)scope.getAttachment()).getStatusCode(); + } + + return null; + } + + public void before2(Object target, Object[] args) { + if (isDebug) { + logger.beforeInterceptor(target, args); + } + final Trace trace = traceContext.currentRawTraceObject(); + if (trace == null) { + return; + } + + final HttpRequest httpRequest = getHttpRequest(args); + + final boolean sampling = trace.canSampled(); + if (!sampling) { + if(isDebug) { + logger.debug("set Sampling flag=false"); + } + if (httpRequest != null) { + httpRequest.setHeader(Header.HTTP_SAMPLED.toString(), SamplingFlagUtils.SAMPLING_RATE_FALSE); + } + return; + } + + trace.traceBlockBegin(); + trace.markBeforeTime(); + + TraceId nextId = trace.getTraceId().getNextTraceId(); + trace.recordNextSpanId(nextId.getSpanId()); + trace.recordServiceType(ServiceType.HTTP_CLIENT); + + if (httpRequest != null) { + httpRequest.setHeader(Header.HTTP_TRACE_ID.toString(), nextId.getTransactionId()); + httpRequest.setHeader(Header.HTTP_SPAN_ID.toString(), String.valueOf(nextId.getSpanId())); + + httpRequest.setHeader(Header.HTTP_PARENT_SPAN_ID.toString(), String.valueOf(nextId.getParentSpanId())); + + httpRequest.setHeader(Header.HTTP_FLAGS.toString(), String.valueOf(nextId.getFlags())); + httpRequest.setHeader(Header.HTTP_PARENT_APPLICATION_NAME.toString(), traceContext.getApplicationName()); + httpRequest.setHeader(Header.HTTP_PARENT_APPLICATION_TYPE.toString(), Short.toString(traceContext.getServerTypeCode())); + } + } + + + + private String getEndpoint(String host, int port) { + if (host == null) { + return "UnknownHttpClient"; + } + if (port < 0) { + return host; + } + StringBuilder sb = new StringBuilder(host.length() + 8); + sb.append(host); + sb.append(':'); + sb.append(port); + return sb.toString(); + } + + public void after2(Object target, Object[] args, Object result, Throwable throwable) { + if (isDebug) { + // Do not log result + logger.afterInterceptor(target, args); + } + + final Trace trace = traceContext.currentTraceObject(); + if (trace == null) { + return; + } + try { + final HttpRequest httpRequest = getHttpRequest(args); + if (httpRequest != null) { + // Accessing httpRequest here not before() becuase it can cause side effect. + trace.recordAttribute(AnnotationKey.HTTP_URL, httpRequest.getRequestLine().getUri()); + final NameIntValuePair host = getHost(args); + if (host != null) { + int port = host.getValue(); + String endpoint = getEndpoint(host.getName(), port); + trace.recordDestinationId(endpoint); + } + + recordHttpRequest(trace, httpRequest, throwable); + } + + if (statusCode) { + Integer statusCodeValue = getStatusCode(result); + + if (statusCodeValue != null) { + trace.recordAttribute(AnnotationKey.HTTP_STATUS_CODE, statusCodeValue); + } + } + + trace.recordApi(descriptor); + trace.recordException(throwable); + + trace.markAfterTime(); + } finally { + trace.traceBlockEnd(); + } + } + + private void recordHttpRequest(Trace trace, HttpRequest httpRequest, Throwable throwable) { + final boolean isException = InterceptorUtils.isThrowable(throwable); + if (cookie) { + if (DumpType.ALWAYS == cookieDumpType) { + recordCookie(httpRequest, trace); + } else if(DumpType.EXCEPTION == cookieDumpType && isException){ + recordCookie(httpRequest, trace); + } + } + if (entity) { + if (DumpType.ALWAYS == entityDumpType) { + recordEntity(httpRequest, trace); + } else if(DumpType.EXCEPTION == entityDumpType && isException) { + recordEntity(httpRequest, trace); + } + } + } + + protected void recordCookie(HttpMessage httpMessage, Trace trace) { + org.apache.http.Header[] cookies = httpMessage.getHeaders("Cookie"); + for (org.apache.http.Header header: cookies) { + final String value = header.getValue(); + if (value != null && !value.isEmpty()) { + if (cookieSampler.isSampling()) { + trace.recordAttribute(AnnotationKey.HTTP_COOKIE, StringUtils.drop(value, 1024)); + } + + // Can a cookie have 2 or more values? + // PMD complains if we use break here + return; + } + } + } + + protected void recordEntity(HttpMessage httpMessage, Trace trace) { + if (httpMessage instanceof HttpEntityEnclosingRequest) { + final HttpEntityEnclosingRequest entityRequest = (HttpEntityEnclosingRequest) httpMessage; + try { + final HttpEntity entity = entityRequest.getEntity(); + if (entity != null && entity.isRepeatable() && entity.getContentLength() > 0) { + if (entitySampler.isSampling()) { + final String entityString = entityUtilsToString(entity, "UTF8", 1024); + trace.recordAttribute(AnnotationKey.HTTP_PARAM_ENTITY, StringUtils.drop(entityString, 1024)); + } + } + } catch (IOException e) { + logger.debug("HttpEntityEnclosingRequest entity record fail. Caused:{}", e.getMessage(), e); + } + } + } + + /** + * copy: EntityUtils + * Get the entity content as a String, using the provided default character set + * if none is found in the entity. + * If defaultCharset is null, the default "ISO-8859-1" is used. + * + * @param entity must not be null + * @param defaultCharset character set to be applied if none found in the entity + * @return the entity content as a String. May be null if + * {@link HttpEntity#getContent()} is null. + * @throws ParseException if header elements cannot be parsed + * @throws IllegalArgumentException if entity is null or if content length > Integer.MAX_VALUE + * @throws IOException if an error occurs reading the input stream + */ + public static String entityUtilsToString(final HttpEntity entity, final String defaultCharset, int maxLength) throws IOException, ParseException { + if (entity == null) { + throw new IllegalArgumentException("HTTP entity may not be null"); + } + final InputStream instream = entity.getContent(); + if (instream == null) { + return null; + } + try { + if (entity.getContentLength() > Integer.MAX_VALUE) { + return "HTTP entity too large to be buffered in memory length:" + entity.getContentLength(); + } + String charset = getContentCharSet(entity); + if (charset == null) { + charset = defaultCharset; + } + if (charset == null) { + charset = HTTP.DEFAULT_CONTENT_CHARSET; + } + Reader reader = new InputStreamReader(instream, charset); + final StringBuilder buffer = new StringBuilder(maxLength * 2); + char[] tmp = new char[1024]; + int l; + while((l = reader.read(tmp)) != -1) { + buffer.append(tmp, 0, l); + if (buffer.length() >= maxLength) { + break; + } + } + return buffer.toString(); + } finally { + instream.close(); + } + } + + /** + * copy: EntityUtils + * Obtains character set of the entity, if known. + * + * @param entity must not be null + * @return the character set, or null if not found + * @throws ParseException if header elements cannot be parsed + * @throws IllegalArgumentException if entity is null + */ + public static String getContentCharSet(final HttpEntity entity) throws ParseException { + if (entity == null) { + throw new IllegalArgumentException("HTTP entity may not be null"); + } + String charset = null; + if (entity.getContentType() != null) { + HeaderElement values[] = entity.getContentType().getElements(); + if (values.length > 0) { + NameValuePair param = values[0].getParameterByName("charset"); + if (param != null) { + charset = param.getValue(); + } + } + } + return charset; + } + + @Override + public void setTraceContext(TraceContext traceContext) { + this.traceContext = traceContext; + + final ProfilerConfig profilerConfig = traceContext.getProfilerConfig(); + this.cookie = profilerConfig.isApacheHttpClient4ProfileCookie(); + this.cookieDumpType = profilerConfig.getApacheHttpClient4ProfileCookieDumpType(); + if (cookie){ + this.cookieSampler = SimpleSamplerFactory.createSampler(cookie, profilerConfig.getApacheHttpClient4ProfileCookieSamplingRate()); + } + + this.entity = profilerConfig.isApacheHttpClient4ProfileEntity(); + this.entityDumpType = profilerConfig.getApacheHttpClient4ProfileEntityDumpType(); + if (entity) { + this.entitySampler = SimpleSamplerFactory.createSampler(entity, profilerConfig.getApacheHttpClient4ProfileEntitySamplingRate()); + } + this.statusCode = profilerConfig.isApacheHttpClient4ProfileStatusCode(); + } + + @Override + public void setMethodDescriptor(MethodDescriptor descriptor) { + this.descriptor = descriptor; + traceContext.cacheApi(descriptor); + } + +} diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/modifier/connector/httpclient4/interceptor/DivergeForAddingStatusCode.java b/profiler/src/main/java/com/navercorp/pinpoint/profiler/modifier/connector/httpclient4/interceptor/DivergeForAddingStatusCode.java deleted file mode 100644 index a5ea79ec1..000000000 --- a/profiler/src/main/java/com/navercorp/pinpoint/profiler/modifier/connector/httpclient4/interceptor/DivergeForAddingStatusCode.java +++ /dev/null @@ -1,131 +0,0 @@ -/* - * Copyright 2014 NAVER Corp. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.navercorp.pinpoint.profiler.modifier.connector.httpclient4.interceptor; - -import org.apache.http.HttpResponse; - -import com.navercorp.pinpoint.bootstrap.context.Trace; -import com.navercorp.pinpoint.bootstrap.instrument.AttachmentScope; -import com.navercorp.pinpoint.bootstrap.instrument.Scope; -import com.navercorp.pinpoint.bootstrap.interceptor.http.HttpCallContext; -import com.navercorp.pinpoint.common.ServiceType; - -/** - * @author minwoo.jung - */ -public abstract class DivergeForAddingStatusCode extends AbstractHttpRequestExecute { - - private boolean isHasCallbackParam; - private AttachmentScope scope; - - public DivergeForAddingStatusCode(Class childClazz, boolean isHasCallbackParam, Scope scope) { - super(childClazz); - this.isHasCallbackParam = isHasCallbackParam; - this.scope = (AttachmentScope)scope; - } - - @Override - public void before(Object target, Object[] args) { - if (!isPassibleBeforeProcess()) { - return; - } - - super.before(target, args); - } - - @Override - public void after(Object target, Object[] args, Object result, Throwable throwable) { - if (!isPassibleAfterProcess()) { - addStatusCode(result); - scope.pop(); - return; - } - - super.after(target, args, result, throwable); - scope.pop(); - }; - - private boolean isPassibleBeforeProcess() { - if (scope.push() == Scope.ZERO) { - return true; - } - - return false; - } - - private boolean isPassibleAfterProcess() { - final int depth = scope.depth(); - - if (depth - 1 == Scope.ZERO) { - return true; - } - - return false; - } - - private void addStatusCode(Object result) { - if(!needGetStatusCode()) { - return; - } - - if (result instanceof HttpResponse) { - HttpResponse response = (HttpResponse)result; - - if (response.getStatusLine() != null) { - HttpCallContext context = new HttpCallContext(); - context.setStatusCode(response.getStatusLine().getStatusCode()); - scope.setAttachment(context); - } - } - } - - private boolean needGetStatusCode() { - if (isHasCallbackParam) { - return false; - } - - final Trace trace = traceContext.currentRawTraceObject(); - - if (trace == null || trace.getServiceType() != ServiceType.HTTP_CLIENT) { - return false; - } - - if(scope.getAttachment() != null) { - return false; - } - - return true; - } - - @Override - Integer getStatusCode(Object result) { - if (result instanceof HttpResponse) { - HttpResponse response = (HttpResponse)result; - - if (response.getStatusLine() != null) { - return response.getStatusLine().getStatusCode(); - } - } - - if (scope.getAttachment() != null && scope.getAttachment() instanceof HttpCallContext) { - return ((HttpCallContext)scope.getAttachment()).getStatusCode(); - } - - return null; - } - -} diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/modifier/connector/httpclient4/interceptor/HttpRequestExecuteInterceptor.java b/profiler/src/main/java/com/navercorp/pinpoint/profiler/modifier/connector/httpclient4/interceptor/HttpRequestExecuteInterceptor.java index cdd43c525..2d3912830 100644 --- a/profiler/src/main/java/com/navercorp/pinpoint/profiler/modifier/connector/httpclient4/interceptor/HttpRequestExecuteInterceptor.java +++ b/profiler/src/main/java/com/navercorp/pinpoint/profiler/modifier/connector/httpclient4/interceptor/HttpRequestExecuteInterceptor.java @@ -38,7 +38,7 @@ import com.navercorp.pinpoint.bootstrap.pair.NameIntValuePair; * @author emeroad * @author minwoo.jung */ -public class HttpRequestExecuteInterceptor extends DivergeForAddingStatusCode implements TargetClassLoader { +public class HttpRequestExecuteInterceptor extends AbstractHttpRequestExecuteWithDivergence implements TargetClassLoader { private static final int HTTP_HOST_INDEX = 0; private static final int HTTP_REQUEST_INDEX = 1; diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/modifier/connector/httpclient4/interceptor/HttpUriRequestExecuteInterceptor.java b/profiler/src/main/java/com/navercorp/pinpoint/profiler/modifier/connector/httpclient4/interceptor/HttpUriRequestExecuteInterceptor.java index a58d22fb1..9055f58b2 100644 --- a/profiler/src/main/java/com/navercorp/pinpoint/profiler/modifier/connector/httpclient4/interceptor/HttpUriRequestExecuteInterceptor.java +++ b/profiler/src/main/java/com/navercorp/pinpoint/profiler/modifier/connector/httpclient4/interceptor/HttpUriRequestExecuteInterceptor.java @@ -37,7 +37,7 @@ import com.navercorp.pinpoint.bootstrap.pair.NameIntValuePair; * @author emeroad * @author minwoo.jung */ -public class HttpUriRequestExecuteInterceptor extends DivergeForAddingStatusCode implements TargetClassLoader { +public class HttpUriRequestExecuteInterceptor extends AbstractHttpRequestExecuteWithDivergence implements TargetClassLoader { private static final int HTTP_URI_REQUEST_INDEX = 0; diff --git a/profiler/src/test/resources/pinpoint.config b/profiler/src/test/resources/pinpoint.config index 8d00f5e78..d8d1493fe 100644 --- a/profiler/src/test/resources/pinpoint.config +++ b/profiler/src/test/resources/pinpoint.config @@ -1,195 +1,199 @@ -# -# Pinpoint agent configuration -# - -########################################################### -# Collector server # -########################################################### -profiler.collector.ip=127.0.0.1 - -# placeHolder support "${key}" -profiler.collector.span.ip=${profiler.collector.ip} -profiler.collector.span.port=9996 - -# placeHolder support "${key}" -profiler.collector.stat.ip=${profiler.collector.ip} -profiler.collector.stat.port=9995 - -# placeHolder support "${key}" -profiler.collector.tcp.ip=${profiler.collector.ip} -profiler.collector.tcp.port=9994 - - -########################################################### -# Profiler Global Configuration # -########################################################### -profiler.enable=true - -profiler.jvm.collect.interval=1000 - -profiler.sampling.enable=true -profiler.sampling.rate=1 - -profiler.io.buffering.enable=true -profiler.io.buffering.buffersize=20 - - - -profiler.spandatasender.write.queue.size=5120 -#profiler.spandatasender.socket.sendbuffersize=1048576 -#profiler.spandatasender.socket.timeout=3000 -profiler.spandatasender.chunk.size=16384 - -profiler.statdatasender.write.queue.size=5120 -#profiler.statdatasender.socket.sendbuffersize=1048576 -#profiler.statdatasender.socket.timeout=3000 -profiler.statdatasender.chunk.size=16384 - -profiler.agentInfo.send.retry.interval=300000 - -profiler.tcpdatasender.command.accept.enable=true - -########################################################### -# application type # -########################################################### -#profiler.applicationservertype=TOMCAT -#profiler.applicationservertype=BLOC - - -########################################################### -# user defined classes # -########################################################### -profiler.include=com.navercorp.pinpoint.testweb.controller.*,com.navercorp.pinpoint.testweb.MyClass - -########################################################### -# TOMCAT # -########################################################### -profiler.tomcat.hidepinpointheader=true -#naver standard l7 check -profiler.tomcat.excludeurl=/monitor/l7check.html -#profiler.tomcat.excludeurl=/aa/test.html, /bb/exclude.html - -########################################################### -# JDBC # -########################################################### -profiler.jdbc=true -profiler.jdbc.sqlcachesize=1024 -profiler.jdbc.maxsqlbindvaluesize=1024 - -# -# MYSQL -# -profiler.jdbc.mysql=true -profiler.jdbc.mysql.setautocommit=true -profiler.jdbc.mysql.commit=true -profiler.jdbc.mysql.rollback=true - -# -# MSSQL Jtds -# -profiler.jdbc.jtds=true -profiler.jdbc.jtds.setautocommit=true -profiler.jdbc.jtds.commit=true -profiler.jdbc.jtds.rollback=true - -# -# Oracle -# -profiler.jdbc.oracle=true -profiler.jdbc.oracle.setautocommit=true -profiler.jdbc.oracle.commit=true -profiler.jdbc.oracle.rollback=true - -# -# CUBRID -# -profiler.jdbc.cubrid=true -profiler.jdbc.cubrid.setautocommit=true -profiler.jdbc.cubrid.commit=true -profiler.jdbc.cubrid.rollback=true - -# -# DBCP -# -profiler.jdbc.dbcp=true -profiler.jdbc.dbcp.connectionclose=true - - -########################################################### -# Apache HTTP Client 4.x # -########################################################### -profiler.apache.httpclient4=true - -profiler.apache.httpclient4.cookie=true -profiler.apache.httpclient4.cookie.dumptype=ALWAYS -profiler.apache.httpclient4.cookie.sampling.rate=1 - -profiler.apache.httpclient4.entity=true -profiler.apache.httpclient4.entity.dumptype=ALWAYS -profiler.apache.httpclient4.entity.sampling.rate=1 - -profiler.apache.nio.httpclient4=true - - -########################################################### -# Ning Async HTTP Client # -########################################################### -profiler.ning.asynchttpclient=true -profiler.ning.asynchttpclient.cookie=true -profiler.ning.asynchttpclient.cookie.dumptype=ALWAYS -profiler.ning.asynchttpclient.cookie.dumpsize=1024 -profiler.ning.asynchttpclient.cookie.sampling.rate=1 -profiler.ning.asynchttpclient.entity=true -profiler.ning.asynchttpclient.entity.dumptype=ALWAYS -profiler.ning.asynchttpclient.entity.dumpsize=1024 -profiler.ning.asynchttpclient.entity.sampling.rate=1 -profiler.ning.asynchttpclient.param=true -profiler.ning.asynchttpclient.param.dumptype=ALWAYS -profiler.ning.asynchttpclient.param.dumpsize=1024 -profiler.ning.asynchttpclient.param.sampling.rate=1 - - -########################################################### -# Arcus # -########################################################### -profiler.arcus=true -profiler.arcus.keytrace=true - - -########################################################### -# Memcached # -########################################################### -profiler.memcached=true -profiler.memcached.keytrace=true - - -########################################################### -# ibatis # -########################################################### -profiler.orm.ibatis=true - - -########################################################### -# mybatis # -########################################################### -profiler.orm.mybatis=true - -########################################################### -# redis # -########################################################### -profiler.redis=true -profiler.redis.pipeline=true - -########################################################### -# nBase-ARC # -########################################################### -profiler.nbase_arc=true -profiler.nbase_arc.pipeline=true - -########################################################### -# spring-beans -########################################################### -profiler.spring.beans=false -profiler.spring.beans.name.pattern= -profiler.spring.beans.class.pattern= -profiler.spring.beans.annotation=org.springframework.stereotype.Controller,org.springframework.stereotype.Service,org.springframework.stereotype.Repository +# +# Pinpoint agent configuration +# + +########################################################### +# Collector server # +########################################################### +profiler.collector.ip=127.0.0.1 + +# placeHolder support "${key}" +profiler.collector.span.ip=${profiler.collector.ip} +profiler.collector.span.port=9996 + +# placeHolder support "${key}" +profiler.collector.stat.ip=${profiler.collector.ip} +profiler.collector.stat.port=9995 + +# placeHolder support "${key}" +profiler.collector.tcp.ip=${profiler.collector.ip} +profiler.collector.tcp.port=9994 + + +########################################################### +# Profiler Global Configuration # +########################################################### +profiler.enable=true + +profiler.jvm.collect.interval=1000 + +profiler.sampling.enable=true +profiler.sampling.rate=1 + +profiler.io.buffering.enable=true +profiler.io.buffering.buffersize=20 + + + +profiler.spandatasender.write.queue.size=5120 +#profiler.spandatasender.socket.sendbuffersize=1048576 +#profiler.spandatasender.socket.timeout=3000 +profiler.spandatasender.chunk.size=16384 + +profiler.statdatasender.write.queue.size=5120 +#profiler.statdatasender.socket.sendbuffersize=1048576 +#profiler.statdatasender.socket.timeout=3000 +profiler.statdatasender.chunk.size=16384 + +profiler.agentInfo.send.retry.interval=300000 + +profiler.tcpdatasender.command.accept.enable=true + +########################################################### +# application type # +########################################################### +#profiler.applicationservertype=TOMCAT +#profiler.applicationservertype=BLOC + + +########################################################### +# user defined classes # +########################################################### +profiler.include=com.navercorp.pinpoint.testweb.controller.*,com.navercorp.pinpoint.testweb.MyClass + +########################################################### +# TOMCAT # +########################################################### +profiler.tomcat.hidepinpointheader=true +#naver standard l7 check +profiler.tomcat.excludeurl=/monitor/l7check.html +#profiler.tomcat.excludeurl=/aa/test.html, /bb/exclude.html + +########################################################### +# JDBC # +########################################################### +profiler.jdbc=true +profiler.jdbc.sqlcachesize=1024 +profiler.jdbc.maxsqlbindvaluesize=1024 + +# +# MYSQL +# +profiler.jdbc.mysql=true +profiler.jdbc.mysql.setautocommit=true +profiler.jdbc.mysql.commit=true +profiler.jdbc.mysql.rollback=true + +# +# MSSQL Jtds +# +profiler.jdbc.jtds=true +profiler.jdbc.jtds.setautocommit=true +profiler.jdbc.jtds.commit=true +profiler.jdbc.jtds.rollback=true + +# +# Oracle +# +profiler.jdbc.oracle=true +profiler.jdbc.oracle.setautocommit=true +profiler.jdbc.oracle.commit=true +profiler.jdbc.oracle.rollback=true + +# +# CUBRID +# +profiler.jdbc.cubrid=true +profiler.jdbc.cubrid.setautocommit=true +profiler.jdbc.cubrid.commit=true +profiler.jdbc.cubrid.rollback=true + +# +# DBCP +# +profiler.jdbc.dbcp=true +profiler.jdbc.dbcp.connectionclose=true + + +########################################################### +# Apache HTTP Client 4.x # +########################################################### +profiler.apache.httpclient4=true + +profiler.apache.httpclient4.cookie=true +profiler.apache.httpclient4.cookie.dumptype=ALWAYS +profiler.apache.httpclient4.cookie.sampling.rate=1 + +profiler.apache.httpclient4.entity=true +profiler.apache.httpclient4.entity.dumptype=ALWAYS +profiler.apache.httpclient4.entity.sampling.rate=1 + +# Can profile status code value +profiler.apache.httpclient4.entity.statuscode=true + +# Not supported yet +#profiler.apache.nio.httpclient4=true + + +########################################################### +# Ning Async HTTP Client # +########################################################### +profiler.ning.asynchttpclient=true +profiler.ning.asynchttpclient.cookie=true +profiler.ning.asynchttpclient.cookie.dumptype=ALWAYS +profiler.ning.asynchttpclient.cookie.dumpsize=1024 +profiler.ning.asynchttpclient.cookie.sampling.rate=1 +profiler.ning.asynchttpclient.entity=true +profiler.ning.asynchttpclient.entity.dumptype=ALWAYS +profiler.ning.asynchttpclient.entity.dumpsize=1024 +profiler.ning.asynchttpclient.entity.sampling.rate=1 +profiler.ning.asynchttpclient.param=true +profiler.ning.asynchttpclient.param.dumptype=ALWAYS +profiler.ning.asynchttpclient.param.dumpsize=1024 +profiler.ning.asynchttpclient.param.sampling.rate=1 + + +########################################################### +# Arcus # +########################################################### +profiler.arcus=true +profiler.arcus.keytrace=true + + +########################################################### +# Memcached # +########################################################### +profiler.memcached=true +profiler.memcached.keytrace=true + + +########################################################### +# ibatis # +########################################################### +profiler.orm.ibatis=true + + +########################################################### +# mybatis # +########################################################### +profiler.orm.mybatis=true + +########################################################### +# redis # +########################################################### +profiler.redis=true +profiler.redis.pipeline=true + +########################################################### +# nBase-ARC # +########################################################### +profiler.nbase_arc=true +profiler.nbase_arc.pipeline=true + +########################################################### +# spring-beans +########################################################### +profiler.spring.beans=false +profiler.spring.beans.name.pattern= +profiler.spring.beans.class.pattern= +profiler.spring.beans.annotation=org.springframework.stereotype.Controller,org.springframework.stereotype.Service,org.springframework.stereotype.Repository diff --git a/quickstart/agent/src/main/resources/pinpoint.config b/quickstart/agent/src/main/resources/pinpoint.config index 96e6238d7..3ed92a3b1 100644 --- a/quickstart/agent/src/main/resources/pinpoint.config +++ b/quickstart/agent/src/main/resources/pinpoint.config @@ -1,194 +1,197 @@ -# -# Pinpoint agent configuration -# - -########################################################### -# Collector server # -########################################################### -profiler.collector.ip=127.0.0.1 - -# placeHolder support "${key}" -profiler.collector.span.ip=${profiler.collector.ip} -profiler.collector.span.port=29996 - -# placeHolder support "${key}" -profiler.collector.stat.ip=${profiler.collector.ip} -profiler.collector.stat.port=29995 - -# placeHolder support "${key}" -profiler.collector.tcp.ip=${profiler.collector.ip} -profiler.collector.tcp.port=29994 - - -########################################################### -# Profiler Global Configuration # -########################################################### -profiler.enable=true - -profiler.jvm.collect.interval=1000 - -profiler.sampling.enable=true - -# Set sampling rate. If you set it to 10, 1 out of 10 transaction will be sampled. -profiler.sampling.rate=1 - -profiler.io.buffering.enable=true -profiler.io.buffering.buffersize=20 - -profiler.spandatasender.write.queue.size=5120 -#profiler.spandatasender.socket.sendbuffersize=1048576 -#profiler.spandatasender.socket.timeout=3000 -profiler.spandatasender.chunk.size=16384 - -profiler.statdatasender.write.queue.size=5120 -#profiler.statdatasender.socket.sendbuffersize=1048576 -#profiler.statdatasender.socket.timeout=3000 -profiler.statdatasender.chunk.size=16384 - -profiler.agentInfo.send.retry.interval=300000 - -# Allows TCP data command -profiler.tcpdatasender.command.accept.enable=true - -########################################################### -# application type # -########################################################### -profiler.applicationservertype=TOMCAT -#profiler.applicationservertype=BLOC - - -########################################################### -# user defined classes # -########################################################### -profiler.include= - -########################################################### -# TOMCAT # -########################################################### -profiler.tomcat.hidepinpointheader=true -profiler.tomcat.excludeurl=/aa/test.html, /bb/exclude.html - -########################################################### -# JDBC # -########################################################### -profiler.jdbc=true -profiler.jdbc.sqlcachesize=1024 -profiler.jdbc.maxsqlbindvaluesize=1024 - -# -# MYSQL -# -profiler.jdbc.mysql=true -profiler.jdbc.mysql.setautocommit=true -profiler.jdbc.mysql.commit=true -profiler.jdbc.mysql.rollback=true - -# -# MSSQL Jtds -# -profiler.jdbc.jtds=true -profiler.jdbc.jtds.setautocommit=true -profiler.jdbc.jtds.commit=true -profiler.jdbc.jtds.rollback=true - -# -# Oracle -# -profiler.jdbc.oracle=true -profiler.jdbc.oracle.setautocommit=true -profiler.jdbc.oracle.commit=true -profiler.jdbc.oracle.rollback=true - -# -# CUBRID -# -profiler.jdbc.cubrid=true -profiler.jdbc.cubrid.setautocommit=true -profiler.jdbc.cubrid.commit=true -profiler.jdbc.cubrid.rollback=true - -# -# DBCP -# -profiler.jdbc.dbcp=true -profiler.jdbc.dbcp.connectionclose=true - - -########################################################### -# Apache HTTP Client 4.x # -########################################################### -profiler.apache.httpclient4=true -profiler.apache.httpclient4.cookie=true - -# When cookies should be dumped. It could be ALWAYS or EXCEPTION. -profiler.apache.httpclient4.cookie.dumptype=ALWAYS -profiler.apache.httpclient4.cookie.sampling.rate=1 - -# Dump entities of POST or PUT request. limited to entities which is HttpEtity.isRepeatable() == true. -profiler.apache.httpclient4.entity=true - -# When entities should be dumped. ALWAYS or EXCEPTION. -profiler.apache.httpclient4.entity.dumptype=ALWAYS -profiler.apache.httpclient4.entity.sampling.rate=1 - -profiler.apache.nio.httpclient4=true - - -########################################################### -# Ning Async HTTP Client # -########################################################### -profiler.ning.asynchttpclient=true -profiler.ning.asynchttpclient.cookie=true -profiler.ning.asynchttpclient.cookie.dumptype=ALWAYS -profiler.ning.asynchttpclient.cookie.dumpsize=1024 -profiler.ning.asynchttpclient.cookie.sampling.rate=1 -profiler.ning.asynchttpclient.entity=true -profiler.ning.asynchttpclient.entity.dumptype=ALWAYS -profiler.ning.asynchttpclient.entity.dumpsize=1024 -profiler.ning.asynchttpclient.entity.sampling.rate=1 -profiler.ning.asynchttpclient.param=true -profiler.ning.asynchttpclient.param.dumptype=ALWAYS -profiler.ning.asynchttpclient.param.dumpsize=1024 -profiler.ning.asynchttpclient.param.sampling.rate=1 - - -########################################################### -# LINE+ baseframework # -########################################################### -profiler.line.game.netty.param.dumpsize=512 -profiler.line.game.netty.entity.dumpsize=512 - - -########################################################### -# Arcus # -########################################################### -profiler.arcus=true -profiler.arcus.keytrace=true - - -########################################################### -# Memcached # -########################################################### -profiler.memcached=true -profiler.memcached.keytrace=true - - -########################################################### -# ibatis # -########################################################### -profiler.orm.ibatis=true - - -########################################################### -# mybatis # -########################################################### -profiler.orm.mybatis=true - - -########################################################### -# spring-beans -########################################################### -profiler.spring.beans=true -profiler.spring.beans.name.pattern= -profiler.spring.beans.class.pattern= -profiler.spring.beans.annotation=org.springframework.stereotype.Controller,org.springframework.stereotype.Service,org.springframework.stereotype.Repository +# +# Pinpoint agent configuration +# + +########################################################### +# Collector server # +########################################################### +profiler.collector.ip=127.0.0.1 + +# placeHolder support "${key}" +profiler.collector.span.ip=${profiler.collector.ip} +profiler.collector.span.port=29996 + +# placeHolder support "${key}" +profiler.collector.stat.ip=${profiler.collector.ip} +profiler.collector.stat.port=29995 + +# placeHolder support "${key}" +profiler.collector.tcp.ip=${profiler.collector.ip} +profiler.collector.tcp.port=29994 + + +########################################################### +# Profiler Global Configuration # +########################################################### +profiler.enable=true + +profiler.jvm.collect.interval=1000 + +profiler.sampling.enable=true + +# Set sampling rate. If you set it to 10, 1 out of 10 transaction will be sampled. +profiler.sampling.rate=1 + +profiler.io.buffering.enable=true +profiler.io.buffering.buffersize=20 + +profiler.spandatasender.write.queue.size=5120 +#profiler.spandatasender.socket.sendbuffersize=1048576 +#profiler.spandatasender.socket.timeout=3000 +profiler.spandatasender.chunk.size=16384 + +profiler.statdatasender.write.queue.size=5120 +#profiler.statdatasender.socket.sendbuffersize=1048576 +#profiler.statdatasender.socket.timeout=3000 +profiler.statdatasender.chunk.size=16384 + +profiler.agentInfo.send.retry.interval=300000 + +# Allows TCP data command +profiler.tcpdatasender.command.accept.enable=true + +########################################################### +# application type # +########################################################### +profiler.applicationservertype=TOMCAT +#profiler.applicationservertype=BLOC + + +########################################################### +# user defined classes # +########################################################### +profiler.include= + +########################################################### +# TOMCAT # +########################################################### +profiler.tomcat.hidepinpointheader=true +profiler.tomcat.excludeurl=/aa/test.html, /bb/exclude.html + +########################################################### +# JDBC # +########################################################### +profiler.jdbc=true +profiler.jdbc.sqlcachesize=1024 +profiler.jdbc.maxsqlbindvaluesize=1024 + +# +# MYSQL +# +profiler.jdbc.mysql=true +profiler.jdbc.mysql.setautocommit=true +profiler.jdbc.mysql.commit=true +profiler.jdbc.mysql.rollback=true + +# +# MSSQL Jtds +# +profiler.jdbc.jtds=true +profiler.jdbc.jtds.setautocommit=true +profiler.jdbc.jtds.commit=true +profiler.jdbc.jtds.rollback=true + +# +# Oracle +# +profiler.jdbc.oracle=true +profiler.jdbc.oracle.setautocommit=true +profiler.jdbc.oracle.commit=true +profiler.jdbc.oracle.rollback=true + +# +# CUBRID +# +profiler.jdbc.cubrid=true +profiler.jdbc.cubrid.setautocommit=true +profiler.jdbc.cubrid.commit=true +profiler.jdbc.cubrid.rollback=true + +# +# DBCP +# +profiler.jdbc.dbcp=true +profiler.jdbc.dbcp.connectionclose=true + + +########################################################### +# Apache HTTP Client 4.x # +########################################################### +profiler.apache.httpclient4=true +profiler.apache.httpclient4.cookie=true + +# When cookies should be dumped. It could be ALWAYS or EXCEPTION. +profiler.apache.httpclient4.cookie.dumptype=ALWAYS +profiler.apache.httpclient4.cookie.sampling.rate=1 + +# Dump entities of POST or PUT request. limited to entities which is HttpEtity.isRepeatable() == true. +profiler.apache.httpclient4.entity=true + +# When entities should be dumped. ALWAYS or EXCEPTION. +profiler.apache.httpclient4.entity.dumptype=ALWAYS +profiler.apache.httpclient4.entity.sampling.rate=1 + +# Can profile status code value +profiler.apache.httpclient4.entity.statuscode=true + +# Not supported yet +#profiler.apache.nio.httpclient4=true + +########################################################### +# Ning Async HTTP Client # +########################################################### +profiler.ning.asynchttpclient=true +profiler.ning.asynchttpclient.cookie=true +profiler.ning.asynchttpclient.cookie.dumptype=ALWAYS +profiler.ning.asynchttpclient.cookie.dumpsize=1024 +profiler.ning.asynchttpclient.cookie.sampling.rate=1 +profiler.ning.asynchttpclient.entity=true +profiler.ning.asynchttpclient.entity.dumptype=ALWAYS +profiler.ning.asynchttpclient.entity.dumpsize=1024 +profiler.ning.asynchttpclient.entity.sampling.rate=1 +profiler.ning.asynchttpclient.param=true +profiler.ning.asynchttpclient.param.dumptype=ALWAYS +profiler.ning.asynchttpclient.param.dumpsize=1024 +profiler.ning.asynchttpclient.param.sampling.rate=1 + + +########################################################### +# LINE+ baseframework # +########################################################### +profiler.line.game.netty.param.dumpsize=512 +profiler.line.game.netty.entity.dumpsize=512 + + +########################################################### +# Arcus # +########################################################### +profiler.arcus=true +profiler.arcus.keytrace=true + + +########################################################### +# Memcached # +########################################################### +profiler.memcached=true +profiler.memcached.keytrace=true + + +########################################################### +# ibatis # +########################################################### +profiler.orm.ibatis=true + + +########################################################### +# mybatis # +########################################################### +profiler.orm.mybatis=true + + +########################################################### +# spring-beans +########################################################### +profiler.spring.beans=true +profiler.spring.beans.name.pattern= +profiler.spring.beans.class.pattern= +profiler.spring.beans.annotation=org.springframework.stereotype.Controller,org.springframework.stereotype.Service,org.springframework.stereotype.Repository diff --git a/quickstart/conf/pinpoint.config b/quickstart/conf/pinpoint.config index 96e6238d7..567b1b681 100644 --- a/quickstart/conf/pinpoint.config +++ b/quickstart/conf/pinpoint.config @@ -1,194 +1,198 @@ -# -# Pinpoint agent configuration -# - -########################################################### -# Collector server # -########################################################### -profiler.collector.ip=127.0.0.1 - -# placeHolder support "${key}" -profiler.collector.span.ip=${profiler.collector.ip} -profiler.collector.span.port=29996 - -# placeHolder support "${key}" -profiler.collector.stat.ip=${profiler.collector.ip} -profiler.collector.stat.port=29995 - -# placeHolder support "${key}" -profiler.collector.tcp.ip=${profiler.collector.ip} -profiler.collector.tcp.port=29994 - - -########################################################### -# Profiler Global Configuration # -########################################################### -profiler.enable=true - -profiler.jvm.collect.interval=1000 - -profiler.sampling.enable=true - -# Set sampling rate. If you set it to 10, 1 out of 10 transaction will be sampled. -profiler.sampling.rate=1 - -profiler.io.buffering.enable=true -profiler.io.buffering.buffersize=20 - -profiler.spandatasender.write.queue.size=5120 -#profiler.spandatasender.socket.sendbuffersize=1048576 -#profiler.spandatasender.socket.timeout=3000 -profiler.spandatasender.chunk.size=16384 - -profiler.statdatasender.write.queue.size=5120 -#profiler.statdatasender.socket.sendbuffersize=1048576 -#profiler.statdatasender.socket.timeout=3000 -profiler.statdatasender.chunk.size=16384 - -profiler.agentInfo.send.retry.interval=300000 - -# Allows TCP data command -profiler.tcpdatasender.command.accept.enable=true - -########################################################### -# application type # -########################################################### -profiler.applicationservertype=TOMCAT -#profiler.applicationservertype=BLOC - - -########################################################### -# user defined classes # -########################################################### -profiler.include= - -########################################################### -# TOMCAT # -########################################################### -profiler.tomcat.hidepinpointheader=true -profiler.tomcat.excludeurl=/aa/test.html, /bb/exclude.html - -########################################################### -# JDBC # -########################################################### -profiler.jdbc=true -profiler.jdbc.sqlcachesize=1024 -profiler.jdbc.maxsqlbindvaluesize=1024 - -# -# MYSQL -# -profiler.jdbc.mysql=true -profiler.jdbc.mysql.setautocommit=true -profiler.jdbc.mysql.commit=true -profiler.jdbc.mysql.rollback=true - -# -# MSSQL Jtds -# -profiler.jdbc.jtds=true -profiler.jdbc.jtds.setautocommit=true -profiler.jdbc.jtds.commit=true -profiler.jdbc.jtds.rollback=true - -# -# Oracle -# -profiler.jdbc.oracle=true -profiler.jdbc.oracle.setautocommit=true -profiler.jdbc.oracle.commit=true -profiler.jdbc.oracle.rollback=true - -# -# CUBRID -# -profiler.jdbc.cubrid=true -profiler.jdbc.cubrid.setautocommit=true -profiler.jdbc.cubrid.commit=true -profiler.jdbc.cubrid.rollback=true - -# -# DBCP -# -profiler.jdbc.dbcp=true -profiler.jdbc.dbcp.connectionclose=true - - -########################################################### -# Apache HTTP Client 4.x # -########################################################### -profiler.apache.httpclient4=true -profiler.apache.httpclient4.cookie=true - -# When cookies should be dumped. It could be ALWAYS or EXCEPTION. -profiler.apache.httpclient4.cookie.dumptype=ALWAYS -profiler.apache.httpclient4.cookie.sampling.rate=1 - -# Dump entities of POST or PUT request. limited to entities which is HttpEtity.isRepeatable() == true. -profiler.apache.httpclient4.entity=true - -# When entities should be dumped. ALWAYS or EXCEPTION. -profiler.apache.httpclient4.entity.dumptype=ALWAYS -profiler.apache.httpclient4.entity.sampling.rate=1 - -profiler.apache.nio.httpclient4=true - - -########################################################### -# Ning Async HTTP Client # -########################################################### -profiler.ning.asynchttpclient=true -profiler.ning.asynchttpclient.cookie=true -profiler.ning.asynchttpclient.cookie.dumptype=ALWAYS -profiler.ning.asynchttpclient.cookie.dumpsize=1024 -profiler.ning.asynchttpclient.cookie.sampling.rate=1 -profiler.ning.asynchttpclient.entity=true -profiler.ning.asynchttpclient.entity.dumptype=ALWAYS -profiler.ning.asynchttpclient.entity.dumpsize=1024 -profiler.ning.asynchttpclient.entity.sampling.rate=1 -profiler.ning.asynchttpclient.param=true -profiler.ning.asynchttpclient.param.dumptype=ALWAYS -profiler.ning.asynchttpclient.param.dumpsize=1024 -profiler.ning.asynchttpclient.param.sampling.rate=1 - - -########################################################### -# LINE+ baseframework # -########################################################### -profiler.line.game.netty.param.dumpsize=512 -profiler.line.game.netty.entity.dumpsize=512 - - -########################################################### -# Arcus # -########################################################### -profiler.arcus=true -profiler.arcus.keytrace=true - - -########################################################### -# Memcached # -########################################################### -profiler.memcached=true -profiler.memcached.keytrace=true - - -########################################################### -# ibatis # -########################################################### -profiler.orm.ibatis=true - - -########################################################### -# mybatis # -########################################################### -profiler.orm.mybatis=true - - -########################################################### -# spring-beans -########################################################### -profiler.spring.beans=true -profiler.spring.beans.name.pattern= -profiler.spring.beans.class.pattern= -profiler.spring.beans.annotation=org.springframework.stereotype.Controller,org.springframework.stereotype.Service,org.springframework.stereotype.Repository +# +# Pinpoint agent configuration +# + +########################################################### +# Collector server # +########################################################### +profiler.collector.ip=127.0.0.1 + +# placeHolder support "${key}" +profiler.collector.span.ip=${profiler.collector.ip} +profiler.collector.span.port=29996 + +# placeHolder support "${key}" +profiler.collector.stat.ip=${profiler.collector.ip} +profiler.collector.stat.port=29995 + +# placeHolder support "${key}" +profiler.collector.tcp.ip=${profiler.collector.ip} +profiler.collector.tcp.port=29994 + + +########################################################### +# Profiler Global Configuration # +########################################################### +profiler.enable=true + +profiler.jvm.collect.interval=1000 + +profiler.sampling.enable=true + +# Set sampling rate. If you set it to 10, 1 out of 10 transaction will be sampled. +profiler.sampling.rate=1 + +profiler.io.buffering.enable=true +profiler.io.buffering.buffersize=20 + +profiler.spandatasender.write.queue.size=5120 +#profiler.spandatasender.socket.sendbuffersize=1048576 +#profiler.spandatasender.socket.timeout=3000 +profiler.spandatasender.chunk.size=16384 + +profiler.statdatasender.write.queue.size=5120 +#profiler.statdatasender.socket.sendbuffersize=1048576 +#profiler.statdatasender.socket.timeout=3000 +profiler.statdatasender.chunk.size=16384 + +profiler.agentInfo.send.retry.interval=300000 + +# Allows TCP data command +profiler.tcpdatasender.command.accept.enable=true + +########################################################### +# application type # +########################################################### +profiler.applicationservertype=TOMCAT +#profiler.applicationservertype=BLOC + + +########################################################### +# user defined classes # +########################################################### +profiler.include= + +########################################################### +# TOMCAT # +########################################################### +profiler.tomcat.hidepinpointheader=true +profiler.tomcat.excludeurl=/aa/test.html, /bb/exclude.html + +########################################################### +# JDBC # +########################################################### +profiler.jdbc=true +profiler.jdbc.sqlcachesize=1024 +profiler.jdbc.maxsqlbindvaluesize=1024 + +# +# MYSQL +# +profiler.jdbc.mysql=true +profiler.jdbc.mysql.setautocommit=true +profiler.jdbc.mysql.commit=true +profiler.jdbc.mysql.rollback=true + +# +# MSSQL Jtds +# +profiler.jdbc.jtds=true +profiler.jdbc.jtds.setautocommit=true +profiler.jdbc.jtds.commit=true +profiler.jdbc.jtds.rollback=true + +# +# Oracle +# +profiler.jdbc.oracle=true +profiler.jdbc.oracle.setautocommit=true +profiler.jdbc.oracle.commit=true +profiler.jdbc.oracle.rollback=true + +# +# CUBRID +# +profiler.jdbc.cubrid=true +profiler.jdbc.cubrid.setautocommit=true +profiler.jdbc.cubrid.commit=true +profiler.jdbc.cubrid.rollback=true + +# +# DBCP +# +profiler.jdbc.dbcp=true +profiler.jdbc.dbcp.connectionclose=true + + +########################################################### +# Apache HTTP Client 4.x # +########################################################### +profiler.apache.httpclient4=true +profiler.apache.httpclient4.cookie=true + +# When cookies should be dumped. It could be ALWAYS or EXCEPTION. +profiler.apache.httpclient4.cookie.dumptype=ALWAYS +profiler.apache.httpclient4.cookie.sampling.rate=1 + +# Dump entities of POST or PUT request. limited to entities which is HttpEtity.isRepeatable() == true. +profiler.apache.httpclient4.entity=true + +# When entities should be dumped. ALWAYS or EXCEPTION. +profiler.apache.httpclient4.entity.dumptype=ALWAYS +profiler.apache.httpclient4.entity.sampling.rate=1 + +# Can profile status code value +profiler.apache.httpclient4.entity.statuscode=true + +# Not supported yet +profiler.apache.nio.httpclient4=true + + +########################################################### +# Ning Async HTTP Client # +########################################################### +profiler.ning.asynchttpclient=true +profiler.ning.asynchttpclient.cookie=true +profiler.ning.asynchttpclient.cookie.dumptype=ALWAYS +profiler.ning.asynchttpclient.cookie.dumpsize=1024 +profiler.ning.asynchttpclient.cookie.sampling.rate=1 +profiler.ning.asynchttpclient.entity=true +profiler.ning.asynchttpclient.entity.dumptype=ALWAYS +profiler.ning.asynchttpclient.entity.dumpsize=1024 +profiler.ning.asynchttpclient.entity.sampling.rate=1 +profiler.ning.asynchttpclient.param=true +profiler.ning.asynchttpclient.param.dumptype=ALWAYS +profiler.ning.asynchttpclient.param.dumpsize=1024 +profiler.ning.asynchttpclient.param.sampling.rate=1 + + +########################################################### +# LINE+ baseframework # +########################################################### +profiler.line.game.netty.param.dumpsize=512 +profiler.line.game.netty.entity.dumpsize=512 + + +########################################################### +# Arcus # +########################################################### +profiler.arcus=true +profiler.arcus.keytrace=true + + +########################################################### +# Memcached # +########################################################### +profiler.memcached=true +profiler.memcached.keytrace=true + + +########################################################### +# ibatis # +########################################################### +profiler.orm.ibatis=true + + +########################################################### +# mybatis # +########################################################### +profiler.orm.mybatis=true + + +########################################################### +# spring-beans +########################################################### +profiler.spring.beans=true +profiler.spring.beans.name.pattern= +profiler.spring.beans.class.pattern= +profiler.spring.beans.annotation=org.springframework.stereotype.Controller,org.springframework.stereotype.Service,org.springframework.stereotype.Repository