Skip to content

Commit

Permalink
Don't consider unset env var to be an error during resource detection (
Browse files Browse the repository at this point in the history
…#1170)

* Don't consider unset env var an error during detection

* update CHANGELOG
  • Loading branch information
matej-g authored Sep 14, 2020
1 parent 77de199 commit 1f7c220
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 14 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

### Fixed

Expand Down
14 changes: 4 additions & 10 deletions sdk/resource/auto.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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)
}

Expand Down
2 changes: 1 addition & 1 deletion sdk/resource/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
5 changes: 2 additions & 3 deletions sdk/resource/env_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down

0 comments on commit 1f7c220

Please sign in to comment.