Permalink
Browse files

Deprecate InitGlobalTracer in favor of SetGlobalTracer (#128)

and clarify the purpose of NoopTracer
  • Loading branch information...
1 parent 137bfce commit ac5446f53f2c0fc68dc16dc5f426eae1cd288b34 @yurishkuro yurishkuro committed on GitHub Dec 2, 2016
Showing with 38 additions and 8 deletions.
  1. +14 −0 CHANGELOG.md
  2. +10 −5 globaltracer.go
  3. +1 −1 mocktracer/mocktracer_test.go
  4. +13 −2 noop.go
View
@@ -0,0 +1,14 @@
+Changes by Version
+==================
+
+1.1.0 (unreleased)
+-------------------
+
+- Deprecate InitGlobalTracer() in favor of SetGlobalTracer()
+
+
+1.0.0 (2016-09-26)
+-------------------
+
+- This release implements OpenTracing Specification 1.0 (http://opentracing.io/spec)
+
View
@@ -4,18 +4,18 @@ var (
globalTracer Tracer = NoopTracer{}
)
-// InitGlobalTracer sets the [singleton] opentracing.Tracer returned by
+// SetGlobalTracer sets the [singleton] opentracing.Tracer returned by
// GlobalTracer(). Those who use GlobalTracer (rather than directly manage an
-// opentracing.Tracer instance) should call InitGlobalTracer as early as
+// opentracing.Tracer instance) should call SetGlobalTracer as early as
// possible in main(), prior to calling the `StartSpan` global func below.
-// Prior to calling `InitGlobalTracer`, any Spans started via the `StartSpan`
+// Prior to calling `SetGlobalTracer`, any Spans started via the `StartSpan`
// (etc) globals are noops.
-func InitGlobalTracer(tracer Tracer) {
+func SetGlobalTracer(tracer Tracer) {
globalTracer = tracer
}
// GlobalTracer returns the global singleton `Tracer` implementation.
-// Before `InitGlobalTracer()` is called, the `GlobalTracer()` is a noop
+// Before `SetGlobalTracer()` is called, the `GlobalTracer()` is a noop
// implementation that drops all data handed to it.
func GlobalTracer() Tracer {
return globalTracer
@@ -25,3 +25,8 @@ func GlobalTracer() Tracer {
func StartSpan(operationName string, opts ...StartSpanOption) Span {
return globalTracer.StartSpan(operationName, opts...)
}
+
+// InitGlobalTracer is deprecated. Please use SetGlobalTracer.
+func InitGlobalTracer(tracer Tracer) {
+ SetGlobalTracer(tracer)
+}
@@ -133,7 +133,7 @@ func TestMockSpan_LogFields(t *testing.T) {
}))
span.FinishWithOptions(opentracing.FinishOptions{
LogRecords: []opentracing.LogRecord{
- {time.Now(), []log.Field{log.String("key9", "finish")}},
+ {Timestamp: time.Now(), Fields: []log.Field{log.String("key9", "finish")}},
}})
spans := tracer.FinishedSpans()
assert.Equal(t, 1, len(spans))
View
@@ -2,8 +2,19 @@ package opentracing
import "github.com/opentracing/opentracing-go/log"
-// A NoopTracer is a trivial implementation of Tracer for which all operations
-// are no-ops.
+// A NoopTracer is a trivial, minimum overhead implementation of Tracer
+// for which all operations are no-ops.
+//
+// The primary use of this implementation is in libraries, such as RPC
+// frameworks, that make tracing an optional feature controlled by the
+// end user. A no-op implementation allows said libraries to use it
+// as the default Tracer and to write instrumentation that does
+// not need to keep checking if the tracer instance is nil.
+//
+// For the same reason, the NoopTracer is the default "global" tracer
+// (see GlobalTracer and SetGlobalTracer functions).
+//
+// WARNING: NoopTracer does not support baggage propagation.
type NoopTracer struct{}
type noopSpan struct{}

0 comments on commit ac5446f

Please sign in to comment.