private void addGCEAttributes()

in detectors/resources/src/main/java/com/google/cloud/opentelemetry/detectors/GCPResource.java [108:131]


  private void addGCEAttributes(AttributesBuilder attrBuilder, Map<String, String> attributesMap) {
    attrBuilder.put(
        ResourceAttributes.CLOUD_PLATFORM,
        ResourceAttributes.CloudPlatformValues.GCP_COMPUTE_ENGINE);

    Optional.ofNullable(attributesMap.get(GCE_AVAILABILITY_ZONE))
        .ifPresent(zone -> attrBuilder.put(ResourceAttributes.CLOUD_AVAILABILITY_ZONE, zone));
    Optional.ofNullable(attributesMap.get(GCE_CLOUD_REGION))
        .ifPresent(region -> attrBuilder.put(ResourceAttributes.CLOUD_REGION, region));
    Optional.ofNullable(attributesMap.get(GCE_INSTANCE_ID))
        .ifPresent(instanceId -> attrBuilder.put(ResourceAttributes.HOST_ID, instanceId));
    Optional.ofNullable(attributesMap.get(GCE_INSTANCE_NAME))
        .ifPresent(
            instanceName -> {
              attrBuilder.put(ResourceAttributes.HOST_NAME, instanceName);
              attrBuilder.put(ResourceAttributes.GCP_GCE_INSTANCE_NAME, instanceName);
            });
    Optional.ofNullable(attributesMap.get(GCE_INSTANCE_HOSTNAME))
        .ifPresent(
            instanceHostname ->
                attrBuilder.put(ResourceAttributes.GCP_GCE_INSTANCE_HOSTNAME, instanceHostname));
    Optional.ofNullable(attributesMap.get(GCE_MACHINE_TYPE))
        .ifPresent(machineType -> attrBuilder.put(ResourceAttributes.HOST_TYPE, machineType));
  }