Skip to content

Commit

Permalink
fix: use jsonpb.Marshaler instead of json.Marshal (#190)
Browse files Browse the repository at this point in the history
Signed-off-by: Shubham Jain <shubhamkjain@outlook.com>
  • Loading branch information
slayerjain authored Apr 29, 2023
1 parent d505b48 commit 640732a
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions integrations/kgrpcserver/kgrpcserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"context"
"encoding/json"
"fmt"
"github.com/golang/protobuf/jsonpb"
"github.com/golang/protobuf/proto"
"strings"

"github.com/keploy/go-sdk/keploy"
Expand Down Expand Up @@ -69,11 +71,12 @@ func serverInterceptor(k *keploy.Keploy) func(
ctx = context.WithValue(ctx, internal.KCTX, &internal.Context{
Mode: keploy.MODE_RECORD,
})
reqByte, err1 := json.Marshal(req)

m := jsonpb.Marshaler{}
reqJSON, err1 := m.MarshalToString(req.(proto.Message))
if err1 != nil {
k.Log.Error("failed to marshal grpc request body and tcs is not captured", zap.Error(err1))
}
requestJson := string(reqByte)
infoByte, err1 := json.Marshal(info)
if err1 != nil {
k.Log.Error("", zap.Error(err1))
Expand Down Expand Up @@ -104,7 +107,7 @@ func serverInterceptor(k *keploy.Keploy) func(
return c, err1
}
resp := string(respByte)
keploy.CaptureGrpcTC(k, ctx, models.GrpcReq{Body: requestJson, Method: method}, models.GrpcResp{Body: resp, Err: errStr})
keploy.CaptureGrpcTC(k, ctx, models.GrpcReq{Body: reqJSON, Method: method}, models.GrpcResp{Body: resp, Err: errStr})
return c, err
}
}
Expand Down

0 comments on commit 640732a

Please sign in to comment.