From bf544a05eb2c79e5aba87b25a5593ae9c55b2944 Mon Sep 17 00:00:00 2001 From: Ben Sigelman Date: Wed, 10 Feb 2016 17:09:25 -0800 Subject: [PATCH 1/3] add the notion of a ImplementationID --- examples/dapperish/dapper.go | 7 ++++++- ext/tags_test.go | 3 ++- noop.go | 15 ++++++++++++--- standardtracer/spanpropagator_test.go | 2 +- standardtracer/tracer.go | 8 +++++++- tracer.go | 17 +++++++++++++++++ 6 files changed, 45 insertions(+), 7 deletions(-) diff --git a/examples/dapperish/dapper.go b/examples/dapperish/dapper.go index 62d0495..a995904 100644 --- a/examples/dapperish/dapper.go +++ b/examples/dapperish/dapper.go @@ -7,5 +7,10 @@ import ( // NewTracer returns a new dapperish Tracer instance. func NewTracer(processName string) opentracing.Tracer { - return standardtracer.New(NewTrivialRecorder(processName)) + return standardtracer.New( + NewTrivialRecorder(processName), + &opentracing.ImplementationID{ + Name: "dapperish", + Version: "0.1.0", + }) } diff --git a/ext/tags_test.go b/ext/tags_test.go index b1902cf..1f5b8de 100644 --- a/ext/tags_test.go +++ b/ext/tags_test.go @@ -3,6 +3,7 @@ package ext_test import ( "testing" + "github.com/opentracing/opentracing-go" "github.com/opentracing/opentracing-go/ext" "github.com/opentracing/opentracing-go/standardtracer" "github.com/opentracing/opentracing-go/testutils" @@ -14,7 +15,7 @@ func TestPeerTags(t *testing.T) { t.Fatalf("Invalid PeerService %v", ext.PeerService) } recorder := testutils.NewInMemoryRecorder() - tracer := standardtracer.New(recorder) + tracer := standardtracer.New(recorder, &opentracing.ImplementationID{}) span := tracer.StartTrace("my-trace") ext.PeerService.Add(span, "my-service") ext.PeerHostname.Add(span, "my-hostname") diff --git a/noop.go b/noop.go index a8214b5..c3631ef 100644 --- a/noop.go +++ b/noop.go @@ -9,9 +9,13 @@ type noopSpan struct{} var ( defaultNoopSpan = noopSpan{} defaultNoopTracer = NoopTracer{} - emptyTags = Tags{} - emptyBytes = []byte{} - emptyStringMap = map[string]string{} + noopImplID = &ImplementationID{ + Name: "noop", + Version: "1.0.0", + } + emptyTags = Tags{} + emptyBytes = []byte{} + emptyStringMap = map[string]string{} ) const ( @@ -68,3 +72,8 @@ func (n NoopTracer) StartTrace(operationName string) Span { func (n NoopTracer) JoinTrace(operationName string, parent interface{}) Span { return defaultNoopSpan } + +// ImplementationID belongs to the Tracer interface. +func (n NoopTracer) ImplementationID() *ImplementationID { + return noopImplID +} diff --git a/standardtracer/spanpropagator_test.go b/standardtracer/spanpropagator_test.go index 794544f..4464747 100644 --- a/standardtracer/spanpropagator_test.go +++ b/standardtracer/spanpropagator_test.go @@ -14,7 +14,7 @@ import ( func TestSpanPropagator(t *testing.T) { const op = "test" recorder := testutils.NewInMemoryRecorder() - tracer := standardtracer.New(recorder) + tracer := standardtracer.New(recorder, &opentracing.ImplementationID{}) sp := tracer.StartTrace(op) sp.SetTraceAttribute("foo", "bar") diff --git a/standardtracer/tracer.go b/standardtracer/tracer.go index ecf8244..e0dcd23 100644 --- a/standardtracer/tracer.go +++ b/standardtracer/tracer.go @@ -8,15 +8,17 @@ import ( // New creates and returns a standard Tracer which defers to `recorder` after // RawSpans have been assembled. -func New(recorder SpanRecorder) opentracing.Tracer { +func New(recorder SpanRecorder, implID *opentracing.ImplementationID) opentracing.Tracer { return &tracerImpl{ recorder: recorder, + implID: implID, } } // Implements the `Tracer` interface. type tracerImpl struct { recorder SpanRecorder + implID *opentracing.ImplementationID } func (s *tracerImpl) StartTrace( @@ -58,3 +60,7 @@ func (s *tracerImpl) startSpanGeneric( } return span } + +func (t *tracerImpl) ImplementationID() *opentracing.ImplementationID { + return t.implID +} diff --git a/tracer.go b/tracer.go index 3071334..023a387 100644 --- a/tracer.go +++ b/tracer.go @@ -23,4 +23,21 @@ type Tracer interface { // SetTag("lucky_number", 42) // StartTrace(operationName string) Span + + // ImplementationID returns information about the OpenTracing + // implementation backing the Tracer. The return value should not change + // over the life of a particular Tracer instance. + ImplementationID() *ImplementationID +} + +// ImplementationID is a simple, extensible struct that describes an +// OpenTracing implementation. +type ImplementationID struct { + // The (stable) name of the implementation. E.g., "Dapper" or "Zipkin". The + // Name should not reflect the host language or platform. + Name string + + // Version may take any form, but SemVer (http://semver.org/) is strongly + // encouraged. + Version string } From 21dec98ac0038722caccaf0752203439a474ef7f Mon Sep 17 00:00:00 2001 From: Ben Sigelman Date: Wed, 10 Feb 2016 20:49:02 -0800 Subject: [PATCH 2/3] add a constant for the OpenTracing semver --- tracer.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tracer.go b/tracer.go index 023a387..b24020b 100644 --- a/tracer.go +++ b/tracer.go @@ -41,3 +41,9 @@ type ImplementationID struct { // encouraged. Version string } + +const ( + // OpenTracingSemVer identifies the semantic version (http://semver.org/) + // of the OpenTracing Go library itself. + OpenTracingSemVer = "0.9.0" +) From 61e5cab3d6bd37423877d44c29014e3ddcbc4bbb Mon Sep 17 00:00:00 2001 From: Ben Sigelman Date: Thu, 11 Feb 2016 11:16:12 -0800 Subject: [PATCH 3/3] get rid of impl ids for now --- examples/dapperish/dapper.go | 7 +------ ext/tags_test.go | 3 +-- noop.go | 15 +++------------ standardtracer/spanpropagator_test.go | 2 +- standardtracer/tracer.go | 8 +------- tracer.go | 24 +++++------------------- 6 files changed, 12 insertions(+), 47 deletions(-) diff --git a/examples/dapperish/dapper.go b/examples/dapperish/dapper.go index a995904..62d0495 100644 --- a/examples/dapperish/dapper.go +++ b/examples/dapperish/dapper.go @@ -7,10 +7,5 @@ import ( // NewTracer returns a new dapperish Tracer instance. func NewTracer(processName string) opentracing.Tracer { - return standardtracer.New( - NewTrivialRecorder(processName), - &opentracing.ImplementationID{ - Name: "dapperish", - Version: "0.1.0", - }) + return standardtracer.New(NewTrivialRecorder(processName)) } diff --git a/ext/tags_test.go b/ext/tags_test.go index 1f5b8de..b1902cf 100644 --- a/ext/tags_test.go +++ b/ext/tags_test.go @@ -3,7 +3,6 @@ package ext_test import ( "testing" - "github.com/opentracing/opentracing-go" "github.com/opentracing/opentracing-go/ext" "github.com/opentracing/opentracing-go/standardtracer" "github.com/opentracing/opentracing-go/testutils" @@ -15,7 +14,7 @@ func TestPeerTags(t *testing.T) { t.Fatalf("Invalid PeerService %v", ext.PeerService) } recorder := testutils.NewInMemoryRecorder() - tracer := standardtracer.New(recorder, &opentracing.ImplementationID{}) + tracer := standardtracer.New(recorder) span := tracer.StartTrace("my-trace") ext.PeerService.Add(span, "my-service") ext.PeerHostname.Add(span, "my-hostname") diff --git a/noop.go b/noop.go index c3631ef..a8214b5 100644 --- a/noop.go +++ b/noop.go @@ -9,13 +9,9 @@ type noopSpan struct{} var ( defaultNoopSpan = noopSpan{} defaultNoopTracer = NoopTracer{} - noopImplID = &ImplementationID{ - Name: "noop", - Version: "1.0.0", - } - emptyTags = Tags{} - emptyBytes = []byte{} - emptyStringMap = map[string]string{} + emptyTags = Tags{} + emptyBytes = []byte{} + emptyStringMap = map[string]string{} ) const ( @@ -72,8 +68,3 @@ func (n NoopTracer) StartTrace(operationName string) Span { func (n NoopTracer) JoinTrace(operationName string, parent interface{}) Span { return defaultNoopSpan } - -// ImplementationID belongs to the Tracer interface. -func (n NoopTracer) ImplementationID() *ImplementationID { - return noopImplID -} diff --git a/standardtracer/spanpropagator_test.go b/standardtracer/spanpropagator_test.go index 4464747..794544f 100644 --- a/standardtracer/spanpropagator_test.go +++ b/standardtracer/spanpropagator_test.go @@ -14,7 +14,7 @@ import ( func TestSpanPropagator(t *testing.T) { const op = "test" recorder := testutils.NewInMemoryRecorder() - tracer := standardtracer.New(recorder, &opentracing.ImplementationID{}) + tracer := standardtracer.New(recorder) sp := tracer.StartTrace(op) sp.SetTraceAttribute("foo", "bar") diff --git a/standardtracer/tracer.go b/standardtracer/tracer.go index e0dcd23..ecf8244 100644 --- a/standardtracer/tracer.go +++ b/standardtracer/tracer.go @@ -8,17 +8,15 @@ import ( // New creates and returns a standard Tracer which defers to `recorder` after // RawSpans have been assembled. -func New(recorder SpanRecorder, implID *opentracing.ImplementationID) opentracing.Tracer { +func New(recorder SpanRecorder) opentracing.Tracer { return &tracerImpl{ recorder: recorder, - implID: implID, } } // Implements the `Tracer` interface. type tracerImpl struct { recorder SpanRecorder - implID *opentracing.ImplementationID } func (s *tracerImpl) StartTrace( @@ -60,7 +58,3 @@ func (s *tracerImpl) startSpanGeneric( } return span } - -func (t *tracerImpl) ImplementationID() *opentracing.ImplementationID { - return t.implID -} diff --git a/tracer.go b/tracer.go index b24020b..6794bc8 100644 --- a/tracer.go +++ b/tracer.go @@ -23,27 +23,13 @@ type Tracer interface { // SetTag("lucky_number", 42) // StartTrace(operationName string) Span - - // ImplementationID returns information about the OpenTracing - // implementation backing the Tracer. The return value should not change - // over the life of a particular Tracer instance. - ImplementationID() *ImplementationID -} - -// ImplementationID is a simple, extensible struct that describes an -// OpenTracing implementation. -type ImplementationID struct { - // The (stable) name of the implementation. E.g., "Dapper" or "Zipkin". The - // Name should not reflect the host language or platform. - Name string - - // Version may take any form, but SemVer (http://semver.org/) is strongly - // encouraged. - Version string } const ( - // OpenTracingSemVer identifies the semantic version (http://semver.org/) - // of the OpenTracing Go library itself. + // OpenTracingGoAPISemVer is, well,tThe OpenTracing Go API's SemVer + // (http://semver.org/). Note that each OpenTracing platform API has its + // own semver (which has more to do with refactors or other compatibility + // changes and less to do with the platform-independent OpenTracing + // semantic specification). OpenTracingSemVer = "0.9.0" )