TUN-6250: Add upstream response status code to tracing span attributes

This commit is contained in:
João Oliveirinha
2022-05-18 12:11:38 +01:00
parent 26a7b59f6f
commit 6f78ccde04
4 changed files with 44 additions and 15 deletions

View File

@@ -1,6 +1,7 @@
package ingress
import (
"fmt"
"net"
"net/http"
@@ -49,7 +50,13 @@ func (o *httpService) RoundTrip(req *http.Request) (*http.Response, error) {
}
func (o *statusCode) RoundTrip(_ *http.Request) (*http.Response, error) {
return o.resp, nil
resp := &http.Response{
StatusCode: o.code,
Status: fmt.Sprintf("%d %s", o.code, http.StatusText(o.code)),
Body: new(NopReadCloser),
}
return resp, nil
}
func (o *rawTCPService) EstablishConnection(dest string) (OriginConnection, error) {

View File

@@ -238,20 +238,15 @@ func (o helloWorld) MarshalJSON() ([]byte, error) {
// statusCode is an OriginService that just responds with a given HTTP status.
// Typical use-case is "user wants the catch-all rule to just respond 404".
type statusCode struct {
resp *http.Response
code int
}
func newStatusCode(status int) statusCode {
resp := &http.Response{
StatusCode: status,
Status: fmt.Sprintf("%d %s", status, http.StatusText(status)),
Body: new(NopReadCloser),
}
return statusCode{resp: resp}
return statusCode{code: status}
}
func (o *statusCode) String() string {
return fmt.Sprintf("http_status:%d", o.resp.StatusCode)
return fmt.Sprintf("http_status:%d", o.code)
}
func (o *statusCode) start(