diff --git a/server.go b/server.go index 952420a..99f06c5 100644 --- a/server.go +++ b/server.go @@ -19,6 +19,7 @@ import ( "github.com/google/uuid" "go.opentelemetry.io/otel" + "go.opentelemetry.io/otel/attribute" "go.opentelemetry.io/otel/codes" ) @@ -106,6 +107,8 @@ func (server *RPCServer) ServeHTTP(w http.ResponseWriter, r *http.Request) { payload, err := readRequestBody(ctx, r.Body) if err != nil { payloadLen := len(payload) + span.SetStatus(codes.Error, "Got error from readRequestBody.") + span.RecordError(err) server.logger.Error(err, "Error reading body", "client_ver", cltVersion, "client_platform", cltPlatform, "client_ip", cltIP, "body_len", payloadLen) return } @@ -126,8 +129,13 @@ func readRequestBody(ctx context.Context, body io.Reader) ([]byte, error) { defer span.End() payload, err := ioutil.ReadAll(body) + + span.SetAttributes( + attribute.Int("body_len", len(payload)), + ) + if err != nil { - span.SetStatus(codes.Error, "Got error from ioutil.ReadAll.") + span.SetStatus(codes.Error, "Error reading body. Got error from ioutil.ReadAll.") span.RecordError(err) return payload, err }