mirror of
https://github.com/zitadel/zitadel.git
synced 2024-12-29 11:07:51 +00:00
47 lines
897 B
Go
47 lines
897 B
Go
package tracing
|
|
|
|
import (
|
|
"go.opentelemetry.io/otel/attribute"
|
|
"go.opentelemetry.io/otel/trace"
|
|
|
|
grpc_errs "github.com/zitadel/zitadel/internal/api/grpc/errors"
|
|
)
|
|
|
|
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, _ := grpc_errs.ExtractCaosError(err)
|
|
s.span.SetAttributes(attribute.Int("grpc_code", int(code)), attribute.String("grpc_msg", msg), attribute.String("error_id", id))
|
|
}
|