Skip to content

Commit 640732a

Browse files
authored
fix: use jsonpb.Marshaler instead of json.Marshal (#190)
Signed-off-by: Shubham Jain <[email protected]>
1 parent d505b48 commit 640732a

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

integrations/kgrpcserver/kgrpcserver.go

+6-3
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import (
44
"context"
55
"encoding/json"
66
"fmt"
7+
"github.com/golang/protobuf/jsonpb"
8+
"github.com/golang/protobuf/proto"
79
"strings"
810

911
"github.com/keploy/go-sdk/keploy"
@@ -69,11 +71,12 @@ func serverInterceptor(k *keploy.Keploy) func(
6971
ctx = context.WithValue(ctx, internal.KCTX, &internal.Context{
7072
Mode: keploy.MODE_RECORD,
7173
})
72-
reqByte, err1 := json.Marshal(req)
74+
75+
m := jsonpb.Marshaler{}
76+
reqJSON, err1 := m.MarshalToString(req.(proto.Message))
7377
if err1 != nil {
7478
k.Log.Error("failed to marshal grpc request body and tcs is not captured", zap.Error(err1))
7579
}
76-
requestJson := string(reqByte)
7780
infoByte, err1 := json.Marshal(info)
7881
if err1 != nil {
7982
k.Log.Error("", zap.Error(err1))
@@ -104,7 +107,7 @@ func serverInterceptor(k *keploy.Keploy) func(
104107
return c, err1
105108
}
106109
resp := string(respByte)
107-
keploy.CaptureGrpcTC(k, ctx, models.GrpcReq{Body: requestJson, Method: method}, models.GrpcResp{Body: resp, Err: errStr})
110+
keploy.CaptureGrpcTC(k, ctx, models.GrpcReq{Body: reqJSON, Method: method}, models.GrpcResp{Body: resp, Err: errStr})
108111
return c, err
109112
}
110113
}

0 commit comments

Comments
 (0)