Add span attr "body_len"
This commit is contained in:
parent
fc1292f24c
commit
ad59658962
10
server.go
10
server.go
|
@ -19,6 +19,7 @@ import (
|
||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
|
|
||||||
"go.opentelemetry.io/otel"
|
"go.opentelemetry.io/otel"
|
||||||
|
"go.opentelemetry.io/otel/attribute"
|
||||||
"go.opentelemetry.io/otel/codes"
|
"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)
|
payload, err := readRequestBody(ctx, r.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
payloadLen := len(payload)
|
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)
|
server.logger.Error(err, "Error reading body", "client_ver", cltVersion, "client_platform", cltPlatform, "client_ip", cltIP, "body_len", payloadLen)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -126,8 +129,13 @@ func readRequestBody(ctx context.Context, body io.Reader) ([]byte, error) {
|
||||||
defer span.End()
|
defer span.End()
|
||||||
|
|
||||||
payload, err := ioutil.ReadAll(body)
|
payload, err := ioutil.ReadAll(body)
|
||||||
|
|
||||||
|
span.SetAttributes(
|
||||||
|
attribute.Int("body_len", len(payload)),
|
||||||
|
)
|
||||||
|
|
||||||
if err != nil {
|
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)
|
span.RecordError(err)
|
||||||
return payload, err
|
return payload, err
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue