Skip to content

Commit

Permalink
Fix HTTPClient error statuses default test for Go' mark FeatureFlag o…
Browse files Browse the repository at this point in the history
…ne as missing_feature
  • Loading branch information
mtoffl01 committed Sep 20, 2024
1 parent 89dc6f1 commit 18b02f8
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 26 deletions.
6 changes: 3 additions & 3 deletions manifests/golang.yml
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,7 @@ tests/:
test_otel_sdk_interoperability.py: missing_feature
test_span_links.py: missing_feature
test_telemetry.py:
Test_Consistent_Configs: v1.67.0
Test_Consistent_Configs: v1.68.0
Test_Defaults: missing_feature
Test_Environment: missing_feature
Test_TelemetryInstallSignature: missing_feature
Expand Down Expand Up @@ -490,8 +490,8 @@ tests/:
Test_Config_ClientIPHeader_Precedence: missing_feature (all headers listed in the RFC are not supported)
Test_Config_ClientTagQueryString_Configured: missing_feature (supports DD_TRACE_HTTP_URL_QUERY_STRING_DISABLED)
Test_Config_ClientTagQueryString_Empty: v1.60.0
Test_Config_HttpClientErrorStatuses_Default: v1.69.0
Test_Config_HttpClientErrorStatuses_FeatureFlagCustom: v1.69.0
Test_Config_HttpClientErrorStatuses_Default: v1.67.0
Test_Config_HttpClientErrorStatuses_FeatureFlagCustom: missing_feature
Test_Config_HttpServerErrorStatuses_Default: v1.67.0
Test_Config_HttpServerErrorStatuses_FeatureFlagCustom: v1.67.0
Test_Config_UnifiedServiceTagging_CustomService: missing_feature
Expand Down
38 changes: 18 additions & 20 deletions tests/test_config_consistency.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,8 @@ def setup_status_code_400(self):

def test_status_code_400(self):
assert self.r.status_code == 200
# This doesn't work for Go app
# content = json.loads(self.r.text)
# assert content["status_code"] == 400
content = json.loads(self.r.text)
assert content["status_code"] == 400

interfaces.library.assert_trace_exists(self.r)
spans = [s for _, _, s in interfaces.library.get_spans(request=self.r, full_trace=True)]
Expand All @@ -103,9 +102,8 @@ def setup_status_code_500(self):

def test_status_code_500(self):
assert self.r.status_code == 200
# This doesn't work for Go app
# content = json.loads(self.r.text)
# assert content["status_code"] == 500
content = json.loads(self.r.text)
assert content["status_code"] == 500

interfaces.library.assert_trace_exists(self.r)
spans = [s for _, _, s in interfaces.library.get_spans(request=self.r, full_trace=True)]
Expand All @@ -126,8 +124,8 @@ def setup_status_code_200(self):

def test_status_code_200(self):
assert self.r.status_code == 200
# content = json.loads(self.r.text)
# assert content["status_code"] == 200
content = json.loads(self.r.text)
assert content["status_code"] == 200

interfaces.library.assert_trace_exists(self.r)
spans = [s for _, _, s in interfaces.library.get_spans(request=self.r, full_trace=True)]
Expand All @@ -136,21 +134,21 @@ def test_status_code_200(self):
assert client_span, spans
assert client_span.get("error") == 1

def setup_status_code_202(self):
self.url = "http://weblog:7777/status?code=202"
self.r = weblog.get("/make_distant_call", params={"url": self.url})
# def setup_status_code_202(self):
# self.url = "http://weblog:7777/status?code=202"
# self.r = weblog.get("/make_distant_call", params={"url": self.url})

def test_status_code_202(self):
assert self.r.status_code == 200
# content = json.loads(self.r.text)
# assert content["status_code"] == 202
# def test_status_code_202(self):
# assert self.r.status_code == 200
# content = json.loads(self.r.text)
# assert content["status_code"] == 202

interfaces.library.assert_trace_exists(self.r)
spans = [s for _, _, s in interfaces.library.get_spans(request=self.r, full_trace=True)]
# interfaces.library.assert_trace_exists(self.r)
# spans = [s for _, _, s in interfaces.library.get_spans(request=self.r, full_trace=True)]

client_span = _get_span_by_tags(spans, tags={"span.kind": "client", "http.status_code": "202"})
assert client_span, spans
assert client_span.get("error") == 1
# client_span = _get_span_by_tags(spans, tags={"span.kind": "client", "http.status_code": "202"})
# assert client_span, spans
# assert client_span.get("error") == 1


@scenarios.default
Expand Down
15 changes: 12 additions & 3 deletions utils/build/docker/golang/app/net-http/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,14 +121,23 @@ func main() {

client := httptrace.WrapClient(http.DefaultClient)
req, _ := http.NewRequestWithContext(r.Context(), http.MethodGet, url, nil)
_, err := client.Do(req)

res, err := client.Do(req)
sc := res.StatusCode
if err != nil {
log.Fatalln(err)
w.WriteHeader(500)
} else {
type Response struct {
Status_Code int `json:"status_code"`
}
response := Response{Status_Code: sc}
jsonResponse, err := json.Marshal(response)
if err == nil {
w.Header().Set("Content-Type", "application/json")
w.Write(jsonResponse)
}
}
}
w.Write([]byte("OK"))
})

mux.HandleFunc("/headers", headers)
Expand Down

0 comments on commit 18b02f8

Please sign in to comment.