in aws-xray-agent/src/main/java/com/amazonaws/xray/agent/runtime/handlers/XRayHandler.java [72:98]
protected Segment beginSegment(String segmentName, @Nullable TraceID traceID, @Nullable String parentID) {
Segment segment;
if (traceID == null || parentID == null) {
segment = AWSXRay.beginSegment(segmentName);
} else {
segment = AWSXRay.beginSegment(segmentName, traceID, parentID);
}
Map<String, Object> awsMap = segment.getAws();
if (awsMap == null) {
// If this is null, the global recorder wasn't properly initialized. Just ignore putting in the version
// altogether, log this, and continue along.
log.error("Unable to retrieve AWS map to set the auto instrumentation flag.");
return segment;
}
Map<String, Object> xrayMap = (Map<String, Object>) awsMap.get(XRAY_AWS_KEY);
if (xrayMap != null) {
Map<String, Object> agentMap = new HashMap<>(xrayMap);
agentMap.put(AUTO_INSTRUMENTATION_KEY, true);
segment.putAws(XRAY_AWS_KEY, Collections.unmodifiableMap(agentMap));
} else {
log.debug("Unable to retrieve X-Ray attribute map from segment.");
}
return segment;
}