add span status method #171
@@ -33,10 +33,12 @@ func (t *noopTracer) Name() string {
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
type noopSpan struct {
 | 
					type noopSpan struct {
 | 
				
			||||||
	ctx    context.Context
 | 
						ctx       context.Context
 | 
				
			||||||
	tracer Tracer
 | 
						tracer    Tracer
 | 
				
			||||||
	name   string
 | 
						name      string
 | 
				
			||||||
	opts   SpanOptions
 | 
						opts      SpanOptions
 | 
				
			||||||
 | 
						status    SpanStatus
 | 
				
			||||||
 | 
						statusMsg string
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (s *noopSpan) Finish(opts ...SpanOption) {
 | 
					func (s *noopSpan) Finish(opts ...SpanOption) {
 | 
				
			||||||
@@ -69,6 +71,15 @@ func (s *noopSpan) Kind() SpanKind {
 | 
				
			|||||||
	return s.opts.Kind
 | 
						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
 | 
					// NewTracer returns new memory tracer
 | 
				
			||||||
func NewTracer(opts ...Option) Tracer {
 | 
					func NewTracer(opts ...Option) Tracer {
 | 
				
			||||||
	return &noopTracer{
 | 
						return &noopTracer{
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -6,6 +6,33 @@ import (
 | 
				
			|||||||
	"go.unistack.org/micro/v3/logger"
 | 
						"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
 | 
					type SpanKind int
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const (
 | 
					const (
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -29,6 +29,10 @@ type Span interface {
 | 
				
			|||||||
	Context() context.Context
 | 
						Context() context.Context
 | 
				
			||||||
	// SetName set the span name
 | 
						// SetName set the span name
 | 
				
			||||||
	SetName(name string)
 | 
						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 set the span labels
 | 
				
			||||||
	SetLabels(labels ...interface{})
 | 
						SetLabels(labels ...interface{})
 | 
				
			||||||
	// AddLabels append the span labels
 | 
						// AddLabels append the span labels
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -22,7 +22,8 @@ var (
 | 
				
			|||||||
			}
 | 
								}
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		if err != nil {
 | 
							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())
 | 
							labels = append(labels, "kind", sp.Kind())
 | 
				
			||||||
		sp.SetLabels(labels...)
 | 
							sp.SetLabels(labels...)
 | 
				
			||||||
@@ -38,7 +39,8 @@ var (
 | 
				
			|||||||
			}
 | 
								}
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		if err != nil {
 | 
							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())
 | 
							labels = append(labels, "kind", sp.Kind())
 | 
				
			||||||
		sp.SetLabels(labels...)
 | 
							sp.SetLabels(labels...)
 | 
				
			||||||
@@ -54,7 +56,8 @@ var (
 | 
				
			|||||||
			}
 | 
								}
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		if err != nil {
 | 
							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())
 | 
							labels = append(labels, "kind", sp.Kind())
 | 
				
			||||||
		sp.SetLabels(labels...)
 | 
							sp.SetLabels(labels...)
 | 
				
			||||||
@@ -70,7 +73,8 @@ var (
 | 
				
			|||||||
			}
 | 
								}
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		if err != nil {
 | 
							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())
 | 
							labels = append(labels, "kind", sp.Kind())
 | 
				
			||||||
		sp.SetLabels(labels...)
 | 
							sp.SetLabels(labels...)
 | 
				
			||||||
@@ -86,7 +90,8 @@ var (
 | 
				
			|||||||
			}
 | 
								}
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		if err != nil {
 | 
							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())
 | 
							labels = append(labels, "kind", sp.Kind())
 | 
				
			||||||
		sp.SetLabels(labels...)
 | 
							sp.SetLabels(labels...)
 | 
				
			||||||
@@ -102,7 +107,8 @@ var (
 | 
				
			|||||||
			}
 | 
								}
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		if err != nil {
 | 
							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())
 | 
							labels = append(labels, "kind", sp.Kind())
 | 
				
			||||||
		sp.SetLabels(labels...)
 | 
							sp.SetLabels(labels...)
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user