Compare commits
11 Commits
Author | SHA1 | Date | |
---|---|---|---|
474fc506dd | |||
c94af432a0 | |||
3f9704aef8 | |||
5224363bfc | |||
52ec3cf264 | |||
d2b9201423 | |||
6543196faf | |||
f9dad57eb2 | |||
59283b64c9 | |||
4805482921 | |||
c2225cb92a |
6
go.mod
6
go.mod
@@ -1,10 +1,10 @@
|
|||||||
module go.unistack.org/micro-tracer-opentracing/v4
|
module go.unistack.org/micro-tracer-opentracing/v3
|
||||||
|
|
||||||
go 1.20
|
go 1.20
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/opentracing/opentracing-go v1.2.0
|
github.com/opentracing/opentracing-go v1.2.0
|
||||||
go.unistack.org/micro/v4 v4.0.13
|
go.unistack.org/micro/v3 v3.10.43
|
||||||
)
|
)
|
||||||
|
|
||||||
require github.com/stretchr/testify v1.8.3 // indirect
|
require github.com/stretchr/testify v1.8.1 // indirect
|
||||||
|
16
go.sum
16
go.sum
@@ -1,13 +1,21 @@
|
|||||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||||
|
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
github.com/opentracing/opentracing-go v1.2.0 h1:uEJPy/1a5RIPAJ0Ov+OIO8OxWu77jEv+1B0VhjKrZUs=
|
github.com/opentracing/opentracing-go v1.2.0 h1:uEJPy/1a5RIPAJ0Ov+OIO8OxWu77jEv+1B0VhjKrZUs=
|
||||||
github.com/opentracing/opentracing-go v1.2.0/go.mod h1:GxEUsuufX4nBwe+T+Wl9TAgYrxe9dPLANfrWvHYVTgc=
|
github.com/opentracing/opentracing-go v1.2.0/go.mod h1:GxEUsuufX4nBwe+T+Wl9TAgYrxe9dPLANfrWvHYVTgc=
|
||||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||||
|
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
|
||||||
|
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
|
||||||
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
|
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
|
||||||
github.com/stretchr/testify v1.8.3 h1:RP3t2pwF7cMEbC1dqtB6poj3niw/9gnV4Cjg5oW5gtY=
|
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||||
github.com/stretchr/testify v1.8.3/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
|
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
|
||||||
go.unistack.org/micro/v4 v4.0.13 h1:wyprk+KNAv/zR6bri6p6ucmXcJ9WyZ/vzru4zjPd8dA=
|
github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk=
|
||||||
go.unistack.org/micro/v4 v4.0.13/go.mod h1:ZDgU9931vm2l7X6RN/6UuwRIVp24GRdmQ7dKmegArk4=
|
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
|
||||||
|
go.unistack.org/micro/v3 v3.10.43 h1:GjUgu1lSKrhIov67jZQg6hUVUw0xZ6+ub8s6JRu6uj4=
|
||||||
|
go.unistack.org/micro/v3 v3.10.43/go.mod h1:CSmEf5ddmft94MyKHnUSMM0W5dpmmTVbgImbgQWV5Ak=
|
||||||
|
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||||
|
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||||
|
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||||
|
@@ -7,10 +7,9 @@ import (
|
|||||||
|
|
||||||
ot "github.com/opentracing/opentracing-go"
|
ot "github.com/opentracing/opentracing-go"
|
||||||
otlog "github.com/opentracing/opentracing-go/log"
|
otlog "github.com/opentracing/opentracing-go/log"
|
||||||
"go.unistack.org/micro/v4/metadata"
|
"go.unistack.org/micro/v3/metadata"
|
||||||
"go.unistack.org/micro/v4/options"
|
"go.unistack.org/micro/v3/tracer"
|
||||||
"go.unistack.org/micro/v4/tracer"
|
rutil "go.unistack.org/micro/v3/util/reflect"
|
||||||
rutil "go.unistack.org/micro/v4/util/reflect"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var _ tracer.Tracer = &otTracer{}
|
var _ tracer.Tracer = &otTracer{}
|
||||||
@@ -28,11 +27,9 @@ func (t *otTracer) Flush(ctx context.Context) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *otTracer) Init(opts ...options.Option) error {
|
func (t *otTracer) Init(opts ...tracer.Option) error {
|
||||||
for _, o := range opts {
|
for _, o := range opts {
|
||||||
if err := o(&t.opts); err != nil {
|
o(&t.opts)
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if tr, ok := t.opts.Context.Value(tracerKey{}).(ot.Tracer); ok {
|
if tr, ok := t.opts.Context.Value(tracerKey{}).(ot.Tracer); ok {
|
||||||
@@ -49,7 +46,7 @@ type spanContext interface {
|
|||||||
SpanID() idStringer
|
SpanID() idStringer
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *otTracer) Start(ctx context.Context, name string, opts ...options.Option) (context.Context, tracer.Span) {
|
func (t *otTracer) Start(ctx context.Context, name string, opts ...tracer.SpanOption) (context.Context, tracer.Span) {
|
||||||
options := tracer.NewSpanOptions(opts...)
|
options := tracer.NewSpanOptions(opts...)
|
||||||
var span ot.Span
|
var span ot.Span
|
||||||
switch options.Kind {
|
switch options.Kind {
|
||||||
@@ -119,11 +116,7 @@ func (os *otSpan) Tracer() tracer.Tracer {
|
|||||||
return &otTracer{tracer: os.span.Tracer()}
|
return &otTracer{tracer: os.span.Tracer()}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (os *otSpan) AddLogs(kv ...interface{}) {
|
func (os *otSpan) Finish(opts ...tracer.SpanOption) {
|
||||||
os.span.LogKV(kv...)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (os *otSpan) Finish(opts ...options.Option) {
|
|
||||||
if len(os.opts.Labels)%2 != 0 {
|
if len(os.opts.Labels)%2 != 0 {
|
||||||
os.opts.Labels = os.opts.Labels[:len(os.opts.Labels)-1]
|
os.opts.Labels = os.opts.Labels[:len(os.opts.Labels)-1]
|
||||||
}
|
}
|
||||||
@@ -133,25 +126,8 @@ func (os *otSpan) Finish(opts ...options.Option) {
|
|||||||
if !ok {
|
if !ok {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
v, ok := os.opts.Labels[idx+1].(string)
|
v := os.opts.Labels[idx+1]
|
||||||
if !ok {
|
os.span.SetTag(k, v)
|
||||||
v = fmt.Sprintf("%v", os.opts.Labels[idx+1])
|
|
||||||
}
|
|
||||||
switch k {
|
|
||||||
case "err":
|
|
||||||
os.status = tracer.SpanStatusError
|
|
||||||
os.statusMsg = v
|
|
||||||
case "error":
|
|
||||||
continue
|
|
||||||
case "X-Request-Id", "x-request-id":
|
|
||||||
os.span.SetTag("x-request-id", v)
|
|
||||||
case "rpc.call", "rpc.call_type", "rpc.flavor", "rpc.service", "rpc.method",
|
|
||||||
"sdk.database", "db.statement", "db.args", "db.query", "db.method",
|
|
||||||
"messaging.destination.name", "messaging.source.name", "messaging.operation":
|
|
||||||
os.span.SetTag(k, v)
|
|
||||||
default:
|
|
||||||
os.span.LogKV(k, v)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if os.status == tracer.SpanStatusError {
|
if os.status == tracer.SpanStatusError {
|
||||||
os.span.SetTag("error", true)
|
os.span.SetTag("error", true)
|
||||||
@@ -161,10 +137,14 @@ func (os *otSpan) Finish(opts ...options.Option) {
|
|||||||
os.span.Finish()
|
os.span.Finish()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (os *otSpan) AddEvent(name string, opts ...options.Option) {
|
func (os *otSpan) AddEvent(name string, opts ...tracer.EventOption) {
|
||||||
os.span.LogFields(otlog.Event(name))
|
os.span.LogFields(otlog.Event(name))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (os *otSpan) AddLogs(kv ...interface{}) {
|
||||||
|
os.span.LogKV(kv...)
|
||||||
|
}
|
||||||
|
|
||||||
func (os *otSpan) Context() context.Context {
|
func (os *otSpan) Context() context.Context {
|
||||||
return ot.ContextWithSpan(context.Background(), os.span)
|
return ot.ContextWithSpan(context.Background(), os.span)
|
||||||
}
|
}
|
||||||
@@ -182,10 +162,20 @@ func (os *otSpan) Kind() tracer.SpanKind {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (os *otSpan) AddLabels(labels ...interface{}) {
|
func (os *otSpan) AddLabels(labels ...interface{}) {
|
||||||
os.opts.Labels = append(os.opts.Labels, labels...)
|
if len(labels)%2 != 0 {
|
||||||
|
labels = labels[:len(labels)-1]
|
||||||
|
}
|
||||||
|
for idx := 0; idx < len(labels); idx += 2 {
|
||||||
|
k, kok := labels[idx].(string)
|
||||||
|
if !kok {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
v := labels[idx+1]
|
||||||
|
os.span.SetTag(k, v)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewTracer(opts ...options.Option) *otTracer {
|
func NewTracer(opts ...tracer.Option) *otTracer {
|
||||||
options := tracer.NewOptions(opts...)
|
options := tracer.NewOptions(opts...)
|
||||||
return &otTracer{opts: options}
|
return &otTracer{opts: options}
|
||||||
}
|
}
|
||||||
|
@@ -5,8 +5,8 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/opentracing/opentracing-go/mocktracer"
|
"github.com/opentracing/opentracing-go/mocktracer"
|
||||||
"go.unistack.org/micro/v4/metadata"
|
"go.unistack.org/micro/v3/metadata"
|
||||||
"go.unistack.org/micro/v4/tracer"
|
"go.unistack.org/micro/v3/tracer"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestTraceID(t *testing.T) {
|
func TestTraceID(t *testing.T) {
|
||||||
|
@@ -2,11 +2,11 @@ package opentracing
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/opentracing/opentracing-go"
|
"github.com/opentracing/opentracing-go"
|
||||||
"go.unistack.org/micro/v4/options"
|
"go.unistack.org/micro/v3/tracer"
|
||||||
)
|
)
|
||||||
|
|
||||||
type tracerKey struct{}
|
type tracerKey struct{}
|
||||||
|
|
||||||
func Tracer(ot opentracing.Tracer) options.Option {
|
func Tracer(ot opentracing.Tracer) tracer.Option {
|
||||||
return options.ContextOption(tracerKey{}, ot)
|
return tracer.SetOption(tracerKey{}, ot)
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user