Skip to content

Commit e5f4d84

Browse files
committed
Fix GoogleCloudPlatform#258 enable mapping when not gcp kubernetes
1 parent da9f225 commit e5f4d84

File tree

2 files changed

+488
-2
lines changed

2 files changed

+488
-2
lines changed

shared/resourcemapping/src/main/java/com/google/cloud/opentelemetry/resource/ResourceTranslator.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,13 +153,22 @@ public static GcpResource mapResource(Resource resource) {
153153
switch (platform) {
154154
case ResourceAttributes.CloudPlatformValues.GCP_COMPUTE_ENGINE:
155155
return mapBase(resource, "gce_instance", GCE_INSTANCE_LABELS);
156-
case ResourceAttributes.CloudPlatformValues.GCP_KUBERNETES_ENGINE:
157-
return mapBase(resource, "k8s_container", K8S_CONTAINER_LABELS);
158156
case ResourceAttributes.CloudPlatformValues.AWS_EC2:
159157
return mapBase(resource, "aws_ec2_instance", AWS_EC2_INSTANCE_LABELS);
160158
case ResourceAttributes.CloudPlatformValues.GCP_APP_ENGINE:
161159
return mapBase(resource, "gae_instance", GOOGLE_CLOUD_APP_ENGINE_INSTANCE_LABELS);
162160
default:
161+
if (resource.getAttribute(ResourceAttributes.K8S_CLUSTER_NAME) != null) {
162+
if (resource.getAttribute(ResourceAttributes.K8S_CONTAINER_NAME) != null) {
163+
return mapBase(resource, "k8s_container", K8S_CONTAINER_LABELS);
164+
} else if (resource.getAttribute(ResourceAttributes.K8S_POD_NAME) != null) {
165+
return mapBase(resource, "k8s_pod", K8S_CONTAINER_LABELS);
166+
} else if (resource.getAttribute(ResourceAttributes.K8S_NODE_NAME) != null) {
167+
return mapBase(resource, "k8s_node", K8S_CONTAINER_LABELS);
168+
} else {
169+
return mapBase(resource, "k8s_cluster", K8S_CONTAINER_LABELS);
170+
}
171+
}
163172
return genericTaskOrNode(resource);
164173
}
165174
}

0 commit comments

Comments
 (0)