in aws-xray-recorder-sdk-core/src/main/java/com/amazonaws/xray/AWSXRayRecorder.java [488:520]
private Segment beginSegment(Segment segment) {
SegmentContext context = getSegmentContext();
if (context == null) {
// No context available, we return a no-op segment so user code does not have to work around this. Based on
// ContextMissingStrategy they will still know about the issue unless they explicitly opt-ed out.
return Segment.noOp(segment.getTraceId(), this);
}
Entity current = getTraceEntity();
if (current != 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.putAllAws(getAwsRuntimeContext());
if (origin != null) {
segment.setOrigin(origin);
}
segment.putAllService(getServiceRuntimeContext());
if (logReferences != null && !logReferences.isEmpty()) {
segment.putAws(CW_LOGS_KEY, logReferences);
}
setTraceEntity(segment);
segmentListeners.stream()
.filter(Objects::nonNull)
.forEach(listener -> listener.onBeginSegment(segment));
return context.beginSegment(this, segment);
}