use of com.amazonaws.xray.exceptions.SubsegmentNotFoundException in project aws-xray-sdk-java by aws.
the class LambdaSegmentContext method endSubsegment.
@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;
currentSubsegment.end();
if (recorder.getStreamingStrategy().requiresStreaming(currentSubsegment.getParentSegment())) {
recorder.getStreamingStrategy().streamSome(currentSubsegment.getParentSegment(), recorder.getEmitter());
}
Entity parentEntity = current.getParent();
if (parentEntity instanceof FacadeSegment) {
if (((FacadeSegment) parentEntity).isSampled()) {
current.getCreator().getEmitter().sendSubsegment((Subsegment) current);
}
clearTraceEntity();
} else {
setTraceEntity(current.getParent());
}
} else {
throw new SubsegmentNotFoundException("Failed to end a subsegment: subsegment cannot be found.");
}
}
use of com.amazonaws.xray.exceptions.SubsegmentNotFoundException in project aws-xray-sdk-java by aws.
the class AWSXRayRecorder method getCurrentSubsegment.
/**
* @throws SegmentNotFoundException
* if {@code contextMissingStrategy} throws exceptions and the segment context cannot be found
* @throws SubsegmentNotFoundException
* if {@code contextMissingStrategy} throws exceptions and the current segment has no subsegments in progress
* @return the current subsegment, or {@code null} if {@code contextMissingStrategy} suppresses exceptions and the segment context cannot be found or the segment has no subsegments in progress
*/
public Subsegment getCurrentSubsegment() {
SegmentContext context = getSegmentContext();
if (null == context) {
return null;
}
Entity current = context.getTraceEntity();
if (null == current) {
contextMissingStrategy.contextMissing("No segment in progress.", SegmentNotFoundException.class);
} else if (current instanceof Subsegment) {
return (Subsegment) current;
} else {
contextMissingStrategy.contextMissing("No subsegment in progress.", SubsegmentNotFoundException.class);
}
return null;
}
Aggregations