2024-08-11 20:34:28 +00:00
|
|
|
package utils
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2024-08-12 09:15:21 +00:00
|
|
|
|
2024-08-11 20:34:28 +00:00
|
|
|
log "github.com/sirupsen/logrus"
|
2024-08-12 09:15:21 +00:00
|
|
|
"go.opentelemetry.io/otel/codes"
|
2024-08-11 20:34:28 +00:00
|
|
|
"go.opentelemetry.io/otel/trace"
|
|
|
|
)
|
|
|
|
|
2024-08-13 08:54:21 +00:00
|
|
|
// HandleError logs the provided error, records it in the given trace span,
|
|
|
|
// sets the span status to error, and returns the error.
|
|
|
|
//
|
|
|
|
// Parameters:
|
|
|
|
// - ctx: context.Context, the context in which the error occurred.
|
|
|
|
// - span: trace.Span, the trace span where the error will be recorded.
|
|
|
|
// - logger: *log.Entry, a log entry used to log the error message.
|
|
|
|
// - error: error, the error to be handled.
|
|
|
|
//
|
|
|
|
// Returns:
|
|
|
|
// - error: The same error that was passed in.
|
|
|
|
func HandleError(_ context.Context, span trace.Span, logger *log.Entry, error error) error {
|
2024-08-12 09:15:21 +00:00
|
|
|
logger.Error(error)
|
2024-08-11 20:34:28 +00:00
|
|
|
span.RecordError(error)
|
2024-08-12 09:15:21 +00:00
|
|
|
span.SetStatus(codes.Error, error.Error())
|
2024-08-11 20:34:28 +00:00
|
|
|
return error
|
|
|
|
}
|