mirror of
https://github.com/zitadel/zitadel.git
synced 2024-12-15 12:27:59 +00:00
f680dd934d
* chore: rename package errors to zerrors * rename package errors to gerrors * fix error related linting issues * fix zitadel error assertion * fix gosimple linting issues * fix deprecated linting issues * resolve gci linting issues * fix import structure --------- Co-authored-by: Elio Bischof <elio@zitadel.com>
47 lines
889 B
Go
47 lines
889 B
Go
package tracing
|
|
|
|
import (
|
|
"go.opentelemetry.io/otel/attribute"
|
|
"go.opentelemetry.io/otel/trace"
|
|
|
|
"github.com/zitadel/zitadel/internal/api/grpc/gerrors"
|
|
)
|
|
|
|
type Span struct {
|
|
span trace.Span
|
|
opts []trace.SpanEndOption
|
|
}
|
|
|
|
func CreateSpan(span trace.Span) *Span {
|
|
return &Span{span: span, opts: []trace.SpanEndOption{}}
|
|
}
|
|
|
|
func (s *Span) End() {
|
|
if s.span == nil {
|
|
return
|
|
}
|
|
|
|
s.span.End(s.opts...)
|
|
}
|
|
|
|
func (s *Span) EndWithError(err error) {
|
|
s.SetStatusByError(err)
|
|
s.End()
|
|
}
|
|
|
|
func (s *Span) SetStatusByError(err error) {
|
|
if s.span == nil {
|
|
return
|
|
}
|
|
if err != nil {
|
|
// trace.WithErrorStatus(codes.Error)
|
|
s.span.RecordError(err)
|
|
s.span.SetAttributes(
|
|
attribute.KeyValue{},
|
|
)
|
|
}
|
|
|
|
code, msg, id, _ := gerrors.ExtractZITADELError(err)
|
|
s.span.SetAttributes(attribute.Int("grpc_code", int(code)), attribute.String("grpc_msg", msg), attribute.String("error_id", id))
|
|
}
|