buildGCPLoggingEntry converts the binary log entry into a gcp logging entry.
(ctx context.Context, c iblog.LogEntryConfig)
| 251 | // buildGCPLoggingEntry converts the binary log entry into a gcp logging |
| 252 | // entry. |
| 253 | func (bml *binaryMethodLogger) buildGCPLoggingEntry(ctx context.Context, c iblog.LogEntryConfig) gcplogging.Entry { |
| 254 | binLogEntry := bml.mlb.Build(c) |
| 255 | |
| 256 | grpcLogEntry := &grpcLogEntry{ |
| 257 | CallID: bml.callID, |
| 258 | SequenceID: binLogEntry.GetSequenceIdWithinCall(), |
| 259 | Logger: loggerTypeToEventLogger[binLogEntry.Logger], |
| 260 | } |
| 261 | |
| 262 | switch binLogEntry.GetType() { |
| 263 | case binlogpb.GrpcLogEntry_EVENT_TYPE_UNKNOWN: |
| 264 | grpcLogEntry.Type = eventTypeUnknown |
| 265 | case binlogpb.GrpcLogEntry_EVENT_TYPE_CLIENT_HEADER: |
| 266 | grpcLogEntry.Type = eventTypeClientHeader |
| 267 | if binLogEntry.GetClientHeader() != nil { |
| 268 | methodName := binLogEntry.GetClientHeader().MethodName |
| 269 | // Example method name: /grpc.testing.TestService/UnaryCall |
| 270 | if strings.Contains(methodName, "/") { |
| 271 | tokens := strings.Split(methodName, "/") |
| 272 | if len(tokens) == 3 { |
| 273 | // Record service name and method name for all events. |
| 274 | bml.serviceName = tokens[1] |
| 275 | bml.methodName = tokens[2] |
| 276 | } else { |
| 277 | logger.Infof("Malformed method name: %v", methodName) |
| 278 | } |
| 279 | } |
| 280 | bml.authority = binLogEntry.GetClientHeader().GetAuthority() |
| 281 | grpcLogEntry.Payload.Timeout = binLogEntry.GetClientHeader().GetTimeout().AsDuration() |
| 282 | grpcLogEntry.Payload.Metadata = translateMetadata(binLogEntry.GetClientHeader().GetMetadata()) |
| 283 | } |
| 284 | grpcLogEntry.PayloadTruncated = binLogEntry.GetPayloadTruncated() |
| 285 | setPeerIfPresent(binLogEntry, grpcLogEntry) |
| 286 | case binlogpb.GrpcLogEntry_EVENT_TYPE_SERVER_HEADER: |
| 287 | grpcLogEntry.Type = eventTypeServerHeader |
| 288 | if binLogEntry.GetServerHeader() != nil { |
| 289 | grpcLogEntry.Payload.Metadata = translateMetadata(binLogEntry.GetServerHeader().GetMetadata()) |
| 290 | } |
| 291 | grpcLogEntry.PayloadTruncated = binLogEntry.GetPayloadTruncated() |
| 292 | setPeerIfPresent(binLogEntry, grpcLogEntry) |
| 293 | case binlogpb.GrpcLogEntry_EVENT_TYPE_CLIENT_MESSAGE: |
| 294 | grpcLogEntry.Type = eventTypeClientMessage |
| 295 | grpcLogEntry.Payload.Message = binLogEntry.GetMessage().GetData() |
| 296 | grpcLogEntry.Payload.MessageLength = binLogEntry.GetMessage().GetLength() |
| 297 | grpcLogEntry.PayloadTruncated = binLogEntry.GetPayloadTruncated() |
| 298 | case binlogpb.GrpcLogEntry_EVENT_TYPE_SERVER_MESSAGE: |
| 299 | grpcLogEntry.Type = eventTypeServerMessage |
| 300 | grpcLogEntry.Payload.Message = binLogEntry.GetMessage().GetData() |
| 301 | grpcLogEntry.Payload.MessageLength = binLogEntry.GetMessage().GetLength() |
| 302 | grpcLogEntry.PayloadTruncated = binLogEntry.GetPayloadTruncated() |
| 303 | case binlogpb.GrpcLogEntry_EVENT_TYPE_CLIENT_HALF_CLOSE: |
| 304 | grpcLogEntry.Type = eventTypeClientHalfClose |
| 305 | case binlogpb.GrpcLogEntry_EVENT_TYPE_SERVER_TRAILER: |
| 306 | grpcLogEntry.Type = eventTypeServerTrailer |
| 307 | grpcLogEntry.Payload.Metadata = translateMetadata(binLogEntry.GetTrailer().Metadata) |
| 308 | grpcLogEntry.Payload.StatusCode = canonicalString(codes.Code(binLogEntry.GetTrailer().GetStatusCode())) |
| 309 | grpcLogEntry.Payload.StatusMessage = binLogEntry.GetTrailer().GetStatusMessage() |
| 310 | grpcLogEntry.Payload.StatusDetails = binLogEntry.GetTrailer().GetStatusDetails() |
no test coverage detected