From caefa6a7d46fc45d0b87cab75414576f63a96995 Mon Sep 17 00:00:00 2001 From: Yuchen Ying Date: Tue, 24 Nov 2020 02:29:56 -0800 Subject: [PATCH] Hardcode service.namespace label to cloud-run-managed per review discussion. --- detectors/gcp/cloud-run.go | 7 ++++++- detectors/gcp/cloud-run_test.go | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/detectors/gcp/cloud-run.go b/detectors/gcp/cloud-run.go index bceac97d1bb..78757dae195 100644 --- a/detectors/gcp/cloud-run.go +++ b/detectors/gcp/cloud-run.go @@ -26,6 +26,8 @@ import ( "go.opentelemetry.io/otel/semconv" ) +const serviceNamespace = "cloud-run-managed" + type metadataClient interface { ProjectID() (string, error) Get(string) (string, error) @@ -60,6 +62,9 @@ func (c *CloudRun) setupForTest(mc metadataClient, ongce func() bool, getenv fun } // Detect detects associated resources when running on Cloud Run hosts. +// NOTE: the service.namespace label is currently hardcoded to be +// "cloud-run-managed". This may change in the future, please do not rely on +// this behavior yet. func (c *CloudRun) Detect(ctx context.Context) (*resource.Resource, error) { // .OnGCE is actually testing whether the metadata server is available. // Metadata server is supported on Cloud Run. @@ -99,7 +104,7 @@ func (c *CloudRun) Detect(ctx context.Context) (*resource.Resource, error) { errInfo = append(errInfo, "envvar K_SERVICE contains empty string.") } else { labels = append(labels, - semconv.ServiceNamespaceKey.String(service), + semconv.ServiceNamespaceKey.String(serviceNamespace), semconv.ServiceNameKey.String(service), ) } diff --git a/detectors/gcp/cloud-run_test.go b/detectors/gcp/cloud-run_test.go index c1683484f11..ac4f199008f 100644 --- a/detectors/gcp/cloud-run_test.go +++ b/detectors/gcp/cloud-run_test.go @@ -90,7 +90,7 @@ func TestCloudRunDetectorExpectSuccess(t *testing.T) { label.String("cloud.region", "utopia"), label.String("service.instance.id", "bar"), label.String("service.name", "x-service"), - label.String("service.namespace", "x-service"), + label.String("service.namespace", "cloud-run-managed"), ) c := NewCloudRun() c.setupForTest(&client{m: metadata}, onGCE, getenv(envvars))