update
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
parent
a5c1f0a9a7
commit
2abea05b41
@ -1,10 +1,10 @@
|
|||||||
// Package opentracing provides wrappers for OpenTracing
|
|
||||||
package opentracing
|
package opentracing
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
|
||||||
opentracing "github.com/opentracing/opentracing-go"
|
"github.com/opentracing/opentracing-go"
|
||||||
|
"github.com/opentracing/opentracing-go/log"
|
||||||
"go.unistack.org/micro/v3/metadata"
|
"go.unistack.org/micro/v3/metadata"
|
||||||
"go.unistack.org/micro/v3/tracer"
|
"go.unistack.org/micro/v3/tracer"
|
||||||
)
|
)
|
||||||
@ -12,7 +12,8 @@ import (
|
|||||||
var _ tracer.Tracer = &opentracingTracer{}
|
var _ tracer.Tracer = &opentracingTracer{}
|
||||||
|
|
||||||
type opentracingTracer struct {
|
type opentracingTracer struct {
|
||||||
opts tracer.Options
|
opts tracer.Options
|
||||||
|
tracer opentracing.Tracer
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ot *opentracingTracer) Name() string {
|
func (ot *opentracingTracer) Name() string {
|
||||||
@ -20,11 +21,49 @@ func (ot *opentracingTracer) Name() string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (ot *opentracingTracer) Init(opts ...tracer.Option) error {
|
func (ot *opentracingTracer) Init(opts ...tracer.Option) error {
|
||||||
|
ot.opts = tracer.NewOptions(opts...)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ot *opentracingTracer) Start(ctx context.Context, name string, opts ...tracer.SpanOption) (context.Context, tracer.Span) {
|
func (ot *opentracingTracer) Start(ctx context.Context, name string, opts ...tracer.SpanOption) (context.Context, tracer.Span) {
|
||||||
return nil, nil
|
ctx, span, _ := StartSpanFromIncomingContext(ctx, ot.tracer, name)
|
||||||
|
return ctx, &opentracingSpan{span: span}
|
||||||
|
}
|
||||||
|
|
||||||
|
type opentracingSpan struct {
|
||||||
|
span opentracing.Span
|
||||||
|
labels []interface{}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (os *opentracingSpan) Tracer() tracer.Tracer {
|
||||||
|
return &opentracingTracer{tracer: os.span.Tracer()}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (os *opentracingSpan) Finish(opts ...tracer.SpanOption) {
|
||||||
|
if len(os.labels) > 0 {
|
||||||
|
os.span.LogKV(os.labels...)
|
||||||
|
}
|
||||||
|
os.span.Finish()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (os *opentracingSpan) AddEvent(name string, opts ...tracer.EventOption) {
|
||||||
|
os.span.LogFields(log.Event(name))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (os *opentracingSpan) Context() context.Context {
|
||||||
|
return tracer.NewSpanContext(context.Background(), os)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (os *opentracingSpan) SetName(name string) {
|
||||||
|
os.span = os.span.SetOperationName(name)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (os *opentracingSpan) SetLabels(labels ...interface{}) {
|
||||||
|
os.labels = labels
|
||||||
|
}
|
||||||
|
|
||||||
|
func (os *opentracingSpan) AddLabels(labels ...interface{}) {
|
||||||
|
os.labels = append(os.labels, labels...)
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewTracer(opts ...tracer.Option) *opentracingTracer {
|
func NewTracer(opts ...tracer.Option) *opentracingTracer {
|
||||||
|
Loading…
Reference in New Issue
Block a user