28 lines
815 B
Go
28 lines
815 B
Go
package utils
|
|
|
|
import (
|
|
"context"
|
|
|
|
log "github.com/sirupsen/logrus"
|
|
"go.opentelemetry.io/otel/codes"
|
|
"go.opentelemetry.io/otel/trace"
|
|
)
|
|
|
|
// 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 {
|
|
logger.Error(error)
|
|
span.RecordError(error)
|
|
span.SetStatus(codes.Error, error.Error())
|
|
return error
|
|
}
|