diff --git a/gaelog.go b/gaelog.go index 5ba6fef..030e931 100644 --- a/gaelog.go +++ b/gaelog.go @@ -80,18 +80,18 @@ func newServiceInfo() (serviceInfo, error) { }, nil } - // Try the metadata service for the project ID. - crProjectID, err := projectIDFromMetadataService() - if err != nil { - return serviceInfo{}, err - } - - // We got the project ID, so get and check the env vars expected to be set on Cloud Run. + // Get and check the env vars expected to be set on Cloud Run. crService := os.Getenv("K_SERVICE") crRevision := os.Getenv("K_REVISION") crConfiguration := os.Getenv("K_CONFIGURATION") if crService == "" || crRevision == "" || crConfiguration == "" { - return serviceInfo{}, fmt.Errorf("gaelog: the project ID was fetched from the metadata service so $K_SERVICE, $K_REVISION, and $K_CONFIGURATION are expected to be set, but one or more are not. Falling back to standard library log.") + return serviceInfo{}, fmt.Errorf("gaelog: GAE env vars were not set so Cloud Run vars $K_SERVICE, $K_REVISION, and $K_CONFIGURATION are expected to be set, but one or more are not. Falling back to standard library log.") + } + + // Finally, try the metadata service for the project ID. + crProjectID, err := projectIDFromMetadataService() + if err != nil { + return serviceInfo{}, err } return serviceInfo{ diff --git a/gaelog_test.go b/gaelog_test.go index 609b669..6ad9f63 100644 --- a/gaelog_test.go +++ b/gaelog_test.go @@ -69,8 +69,8 @@ func TestNew(t *testing.T) { expectResource *monitoredres.MonitoredResource expectErr string }{ - {"no_env_vars_without_header", nil, false, nil, "the project ID was fetched from the metadata service"}, - {"no_env_vars_with_header", nil, true, nil, "the project ID was fetched from the metadata service"}, + {"no_env_vars_without_header", nil, false, nil, "GAE env vars were not set so Cloud Run vars"}, + {"no_env_vars_with_header", nil, true, nil, "GAE env vars were not set so Cloud Run vars"}, { "gae_env_vars_with_header", map[string]string{