Skip to content

Commit 45ab725

Browse files
committed
adding comments
Signed-off-by: Andreas Gkizas <[email protected]>
1 parent a6db9e1 commit 45ab725

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

receiver/otlpreceiver/internal/errors/errors.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,12 @@ func GetStatusFromError(err error) error {
5353
// For client disconnection errors, we want to ensure they are marked as retryable
5454
// and provide a descriptive message
5555
s = status.New(codes.Unavailable, GetClientDisconnectMessage(err))
56+
} else if consumererror.IsPermanent(err) {
57+
// For permanent errors, convert to InvalidArgument (equivalent to HTTP 400)
58+
s = status.New(codes.InvalidArgument, err.Error())
59+
} else {
60+
// For non-permanent errors, convert to Unavailable (equivalent to HTTP 503)
61+
s = status.New(codes.Unavailable, err.Error())
5662
}
5763
return s.Err()
5864
}

receiver/otlpreceiver/internal/trace/otlp.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,12 @@ func (r *Receiver) Export(ctx context.Context, req ptraceotlp.ExportRequest) (pt
4141
err := r.nextConsumer.ConsumeTraces(ctx, td)
4242
r.obsreport.EndTracesOp(ctx, dataFormatProtobuf, spanCount, err)
4343

44+
// Use appropriate status codes for permanent/non-permanent errors
45+
// If we return the error straightaway, then the grpc implementation will set status code to Unknown
46+
// Refer: https://github.com/grpc/grpc-go/blob/v1.59.0/server.go#L1345
47+
// So, convert the error to appropriate grpc status and return the error
48+
// NonPermanent errors will be converted to codes.Unavailable (equivalent to HTTP 503)
49+
// Permanent errors will be converted to codes.InvalidArgument (equivalent to HTTP 400)
4450
if err != nil {
4551
return ptraceotlp.NewExportResponse(), errors.GetStatusFromError(err)
4652
}

0 commit comments

Comments
 (0)