in aws-xray-recorder-sdk-core/src/main/java/com/amazonaws/xray/utils/DockerUtils.java [65:98]
public String getContainerId() throws IOException {
if (cgroupLocation == null) {
return null;
}
final File procFile;
try {
procFile = new File(cgroupLocation.toURI());
} catch (URISyntaxException e) {
logger.warn("Failed to read container ID because " + cgroupLocation.toString() + " didn't contain an ID.");
return null;
}
if (procFile.exists()) {
try (InputStream inputStream = new FileInputStream(procFile);
BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream, StandardCharsets.UTF_8))) {
String line;
do {
line = reader.readLine();
if (line == null) {
logger.warn("Failed to read container ID because " + cgroupLocation.toString()
+ " didn't contain an ID.");
} else if (line.length() > CONTAINER_ID_LENGTH) {
return line.substring(line.length() - CONTAINER_ID_LENGTH);
}
} while (line != null);
}
} else {
logger.warn("Failed to read container ID because " + cgroupLocation.toString() + " does not exist.");
}
return null;
}