Skip to content

Commit

Permalink
[pinpoint-apm#11579] Update httpclient5 plugin option - mark.error
Browse files Browse the repository at this point in the history
  • Loading branch information
jaehong-kim committed Oct 16, 2024
1 parent eb07dd9 commit a3ba868
Show file tree
Hide file tree
Showing 18 changed files with 137 additions and 57 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,32 @@ public String handleResponse(ClassicHttpResponse classicHttpResponse) throws Htt
return responseBody;
}

@GetMapping("/client/notofound")
public String clientNotFound() throws Exception {
try {
final CloseableHttpClient httpClient = HttpClients.createDefault();
final HttpGet httpGet = new HttpGet("http://fjakfjlagjlkj");

final HttpClientResponseHandler<String> responseHandler = new HttpClientResponseHandler<String>() {
@Override
public String handleResponse(ClassicHttpResponse classicHttpResponse) throws HttpException, IOException {
final int status = classicHttpResponse.getCode();
if (status >= HttpStatus.SC_SUCCESS && status < HttpStatus.SC_REDIRECTION) {
final HttpEntity entity = classicHttpResponse.getEntity();
return entity != null ? EntityUtils.toString(entity) : null;
}

return null;
}
};

final String responseBody = httpClient.execute(httpGet, responseHandler);
return responseBody;
} catch (Exception ignored) {
}
return "OK";
}

@GetMapping("/client/local")
public String clientLocal() throws Exception {
final CloseableHttpClient httpClient = HttpClients.createDefault();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -933,6 +933,11 @@ profiler.apache.httpclient5.entity.dumpsize=1024
# Allow profiling status code value.
profiler.apache.httpclient5.entity.statuscode=true

# Trace ComplexFuture.failed(Exception exception), BasicFuture.failed(Exception exception)
profiler.apache.httpclient5.trace.future.error=true
# Mark error
profiler.apache.httpclient5.mark.error=true

###########################################################
# JDK HTTPURLConnection #
###########################################################
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -930,6 +930,11 @@ profiler.apache.httpclient5.entity.dumpsize=1024
# Allow profiling status code value.
profiler.apache.httpclient5.entity.statuscode=true

# Trace ComplexFuture.failed(Exception exception), BasicFuture.failed(Exception exception)
profiler.apache.httpclient5.trace.future.error=true
# Mark error
profiler.apache.httpclient5.mark.error=true

###########################################################
# JDK HTTPURLConnection #
###########################################################
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public void setup(ProfilerPluginSetupContext context) {
logger.info("{} disabled", this.getClass().getSimpleName());
return;
}
logger.info("{} version range=(5.0 ~ 5.1, config:{}", this.getClass().getSimpleName(), config);
logger.info("{} config:{}", this.getClass().getSimpleName(), config);

// Sync(classic)
// request
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,44 +24,50 @@ public class HttpClient5PluginConfig {
private boolean enable;
private boolean param = true;
private boolean statusCode = true;
private boolean io;
private HttpDumpConfig httpDumpConfig;
private boolean markError;
private boolean traceFutureError;

public HttpClient5PluginConfig(ProfilerConfig src) {
this.enable = src.readBoolean("profiler.apache.httpclient5.enable", true);
this.param = src.readBoolean("profiler.apache.httpclient5.param", true);
public static boolean isParam(ProfilerConfig config) {
return config.readBoolean("profiler.apache.httpclient5.param", Boolean.TRUE);
}

boolean cookie = src.readBoolean("profiler.apache.httpclient5.cookie", false);
DumpType cookieDumpType = src.readDumpType("profiler.apache.httpclient5.cookie.dumptype", DumpType.EXCEPTION);
int cookieSamplingRate = src.readInt("profiler.apache.httpclient5.cookie.sampling.rate", 1);
int cookieDumpSize = src.readInt("profiler.apache.httpclient5.cookie.dumpsize", 1024);
boolean entity = src.readBoolean("profiler.apache.httpclient5.entity", false);
DumpType entityDumpType = src.readDumpType("profiler.apache.httpclient5.entity.dumptype", DumpType.EXCEPTION);
int entitySamplingRate = src.readInt("profiler.apache.httpclient5.entity.sampling.rate", 1);
int entityDumpSize = src.readInt("profiler.apache.httpclient5.entity.dumpsize", 1024);
this.httpDumpConfig = HttpDumpConfig.get(cookie, cookieDumpType, cookieSamplingRate, cookieDumpSize, entity, entityDumpType, entitySamplingRate, entityDumpSize);
public static HttpDumpConfig getHttpDumpConfig(ProfilerConfig config) {
boolean cookie = config.readBoolean("profiler.apache.httpclient5.cookie", false);
DumpType cookieDumpType = config.readDumpType("profiler.apache.httpclient5.cookie.dumptype", DumpType.EXCEPTION);
int cookieSamplingRate = config.readInt("profiler.apache.httpclient5.cookie.sampling.rate", 1);
int cookieDumpSize = config.readInt("profiler.apache.httpclient5.cookie.dumpsize", 1024);
boolean entity = config.readBoolean("profiler.apache.httpclient5.entity", false);
DumpType entityDumpType = config.readDumpType("profiler.apache.httpclient5.entity.dumptype", DumpType.EXCEPTION);
int entitySamplingRate = config.readInt("profiler.apache.httpclient5.entity.sampling.rate", 1);
int entityDumpSize = config.readInt("profiler.apache.httpclient5.entity.dumpsize", 1024);

this.statusCode = src.readBoolean("profiler.apache.httpclient5.entity.statuscode", true);
return HttpDumpConfig.get(cookie, cookieDumpType, cookieSamplingRate, cookieDumpSize, entity, entityDumpType, entitySamplingRate, entityDumpSize);
}

public boolean isEnable() {
return enable;
public static boolean isStatusCode(ProfilerConfig config) {
return config.readBoolean("profiler.apache.httpclient5.entity.statuscode", Boolean.TRUE);
}

public boolean isParam() {
return param;
public static boolean isMarkError(ProfilerConfig config) {
return config.readBoolean("profiler.apache.httpclient5.mark.error", Boolean.TRUE);
}

public boolean isStatusCode() {
return statusCode;
public static boolean isTraceFutureError(ProfilerConfig config) {
return config.readBoolean("profiler.apache.httpclient5.trace.future.error", Boolean.TRUE);
}

public boolean isIo() {
return io;
public HttpClient5PluginConfig(ProfilerConfig src) {
this.enable = src.readBoolean("profiler.apache.httpclient5.enable", true);
this.param = isParam(src);
this.httpDumpConfig = getHttpDumpConfig(src);
this.statusCode = isStatusCode(src);
this.markError = isMarkError(src);
this.traceFutureError = isTraceFutureError(src);
}

public HttpDumpConfig getHttpDumpConfig() {
return httpDumpConfig;
public boolean isEnable() {
return enable;
}

@Override
Expand All @@ -70,8 +76,9 @@ public String toString() {
"enable=" + enable +
", param=" + param +
", statusCode=" + statusCode +
", io=" + io +
", httpDumpConfig=" + httpDumpConfig +
", markError=" + markError +
", traceFutureError=" + traceFutureError +
'}';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,14 @@
import com.navercorp.pinpoint.bootstrap.context.TraceContext;
import com.navercorp.pinpoint.bootstrap.interceptor.AsyncContextSpanEventSimpleAroundInterceptor;
import com.navercorp.pinpoint.plugin.httpclient5.HttpClient5Constants;
import com.navercorp.pinpoint.plugin.httpclient5.HttpClient5PluginConfig;

public class AsyncClientConnectionManagerConnectInterceptor extends AsyncContextSpanEventSimpleAroundInterceptor {
private final boolean markError;

public AsyncClientConnectionManagerConnectInterceptor(TraceContext traceContext, MethodDescriptor methodDescriptor) {
super(traceContext, methodDescriptor);
this.markError = HttpClient5PluginConfig.isMarkError(traceContext.getProfilerConfig());
}

public AsyncContext getAsyncContext(Object target, Object[] args) {
Expand All @@ -44,7 +48,7 @@ public AsyncContext getAsyncContext(Object target, Object[] args, Object result,
@Override
public void doInAfterTrace(SpanEventRecorder recorder, Object target, Object[] args, Object result, Throwable throwable) {
recorder.recordApi(methodDescriptor);
recorder.recordException(throwable);
recorder.recordException(markError, throwable);
recorder.recordServiceType(HttpClient5Constants.HTTP_CLIENT5_INTERNAL);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,12 @@

public class AsyncExecCallbackHandleResponseInterceptor extends AsyncContextSpanEventSimpleAroundInterceptor {
private final boolean statusCode;
private final boolean markError;

public AsyncExecCallbackHandleResponseInterceptor(TraceContext traceContext, MethodDescriptor methodDescriptor) {
super(traceContext, methodDescriptor);
final HttpClient5PluginConfig config = new HttpClient5PluginConfig(traceContext.getProfilerConfig());
this.statusCode = config.isStatusCode();
this.statusCode = HttpClient5PluginConfig.isStatusCode(traceContext.getProfilerConfig());
this.markError = HttpClient5PluginConfig.isMarkError(traceContext.getProfilerConfig());
}

@Override
Expand All @@ -50,7 +51,7 @@ public void doInBeforeTrace(SpanEventRecorder recorder, AsyncContext asyncContex
@Override
public void doInAfterTrace(SpanEventRecorder recorder, Object target, Object[] args, Object result, Throwable throwable) {
recorder.recordApi(methodDescriptor);
recorder.recordException(throwable);
recorder.recordException(markError, throwable);
recorder.recordServiceType(HttpClient5Constants.HTTP_CLIENT5_INTERNAL);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,12 @@

public class BasicClientExchangeHandlerConsumeResponseInterceptor extends AsyncContextSpanEventSimpleAroundInterceptor {
private final boolean statusCode;
private final boolean markError;

public BasicClientExchangeHandlerConsumeResponseInterceptor(TraceContext traceContext, MethodDescriptor methodDescriptor) {
super(traceContext, methodDescriptor);
final HttpClient5PluginConfig config = new HttpClient5PluginConfig(traceContext.getProfilerConfig());
this.statusCode = config.isStatusCode();
this.statusCode = HttpClient5PluginConfig.isStatusCode(traceContext.getProfilerConfig());
this.markError = HttpClient5PluginConfig.isMarkError(traceContext.getProfilerConfig());
}

@Override
Expand All @@ -50,7 +51,7 @@ public void doInBeforeTrace(SpanEventRecorder recorder, AsyncContext asyncContex
@Override
public void doInAfterTrace(SpanEventRecorder recorder, Object target, Object[] args, Object result, Throwable throwable) {
recorder.recordApi(methodDescriptor);
recorder.recordException(throwable);
recorder.recordException(markError, throwable);
recorder.recordServiceType(HttpClient5Constants.HTTP_CLIENT5_INTERNAL);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,14 @@
import com.navercorp.pinpoint.bootstrap.context.TraceContext;
import com.navercorp.pinpoint.bootstrap.interceptor.SpanEventSimpleAroundInterceptorForPlugin;
import com.navercorp.pinpoint.plugin.httpclient5.HttpClient5Constants;
import com.navercorp.pinpoint.plugin.httpclient5.HttpClient5PluginConfig;

public class ClientConnectionManagerConnectInterceptor extends SpanEventSimpleAroundInterceptorForPlugin {
private final boolean markError;

public ClientConnectionManagerConnectInterceptor(TraceContext traceContext, MethodDescriptor methodDescriptor) {
super(traceContext, methodDescriptor);
this.markError = HttpClient5PluginConfig.isMarkError(traceContext.getProfilerConfig());
}

@Override
Expand All @@ -34,7 +38,7 @@ public void doInBeforeTrace(SpanEventRecorder recorder, Object target, Object[]
@Override
public void doInAfterTrace(SpanEventRecorder recorder, Object target, Object[] args, Object result, Throwable throwable) throws Exception {
recorder.recordApi(methodDescriptor);
recorder.recordException(throwable);
recorder.recordException(markError, throwable);
recorder.recordServiceType(HttpClient5Constants.HTTP_CLIENT5_INTERNAL);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,14 @@ public class CloseableHttpAsyncClientDoExecuteInterceptor implements AroundInter
private final EntityRecorder<HttpRequest> entityRecorder;

private final RequestTraceWriter<HttpRequest> requestTraceWriter;
private final boolean markError;

public CloseableHttpAsyncClientDoExecuteInterceptor(TraceContext traceContext, MethodDescriptor methodDescriptor) {
this.traceContext = traceContext;
this.methodDescriptor = methodDescriptor;

final HttpClient5PluginConfig config = new HttpClient5PluginConfig(traceContext.getProfilerConfig());
final boolean param = config.isParam();
final HttpDumpConfig httpDumpConfig = config.getHttpDumpConfig();
final boolean param = HttpClient5PluginConfig.isParam(traceContext.getProfilerConfig());
final HttpDumpConfig httpDumpConfig = HttpClient5PluginConfig.getHttpDumpConfig(traceContext.getProfilerConfig());

ClientRequestAdaptor<ClientRequestWrapper> clientRequestAdaptor = ClientRequestWrapperAdaptor.INSTANCE;
this.clientRequestRecorder = new ClientRequestRecorder<>(param, clientRequestAdaptor);
Expand All @@ -84,6 +84,8 @@ public CloseableHttpAsyncClientDoExecuteInterceptor(TraceContext traceContext, M

ClientHeaderAdaptor<HttpRequest> clientHeaderAdaptor = new HttpRequest5ClientHeaderAdaptor();
this.requestTraceWriter = new DefaultRequestTraceWriter<>(clientHeaderAdaptor, traceContext);

this.markError = HttpClient5PluginConfig.isMarkError(traceContext.getProfilerConfig());
}

@Override
Expand Down Expand Up @@ -155,7 +157,7 @@ public void after(Object target, Object[] args, Object result, Throwable throwab
this.cookieRecorder.record(recorder, httpRequest, throwable);
this.entityRecorder.record(recorder, httpRequest, throwable);
recorder.recordApi(methodDescriptor);
recorder.recordException(throwable);
recorder.recordException(markError, throwable);
if (result instanceof AsyncContextAccessor) {
// HttpContext
final AsyncContext asyncContext = AsyncContextAccessorUtils.getAsyncContext(args, 4);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,14 @@
import com.navercorp.pinpoint.bootstrap.interceptor.SpanEventSimpleAroundInterceptorForPlugin;
import com.navercorp.pinpoint.common.util.ArrayArgumentUtils;
import com.navercorp.pinpoint.plugin.httpclient5.HttpClient5Constants;
import com.navercorp.pinpoint.plugin.httpclient5.HttpClient5PluginConfig;

public class CloseableHttpAsyncClientExecuteImmediateMethodInterceptor extends SpanEventSimpleAroundInterceptorForPlugin {
private final boolean markError;

public CloseableHttpAsyncClientExecuteImmediateMethodInterceptor(TraceContext traceContext, MethodDescriptor methodDescriptor) {
super(traceContext, methodDescriptor);
this.markError = HttpClient5PluginConfig.isMarkError(traceContext.getProfilerConfig());
}

@Override
Expand All @@ -49,7 +53,7 @@ public void doInBeforeTrace(SpanEventRecorder recorder, Object target, Object[]
public void afterTrace(Trace trace, SpanEventRecorder recorder, Object target, Object[] args, Object result, Throwable throwable) {
if (trace.canSampled()) {
recorder.recordApi(methodDescriptor);
recorder.recordException(throwable);
recorder.recordException(markError, throwable);
recorder.recordServiceType(HttpClient5Constants.HTTP_CLIENT5_INTERNAL);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,15 @@
import com.navercorp.pinpoint.common.trace.AnnotationKey;
import com.navercorp.pinpoint.common.util.ArrayArgumentUtils;
import com.navercorp.pinpoint.plugin.httpclient5.HttpClient5Constants;
import com.navercorp.pinpoint.plugin.httpclient5.HttpClient5PluginConfig;
import org.apache.hc.core5.http.HttpHost;

public class DefaultAsyncClientConnectionOperatorConnectInterceptor extends SpanEventSimpleAroundInterceptorForPlugin {
private final boolean markError;

public DefaultAsyncClientConnectionOperatorConnectInterceptor(TraceContext traceContext, MethodDescriptor methodDescriptor) {
super(traceContext, methodDescriptor);
this.markError = HttpClient5PluginConfig.isMarkError(traceContext.getProfilerConfig());
}

@Override
Expand All @@ -41,7 +45,7 @@ public void doInBeforeTrace(SpanEventRecorder recorder, Object target, Object[]
@Override
public void doInAfterTrace(SpanEventRecorder recorder, Object target, Object[] args, Object result, Throwable throwable) throws Exception {
recorder.recordApi(methodDescriptor);
recorder.recordException(throwable);
recorder.recordException(markError, throwable);
recorder.recordServiceType(HttpClient5Constants.HTTP_CLIENT5_INTERNAL);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,15 @@
import com.navercorp.pinpoint.common.trace.AnnotationKey;
import com.navercorp.pinpoint.common.util.ArrayArgumentUtils;
import com.navercorp.pinpoint.plugin.httpclient5.HttpClient5Constants;
import com.navercorp.pinpoint.plugin.httpclient5.HttpClient5PluginConfig;
import org.apache.hc.core5.http.HttpHost;

public class DefaultHttpClientConnectionOperatorConnectInterceptor extends SpanEventSimpleAroundInterceptorForPlugin {
private final boolean markError;

public DefaultHttpClientConnectionOperatorConnectInterceptor(TraceContext traceContext, MethodDescriptor methodDescriptor) {
super(traceContext, methodDescriptor);
this.markError = HttpClient5PluginConfig.isMarkError(traceContext.getProfilerConfig());
}

@Override
Expand All @@ -41,7 +45,7 @@ public void doInBeforeTrace(SpanEventRecorder recorder, Object target, Object[]
@Override
public void doInAfterTrace(SpanEventRecorder recorder, Object target, Object[] args, Object result, Throwable throwable) throws Exception {
recorder.recordApi(methodDescriptor);
recorder.recordException(throwable);
recorder.recordException(markError, throwable);
recorder.recordServiceType(HttpClient5Constants.HTTP_CLIENT5_INTERNAL);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,14 @@
import com.navercorp.pinpoint.bootstrap.context.TraceContext;
import com.navercorp.pinpoint.bootstrap.interceptor.AsyncContextSpanEventSimpleAroundInterceptor;
import com.navercorp.pinpoint.plugin.httpclient5.HttpClient5Constants;
import com.navercorp.pinpoint.plugin.httpclient5.HttpClient5PluginConfig;

public class FutureCancelInterceptor extends AsyncContextSpanEventSimpleAroundInterceptor {
private final boolean markError;

public FutureCancelInterceptor(TraceContext traceContext, MethodDescriptor methodDescriptor) {
super(traceContext, methodDescriptor);
this.markError = HttpClient5PluginConfig.isMarkError(traceContext.getProfilerConfig());
}

@Override
Expand All @@ -36,7 +39,7 @@ public void doInBeforeTrace(SpanEventRecorder recorder, AsyncContext asyncContex
@Override
public void doInAfterTrace(SpanEventRecorder recorder, Object target, Object[] args, Object result, Throwable throwable) {
recorder.recordApi(methodDescriptor);
recorder.recordException(throwable);
recorder.recordException(markError, throwable);
recorder.recordServiceType(HttpClient5Constants.HTTP_CLIENT5_INTERNAL);
}
}
Loading

0 comments on commit a3ba868

Please sign in to comment.