private void addGKEAttributes()

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


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

    Optional.ofNullable(attributesMap.get(GKE_CLUSTER_NAME))
        .ifPresent(
            clusterName -> attrBuilder.put(ResourceAttributes.K8S_CLUSTER_NAME, clusterName));
    Optional.ofNullable(attributesMap.get(GKE_HOST_ID))
        .ifPresent(hostId -> attrBuilder.put(ResourceAttributes.HOST_ID, hostId));
    Optional.ofNullable(attributesMap.get(GKE_CLUSTER_LOCATION_TYPE))
        .ifPresent(
            locationType -> {
              if (attributesMap.get(GKE_CLUSTER_LOCATION) != null) {
                switch (locationType) {
                  case GKE_LOCATION_TYPE_REGION:
                    attrBuilder.put(
                        ResourceAttributes.CLOUD_REGION, attributesMap.get(GKE_CLUSTER_LOCATION));
                    break;
                  case GKE_LOCATION_TYPE_ZONE:
                    attrBuilder.put(
                        ResourceAttributes.CLOUD_AVAILABILITY_ZONE,
                        attributesMap.get(GKE_CLUSTER_LOCATION));
                  default:
                    // TODO: Figure out how to handle unexpected conditions like this - Issue #183
                    LOGGER.severe(
                        String.format(
                            "Unrecognized format for cluster location: %s",
                            attributesMap.get(GKE_CLUSTER_LOCATION)));
                }
              }
            });
  }