in detectors/resources/src/main/java/com/google/cloud/opentelemetry/detectors/GCPMetadataConfig.java [120:137]
private String fetchAttribute(String attributeName) {
try {
URL url = new URL(this.url + attributeName);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestProperty("Metadata-Flavor", "Google");
if (connection.getResponseCode() == 200
&& ("Google").equals(connection.getHeaderField("Metadata-Flavor"))) {
InputStream input = connection.getInputStream();
try (BufferedReader reader =
new BufferedReader(new InputStreamReader(input, StandardCharsets.UTF_8))) {
return reader.readLine();
}
}
} catch (IOException ignore) {
// ignore
}
return null;
}