add span status method
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
parent
f76b3171d9
commit
7137d99102
@ -33,10 +33,12 @@ func (t *noopTracer) Name() string {
|
||||
}
|
||||
|
||||
type noopSpan struct {
|
||||
ctx context.Context
|
||||
tracer Tracer
|
||||
name string
|
||||
opts SpanOptions
|
||||
ctx context.Context
|
||||
tracer Tracer
|
||||
name string
|
||||
opts SpanOptions
|
||||
status SpanStatus
|
||||
statusMsg string
|
||||
}
|
||||
|
||||
func (s *noopSpan) Finish(opts ...SpanOption) {
|
||||
@ -69,6 +71,15 @@ func (s *noopSpan) Kind() SpanKind {
|
||||
return s.opts.Kind
|
||||
}
|
||||
|
||||
func (s *noopSpan) Status() (SpanStatus, string) {
|
||||
return s.status, s.statusMsg
|
||||
}
|
||||
|
||||
func (s *noopSpan) SetStatus(st SpanStatus, msg string) {
|
||||
s.status = st
|
||||
s.statusMsg = msg
|
||||
}
|
||||
|
||||
// NewTracer returns new memory tracer
|
||||
func NewTracer(opts ...Option) Tracer {
|
||||
return &noopTracer{
|
||||
|
@ -6,6 +6,33 @@ import (
|
||||
"go.unistack.org/micro/v3/logger"
|
||||
)
|
||||
|
||||
type SpanStatus int
|
||||
|
||||
const (
|
||||
// SpanStatusUnset is the default status code.
|
||||
SpanStatusUnset SpanStatus = 0
|
||||
|
||||
// SpanStatusError indicates the operation contains an error.
|
||||
SpanStatusError SpanStatus = 1
|
||||
|
||||
// SpanStatusOK indicates operation has been validated by an Application developers
|
||||
// or Operator to have completed successfully, or contain no error.
|
||||
SpanStatusOK SpanStatus = 2
|
||||
)
|
||||
|
||||
func (s SpanStatus) String() string {
|
||||
switch s {
|
||||
case SpanStatusUnset:
|
||||
return "Unset"
|
||||
case SpanStatusError:
|
||||
return "Error"
|
||||
case SpanStatusOK:
|
||||
return "OK"
|
||||
default:
|
||||
return "Unset"
|
||||
}
|
||||
}
|
||||
|
||||
type SpanKind int
|
||||
|
||||
const (
|
||||
|
@ -29,6 +29,10 @@ type Span interface {
|
||||
Context() context.Context
|
||||
// SetName set the span name
|
||||
SetName(name string)
|
||||
// SetStatus set the span status code and msg
|
||||
SetStatus(status SpanStatus, msg string)
|
||||
// Status returns span status and msg
|
||||
Status() (SpanStatus, string)
|
||||
// SetLabels set the span labels
|
||||
SetLabels(labels ...interface{})
|
||||
// AddLabels append the span labels
|
||||
|
@ -22,7 +22,8 @@ var (
|
||||
}
|
||||
}
|
||||
if err != nil {
|
||||
labels = append(labels, "error", true)
|
||||
labels = append(labels, "error", err.Error())
|
||||
sp.SetStatus(tracer.SpanStatusError, err.Error())
|
||||
}
|
||||
labels = append(labels, "kind", sp.Kind())
|
||||
sp.SetLabels(labels...)
|
||||
@ -38,7 +39,8 @@ var (
|
||||
}
|
||||
}
|
||||
if err != nil {
|
||||
labels = append(labels, "error", true)
|
||||
labels = append(labels, "error", err.Error())
|
||||
sp.SetStatus(tracer.SpanStatusError, err.Error())
|
||||
}
|
||||
labels = append(labels, "kind", sp.Kind())
|
||||
sp.SetLabels(labels...)
|
||||
@ -54,7 +56,8 @@ var (
|
||||
}
|
||||
}
|
||||
if err != nil {
|
||||
labels = append(labels, "error", true)
|
||||
labels = append(labels, "error", err.Error())
|
||||
sp.SetStatus(tracer.SpanStatusError, err.Error())
|
||||
}
|
||||
labels = append(labels, "kind", sp.Kind())
|
||||
sp.SetLabels(labels...)
|
||||
@ -70,7 +73,8 @@ var (
|
||||
}
|
||||
}
|
||||
if err != nil {
|
||||
labels = append(labels, "error", true)
|
||||
labels = append(labels, "error", err.Error())
|
||||
sp.SetStatus(tracer.SpanStatusError, err.Error())
|
||||
}
|
||||
labels = append(labels, "kind", sp.Kind())
|
||||
sp.SetLabels(labels...)
|
||||
@ -86,7 +90,8 @@ var (
|
||||
}
|
||||
}
|
||||
if err != nil {
|
||||
labels = append(labels, "error", true)
|
||||
labels = append(labels, "error", err.Error())
|
||||
sp.SetStatus(tracer.SpanStatusError, err.Error())
|
||||
}
|
||||
labels = append(labels, "kind", sp.Kind())
|
||||
sp.SetLabels(labels...)
|
||||
@ -102,7 +107,8 @@ var (
|
||||
}
|
||||
}
|
||||
if err != nil {
|
||||
labels = append(labels, "error", true)
|
||||
labels = append(labels, "error", err.Error())
|
||||
sp.SetStatus(tracer.SpanStatusError, err.Error())
|
||||
}
|
||||
labels = append(labels, "kind", sp.Kind())
|
||||
sp.SetLabels(labels...)
|
||||
|
Loading…
x
Reference in New Issue
Block a user