diff --git a/CHANGELOG.md b/CHANGELOG.md index 79fd2735a65..d8481d6dd9c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -73,6 +73,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm ### Fixed +- Fix EKS detector erroring outside of Kubernetes. (#7483) - Fix data race when writing log entries with `context.Context` fields in `go.opentelemetry.io/contrib/bridges/otelzap`. (#7368) - Fix nil pointer dereference when `ClientTracer` did not have a span in `go.opentelemetry.io/contrib/instrumentation/net/http/httptrace/otelhttptrace`. (#7464) - Record all non-failure metrics on transport round trip errors in `go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp`. (#7146) diff --git a/detectors/aws/eks/detector.go b/detectors/aws/eks/detector.go index 0cf2f64ff34..f34d38d2a4c 100644 --- a/detectors/aws/eks/detector.go +++ b/detectors/aws/eks/detector.go @@ -65,6 +65,10 @@ func NewResourceDetector() resource.Detector { // Detect returns a Resource describing the Amazon EKS environment being run in. func (detector *resourceDetector) Detect(ctx context.Context) (*resource.Resource, error) { if detector.err != nil { + if errors.Is(detector.err, rest.ErrNotInCluster) { + return resource.Empty(), nil + } + return nil, detector.err } diff --git a/detectors/aws/eks/detector_test.go b/detectors/aws/eks/detector_test.go index 6dec9debbec..f52df69315a 100644 --- a/detectors/aws/eks/detector_test.go +++ b/detectors/aws/eks/detector_test.go @@ -10,6 +10,7 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/mock" "github.com/stretchr/testify/require" + "k8s.io/client-go/rest" "go.opentelemetry.io/otel/attribute" "go.opentelemetry.io/otel/sdk/resource" @@ -82,3 +83,13 @@ func TestNotEKS(t *testing.T) { assert.Equal(t, resource.Empty(), r, "Resource object should be empty") detectorUtils.AssertExpectations(t) } + +// Tests EKS resource detector not running K8S at all. +func TestNotK8S(t *testing.T) { + detectorUtils := new(MockDetectorUtils) + detector := resourceDetector{utils: detectorUtils, err: rest.ErrNotInCluster} + r, err := detector.Detect(context.Background()) + require.NoError(t, err) + assert.Equal(t, resource.Empty(), r, "Resource object should be empty") + detectorUtils.AssertExpectations(t) +}