1
0
mirror of https://github.com/open-telemetry/opentelemetry-go.git synced 2025-11-29 23:07:45 +02:00

fix(2138): add guard to constructOTResources to return an empty resource (#2139)

* fix(2138): add guard to constructOTResources to return an empty resource when attributes are not supplied

Fixes: https://github.com/open-telemetry/opentelemetry-go/issues/2138

* Update CHANGELOG.md

Co-authored-by: Robert Pająk <pellared@hotmail.com>

Co-authored-by: Robert Pająk <pellared@hotmail.com>
Co-authored-by: Tyler Yahn <MrAlias@users.noreply.github.com>
This commit is contained in:
Sean Schade
2021-07-29 12:09:07 -05:00
committed by GitHub
parent 11f62640ee
commit b8561785c0
3 changed files with 19 additions and 0 deletions

View File

@@ -72,6 +72,20 @@ func TestEmpty(t *testing.T) {
assert.Equal(t, Empty(), res)
}
func TestNoResourceAttributesSet(t *testing.T) {
store, err := ottest.SetEnvVariables(map[string]string{
svcNameKey: "bar",
})
require.NoError(t, err)
defer func() { require.NoError(t, store.Restore()) }()
detector := &fromEnv{}
res, err := detector.Detect(context.Background())
require.NoError(t, err)
assert.Equal(t, res, NewSchemaless(
semconv.ServiceNameKey.String("bar"),
))
}
func TestMissingKeyError(t *testing.T) {
store, err := ottest.SetEnvVariables(map[string]string{
resourceAttrKey: "key=value,key",