diff --git a/CHANGELOG.md b/CHANGELOG.md index 505d1fcd863..32a8e204c4a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,7 +11,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm ### Added - The `go.opentelemetry.io/contrib/config` add support to configure periodic reader interval and timeout. (#5661) -- Add the new `go.opentelemetry.io/contrib/detectors/azure/vm` package to provide a resource detector for Azure VMs. (#5422) +- Add the new `go.opentelemetry.io/contrib/detectors/azure/azurevm` package to provide a resource detector for Azure VMs. (#5422) ### Fixed diff --git a/detectors/azure/vm/README.md b/detectors/azure/azurevm/README.md similarity index 89% rename from detectors/azure/vm/README.md rename to detectors/azure/azurevm/README.md index 2046c281fac..4dab2fa308f 100644 --- a/detectors/azure/vm/README.md +++ b/detectors/azure/azurevm/README.md @@ -5,8 +5,8 @@ The Azure VM resource detector supports detecting attributes specific to Azure V ## Usage ```golang -// Instantiate a new azure vm resource detector -azureVmResourceDetector := vm.New() +// Instantiate a new Azure VM resource detector +azureVmResourceDetector := azurevm.New() resource, err := azureVmResourceDetector.Detect(context.Background()) ``` diff --git a/detectors/azure/vm/go.mod b/detectors/azure/azurevm/go.mod similarity index 89% rename from detectors/azure/vm/go.mod rename to detectors/azure/azurevm/go.mod index 236232ed620..1e6498d53fd 100644 --- a/detectors/azure/vm/go.mod +++ b/detectors/azure/azurevm/go.mod @@ -1,4 +1,4 @@ -module go.opentelemetry.io/contrib/detectors/azure/vm +module go.opentelemetry.io/contrib/detectors/azure/azurevm go 1.21 diff --git a/detectors/azure/vm/go.sum b/detectors/azure/azurevm/go.sum similarity index 100% rename from detectors/azure/vm/go.sum rename to detectors/azure/azurevm/go.sum diff --git a/detectors/azure/vm/vm.go b/detectors/azure/azurevm/vm.go similarity index 93% rename from detectors/azure/vm/vm.go rename to detectors/azure/azurevm/vm.go index 8b7f94d89da..a4b59289eb7 100644 --- a/detectors/azure/vm/vm.go +++ b/detectors/azure/azurevm/vm.go @@ -1,11 +1,12 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -package vm // import "go.opentelemetry.io/contrib/detectors/azure/vm" +package azurevm // import "go.opentelemetry.io/contrib/detectors/azure/azurevm" import ( "context" "encoding/json" + "errors" "io" "net/http" @@ -75,7 +76,7 @@ func New(opts ...Option) resource.Detector { func (detector *resourceDetector) Detect(ctx context.Context) (*resource.Resource, error) { jsonMetadata, err := detector.getJSONMetadata() if err != nil { - return nil, err + return resource.Empty(), nil } var metadata vmMetadata @@ -131,6 +132,10 @@ func (detector *resourceDetector) getJSONMetadata() ([]byte, error) { return nil, err } + if resp.StatusCode != http.StatusOK { + return nil, errors.New(http.StatusText(resp.StatusCode)) + } + defer resp.Body.Close() return io.ReadAll(resp.Body) diff --git a/detectors/azure/vm/vm_test.go b/detectors/azure/azurevm/vm_test.go similarity index 94% rename from detectors/azure/vm/vm_test.go rename to detectors/azure/azurevm/vm_test.go index 6ceabb65363..81c991c3202 100644 --- a/detectors/azure/vm/vm_test.go +++ b/detectors/azure/azurevm/vm_test.go @@ -1,7 +1,7 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -package vm +package azurevm import ( "context" @@ -72,19 +72,19 @@ func TestDetect(t *testing.T) { }, { input: input{ - jsonMetadata: "", + jsonMetadata: "{}", statusCode: http.StatusNotFound, }, expected: expected{ - resource: nil, - err: true, + resource: resource.Empty(), + err: false, }, }, } for _, tCase := range testTable { svr := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - w.WriteHeader(http.StatusInternalServerError) + w.WriteHeader(tCase.input.statusCode) if r.Header.Get("Metadata") == "True" { fmt.Fprintf(w, tCase.input.jsonMetadata) diff --git a/versions.yaml b/versions.yaml index b6c97326cfb..09e2f96f9f6 100644 --- a/versions.yaml +++ b/versions.yaml @@ -20,7 +20,7 @@ module-sets: modules: - go.opentelemetry.io/contrib/bridges/prometheus - go.opentelemetry.io/contrib/detectors/aws/lambda - - go.opentelemetry.io/contrib/detectors/azure/vm + - go.opentelemetry.io/contrib/detectors/azure/azurevm - go.opentelemetry.io/contrib/exporters/autoexport - go.opentelemetry.io/contrib/propagators/autoprop - go.opentelemetry.io/contrib/propagators/opencensus