Search in sources :

Example 1 with SubsegmentNotFoundException

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.");
    }
}
Also used : Entity(com.amazonaws.xray.entities.Entity) SubsegmentNotFoundException(com.amazonaws.xray.exceptions.SubsegmentNotFoundException) Subsegment(com.amazonaws.xray.entities.Subsegment) FacadeSegment(com.amazonaws.xray.entities.FacadeSegment)

Example 2 with SubsegmentNotFoundException

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;
}
Also used : SegmentContext(com.amazonaws.xray.contexts.SegmentContext) SubsegmentNotFoundException(com.amazonaws.xray.exceptions.SubsegmentNotFoundException)

Aggregations

SubsegmentNotFoundException (com.amazonaws.xray.exceptions.SubsegmentNotFoundException)2 SegmentContext (com.amazonaws.xray.contexts.SegmentContext)1 Entity (com.amazonaws.xray.entities.Entity)1 FacadeSegment (com.amazonaws.xray.entities.FacadeSegment)1 Subsegment (com.amazonaws.xray.entities.Subsegment)1