Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't consider unset env var to be an error during resource detection #1170

Merged
merged 3 commits into from Sep 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
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
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
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
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