set error status based on severity level of an error

This commit is contained in:
Natalia Goc 2024-05-20 13:55:53 +02:00
parent f5819972a4
commit 265731010e

View File

@ -4,6 +4,7 @@ import (
"git.ma-al.com/maal-libraries/observer/pkg/attr"
"git.ma-al.com/maal-libraries/observer/pkg/level"
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/codes"
"go.opentelemetry.io/otel/trace"
)
@ -107,5 +108,8 @@ func NewErrInSpan[E IntoErrorEvent](err E, span trace.Span) E {
er := err.IntoErrorEvent()
er.extraSkipInStack += 1
span.RecordError(er.Err, er.AsOpts())
if er.Level <= level.ERR {
span.SetStatus(codes.Error, er.Error())
}
return err
}