1
0
mirror of https://github.com/open-telemetry/opentelemetry-go.git synced 2025-09-16 09:26:25 +02:00

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

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

* update CHANGELOG
This commit is contained in:
Matej Gera
2020-09-14 18:08:05 +02:00
committed by GitHub
parent 77de1998cf
commit 1f7c220652
4 changed files with 8 additions and 14 deletions

View File

@@ -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

View File

@@ -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)
}

View File

@@ -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)
}

View File

@@ -55,8 +55,7 @@ func TestEmpty(t *testing.T) {
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)
}