public Frame exit(FrameBuilder builder) { //if the trace is aborted, decrease the counter by 1. If the current counter is negative //that means that all "overflowed" frames exited the trace and now it's time to exit a real frame. if (isAborted(builder)) { long count = subFrameCount(builder); if (count < 0) { return builder.exit(); } return null; } return builder.exit(); }
private Operation workingOperation() { return builder.peek(); }
public void exitAndDiscard() { builder.setHintIfRoot(FrameBuilder.HINT_DISCARD, Boolean.TRUE); Frame frame = _exitNormal(); if (builder.isFrameInTrace(frame)) { discard(frame); } }
public void markObscured(Object o) { ObscuredValueRegistry registry = builder.getHint(FrameBuilder.HINT_OBSCURED_REGISTRY, ObscuredValueRegistry.class); if (registry == null) { registry = new SimpleObscuredValueRegistry(); builder.setHint(FrameBuilder.HINT_OBSCURED_REGISTRY, registry); } registry.markObscured(o); } }
private void afterEvent(ApplicationName applicationName) { if (insightConfig.isContextIgnored(applicationName)) { frameBuilder.dump(); return; } applicationName = applicationMetaData.getApplicationName(applicationName); String application = applicationMetaData.getLabel(applicationName); frameBuilder.setHintIfRoot(FrameBuilder.HINT_APPNAME, applicationName); Operation operation = frameBuilder.peek(); operation.put("application", application) .label("Application Lifecycle: " + application + " " + operation.get("event")); frameBuilder.exit(); }
private void traceNextValve(Request request, Response response, TraceId traceId) throws IOException, ServletException { Operation operation = new Operation().type(OperationType.HTTP); frameBuilder.enter(operation); // TODO: What happens when this throws an exception? We will never add it to the // frame stack ... // Moreover, if we want to try / finally it, do we have enough valid information // in the response to compose the details? getNext().invoke(request, response); try { ApplicationName appName = getApplication(request); frameBuilder.setHintIfRoot(FrameBuilder.HINT_APPNAME, appName); frameBuilder.setHintIfRoot(FrameBuilder.HINT_TRACEID, traceId); fillInOperation(operation, request, response); frameBuilder.exit(); } catch(Throwable e) { // This can happen when frameBuilder.exit() throws an exception // (for instance with an imbalanced frame stack) if (enableLogging) { log.log(SEVERE, "Exception while logging trace to dispatcher", e); } } }
@Override protected void handleEnter(FrameBuilder builder, Operation op) { boolean aborted = isAborted(builder); if (aborted) { addFrameCount(builder); return; } long totalFrames = builder.getFrameCount(); int insightMaxFrames = getInsightMaxFrames(); //check if we reached overflow state and if so print a warning message and mark the trace as //aborted if (totalFrames >= insightMaxFrames) { Logger.getLogger(getClass().getName()).log(Level.WARNING, "Frame stack exceeded MAX_FRAMES_PER_TRACE limit or has been aborted " + "limit: " + insightMaxFrames + " frameCount: " + totalFrames + " aborted: " + aborted); builder.setHint(FrameBuilder.HINT_ABORTED, Boolean.TRUE); addFrameCount(builder); return; } builder.enter(op); }
private Frame exit() { Frame frame=builder.peekFrame(); /* * If about to exit the root frame and current app. name is not set, * make another try to determine it */ if (builder.isCurrentRootFrame(frame)) { ApplicationName name=builder.getHint(FrameBuilder.HINT_APPNAME, ApplicationName.class); if ((name == null) || ApplicationName.UNKOWN_APPLICATION.equals(name)) { ClassLoader cl=ClassUtil.getDefaultClassLoader(getClass()); name = ClassLoaderUtils.findApplicationName(cl); builder.setHint(FrameBuilder.HINT_APPNAME, name); } } return startegy.exit(builder); } }
@Override public void invoke(Request request, Response response) throws IOException, ServletException { if (insightEnabled == false || insight.isContextIgnored(getApplicationName(request))) { // short circuit all Insight logic // create a faux operation to prevent child frames from appearing as unrooted traces Operation operation = new Operation(); frameBuilder.enter(operation); getNext().invoke(request, response); frameBuilder.dump(); return; } TraceId traceId = interceptConfig.generateNextTraceId(); if (canAddTraceIdResponseHeader()) { addTraceIdResponseHeader(response, traceId); } traceNextValve(request, response, traceId); }
private void beforeEvent(String eventType) { Operation operation = new Operation() .type(TYPE) .put("event", eventType); frameBuilder.enter(operation); }
@SuppressWarnings("unchecked") static LinkedList<StopWatchHolder> getStopWatchStack(FrameBuilder builder) { return builder.getHint(COUNTER_STACK_HINT, LinkedList.class); }
private void discard(Frame frame) { if (frame != null && !frame.isRoot()) { builder.discard(frame); } }
FrameId frameId = FrameId.valueOf(builder.getFrameCount()+1);
long totalFrames = builder.getFrameCount(); builder.enter(op); return; builder.setHint(COUNTER_MAP_HINT, counterMap); builder.setHint(COUNTER_STACK_HINT, stack);
/** * Update frames counter ({@link AbstractAbortTraceOverflowStrategy#addFrameCount(FrameBuilder)} * {@link AbstractAbortTraceOverflowStrategy#subFrameCount(FrameBuilder)}) * * @param builder frame builder * @param count update value * @return current counter value */ protected static final long updateFrameCount(FrameBuilder builder, long count) { MutableLong counter = builder.getHint(COUNTER_FIELD_HINT, MutableLong.class); if (counter == null) { counter = new MutableLong(0L); builder.setHint(COUNTER_FIELD_HINT, counter); } counter.increment(count); long countToreturn = counter.longValue(); //if the current counter value is negative reset it, but still return the negative value if (countToreturn < 0) { counter.set(0L); } return countToreturn; }
@SuppressWarnings("unchecked") static Map<OperationType, CounterHolder> getCounterMap(FrameBuilder builder) { return builder.getHint(COUNTER_MAP_HINT, Map.class); }
public void exitAndDiscard(Object returnValue) { builder.setHintIfRoot(FrameBuilder.HINT_DISCARD, Boolean.TRUE); Frame frame = _exitNormal(returnValue); if (builder.isFrameInTrace(frame)) { discard(frame); } }
/** * Return <code>true</code> if the current trace is aborted * * @param builder current builder * @return <code>true</code> if the current trace is aborted, <code>false</code> otherwise */ protected static final boolean isAborted(FrameBuilder builder) { Boolean hint = builder.getHint(FrameBuilder.HINT_ABORTED, Boolean.class); return hint != null && hint.booleanValue(); }