From 65b17cef752000223998694d87807437f746e84a Mon Sep 17 00:00:00 2001 From: chris erway Date: Tue, 23 Jun 2020 12:49:49 -0400 Subject: [PATCH 1/8] Add OpenTracing multitracer --- v1/contrib/multitracer/multitracer.go | 142 ++++++++++++++++++++++++++ 1 file changed, 142 insertions(+) create mode 100644 v1/contrib/multitracer/multitracer.go diff --git a/v1/contrib/multitracer/multitracer.go b/v1/contrib/multitracer/multitracer.go new file mode 100644 index 00000000..02a0d0eb --- /dev/null +++ b/v1/contrib/multitracer/multitracer.go @@ -0,0 +1,142 @@ +// Package multitracer provides a way to run more than one OpenTracing tracers, by multiplexing calls across +// multiple Tracer, Span, and SpanContext implementations. +package multitracer + +import ( + ot "github.com/opentracing/opentracing-go" + "github.com/opentracing/opentracing-go/log" +) + +// MultiTracer multiplexes OpenTracing API calls across multiple Tracer implementations. +type MultiTracer struct { + Tracers []ot.Tracer +} + +// MultiSpan represents a list of Spans returned from multiple Tracers, managed by a MultiTracer. +type MultiSpan struct { + multiTracer *MultiTracer + Spans []ot.Span +} + +// MultiSpanContext represents a list of SpanContext returned from multiple Spans, managed by a MultiTracer. +type MultiSpanContext struct { + multiTracer *MultiTracer + SpanContexts []ot.SpanContext +} + +func (m *MultiTracer) StartSpan(operationName string, opts ...ot.StartSpanOption) ot.Span { + ret := &MultiSpan{ + multiTracer: m, + Spans: make([]ot.Span, len(m.Tracers)), + } + for i, t := range m.Tracers { + ret.Spans[i] = t.StartSpan(operationName, opts...) + } + return ret +} + +// Inject propagates context using multiple tracers. Errors from individual tracers are dropped. +func (m *MultiTracer) Inject(sm ot.SpanContext, format interface{}, carrier interface{}) error { + sc, ok := sm.(*MultiSpanContext) + if !ok { + return ot.ErrInvalidSpanContext + } + for i, t := range m.Tracers { + // XXX drops Inject error in child tracers + _ = t.Inject(sc.SpanContexts[i], format, carrier) + } + return nil +} + +// Extract reads context propagated using multiple tracers. Errors from individual tracers are dropped. +func (m *MultiTracer) Extract(format interface{}, carrier interface{}) (ot.SpanContext, error) { + ret := &MultiSpanContext{ + multiTracer: m, + SpanContexts: make([]ot.SpanContext, len(m.Tracers)), + } + for i, t := range m.Tracers { + // XXX drops Extract error in child tracers + ret.SpanContexts[i], _ = t.Extract(format, carrier) + } + return ret, nil +} + +func (m *MultiSpan) Finish() { + for _, s := range m.Spans { + s.Finish() + } +} + +func (m *MultiSpan) FinishWithOptions(opts ot.FinishOptions) { + for _, s := range m.Spans { + s.FinishWithOptions(opts) + } +} + +func (m *MultiSpan) Context() ot.SpanContext { + ret := &MultiSpanContext{ + multiTracer: m.multiTracer, + SpanContexts: make([]ot.SpanContext, len(m.Spans)), + } + for i, s := range m.Spans { + ret.SpanContexts[i] = s.Context() + } + return ret +} + +func (m *MultiSpan) SetOperationName(operationName string) ot.Span { + for i, s := range m.Spans { + m.Spans[i] = s.SetOperationName(operationName) + } + return m +} + +func (m *MultiSpan) SetTag(key string, value interface{}) ot.Span { + for i, s := range m.Spans { + m.Spans[i] = s.SetTag(key, value) + } + return m +} + +func (m *MultiSpan) LogFields(fields ...log.Field) { + for _, s := range m.Spans { + s.LogFields(fields...) + } +} + +func (m *MultiSpan) LogKV(alternatingKeyValues ...interface{}) { + for _, s := range m.Spans { + s.LogKV(alternatingKeyValues...) + } +} + +// SetBaggageItem does nothing: baggage propagation is not supported. +func (m *MultiSpan) SetBaggageItem(restrictedKey, value string) ot.Span { return m } + +// BaggageItem does nothing: baggage propagation is not supported. +func (m *MultiSpan) BaggageItem(restrictedKey string) string { return "" } + +func (m *MultiSpan) Tracer() ot.Tracer { + return m.multiTracer +} + +func (m *MultiSpan) LogEvent(event string) { + for _, s := range m.Spans { + s.LogEvent(event) //nolint + } +} + +func (m *MultiSpan) LogEventWithPayload(event string, payload interface{}) { + for _, s := range m.Spans { + s.LogEventWithPayload(event, payload) //nolint + } +} + +func (m *MultiSpan) Log(data ot.LogData) { + for _, s := range m.Spans { + s.Log(data) //nolint + } +} + +// ForeachBaggageItem does nothing: baggage propagation is not supported. +func (m *MultiSpanContext) ForeachBaggageItem(handler func(k, v string) bool) {} From 19028d3a4d21ee74239dc239de57da34e184e826 Mon Sep 17 00:00:00 2001 From: chris erway Date: Tue, 23 Jun 2020 12:57:40 -0400 Subject: [PATCH 2/8] Longer package comment --- v1/contrib/multitracer/multitracer.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/v1/contrib/multitracer/multitracer.go b/v1/contrib/multitracer/multitracer.go index 02a0d0eb..518ecd21 100644 --- a/v1/contrib/multitracer/multitracer.go +++ b/v1/contrib/multitracer/multitracer.go @@ -1,5 +1,9 @@ // Package multitracer provides a way to run more than one OpenTracing tracers, by multiplexing calls across -// multiple Tracer, Span, and SpanContext implementations. +// multiple Tracer, Span, and SpanContext implementations. The goal is to support a user sending data to +// two tracing vendors simultaneously (e.g., AppOptics and another implementation). +// +// Currently, baggage propagation is not supported, and the two tracers must use distinct HTTP header +// names, so as not to clobber each other. package multitracer import ( From dcda34d4cb45a0300fe4a868fde56c0ab50a3c0d Mon Sep 17 00:00:00 2001 From: chris erway Date: Mon, 24 Aug 2020 17:38:14 -0400 Subject: [PATCH 3/8] Use opentracing-go API harness to test multitracer --- v1/ao/opentracing/multitracer_test.go | 22 ++++++++++++ v1/contrib/multitracer/multitracer.go | 50 ++++++++++++++++++++++++--- 2 files changed, 67 insertions(+), 5 deletions(-) create mode 100644 v1/ao/opentracing/multitracer_test.go diff --git a/v1/ao/opentracing/multitracer_test.go b/v1/ao/opentracing/multitracer_test.go new file mode 100644 index 00000000..884c1665 --- /dev/null +++ b/v1/ao/opentracing/multitracer_test.go @@ -0,0 +1,22 @@ +package opentracing + +import ( + "testing" + + // aoot "github.com/appoptics/appoptics-apm-go/v1/ao/opentracing" + "github.com/appoptics/appoptics-apm-go/v1/ao/internal/reporter" + mt "github.com/appoptics/appoptics-apm-go/v1/contrib/multitracer" + opentracing "github.com/opentracing/opentracing-go" + "github.com/opentracing/opentracing-go/harness" +) + +func TestMultiTracerAPICheck(t *testing.T) { + _ = reporter.SetTestReporter(reporter.TestReporterDisableDefaultSetting(true)) // set up test reporter + harness.RunAPIChecks(t, func() (tracer opentracing.Tracer, closer func()) { + return &mt.MultiTracer{Tracers: []opentracing.Tracer{NewTracer()}}, nil + }, + harness.CheckBaggageValues(false), + harness.CheckInject(true), + harness.CheckExtract(true), + ) +} diff --git a/v1/contrib/multitracer/multitracer.go b/v1/contrib/multitracer/multitracer.go index 518ecd21..0091219f 100644 --- a/v1/contrib/multitracer/multitracer.go +++ b/v1/contrib/multitracer/multitracer.go @@ -34,7 +34,23 @@ func (m *MultiTracer) StartSpan(operationName string, opts ...ot.StartSpanOption Spans: make([]ot.Span, len(m.Tracers)), } for i, t := range m.Tracers { - ret.Spans[i] = t.StartSpan(operationName, opts...) + // look for ot.StartSpanOptions with a MultiSpanContext in an ot.SpanReference + tracerSpecificOpts := []ot.StartSpanOption{} + for _, opt := range opts { + switch o := opt.(type) { + case ot.SpanReference: + // pull out tracer-specific SpanContext from MultiSpanContext + refCtx := o.ReferencedContext.(*MultiSpanContext) + tracerSpecificReference := ot.SpanReference{ + Type: o.Type, + ReferencedContext: refCtx.SpanContexts[i], + } + tracerSpecificOpts = append(tracerSpecificOpts, tracerSpecificReference) + case ot.StartTime, ot.Tags, ot.Tag: + tracerSpecificOpts = append(tracerSpecificOpts, opt) + } + } + ret.Spans[i] = t.StartSpan(operationName, tracerSpecificOpts...) } return ret } @@ -45,9 +61,21 @@ func (m *MultiTracer) Inject(sm ot.SpanContext, format interface{}, carrier inte if !ok { return ot.ErrInvalidSpanContext } + errs := make([]error, len(m.Tracers)) for i, t := range m.Tracers { - // XXX drops Inject error in child tracers - _ = t.Inject(sc.SpanContexts[i], format, carrier) + errs[i] = t.Inject(sc.SpanContexts[i], format, carrier) + } + + // if every tracer returned an error, then also return the first error. + var allErrors = true + for _, err := range errs { + if err == nil { + allErrors = false + break + } + } + if allErrors { + return errs[0] } return nil } @@ -58,9 +86,21 @@ func (m *MultiTracer) Extract(format interface{}, carrier interface{}) (ot.SpanC multiTracer: m, SpanContexts: make([]ot.SpanContext, len(m.Tracers)), } + errs := make([]error, len(m.Tracers)) for i, t := range m.Tracers { - // XXX drops Extract error in child tracers - ret.SpanContexts[i], _ = t.Extract(format, carrier) + ret.SpanContexts[i], errs[i] = t.Extract(format, carrier) + } + + // if every tracer returned an error, then also return the first error. + var allErrors = true + for _, err := range errs { + if err == nil { + allErrors = false + break + } + } + if allErrors { + return nil, errs[0] } return ret, nil } From 5f7a0bc64fccd71fd631a37632460d94866e5eae Mon Sep 17 00:00:00 2001 From: chris erway Date: Mon, 24 Aug 2020 17:47:26 -0400 Subject: [PATCH 4/8] Have multitracer_test.go set up two tracers --- go.mod | 1 + go.sum | 20 ++++++++++++++++++++ v1/ao/opentracing/multitracer_test.go | 11 +++++++++-- 3 files changed, 30 insertions(+), 2 deletions(-) diff --git a/go.mod b/go.mod index f08c9f42..58b03255 100644 --- a/go.mod +++ b/go.mod @@ -6,6 +6,7 @@ require ( github.com/cespare/xxhash v1.1.0 // indirect github.com/coocood/freecache v1.1.0 github.com/golang/protobuf v1.4.2 + github.com/opentracing/basictracer-go v1.1.0 github.com/opentracing/opentracing-go v1.1.0 github.com/pkg/errors v0.9.1 github.com/stretchr/testify v1.6.1 diff --git a/go.sum b/go.sum index dca4c0a9..1c5552c4 100644 --- a/go.sum +++ b/go.sum @@ -10,10 +10,14 @@ github.com/coocood/freecache v1.1.0 h1:ENiHOsWdj1BrrlPwblhbn4GdAsMymK3pZORJ+bJGA github.com/coocood/freecache v1.1.0/go.mod h1:ePwxCDzOYvARfHdr1pByNct1at3CoKnsipOHwKlNbzI= github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= 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/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98= github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c= +github.com/gogo/protobuf v1.3.1 h1:DqDEcV5aeaTmdFBePNpYsp3FlcVH/2ISVVM9Qf8PSls= +github.com/gogo/protobuf v1.3.1/go.mod h1:SlYgWuQ5SjCEi6WLHjHCa1yvBfUnHcTbrrZtXPKa29o= github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= @@ -31,6 +35,10 @@ github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5a github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/kisielk/errcheck v1.2.0/go.mod h1:/BMXB+zMLi60iA8Vv6Ksmxu/1UDYcXs4uQLJ+jE2L00= +github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= +github.com/opentracing/basictracer-go v1.1.0 h1:Oa1fTSBvAl8pa3U+IJYqrKm0NALwH9OsgwOqDv4xJW0= +github.com/opentracing/basictracer-go v1.1.0/go.mod h1:V2HZueSJEp879yv285Aap1BS69fQMD+MNP1mRs6mBQc= github.com/opentracing/opentracing-go v1.1.0 h1:pWlfV3Bxv7k65HYwkikxat0+s3pV4bsqf19k25Ur8rU= github.com/opentracing/opentracing-go v1.1.0/go.mod h1:UkNAQd3GIcIGf0SeVgPpRdFStlNbqXla1AfSYxPUl2o= github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= @@ -41,17 +49,24 @@ github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1: github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA= github.com/stretchr/objx v0.1.0 h1:4G4v2dO3VZwixGIRoQ5Lfboy6nUhCyYzaqnIAPPhYs4= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0= github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU= golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= +golang.org/x/lint v0.0.0-20200302205851-738671d3881b/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY= +golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg= golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20200421231249-e086a090c8fd/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= golang.org/x/net v0.0.0-20200602114024-627f9648deb9 h1:pNX+40auqi2JqRfOP1akLGtYcn15TUbkhwuCO3foqqM= golang.org/x/net v0.0.0-20200602114024-627f9648deb9/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= @@ -60,13 +75,17 @@ golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJ golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/tools v0.0.0-20181030221726-6c7e314b6563/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY= golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= +golang.org/x/tools v0.0.0-20200130002326-2f3ba24bd6e7/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= +golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= @@ -96,6 +115,7 @@ google.golang.org/protobuf v1.24.0/go.mod h1:r/3tXBNzIEhYS9I1OUVjXDlt8tc493IdKGj gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/mgo.v2 v2.0.0-20190816093944-a6b53ec6cb22 h1:VpOs+IwYnYBaFnrNAeB8UUWtL3vEUnzSCL1nVjPhqrw= gopkg.in/mgo.v2 v2.0.0-20190816093944-a6b53ec6cb22/go.mod h1:yeKp02qBN3iKW1OzL3MGk2IdtZzaj7SFntXj72NppTA= +gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.3.0 h1:clyUAQHOM3G0M3f5vQj7LuJrETvjVot3Z5el9nffUtU= gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo= diff --git a/v1/ao/opentracing/multitracer_test.go b/v1/ao/opentracing/multitracer_test.go index 884c1665..4e9eb4d1 100644 --- a/v1/ao/opentracing/multitracer_test.go +++ b/v1/ao/opentracing/multitracer_test.go @@ -3,9 +3,9 @@ package opentracing import ( "testing" - // aoot "github.com/appoptics/appoptics-apm-go/v1/ao/opentracing" "github.com/appoptics/appoptics-apm-go/v1/ao/internal/reporter" mt "github.com/appoptics/appoptics-apm-go/v1/contrib/multitracer" + bt "github.com/opentracing/basictracer-go" opentracing "github.com/opentracing/opentracing-go" "github.com/opentracing/opentracing-go/harness" ) @@ -13,7 +13,14 @@ import ( func TestMultiTracerAPICheck(t *testing.T) { _ = reporter.SetTestReporter(reporter.TestReporterDisableDefaultSetting(true)) // set up test reporter harness.RunAPIChecks(t, func() (tracer opentracing.Tracer, closer func()) { - return &mt.MultiTracer{Tracers: []opentracing.Tracer{NewTracer()}}, nil + return &mt.MultiTracer{ + Tracers: []opentracing.Tracer{ + NewTracer(), + bt.NewWithOptions(bt.Options{ + Recorder: bt.NewInMemoryRecorder(), + ShouldSample: func(traceID uint64) bool { return true }, // always sample + }), + }}, nil }, harness.CheckBaggageValues(false), harness.CheckInject(true), From 738f8aad427ec03dd78bdf1a132291446f56724e Mon Sep 17 00:00:00 2001 From: chris erway Date: Tue, 25 Aug 2020 10:11:45 -0400 Subject: [PATCH 5/8] Revert "Have multitracer_test.go set up two tracers" This reverts commit 5f7a0bc64fccd71fd631a37632460d94866e5eae. --- go.mod | 1 - go.sum | 20 -------------------- v1/ao/opentracing/multitracer_test.go | 11 ++--------- 3 files changed, 2 insertions(+), 30 deletions(-) diff --git a/go.mod b/go.mod index 58b03255..f08c9f42 100644 --- a/go.mod +++ b/go.mod @@ -6,7 +6,6 @@ require ( github.com/cespare/xxhash v1.1.0 // indirect github.com/coocood/freecache v1.1.0 github.com/golang/protobuf v1.4.2 - github.com/opentracing/basictracer-go v1.1.0 github.com/opentracing/opentracing-go v1.1.0 github.com/pkg/errors v0.9.1 github.com/stretchr/testify v1.6.1 diff --git a/go.sum b/go.sum index 1c5552c4..dca4c0a9 100644 --- a/go.sum +++ b/go.sum @@ -10,14 +10,10 @@ github.com/coocood/freecache v1.1.0 h1:ENiHOsWdj1BrrlPwblhbn4GdAsMymK3pZORJ+bJGA github.com/coocood/freecache v1.1.0/go.mod h1:ePwxCDzOYvARfHdr1pByNct1at3CoKnsipOHwKlNbzI= github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= 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/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98= github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c= -github.com/gogo/protobuf v1.3.1 h1:DqDEcV5aeaTmdFBePNpYsp3FlcVH/2ISVVM9Qf8PSls= -github.com/gogo/protobuf v1.3.1/go.mod h1:SlYgWuQ5SjCEi6WLHjHCa1yvBfUnHcTbrrZtXPKa29o= github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= @@ -35,10 +31,6 @@ github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5a github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= -github.com/kisielk/errcheck v1.2.0/go.mod h1:/BMXB+zMLi60iA8Vv6Ksmxu/1UDYcXs4uQLJ+jE2L00= -github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= -github.com/opentracing/basictracer-go v1.1.0 h1:Oa1fTSBvAl8pa3U+IJYqrKm0NALwH9OsgwOqDv4xJW0= -github.com/opentracing/basictracer-go v1.1.0/go.mod h1:V2HZueSJEp879yv285Aap1BS69fQMD+MNP1mRs6mBQc= github.com/opentracing/opentracing-go v1.1.0 h1:pWlfV3Bxv7k65HYwkikxat0+s3pV4bsqf19k25Ur8rU= github.com/opentracing/opentracing-go v1.1.0/go.mod h1:UkNAQd3GIcIGf0SeVgPpRdFStlNbqXla1AfSYxPUl2o= github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= @@ -49,24 +41,17 @@ github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1: github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA= github.com/stretchr/objx v0.1.0 h1:4G4v2dO3VZwixGIRoQ5Lfboy6nUhCyYzaqnIAPPhYs4= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= -github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0= github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= -golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU= golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= -golang.org/x/lint v0.0.0-20200302205851-738671d3881b/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY= -golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg= golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= -golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= -golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= -golang.org/x/net v0.0.0-20200421231249-e086a090c8fd/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= golang.org/x/net v0.0.0-20200602114024-627f9648deb9 h1:pNX+40auqi2JqRfOP1akLGtYcn15TUbkhwuCO3foqqM= golang.org/x/net v0.0.0-20200602114024-627f9648deb9/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= @@ -75,17 +60,13 @@ golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJ golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= -golang.org/x/tools v0.0.0-20181030221726-6c7e314b6563/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY= golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= -golang.org/x/tools v0.0.0-20200130002326-2f3ba24bd6e7/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= -golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= @@ -115,7 +96,6 @@ google.golang.org/protobuf v1.24.0/go.mod h1:r/3tXBNzIEhYS9I1OUVjXDlt8tc493IdKGj gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/mgo.v2 v2.0.0-20190816093944-a6b53ec6cb22 h1:VpOs+IwYnYBaFnrNAeB8UUWtL3vEUnzSCL1nVjPhqrw= gopkg.in/mgo.v2 v2.0.0-20190816093944-a6b53ec6cb22/go.mod h1:yeKp02qBN3iKW1OzL3MGk2IdtZzaj7SFntXj72NppTA= -gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.3.0 h1:clyUAQHOM3G0M3f5vQj7LuJrETvjVot3Z5el9nffUtU= gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo= diff --git a/v1/ao/opentracing/multitracer_test.go b/v1/ao/opentracing/multitracer_test.go index 4e9eb4d1..884c1665 100644 --- a/v1/ao/opentracing/multitracer_test.go +++ b/v1/ao/opentracing/multitracer_test.go @@ -3,9 +3,9 @@ package opentracing import ( "testing" + // aoot "github.com/appoptics/appoptics-apm-go/v1/ao/opentracing" "github.com/appoptics/appoptics-apm-go/v1/ao/internal/reporter" mt "github.com/appoptics/appoptics-apm-go/v1/contrib/multitracer" - bt "github.com/opentracing/basictracer-go" opentracing "github.com/opentracing/opentracing-go" "github.com/opentracing/opentracing-go/harness" ) @@ -13,14 +13,7 @@ import ( func TestMultiTracerAPICheck(t *testing.T) { _ = reporter.SetTestReporter(reporter.TestReporterDisableDefaultSetting(true)) // set up test reporter harness.RunAPIChecks(t, func() (tracer opentracing.Tracer, closer func()) { - return &mt.MultiTracer{ - Tracers: []opentracing.Tracer{ - NewTracer(), - bt.NewWithOptions(bt.Options{ - Recorder: bt.NewInMemoryRecorder(), - ShouldSample: func(traceID uint64) bool { return true }, // always sample - }), - }}, nil + return &mt.MultiTracer{Tracers: []opentracing.Tracer{NewTracer()}}, nil }, harness.CheckBaggageValues(false), harness.CheckInject(true), From 163dd3f6f9c5a030f66a8e36cdc809a22aa63bb8 Mon Sep 17 00:00:00 2001 From: chris erway Date: Tue, 25 Aug 2020 10:16:27 -0400 Subject: [PATCH 6/8] Add AO+basictracer MultiTracer test using build flag (to keep it out of go modules) --- v1/ao/opentracing/multitracer_test.go | 1 - v1/ao/opentracing/multitracer_two_test.go | 33 +++++++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 v1/ao/opentracing/multitracer_two_test.go diff --git a/v1/ao/opentracing/multitracer_test.go b/v1/ao/opentracing/multitracer_test.go index 884c1665..68ea5fb1 100644 --- a/v1/ao/opentracing/multitracer_test.go +++ b/v1/ao/opentracing/multitracer_test.go @@ -3,7 +3,6 @@ package opentracing import ( "testing" - // aoot "github.com/appoptics/appoptics-apm-go/v1/ao/opentracing" "github.com/appoptics/appoptics-apm-go/v1/ao/internal/reporter" mt "github.com/appoptics/appoptics-apm-go/v1/contrib/multitracer" opentracing "github.com/opentracing/opentracing-go" diff --git a/v1/ao/opentracing/multitracer_two_test.go b/v1/ao/opentracing/multitracer_two_test.go new file mode 100644 index 00000000..37bb307f --- /dev/null +++ b/v1/ao/opentracing/multitracer_two_test.go @@ -0,0 +1,33 @@ +// +build basictracer +// +// Behind a build tag avoid adding a dependency on basictracer-go + +package opentracing + +import ( + "testing" + + "github.com/appoptics/appoptics-apm-go/v1/ao/internal/reporter" + mt "github.com/appoptics/appoptics-apm-go/v1/contrib/multitracer" + bt "github.com/opentracing/basictracer-go" + opentracing "github.com/opentracing/opentracing-go" + "github.com/opentracing/opentracing-go/harness" +) + +// This test sets up AO and the OT "BasicTracer" side by side +func TestMultiTracerBasicTracerAPICheck(t *testing.T) { + _ = reporter.SetTestReporter(reporter.TestReporterDisableDefaultSetting(true)) // set up test reporter + harness.RunAPIChecks(t, func() (tracer opentracing.Tracer, closer func()) { + return &mt.MultiTracer{ + Tracers: []opentracing.Tracer{ + NewTracer(), + bt.NewWithOptions(bt.Options{ + Recorder: bt.NewInMemoryRecorder(), + ShouldSample: func(traceID uint64) bool { return true }, // always sample + }), + }}, nil + }, + harness.CheckBaggageValues(false), + harness.CheckInject(true), + ) +} From 1e865bfe27aa140cbbbe6ba92740510e00200117 Mon Sep 17 00:00:00 2001 From: chris erway Date: Tue, 25 Aug 2020 13:13:16 -0400 Subject: [PATCH 7/8] Add OpenTracing harness.Probe implementations to provide OT API checks for OT Tracer and MultiTracer --- v1/ao/opentracing/api_test.go | 26 ++++++++++++++ v1/ao/opentracing/multitracer_test.go | 44 ++++++++++++++++++++++- v1/ao/opentracing/multitracer_two_test.go | 29 +++++++++++++-- 3 files changed, 96 insertions(+), 3 deletions(-) diff --git a/v1/ao/opentracing/api_test.go b/v1/ao/opentracing/api_test.go index 2ab5539e..858cb02f 100644 --- a/v1/ao/opentracing/api_test.go +++ b/v1/ao/opentracing/api_test.go @@ -10,6 +10,31 @@ import ( "github.com/opentracing/opentracing-go/harness" ) +// apiCheckProbe exposes methods for testing data recorded by a Tracer. +type apiCheckProbe struct{} + +// SameTrace helps tests assert that this tracer's spans are from the same trace. +func (apiCheckProbe) SameTrace(first, second opentracing.Span) bool { + sp1 := first.(*spanImpl) + sp2 := second.(*spanImpl) + return sp1.context.trace.LoggableTraceID() == sp2.context.trace.LoggableTraceID() +} + +// SameSpanContext helps tests assert that a span and a context are from the same trace and span. +func (apiCheckProbe) SameSpanContext(span opentracing.Span, spanCtx opentracing.SpanContext) bool { + sp := span.(*spanImpl) + sc := spanCtx.(spanContext) + var md1, md2 string + md1 = sp.context.span.MetadataString() + if sc.span == nil { + md1 = sc.remoteMD + } else { + md1 = sc.span.MetadataString() + } + md2 = sp.context.span.MetadataString() + return md1 == md2 +} + func TestAPICheck(t *testing.T) { _ = reporter.SetTestReporter(reporter.TestReporterDisableDefaultSetting(true)) // set up test reporter harness.RunAPIChecks(t, func() (tracer opentracing.Tracer, closer func()) { @@ -18,5 +43,6 @@ func TestAPICheck(t *testing.T) { harness.CheckBaggageValues(true), harness.CheckInject(true), harness.CheckExtract(true), + harness.UseProbe(apiCheckProbe{}), ) } diff --git a/v1/ao/opentracing/multitracer_test.go b/v1/ao/opentracing/multitracer_test.go index 68ea5fb1..7d3ccd4d 100644 --- a/v1/ao/opentracing/multitracer_test.go +++ b/v1/ao/opentracing/multitracer_test.go @@ -9,13 +9,55 @@ import ( "github.com/opentracing/opentracing-go/harness" ) +// This test sets up the AO Tracer wrapped in a MultiTracer func TestMultiTracerAPICheck(t *testing.T) { _ = reporter.SetTestReporter(reporter.TestReporterDisableDefaultSetting(true)) // set up test reporter + multiTracer := &mt.MultiTracer{Tracers: []opentracing.Tracer{NewTracer()}} + harness.RunAPIChecks(t, func() (tracer opentracing.Tracer, closer func()) { - return &mt.MultiTracer{Tracers: []opentracing.Tracer{NewTracer()}}, nil + return multiTracer, nil }, harness.CheckBaggageValues(false), harness.CheckInject(true), harness.CheckExtract(true), + harness.UseProbe(&multiApiCheckProbe{ + mt: multiTracer, + probes: []harness.APICheckProbe{apiCheckProbe{}}, + }), ) } + +type multiApiCheckProbe struct { + mt *mt.MultiTracer + probes []harness.APICheckProbe +} + +func (m *multiApiCheckProbe) SameTrace(first, second opentracing.Span) bool { + sp1 := first.(*mt.MultiSpan) + sp2 := second.(*mt.MultiSpan) + + for i := range m.mt.Tracers { + if m.probes[i] == nil { + continue + } + if !m.probes[i].SameTrace(sp1.Spans[i], sp2.Spans[i]) { + return false + } + } + return true +} + +func (m *multiApiCheckProbe) SameSpanContext(span opentracing.Span, spanCtx opentracing.SpanContext) bool { + sp := span.(*mt.MultiSpan) + sc := spanCtx.(*mt.MultiSpanContext) + + for i := range m.mt.Tracers { + if m.probes[i] == nil { + continue + } + if !m.probes[i].SameSpanContext(sp.Spans[i], sc.SpanContexts[i]) { + return false + } + } + return true +} diff --git a/v1/ao/opentracing/multitracer_two_test.go b/v1/ao/opentracing/multitracer_two_test.go index 37bb307f..847a4af0 100644 --- a/v1/ao/opentracing/multitracer_two_test.go +++ b/v1/ao/opentracing/multitracer_two_test.go @@ -14,13 +14,37 @@ import ( "github.com/opentracing/opentracing-go/harness" ) -// This test sets up AO and the OT "BasicTracer" side by side +// This test sets up AO Tracer and the OT "BasicTracer" side by side +func TestMultiTracerAOBasicTracerAPICheck(t *testing.T) { + _ = reporter.SetTestReporter(reporter.TestReporterDisableDefaultSetting(true)) // set up test reporter + multiTracer := &mt.MultiTracer{ + Tracers: []opentracing.Tracer{ + NewTracer(), + bt.NewWithOptions(bt.Options{ + Recorder: bt.NewInMemoryRecorder(), + ShouldSample: func(traceID uint64) bool { return true }, // always sample + }), + }} + + harness.RunAPIChecks(t, func() (tracer opentracing.Tracer, closer func()) { + return multiTracer, nil + }, + harness.CheckBaggageValues(false), + harness.CheckInject(true), + harness.CheckExtract(true), + harness.UseProbe(&multiApiCheckProbe{ + mt: multiTracer, + probes: []harness.APICheckProbe{apiCheckProbe{}, nil}, + }), + ) +} + +// This test sets up the OT "BasicTracer" wrapped in a MultiTracer func TestMultiTracerBasicTracerAPICheck(t *testing.T) { _ = reporter.SetTestReporter(reporter.TestReporterDisableDefaultSetting(true)) // set up test reporter harness.RunAPIChecks(t, func() (tracer opentracing.Tracer, closer func()) { return &mt.MultiTracer{ Tracers: []opentracing.Tracer{ - NewTracer(), bt.NewWithOptions(bt.Options{ Recorder: bt.NewInMemoryRecorder(), ShouldSample: func(traceID uint64) bool { return true }, // always sample @@ -29,5 +53,6 @@ func TestMultiTracerBasicTracerAPICheck(t *testing.T) { }, harness.CheckBaggageValues(false), harness.CheckInject(true), + harness.CheckExtract(true), ) } From ae70a0b8f2fb19e1197650db2fec4a946ab1eec7 Mon Sep 17 00:00:00 2001 From: chris erway Date: Thu, 27 Aug 2020 12:31:42 -0400 Subject: [PATCH 8/8] Update coverpkg to include multitracer --- .github/workflows/test.yaml | 2 +- v1/ao/Makefile | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index ee6aa171..de42c306 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -50,7 +50,7 @@ jobs: go test -v -race -covermode=atomic -coverprofile=cov.out popd pushd opentracing - go test -v -race -covermode=atomic -coverprofile=cov.out -coverpkg github.com/appoptics/appoptics-apm-go/v1/ao/internal/reporter,github.com/appoptics/appoptics-apm-go/v1/ao/internal/log,github.com/appoptics/appoptics-apm-go/v1/ao/internal/bson,github.com/appoptics/appoptics-apm-go/v1/ao/internal/metrics,github.com/appoptics/appoptics-apm-go/v1/ao/opentracing,github.com/appoptics/appoptics-apm-go/v1/ao,github.com/appoptics/appoptics-apm-go/v1/ao/internal/config,github.com/appoptics/appoptics-apm-go/v1/ao/internal/host + go test -v -race -covermode=atomic -coverprofile=cov.out -coverpkg github.com/appoptics/appoptics-apm-go/v1/ao/internal/reporter,github.com/appoptics/appoptics-apm-go/v1/ao/internal/log,github.com/appoptics/appoptics-apm-go/v1/ao/internal/bson,github.com/appoptics/appoptics-apm-go/v1/ao/internal/metrics,github.com/appoptics/appoptics-apm-go/v1/ao/opentracing,github.com/appoptics/appoptics-apm-go/v1/ao,github.com/appoptics/appoptics-apm-go/v1/ao/internal/config,github.com/appoptics/appoptics-apm-go/v1/ao/internal/host,github.com/appoptics/appoptics-apm-go/v1/contrib/multitracer popd popd pushd contrib/aogrpc diff --git a/v1/ao/Makefile b/v1/ao/Makefile index e36e5a7f..765ebacc 100644 --- a/v1/ao/Makefile +++ b/v1/ao/Makefile @@ -2,7 +2,7 @@ SHELL=bash prev_branch :=$(shell git rev-parse --abbrev-ref HEAD) -coverpkg="github.com/appoptics/appoptics-apm-go/v1/ao/internal/reporter,github.com/appoptics/appoptics-apm-go/v1/ao,github.com/appoptics/appoptics-apm-go/v1/ao/opentracing" +coverpkg="github.com/appoptics/appoptics-apm-go/v1/ao/internal/reporter,github.com/appoptics/appoptics-apm-go/v1/ao/internal/log,github.com/appoptics/appoptics-apm-go/v1/ao/internal/bson,github.com/appoptics/appoptics-apm-go/v1/ao/internal/metrics,github.com/appoptics/appoptics-apm-go/v1/ao,github.com/appoptics/appoptics-apm-go/v1/ao/internal/config,github.com/appoptics/appoptics-apm-go/v1/ao/internal/host,github.com/appoptics/appoptics-apm-go/v1/contrib/multitracer" cov_args=-covermode=atomic -coverpkg=$(coverpkg) cov_out=-coverprofile=cov.out cov_files=cov.out internal/reporter/cov.out opentracing/cov.out @@ -20,4 +20,4 @@ $(cov_merge): test $(cov_files) gocovmerge $(cov_files) > $(cov_merge) coverhtml: $(cov_merge) - go tool cover -html=$(cov_merge) \ No newline at end of file + go tool cover -html=$(cov_merge)