From 88eee26b0373d62f6a275c3367dbf6dae00ed47d Mon Sep 17 00:00:00 2001 From: Matej Gera Date: Sun, 13 Sep 2020 19:43:06 +0200 Subject: [PATCH 1/2] Don't consider unset env var an error during detection --- sdk/resource/auto.go | 14 ++++---------- sdk/resource/env.go | 2 +- sdk/resource/env_test.go | 5 ++--- 3 files changed, 7 insertions(+), 14 deletions(-) diff --git a/sdk/resource/auto.go b/sdk/resource/auto.go index 4a1f765fbac..1e572e0a3f8 100644 --- a/sdk/resource/auto.go +++ b/sdk/resource/auto.go @@ -21,9 +21,6 @@ import ( ) var ( - // ErrMissingResource is returned by a detector when source information - // is unavailable for a Resource. - ErrMissingResource = errors.New("missing resource") // ErrPartialResource is returned by a detector when complete source // information for a Resource is unavailable or the source information // contains invalid values that are omitted from the returned Resource. @@ -33,13 +30,10 @@ var ( // Detector detects OpenTelemetry resource information type Detector interface { // Detect returns an initialized Resource based on gathered information. - // If source information to construct a Resource is inaccessible, an - // uninitialized Resource is returned with an appropriately wrapped - // ErrMissingResource error is returned. If the source information to - // construct a Resource contains invalid values, a Resource is returned - // with the valid parts of the source information used for - // initialization along with an appropriately wrapped ErrPartialResource - // error. + // If the source information to construct a Resource contains invalid + // values, a Resource is returned with the valid parts of the source + // information used for initialization along with an appropriately + // wrapped ErrPartialResource error. Detect(ctx context.Context) (*Resource, error) } diff --git a/sdk/resource/env.go b/sdk/resource/env.go index 82690872a20..e0fb72516c7 100644 --- a/sdk/resource/env.go +++ b/sdk/resource/env.go @@ -43,7 +43,7 @@ func (d *FromEnv) Detect(context.Context) (*Resource, error) { labels := strings.TrimSpace(os.Getenv(envVar)) if labels == "" { - return Empty(), ErrMissingResource + return Empty(), nil } return constructOTResources(labels) } diff --git a/sdk/resource/env_test.go b/sdk/resource/env_test.go index 2c412fb8ff2..66c1a123548 100644 --- a/sdk/resource/env_test.go +++ b/sdk/resource/env_test.go @@ -51,12 +51,11 @@ func TestDetectMultiPairs(t *testing.T) { } func TestEmpty(t *testing.T) { - os.Setenv(envVar, "") + os.Setenv(envVar, " ") detector := &FromEnv{} res, err := detector.Detect(context.Background()) - require.Error(t, err) - assert.Equal(t, err, ErrMissingResource) + require.NoError(t, err) assert.Equal(t, Empty(), res) } From d34918b1c0553855a561667536262658aaf0b2e4 Mon Sep 17 00:00:00 2001 From: Matej Gera Date: Sun, 13 Sep 2020 19:54:58 +0200 Subject: [PATCH 2/2] update CHANGELOG --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9bc5a7c89b8..09d306af7b5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -39,6 +39,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm - The [configuration style guide](https://github.com/open-telemetry/opentelemetry-go/blob/master/CONTRIBUTING.md#config) has been updated to recommend the use of `newConfig()` instead of `configure()`. (#1163) - The `otlp.Config` type has been unexported and changed to `otlp.config`, along with its initializer. (#1163) +- Don't consider unset environment variable for resource detection to be an error. (#1170) ## [0.11.0] - 2020-08-24