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

xray client: return an error if the HTTP request failed #5718

Merged
Show file tree
Hide file tree
Changes from 4 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 @@ -16,6 +16,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm

- The superfluous `response.WriteHeader` call in `go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp` when the response writer is flushed. (#5634)
- Custom attributes targeting metrics recorded by the `go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp` are not ignored anymore. (#5129)
- Erroneous response code of `getSamplingRules` in `go.opentelemetry.io/contrib/samplers/aws/xray/internal/client.go` will result in an error despite an empty sampling manifest. (#)
jaedle marked this conversation as resolved.
Show resolved Hide resolved

### Deprecated

Expand Down
4 changes: 4 additions & 0 deletions samplers/aws/xray/internal/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,10 @@ func (c *xrayClient) getSamplingRules(ctx context.Context) (*getSamplingRulesOut
}
defer output.Body.Close()

if output.StatusCode != http.StatusOK {
jaedle marked this conversation as resolved.
Show resolved Hide resolved
return nil, fmt.Errorf("xray client: unable to retrieve sampling settings, expected response status code 200, got: %d", output.StatusCode)
}

var samplingRulesOutput *getSamplingRulesOutput
if err := json.NewDecoder(output.Body).Decode(&samplingRulesOutput); err != nil {
return nil, fmt.Errorf("xray client: unable to unmarshal the response body: %w", err)
Expand Down
19 changes: 19 additions & 0 deletions samplers/aws/xray/internal/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -261,3 +261,22 @@ func TestEndpointIsNotReachable(t *testing.T) {
_, err = client.getSamplingRules(context.Background())
assert.Error(t, err)
}

func TestRespondsWithErrorStatusCode(t *testing.T) {
testServer := httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, _ *http.Request) {
res.WriteHeader(http.StatusForbidden)
_, err := res.Write([]byte(`{}`))
require.NoError(t, err)
}))
t.Cleanup(testServer.Close)

u, err := url.Parse(testServer.URL)
require.NoError(t, err)

client, err := newClient(*u)
require.NoError(t, err)

samplingRules, err := client.getSamplingRules(context.Background())
require.Error(t, err)
jaedle marked this conversation as resolved.
Show resolved Hide resolved
require.Nil(t, samplingRules)
}