private static ContextMissingStrategy getContextMissingStrategy() { return AWSXRay.getGlobalRecorder().getContextMissingStrategy(); }
/** * Checks if the entity has already been emitted to the X-Ray daemon. * * @throws AlreadyEmittedException * if the entity has already been emitted to the X-Ray daemon and the ContextMissingStrategy of the AWSXRayRecorder used to create this entity is configured to throw exceptions * */ protected void checkAlreadyEmitted() { if (emitted) { getCreator().getContextMissingStrategy().contextMissing("Segment " + getName() + " has already been emitted.", AlreadyEmittedException.class); } }
/** * Checks if the entity has already been emitted to the X-Ray daemon. * * @throws AlreadyEmittedException * if the entity has already been emitted to the X-Ray daemon and the ContextMissingStrategy of the AWSXRayRecorder used to create this entity is configured to throw exceptions * */ protected void checkAlreadyEmitted() { if (emitted) { getCreator().getContextMissingStrategy().contextMissing("Segment " + getName() + " has already been emitted.", AlreadyEmittedException.class); } }
@Override public Subsegment beginSubsegment(AWSXRayRecorder recorder, String name) { Entity current = getTraceEntity(); if (null == current) { recorder.getContextMissingStrategy().contextMissing("Failed to begin subsegment named '" + name + "': segment cannot be found.", SegmentNotFoundException.class); return null; } if (logger.isDebugEnabled()) { logger.debug("Beginning subsegment named: " + name); } Segment parentSegment = getTraceEntity().getParentSegment(); Subsegment subsegment = new SubsegmentImpl(recorder, name, parentSegment); subsegment.setParent(current); current.addSubsegment(subsegment); setTraceEntity(subsegment); return subsegment; }
@Override public Subsegment beginSubsegment(AWSXRayRecorder recorder, String name) { Entity current = getTraceEntity(); if (null == current) { recorder.getContextMissingStrategy().contextMissing("Failed to begin subsegment named '" + name + "': segment cannot be found.", SegmentNotFoundException.class); return null; } if (logger.isDebugEnabled()) { logger.debug("Beginning subsegment named: " + name); } Segment parentSegment = getTraceEntity().getParentSegment(); Subsegment subsegment = new SubsegmentImpl(recorder, name, parentSegment); subsegment.setParent(current); current.addSubsegment(subsegment); setTraceEntity(subsegment); return subsegment; }
/** * Ends a segment. * * @throws SegmentNotFoundException * if {@code contextMissingStrategy} throws exceptions and no segment is currently in progress */ public void endSegment() { SegmentContext context = getSegmentContext(); if (null != context) { context.endSegment(this); } Entity current; if ((current = getTraceEntity()) != null) { Segment segment = current.getParentSegment(); logger.debug("Ending segment named '" + segment.getName() + "'."); if(segment.end()) { sendSegment(segment); } else { logger.debug("Not emitting segment named '" + segment.getName() + "' as it parents in-progress subsegments."); } clearTraceEntity(); } else { getContextMissingStrategy().contextMissing("Failed to end segment: segment cannot be found.", SegmentNotFoundException.class); } }
/** * Ends a segment. * * @throws SegmentNotFoundException * if {@code contextMissingStrategy} throws exceptions and no segment is currently in progress */ public void endSegment() { SegmentContext context = getSegmentContext(); if (null != context) { context.endSegment(this); } Entity current; if ((current = getTraceEntity()) != null) { Segment segment = current.getParentSegment(); logger.debug("Ending segment named '" + segment.getName() + "'."); if(segment.end()) { sendSegment(segment); } else { logger.debug("Not emitting segment named '" + segment.getName() + "' as it parents in-progress subsegments."); } clearTraceEntity(); } else { getContextMissingStrategy().contextMissing("Failed to end segment: segment cannot be found.", SegmentNotFoundException.class); } }
@Override public void endSubsegment(AWSXRayRecorder recorder) { Entity current = getTraceEntity(); if (current instanceof Subsegment) { if (logger.isDebugEnabled()) { logger.debug("Ending subsegment named: " + current.getName()); } Subsegment currentSubsegment = (Subsegment) current; if (currentSubsegment.end()) { recorder.sendSegment(currentSubsegment.getParentSegment()); } else { if (recorder.getStreamingStrategy().requiresStreaming(currentSubsegment.getParentSegment())) { recorder.getStreamingStrategy().streamSome(currentSubsegment.getParentSegment(), recorder.getEmitter()); } setTraceEntity(current.getParent()); } } else { recorder.getContextMissingStrategy().contextMissing("Failed to end subsegment: subsegment cannot be found.", SubsegmentNotFoundException.class); } } }
@Override public void endSubsegment(AWSXRayRecorder recorder) { Entity current = getTraceEntity(); if (current instanceof Subsegment) { if (logger.isDebugEnabled()) { logger.debug("Ending subsegment named: " + current.getName()); } Subsegment currentSubsegment = (Subsegment) current; if (currentSubsegment.end()) { recorder.sendSegment(currentSubsegment.getParentSegment()); } else { if (recorder.getStreamingStrategy().requiresStreaming(currentSubsegment.getParentSegment())) { recorder.getStreamingStrategy().streamSome(currentSubsegment.getParentSegment(), recorder.getEmitter()); } setTraceEntity(current.getParent()); } } else { recorder.getContextMissingStrategy().contextMissing("Failed to end subsegment: subsegment cannot be found.", SubsegmentNotFoundException.class); } } }