Search in sources :

Example 1 with SegmentContext

use of com.amazonaws.xray.contexts.SegmentContext in project aws-xray-sdk-java by aws.

the class AWSXRayRecorder method beginSegment.

private Segment beginSegment(Segment segment) {
    SegmentContext context = getSegmentContext();
    if (null == context) {
        return null;
    }
    Entity current;
    if ((current = getTraceEntity()) != null) {
        logger.error("Beginning new segment while another segment exists in the segment context. Overwriting current segment named '" + current.getName() + "' to start new segment named '" + segment.getName() + "'.");
    }
    segment.setAws(getAwsRuntimeContext());
    if (null != getOrigin()) {
        segment.setOrigin(getOrigin());
    }
    segment.putAllService(getServiceRuntimeContext());
    setTraceEntity(segment);
    return context.beginSegment(this, segment);
}
Also used : SegmentContext(com.amazonaws.xray.contexts.SegmentContext)

Example 2 with SegmentContext

use of com.amazonaws.xray.contexts.SegmentContext in project aws-xray-sdk-java by aws.

the class AWSXRayRecorder method currentTraceId.

/**
 * @throws SegmentNotFoundException
 *             if {@code contextMissingStrategy} throws exceptions and no segment or subsegment is currently in progress
 * @return the trace ID of the {@code Segment} currently in progress, or {@code null} if {@code contextMissingStrategy} suppresses exceptions and no segment or subsegment is currently in progress
 */
public TraceID currentTraceId() {
    SegmentContext context = getSegmentContext();
    if (null == context) {
        return null;
    }
    Entity current = context.getTraceEntity();
    if (null != current) {
        return current.getParentSegment().getTraceId();
    } else {
        contextMissingStrategy.contextMissing("Failed to get current trace ID: segment cannot be found.", SegmentNotFoundException.class);
        return null;
    }
}
Also used : SegmentContext(com.amazonaws.xray.contexts.SegmentContext)

Example 3 with SegmentContext

use of com.amazonaws.xray.contexts.SegmentContext in project aws-xray-sdk-java by aws.

the class AWSXRayRecorder method setTraceEntity.

/**
 * Sets the trace entity value using the implementation provided by the SegmentContext resolved from the segmentContextResolverChain.
 *
 * @param entity
 *            the trace entity to set
 */
public void setTraceEntity(Entity entity) {
    SegmentContext context = getSegmentContext();
    if (null == context) {
        return;
    }
    context.setTraceEntity(entity);
}
Also used : SegmentContext(com.amazonaws.xray.contexts.SegmentContext)

Example 4 with SegmentContext

use of com.amazonaws.xray.contexts.SegmentContext in project aws-xray-sdk-java by aws.

the class AWSXRayRecorder method getCurrentSubsegmentOptional.

/**
 * @return the current subsegment, or {@code Optional.empty()} if there is no subsegment
 */
public Optional<Subsegment> getCurrentSubsegmentOptional() {
    // explicitly do not throw context missing exceptions from optional-returning methods
    SegmentContext context = segmentContextResolverChain.resolve();
    if (null == context) {
        return Optional.empty();
    }
    Entity current = context.getTraceEntity();
    if (current instanceof Subsegment) {
        return Optional.of((Subsegment) current);
    } else {
        return Optional.empty();
    }
}
Also used : SegmentContext(com.amazonaws.xray.contexts.SegmentContext)

Example 5 with SegmentContext

use of com.amazonaws.xray.contexts.SegmentContext in project aws-xray-sdk-java by aws.

the class AWSXRayRecorder method clearTraceEntity.

/**
 * Clears the current trace entity value using the implementation provided by the SegmentContext resolved from the segmentContextResolverChain.
 */
public void clearTraceEntity() {
    SegmentContext context = getSegmentContext();
    if (null == context) {
        return;
    }
    context.clearTraceEntity();
}
Also used : SegmentContext(com.amazonaws.xray.contexts.SegmentContext)

Aggregations

SegmentContext (com.amazonaws.xray.contexts.SegmentContext)9 SubsegmentNotFoundException (com.amazonaws.xray.exceptions.SubsegmentNotFoundException)1