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

Fix empty host.id #4317

Merged
merged 6 commits into from
Jul 18, 2023
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm

- Correctly format log messages from the `go.opentelemetry.io/otel/exporters/zipkin` exporter. (#4143)
- Log an error for calls to `NewView` in `go.opentelemetry.io/otel/sdk/metric` that have empty criteria. (#4307)
- Fix `resource.WithHostID()` to not set an empty `host.id`. (#4317)

## [1.16.0/0.39.0] 2023-05-18

Expand Down
2 changes: 1 addition & 1 deletion sdk/resource/host_id_readfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import "os"
func readFile(filename string) (string, error) {
b, err := os.ReadFile(filename)
if err != nil {
return "", nil
return "", err
}

return string(b), nil
Expand Down
53 changes: 53 additions & 0 deletions sdk/resource/host_id_readfile_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// Copyright The OpenTelemetry Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

//go:build linux || dragonfly || freebsd || netbsd || openbsd || solaris

package resource

import (
"os"
"testing"

"github.com/stretchr/testify/require"
)

func TestReadFileExistent(t *testing.T) {
fileContents := "foo"

f, err := os.CreateTemp("", "readfile_")
require.NoError(t, err)

defer os.Remove(f.Name())

_, err = f.WriteString(fileContents)
require.NoError(t, err)
require.NoError(t, f.Close())

result, err := readFile(f.Name())
require.NoError(t, err)
require.Equal(t, result, fileContents)
}

func TestReadFileNonExistent(t *testing.T) {
// create unique filename
f, err := os.CreateTemp("", "readfile_")
require.NoError(t, err)

// make file non-existent
require.NoError(t, os.Remove(f.Name()))

_, err = readFile(f.Name())
require.ErrorIs(t, err, os.ErrNotExist)
}