// Path: detectors/resources/src/main/java/com/google/cloud/opentelemetry/detectors/GKEResource.java
// public final class GKEResource implements ResourceProvider {
//   private final GCPMetadataConfig metadata;
//   private final EnvVars envVars;
// 
//   public GKEResource() {
//     this.metadata = GCPMetadataConfig.DEFAULT_INSTANCE;
//     this.envVars = EnvVars.DEFAULT_INSTANCE;
//   }
// 
//   // For testing only
//   public GKEResource(GCPMetadataConfig metadataConfig, EnvVars envVars) {
//     this.metadata = metadataConfig;
//     this.envVars = envVars;
//   }
// 
//   public Attributes getAttributes() {
//     GCEResource gce = new GCEResource(this.metadata);
// 
//     Attributes gceAttributes = gce.getAttributes();
// 
//     if (envVars.get("KUBERNETES_SERVICE_HOST") == null) {
//       return gceAttributes;
//     }
// 
//     AttributesBuilder attrBuilders = Attributes.builder();
//     attrBuilders.putAll(gceAttributes);
// 
//     attrBuilders.put(
//         ResourceAttributes.CLOUD_PLATFORM,
//         ResourceAttributes.CloudPlatformValues.GCP_KUBERNETES_ENGINE);
//     String podName = envVars.get("POD_NAME");
//     if (podName != null && !podName.isEmpty()) {
//       attrBuilders.put(ResourceAttributes.K8S_POD_NAME, podName);
//     } else {
//       // If nothing else is set, at least use hostname for pod name.
//       attrBuilders.put(ResourceAttributes.K8S_POD_NAME, envVars.get("HOSTNAME"));
//     }
// 
//     String namespace = envVars.get("NAMESPACE");
//     if (namespace != null && !namespace.isEmpty()) {
//       attrBuilders.put(ResourceAttributes.K8S_NAMESPACE_NAME, namespace);
//     }
// 
//     String containerName = envVars.get("CONTAINER_NAME");
//     if (containerName != null && !containerName.isEmpty()) {
//       attrBuilders.put(ResourceAttributes.K8S_CONTAINER_NAME, containerName);
//     }
// 
//     String clusterName = metadata.getClusterName();
//     if (clusterName != null && !clusterName.isEmpty()) {
//       attrBuilders.put(ResourceAttributes.K8S_CLUSTER_NAME, clusterName);
//     }
// 
//     return attrBuilders.build();
//   }
// 
//   @Override
//   public Resource createResource(ConfigProperties config) {
//     return Resource.create(getAttributes());
//   }
// }


import com.google.cloud.opentelemetry.detectors.GKEResource;
import io.opentelemetry.sdk.autoconfigure.AutoConfiguredOpenTelemetrySdk;
/*
 * Copyright 2022 Google
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.google.cloud.opentelemetry.example.resource;


public class ResourceExample {
  public static void main(String[] args) {
    System.out.println("Detecting resource: Autoconfigure");
    io.opentelemetry.sdk.resources.Resource autoResource =
        AutoConfiguredOpenTelemetrySdk.builder()
            .setResultAsGlobal(false)
            .setServiceClassLoader(ResourceExample.class.getClassLoader())
            .build()
            .getResource();
    System.out.println(autoResource.getAttributes());
    System.out.println("Detecting resource: hardcoded");
// Path: detectors/resources/src/main/java/com/google/cloud/opentelemetry/detectors/GKEResource.java
// public final class GKEResource implements ResourceProvider {
//   private final GCPMetadataConfig metadata;
//   private final EnvVars envVars;
// 
//   public GKEResource() {
//     this.metadata = GCPMetadataConfig.DEFAULT_INSTANCE;
//     this.envVars = EnvVars.DEFAULT_INSTANCE;
//   }
// 
//   // For testing only
//   public GKEResource(GCPMetadataConfig metadataConfig, EnvVars envVars) {
//     this.metadata = metadataConfig;
//     this.envVars = envVars;
//   }
// 
//   public Attributes getAttributes() {
//     GCEResource gce = new GCEResource(this.metadata);
// 
//     Attributes gceAttributes = gce.getAttributes();
// 
//     if (envVars.get("KUBERNETES_SERVICE_HOST") == null) {
//       return gceAttributes;
//     }
// 
//     AttributesBuilder attrBuilders = Attributes.builder();
//     attrBuilders.putAll(gceAttributes);
// 
//     attrBuilders.put(
//         ResourceAttributes.CLOUD_PLATFORM,
//         ResourceAttributes.CloudPlatformValues.GCP_KUBERNETES_ENGINE);
//     String podName = envVars.get("POD_NAME");
//     if (podName != null && !podName.isEmpty()) {
//       attrBuilders.put(ResourceAttributes.K8S_POD_NAME, podName);
//     } else {
//       // If nothing else is set, at least use hostname for pod name.
//       attrBuilders.put(ResourceAttributes.K8S_POD_NAME, envVars.get("HOSTNAME"));
//     }
// 
//     String namespace = envVars.get("NAMESPACE");
//     if (namespace != null && !namespace.isEmpty()) {
//       attrBuilders.put(ResourceAttributes.K8S_NAMESPACE_NAME, namespace);
//     }
// 
//     String containerName = envVars.get("CONTAINER_NAME");
//     if (containerName != null && !containerName.isEmpty()) {
//       attrBuilders.put(ResourceAttributes.K8S_CONTAINER_NAME, containerName);
//     }
// 
//     String clusterName = metadata.getClusterName();
//     if (clusterName != null && !clusterName.isEmpty()) {
//       attrBuilders.put(ResourceAttributes.K8S_CLUSTER_NAME, clusterName);
//     }
// 
//     return attrBuilders.build();
//   }
// 
//   @Override
//   public Resource createResource(ConfigProperties config) {
//     return Resource.create(getAttributes());
//   }
// }


// Path: examples/resource/src/main/java/com/google/cloud/opentelemetry/example/resource/ResourceExample.java
import com.google.cloud.opentelemetry.detectors.GKEResource;
import io.opentelemetry.sdk.autoconfigure.AutoConfiguredOpenTelemetrySdk;

/*
 * Copyright 2022 Google
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.google.cloud.opentelemetry.example.resource;


public class ResourceExample {
  public static void main(String[] args) {
    System.out.println("Detecting resource: Autoconfigure");
    io.opentelemetry.sdk.resources.Resource autoResource =
        AutoConfiguredOpenTelemetrySdk.builder()
            .setResultAsGlobal(false)
            .setServiceClassLoader(ResourceExample.class.getClassLoader())
            .build()
            .getResource();
    System.out.println(autoResource.getAttributes());
    System.out.println("Detecting resource: hardcoded");
    GKEResource resource = new GKEResource();