Skip to content

Commit

Permalink
fix(otel): Exporter creating Monitored Resource with task_id for Clou…
Browse files Browse the repository at this point in the history
…d Run

Fixes googleapis#14925

When inside a Cloud Run environment, the [`MonitoredResource`](https://cloud.google.com/monitoring/api/ref_v3/rpc/google.monitoring.v3#google.monitoring.v3.TimeSeries) in a [`CreateTimeSeriesRequest`](https://cloud.google.com/monitoring/api/ref_v3/rpc/google.monitoring.v3#google.monitoring.v3.CreateTimeSeriesRequest) to the Cloud Monitoring API does not include the necessary fields for the [`generic_task`](https://cloud.google.com/monitoring/api/resources#tag_generic_task) resource type, and is rejected.

Should follow the [well-tested Golang implementation](https://github.com/GoogleCloudPlatform/opentelemetry-operations-go/blob/8da0f42dab085c916987891419461d583a2aa96e/internal/resourcemapping/resourcemapping.go#L153) 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 (as in [golang implementation](https://github.com/GoogleCloudPlatform/opentelemetry-operations-go/blob/8da0f42dab085c916987891419461d583a2aa96e/internal/resourcemapping/resourcemapping.go#L250)), rather than being left absent.
  • Loading branch information
DouglasHeriot committed Jan 10, 2025
1 parent bbb1355 commit 7a8688d
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 7a8688d

Please sign in to comment.