private <R> R wrapHttpSupplier(Subsegment subsegment, HttpSupplier<R> supplier) throws IOException, ClientProtocolException { try { return supplier.get(); } catch (Exception e) { if (null != subsegment) { subsegment.addException(e); } throw e; } finally { if (null != subsegment) { recorder.endSubsegment(); } } }
private <R> R wrapHttpSupplier(Subsegment subsegment, HttpSupplier<R> supplier) throws IOException, ClientProtocolException { try { return supplier.get(); } catch (Exception e) { if (null != subsegment) { subsegment.addException(e); } throw e; } finally { if (null != subsegment) { recorder.endSubsegment(); } } }
/** * Begins a subsegment and passes it to the supplied consumer. Intercepts exceptions, adds them to the subsegment, and re-throws them. * * @param name * the name to use for the created subsegment * @param consumer * the function to invoke */ public void createSubsegment(String name, Consumer<Subsegment> consumer) { Subsegment subsegment = beginSubsegment(name); try { consumer.accept(subsegment); } catch (Exception e) { if (subsegment != null) { subsegment.addException(e); } throw e; } finally { endSubsegment(); } }
/** * Begins a subsegment, runs the provided runnable, and ends the subsegment once complete. Intercepts exceptions, adds them to the subsegment, and re-throws them. * * @param name * the name to use for the created subsegment * @param runnable * the runnable to run */ public void createSubsegment(String name, Runnable runnable) { Subsegment subsegment = beginSubsegment(name); try { runnable.run(); } catch (Exception e) { if (subsegment != null) { subsegment.addException(e); } throw e; } finally { endSubsegment(); } }
/** * Begins a subsegment, runs the provided runnable, and ends the subsegment once complete. Intercepts exceptions, adds them to the subsegment, and re-throws them. * * @param name * the name to use for the created subsegment * @param runnable * the runnable to run */ public void createSubsegment(String name, Runnable runnable) { Subsegment subsegment = beginSubsegment(name); try { runnable.run(); } catch (Exception e) { if (subsegment != null) { subsegment.addException(e); } throw e; } finally { endSubsegment(); } }
/** * Begins a subsegment and passes it to the supplied consumer. Intercepts exceptions, adds them to the subsegment, and re-throws them. * * @param name * the name to use for the created subsegment * @param consumer * the function to invoke */ public void createSubsegment(String name, Consumer<Subsegment> consumer) { Subsegment subsegment = beginSubsegment(name); try { consumer.accept(subsegment); } catch (Exception e) { if (subsegment != null) { subsegment.addException(e); } throw e; } finally { endSubsegment(); } }
/** * Begins a subsegment, passes it to the supplied function, and ends the subsegment before returning the supplied function's result. Intercepts exceptions, adds them to the subsegment, and re-throws them. * * @param <R> * the type of the value returned by {@code function} * @param name * the name to use for the created subsegment * @param function * the function to invoke * @return the value returned by the supplied function */ public <R> R createSubsegment(String name, Function<Subsegment, R> function) { Subsegment subsegment = beginSubsegment(name); try { return function.apply(subsegment); } catch (Exception e) { if (subsegment != null) { subsegment.addException(e); } throw e; } finally { endSubsegment(); } }
/** * Begins a subsegment, passes it to the provided supplier, and ends the subsegment before returning the supplier's result. Intercepts exceptions, adds them to the subsegment, and re-throws them. * * @param <R> * the type of the value returned by {@code function} * @param name * the name to use for the created subsegment * @param supplier * the supplier to invoke * @return the value returned by the provided supplier */ public <R> R createSubsegment(String name, Supplier<R> supplier) { Subsegment subsegment = beginSubsegment(name); try { return supplier.get(); } catch (Exception e) { if (subsegment != null) { subsegment.addException(e); } throw e; } finally { endSubsegment(); } }
/** * Begins a subsegment, passes it to the supplied function, and ends the subsegment before returning the supplied function's result. Intercepts exceptions, adds them to the subsegment, and re-throws them. * * @param <R> * the type of the value returned by {@code function} * @param name * the name to use for the created subsegment * @param function * the function to invoke * @return the value returned by the supplied function */ public <R> R createSubsegment(String name, Function<Subsegment, R> function) { Subsegment subsegment = beginSubsegment(name); try { return function.apply(subsegment); } catch (Exception e) { if (subsegment != null) { subsegment.addException(e); } throw e; } finally { endSubsegment(); } }
/** * Begins a subsegment, passes it to the provided supplier, and ends the subsegment before returning the supplier's result. Intercepts exceptions, adds them to the subsegment, and re-throws them. * * @param <R> * the type of the value returned by {@code function} * @param name * the name to use for the created subsegment * @param supplier * the supplier to invoke * @return the value returned by the provided supplier */ public <R> R createSubsegment(String name, Supplier<R> supplier) { Subsegment subsegment = beginSubsegment(name); try { return supplier.get(); } catch (Exception e) { if (subsegment != null) { subsegment.addException(e); } throw e; } finally { endSubsegment(); } }
subsegment.addException(t);
@Override public CloseableHttpResponse execute(HttpHost target, HttpRequest request, HttpContext context) throws IOException, ClientProtocolException { Subsegment subsegment = getRecorder().beginSubsegment(target.getHostName()); try { if (null != subsegment) { TracedHttpClient.addRequestInformation(subsegment, request, TracedHttpClient.getUrl(target, request)); } CloseableHttpResponse response = super.execute(target, request, context); if (null != subsegment) { TracedResponseHandler.addResponseInformation(subsegment, response); } return response; } catch (Exception e) { if (null != subsegment) { subsegment.addException(e); } throw e; } finally { if (null != subsegment) { getRecorder().endSubsegment(); } } }
@Override public CloseableHttpResponse execute(HttpHost target, HttpRequest request) throws IOException, ClientProtocolException { Subsegment subsegment = getRecorder().beginSubsegment(target.getHostName()); try { if (null != subsegment) { TracedHttpClient.addRequestInformation(subsegment, request, TracedHttpClient.getUrl(target, request)); } CloseableHttpResponse response = super.execute(target, request); if (null != subsegment) { TracedResponseHandler.addResponseInformation(subsegment, response); } return response; } catch (Exception e) { if (null != subsegment) { subsegment.addException(e); } throw e; } finally { if (null != subsegment) { getRecorder().endSubsegment(); } } }
@Override public CloseableHttpResponse execute(HttpHost target, HttpRequest request, HttpContext context) throws IOException, ClientProtocolException { Subsegment subsegment = getRecorder().beginSubsegment(target.getHostName()); try { if (null != subsegment) { TracedHttpClient.addRequestInformation(subsegment, request, TracedHttpClient.getUrl(target, request)); } CloseableHttpResponse response = super.execute(target, request, context); if (null != subsegment) { TracedResponseHandler.addResponseInformation(subsegment, response); } return response; } catch (Exception e) { if (null != subsegment) { subsegment.addException(e); } throw e; } finally { if (null != subsegment) { getRecorder().endSubsegment(); } } }
@Override public CloseableHttpResponse execute(HttpHost target, HttpRequest request) throws IOException, ClientProtocolException { Subsegment subsegment = getRecorder().beginSubsegment(target.getHostName()); try { if (null != subsegment) { TracedHttpClient.addRequestInformation(subsegment, request, TracedHttpClient.getUrl(target, request)); } CloseableHttpResponse response = super.execute(target, request); if (null != subsegment) { TracedResponseHandler.addResponseInformation(subsegment, response); } return response; } catch (Exception e) { if (null != subsegment) { subsegment.addException(e); } throw e; } finally { if (null != subsegment) { getRecorder().endSubsegment(); } } }
@Override public CloseableHttpResponse execute(HttpUriRequest request, HttpContext context) throws IOException, ClientProtocolException { Subsegment subsegment = getRecorder().beginSubsegment(TracedHttpClient.determineTarget(request).getHostName()); try { if (null != subsegment) { TracedHttpClient.addRequestInformation(subsegment, request, TracedHttpClient.getUrl(request)); } CloseableHttpResponse response = super.execute(request, context); if (null != subsegment) { TracedResponseHandler.addResponseInformation(subsegment, response); } return response; } catch (Exception e) { if (null != subsegment) { subsegment.addException(e); } throw e; } finally { if (null != subsegment) { getRecorder().endSubsegment(); } } }
@Override public CloseableHttpResponse execute(HttpUriRequest request, HttpContext context) throws IOException, ClientProtocolException { Subsegment subsegment = getRecorder().beginSubsegment(TracedHttpClient.determineTarget(request).getHostName()); try { if (null != subsegment) { TracedHttpClient.addRequestInformation(subsegment, request, TracedHttpClient.getUrl(request)); } CloseableHttpResponse response = super.execute(request, context); if (null != subsegment) { TracedResponseHandler.addResponseInformation(subsegment, response); } return response; } catch (Exception e) { if (null != subsegment) { subsegment.addException(e); } throw e; } finally { if (null != subsegment) { getRecorder().endSubsegment(); } } }
private void populateSubsegmentException(Subsegment subsegment, Context.FailedExecution context) { Throwable exception = context.exception(); subsegment.addException(exception); int statusCode = -1; if (exception instanceof SdkServiceException) { statusCode = ((SdkServiceException) exception).statusCode(); subsegment.getCause().setMessage(exception.getMessage()); if (((SdkServiceException) exception).isThrottlingException()) { subsegment.setThrottle(true); // throttling errors are considered client-side errors subsegment.setError(true); } setRemoteForException(subsegment, exception); } else if (context.httpResponse().isPresent()) { statusCode = context.httpResponse().get().statusCode(); } if (statusCode == -1) { return; } if (statusCode >= 400 && statusCode < 500) { subsegment.setFault(false); subsegment.setError(true); if (statusCode == 429) { subsegment.setThrottle(true); } } else if (statusCode >= 500) { subsegment.setFault(true); } }
private void populateSubsegmentException(Subsegment subsegment, Context.FailedExecution context) { Throwable exception = context.exception(); subsegment.addException(exception); int statusCode = -1; if (exception instanceof SdkServiceException) { statusCode = ((SdkServiceException) exception).statusCode(); subsegment.getCause().setMessage(exception.getMessage()); if (((SdkServiceException) exception).isThrottlingException()) { subsegment.setThrottle(true); // throttling errors are considered client-side errors subsegment.setError(true); } setRemoteForException(subsegment, exception); } else if (context.httpResponse().isPresent()) { statusCode = context.httpResponse().get().statusCode(); } if (statusCode == -1) { return; } if (statusCode >= 400 && statusCode < 500) { subsegment.setFault(false); subsegment.setError(true); if (statusCode == 429) { subsegment.setThrottle(true); } } else if (statusCode >= 500) { subsegment.setFault(true); } }