/** * Begins a segment and passes it to the supplied consumer. Intercepts exceptions, adds them to the segment, and re-throws them. * * @param name * the name to use for the created segment * @param consumer * the function to invoke */ public void createSegment(String name, Consumer<Segment> consumer) { Segment segment = beginSegment(name); try { consumer.accept(segment); } catch (Exception e) { segment.addException(e); throw e; } finally { endSegment(); } }
/** * Begins a segment, runs the provided runnable, and ends the segment before returning the supplier's result. Intercepts exceptions, adds them to the segment, and re-throws them. * * @param name * the name to use for the created segment * @param runnable * the runnable to run */ public void createSegment(String name, Runnable runnable) { Segment segment = beginSegment(name); try { runnable.run(); } catch (Exception e) { segment.addException(e); throw e; } finally { endSegment(); } }
/** * Begins a segment, runs the provided runnable, and ends the segment before returning the supplier's result. Intercepts exceptions, adds them to the segment, and re-throws them. * * @param name * the name to use for the created segment * @param runnable * the runnable to run */ public void createSegment(String name, Runnable runnable) { Segment segment = beginSegment(name); try { runnable.run(); } catch (Exception e) { segment.addException(e); throw e; } finally { endSegment(); } }
/** * Begins a segment and passes it to the supplied consumer. Intercepts exceptions, adds them to the segment, and re-throws them. * * @param name * the name to use for the created segment * @param consumer * the function to invoke */ public void createSegment(String name, Consumer<Segment> consumer) { Segment segment = beginSegment(name); try { consumer.accept(segment); } catch (Exception e) { segment.addException(e); throw e; } finally { endSegment(); } }
@Around("queryExecution()") public Object traceSQL(ProceedingJoinPoint pjp) throws Throwable { try { Subsegment subsegment = AWSXRay.beginSubsegment(pjp.getSignature().getName()); XRayInterceptorUtils.generateMetadata(pjp, subsegment); return XRayInterceptorUtils.conditionalProceed(pjp); } catch (Exception e) { logger.error(e.getMessage()); AWSXRay.getCurrentSegment().addException(e); throw e; } finally { logger.trace("Ending Subsegment"); AWSXRay.endSubsegment(); } }
/** * Begins a segment, invokes the provided supplier, and ends the segment before returning the supplier's result. Intercepts exceptions, adds them to the segment, and re-throws them. * * @param <R> * the type of the value returned by {@code supplier} * @param name * the name to use for the created segment * @param supplier * the supplier to invoke * @return the value returned by the provided supplier */ public <R> R createSegment(String name, Supplier<R> supplier) { Segment segment = beginSegment(name); try { return supplier.get(); } catch (Exception e) { segment.addException(e); throw e; } finally { endSegment(); } }
/** * Begins a segment, passes it to the supplied function, and ends the segment before returning the supplied function's result. Intercepts exceptions, adds them to the segment, and re-throws them. * * @param <R> * the type of the value returned by {@code function} * @param name * the name to use for the created segment * @param function * the function to invoke * @return the value returned by the supplied function */ public <R> R createSegment(String name, Function<Segment, R> function) { Segment segment = beginSegment(name); try { return function.apply(segment); } catch (Exception e) { segment.addException(e); throw e; } finally { endSegment(); } }
/** * Begins a segment, passes it to the supplied function, and ends the segment before returning the supplied function's result. Intercepts exceptions, adds them to the segment, and re-throws them. * * @param <R> * the type of the value returned by {@code function} * @param name * the name to use for the created segment * @param function * the function to invoke * @return the value returned by the supplied function */ public <R> R createSegment(String name, Function<Segment, R> function) { Segment segment = beginSegment(name); try { return function.apply(segment); } catch (Exception e) { segment.addException(e); throw e; } finally { endSegment(); } }
/** * Begins a segment, invokes the provided supplier, and ends the segment before returning the supplier's result. Intercepts exceptions, adds them to the segment, and re-throws them. * * @param <R> * the type of the value returned by {@code supplier} * @param name * the name to use for the created segment * @param supplier * the supplier to invoke * @return the value returned by the provided supplier */ public <R> R createSegment(String name, Supplier<R> supplier) { Segment segment = beginSegment(name); try { return supplier.get(); } catch (Exception e) { segment.addException(e); throw e; } finally { endSegment(); } }
@Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { if (logger.isDebugEnabled()) { logger.debug("AWSXRayServletFilter is beginning to process request: " + request.toString()); } Segment segment = preFilter(request, response); try { chain.doFilter(request, response); } catch (Exception e) { if (null != segment) { segment.addException(e); } throw e; } finally { if (request.isAsyncStarted()) { request.setAttribute(AWSXRayServletAsyncListener.ENTITY_ATTRIBUTE_KEY, segment); try { request.getAsyncContext().addListener(listener); } catch (IllegalStateException ise) { // race condition that occurs when async processing finishes before adding the listener postFilter(request, response); } } else { postFilter(request, response); } if (logger.isDebugEnabled()) { logger.debug("AWSXRayServletFilter is finished processing request: " + request.toString()); } } }
protected Object processXRayTrace(ProceedingJoinPoint pjp) throws Throwable { try { Subsegment subsegment = AWSXRay.beginSubsegment(pjp.getSignature().getName()); if(subsegment != null) { subsegment.setMetadata(generateMetadata(pjp, subsegment)); } return XRayInterceptorUtils.conditionalProceed(pjp); } catch (Exception e) { AWSXRay.getCurrentSegment().addException(e); throw e; } finally { logger.trace("Ending Subsegment"); AWSXRay.endSubsegment(); } }
@Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { if (logger.isDebugEnabled()) { logger.debug("AWSXRayServletFilter is beginning to process request: " + request.toString()); } Segment segment = preFilter(request, response); try { chain.doFilter(request, response); } catch (Exception e) { if (null != segment) { segment.addException(e); } throw e; } finally { if (request.isAsyncStarted()) { request.setAttribute(AWSXRayServletAsyncListener.ENTITY_ATTRIBUTE_KEY, segment); try { request.getAsyncContext().addListener(listener); recorder.clearTraceEntity(); } catch (IllegalStateException ise) { // race condition that occurs when async processing finishes before adding the listener postFilter(request, response); } } else { postFilter(request, response); } if (logger.isDebugEnabled()) { logger.debug("AWSXRayServletFilter is finished processing request: " + request.toString()); } } }