Skip to content

Commit

Permalink
fix(otel): Monitored Resource with task_id for Cloud Run
Browse files Browse the repository at this point in the history
Fixes googleapis#14925

When inside a Cloud Run environment, the `MonitoredResource` in a `CreateTimeSeriesRequest` to the Cloud Monitoring API does not include the necessary fields for the `generic_task` resource type, and is rejected.

Should follow the well-tested Golang implementation where the `faas.instance` OTel Resource Attribute is mapped to `MonitoredResource` `task_id`. As the `service.namespace` OTel Resource Attribute is not set by the Resource Detector from within Cloud Run, it should be mapped as an empty string, rather than being left absent.

https://github.com/GoogleCloudPlatform/opentelemetry-operations-go/blob/8da0f42dab085c916987891419461d583a2aa96e/internal/resourcemapping/resourcemapping.go#L153
  • Loading branch information
DouglasHeriot committed Jan 10, 2025
1 parent bbb1355 commit 644efe9
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions google/cloud/opentelemetry/internal/monitored_resource.cc
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ class MonitoredResourceProvider {
mr.labels[kv.first] = AsString(attributes.at(*found));
} else if (kv.second.fallback) {
mr.labels[kv.first] = *kv.second.fallback;
} else {
mr.labels[kv.first] = "";
}
}
return mr;
Expand Down Expand Up @@ -162,8 +164,8 @@ MonitoredResourceProvider GenericTask() {
{"location",
{{sc::kCloudAvailabilityZone, sc::kCloudRegion}, "global"}},
{"namespace", {{sc::kServiceNamespace}}},
{"job", {{sc::kServiceName}}},
{"task_id", {{sc::kServiceInstanceId}}},
{"job", {{sc::kServiceName, sc::kFaasName}}},
{"task_id", {{sc::kServiceInstanceId, sc::kFaasInstance}}},
});
}

Expand All @@ -174,7 +176,7 @@ MonitoredResourceProvider GenericNode() {
{"location",
{{sc::kCloudAvailabilityZone, sc::kCloudRegion}, "global"}},
{"namespace", {{sc::kServiceNamespace}}},
{"node_id", {{sc::kHostId}}},
{"node_id", {{sc::kHostId, sc::kHostName}}},
});
}

Expand Down

0 comments on commit 644efe9

Please sign in to comment.