@@ -72,37 +72,24 @@ func (c *reporter) PostMsgSend(payload any, err error, duration time.Duration) {
72
72
if err != nil || ! has (c .opts .loggableEvents , PayloadSent ) {
73
73
return
74
74
}
75
+ callType := "response"
75
76
if c .CallMeta .IsClient {
76
- p , ok := payload .(proto.Message )
77
- if ! ok {
78
- c .logger .Log (
79
- c .ctx ,
80
- LevelError ,
81
- "payload is not a google.golang.org/protobuf/proto.Message; programmatic error?" ,
82
- fields .AppendUnique (Fields {"grpc.request.type" , fmt .Sprintf ("%T" , payload )})... ,
83
- )
84
- return
85
- }
86
-
87
- fields = fields .AppendUnique (Fields {"grpc.send.duration" , duration .String (), "grpc.request.content" , p })
88
- fields = fields .AppendUnique (c .opts .durationFieldFunc (duration ))
89
- c .logger .Log (c .ctx , logLvl , "request sent" , fields ... )
90
- } else {
91
- p , ok := payload .(proto.Message )
92
- if ! ok {
93
- c .logger .Log (
94
- c .ctx ,
95
- LevelError ,
96
- "payload is not a google.golang.org/protobuf/proto.Message; programmatic error?" ,
97
- fields .AppendUnique (Fields {"grpc.response.type" , fmt .Sprintf ("%T" , payload )})... ,
98
- )
99
- return
100
- }
101
-
102
- fields = fields .AppendUnique (Fields {"grpc.send.duration" , duration .String (), "grpc.response.content" , p })
103
- fields = fields .AppendUnique (c .opts .durationFieldFunc (duration ))
104
- c .logger .Log (c .ctx , logLvl , "response sent" , fields ... )
77
+ callType = "request"
105
78
}
79
+ p , ok := payload .(proto.Message )
80
+ if ! ok {
81
+ c .logger .Log (
82
+ c .ctx ,
83
+ LevelError ,
84
+ "payload is not a google.golang.org/protobuf/proto.Message; programmatic error?" ,
85
+ fields .AppendUnique (Fields {fmt .Sprintf ("grpc.%s.type" , callType ), fmt .Sprintf ("%T" , payload )})... ,
86
+ )
87
+ return
88
+ }
89
+
90
+ fields = fields .AppendUnique (Fields {"grpc.send.duration" , duration .String (), fmt .Sprintf ("grpc.%s.content" , callType ), p })
91
+ fields = fields .AppendUnique (c .opts .durationFieldFunc (duration ))
92
+ c .logger .Log (c .ctx , logLvl , fmt .Sprintf ("%s sent" , callType ), fields ... )
106
93
}
107
94
108
95
func (c * reporter ) PostMsgReceive (payload any , err error , duration time.Duration ) {
@@ -126,37 +113,24 @@ func (c *reporter) PostMsgReceive(payload any, err error, duration time.Duration
126
113
if err != nil || ! has (c .opts .loggableEvents , PayloadReceived ) {
127
114
return
128
115
}
129
- if ! c .CallMeta .IsClient {
130
- p , ok := payload .(proto.Message )
131
- if ! ok {
132
- c .logger .Log (
133
- c .ctx ,
134
- LevelError ,
135
- "payload is not a google.golang.org/protobuf/proto.Message; programmatic error?" ,
136
- fields .AppendUnique (Fields {"grpc.request.type" , fmt .Sprintf ("%T" , payload )})... ,
137
- )
138
- return
139
- }
140
-
141
- fields = fields .AppendUnique (Fields {"grpc.recv.duration" , duration .String (), "grpc.request.content" , p })
142
- fields = fields .AppendUnique (c .opts .durationFieldFunc (duration ))
143
- c .logger .Log (c .ctx , logLvl , "request received" , fields ... )
144
- } else {
145
- p , ok := payload .(proto.Message )
146
- if ! ok {
147
- c .logger .Log (
148
- c .ctx ,
149
- LevelError ,
150
- "payload is not a google.golang.org/protobuf/proto.Message; programmatic error?" ,
151
- fields .AppendUnique (Fields {"grpc.response.type" , fmt .Sprintf ("%T" , payload )})... ,
152
- )
153
- return
154
- }
155
-
156
- fields = fields .AppendUnique (Fields {"grpc.recv.duration" , duration .String (), "grpc.response.content" , p })
157
- fields = fields .AppendUnique (c .opts .durationFieldFunc (duration ))
158
- c .logger .Log (c .ctx , logLvl , "response received" , fields ... )
116
+ callType := "request"
117
+ if c .CallMeta .IsClient {
118
+ callType = "response"
159
119
}
120
+ p , ok := payload .(proto.Message )
121
+ if ! ok {
122
+ c .logger .Log (
123
+ c .ctx ,
124
+ LevelError ,
125
+ "payload is not a google.golang.org/protouf/proto.Message; programmatic error?" ,
126
+ fields .AppendUnique (Fields {fmt .Sprintf ("grpc.%s.type" , callType ), fmt .Sprintf ("%T" , payload )})... ,
127
+ )
128
+ return
129
+ }
130
+
131
+ fields = fields .AppendUnique (Fields {"grpc.recv.duration" , duration .String (), fmt .Sprintf ("grpc.%s.content" , callType ), p })
132
+ fields = fields .AppendUnique (c .opts .durationFieldFunc (duration ))
133
+ c .logger .Log (c .ctx , logLvl , fmt .Sprintf ("%s received" , callType ), fields ... )
160
134
}
161
135
162
136
func reportable (logger Logger , opts * options ) interceptors.CommonReportableFunc {
0 commit comments