Skip to content
This repository has been archived by the owner on May 23, 2023. It is now read-only.

Commit

Permalink
Renames OpenTracer to just Tracer; fixes minor lint issues; adds Make…
Browse files Browse the repository at this point in the history
…file
  • Loading branch information
Yuri Shkuro committed Dec 26, 2015
1 parent 486bca7 commit d2d4060
Show file tree
Hide file tree
Showing 11 changed files with 81 additions and 48 deletions.
13 changes: 13 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# IntelliJ project files
.idea/
api-golang.iml
api-golang.ipr
api-golang.iws

# Test results
*.cov
*.html
test.log

# Build dir
build/
20 changes: 20 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@


.DEFAULT_GOAL := test

.PHONY: test
test:
go test ./...

.PHONY: lint
lint:
golint ./...

.PHONY: vet
vet:
go vet ./...

.PHONY: example
example:
go build -o build/dapperish-example ./examples/dapperish/.
./build/dapperish-example
4 changes: 2 additions & 2 deletions examples/dapperish/dapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import (
"github.com/opentracing/api-golang/opentracing/standardtracer"
)

// NewTracer returns a new dapperish OpenTracer instance.
func NewTracer(processName string) opentracing.OpenTracer {
// NewTracer returns a new dapperish Tracer instance.
func NewTracer(processName string) opentracing.Tracer {
return standardtracer.New(
NewTrivialRecorder(processName),
NewTraceContextSource())
Expand Down
4 changes: 2 additions & 2 deletions opentracing/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ The simplest starting point is `./default_tracer.go`. As early as possible, call
##### Non-Singleton initialization

If you prefer direct control to singletons, use `standardtracer.New(...)`
directly and manage ownership of the `opentracing.OpenTracer` implementation
directly and manage ownership of the `opentracing.Tracer` implementation
explicitly.

#### Starting an empty trace by creating a "root span"
Expand Down Expand Up @@ -107,7 +107,7 @@ associated with any `opentracing.Span` instance.
## API pointers for those implementing a tracing system

There should be no need for most tracing system implementors to worry about the
`opentracing.Span` or `opentracing.OpenTracer` interfaces directly:
`opentracing.Span` or `opentracing.Tracer` interfaces directly:
`standardtracer.New(...)` should work well enough in most circumstances.

That said, tracing system authors must provide implementations of:
Expand Down
32 changes: 16 additions & 16 deletions opentracing/defaulttracer.go
Original file line number Diff line number Diff line change
@@ -1,64 +1,64 @@
package opentracing

var (
defaultOpenTracer OpenTracer = noopOpenTracer{noopTraceContextSource{}}
defaultTracer Tracer = noopTracer{noopTraceContextSource{}}
)

// InitDefaultTracer sets the [singleton] OpenTracer returned by
// InitDefaultTracer sets the [singleton] opentracing.Tracer returned by
// DefaultTracer(). Those who use DefaultTracer (rather than directly manage an
// OpenTracer instance) should call InitDefaultTracer as early as possible in
// opentracing.Tracer instance) should call InitDefaultTracer as early as possible in
// main(), prior to calling the `StartTrace` (etc) global funcs below. Prior to
// calling `InitDefaultTracer`, any Spans started via the `StartTrace` (etc)
// globals are noops.
func InitDefaultTracer(tracer OpenTracer) {
defaultOpenTracer = tracer
func InitDefaultTracer(tracer Tracer) {
defaultTracer = tracer
}

// DefaultTracer returns the global singleton `OpenTracer` implementation.
// DefaultTracer returns the global singleton `Tracer` implementation.
// Before `InitDefaultTracer()` is called, the `DefaultTracer()` is a noop
// implementation that drops all data handed to it.
func DefaultTracer() OpenTracer {
return defaultOpenTracer
func DefaultTracer() Tracer {
return defaultTracer
}

// StartTrace defers to `OpenTracer.StartTrace`. See `DefaultTracer()`.
// StartTrace defers to `Tracer.StartTrace`. See `DefaultTracer()`.
func StartTrace(operationName string) Span {
return defaultOpenTracer.StartTrace(operationName)
return defaultTracer.StartTrace(operationName)
}

// JoinTrace defers to `OpenTracer.JoinTrace`. See `DefaultTracer()`.
// JoinTrace defers to `Tracer.JoinTrace`. See `DefaultTracer()`.
func JoinTrace(operationName string, parent interface{}) Span {
return defaultOpenTracer.JoinTrace(operationName, parent)
return defaultTracer.JoinTrace(operationName, parent)
}

// MarshalTraceContextBinary defers to
// `TraceContextMarshaler.MarshalTraceContextBinary`.
//
// See `DefaultTracer()`.
func MarshalTraceContextBinary(ctx TraceContext) ([]byte, []byte) {
return defaultOpenTracer.MarshalTraceContextBinary(ctx)
return defaultTracer.MarshalTraceContextBinary(ctx)
}

// MarshalTraceContextStringMap defers to
// `TraceContextMarshaler.MarshalTraceContextStringMap`.
//
// See `DefaultTracer()`.
func MarshalTraceContextStringMap(ctx TraceContext) (map[string]string, map[string]string) {
return defaultOpenTracer.MarshalTraceContextStringMap(ctx)
return defaultTracer.MarshalTraceContextStringMap(ctx)
}

// UnmarshalTraceContextBinary defers to
// `TraceContextUnmarshaler.UnmarshalTraceContextBinary`.
//
// See `DefaultTracer()`.
func UnmarshalTraceContextBinary(traceContextID []byte, traceTags []byte) (TraceContext, error) {
return defaultOpenTracer.UnmarshalTraceContextBinary(traceContextID, traceTags)
return defaultTracer.UnmarshalTraceContextBinary(traceContextID, traceTags)
}

// UnmarshalTraceContextStringMap defers to
// `TraceContextUnmarshaler.UnmarshaTraceContextStringMap`.
//
// See `DefaultTracer()`.
func UnmarshalTraceContextStringMap(traceContextID map[string]string, traceTags map[string]string) (TraceContext, error) {
return defaultOpenTracer.UnmarshalTraceContextStringMap(traceContextID, traceTags)
return defaultTracer.UnmarshalTraceContextStringMap(traceContextID, traceTags)
}
10 changes: 5 additions & 5 deletions opentracing/noop.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ type noopTraceContext struct{}
type noopSpan struct{}
type noopRecorder struct{}
type noopTraceContextSource struct{}
type noopOpenTracer struct {
type noopTracer struct {
noopTraceContextSource
}

Expand All @@ -15,7 +15,7 @@ var (
defaultNoopSpan = noopSpan{}
defaultNoopRecorder = noopRecorder{}
defaultNoopTraceContextSource = noopTraceContextSource{}
defaultNoopOpenTracer = noopOpenTracer{}
defaultNoopTracer = noopTracer{}
emptyTags = Tags{}
emptyBytes = []byte{}
emptyStringMap = map[string]string{}
Expand Down Expand Up @@ -76,11 +76,11 @@ func (n noopRecorder) SetTag(key string, val interface{}) ProcessIdentifier { re
func (n noopRecorder) RecordSpan(span *RawSpan) {}
func (n noopRecorder) ProcessName() string { return "" }

// noopOpenTracer:
func (n noopOpenTracer) StartTrace(operationName string) Span {
// noopTracer:
func (n noopTracer) StartTrace(operationName string) Span {
return defaultNoopSpan
}

func (n noopOpenTracer) JoinTrace(operationName string, parent interface{}) Span {
func (n noopTracer) JoinTrace(operationName string, parent interface{}) Span {
return defaultNoopSpan
}
2 changes: 1 addition & 1 deletion opentracing/recorder.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ type ProcessIdentifier interface {
}

// A Recorder handles all of the `RawSpan` data generated via an
// associated `OpenTracer` (see `NewStandardTracer`) instance. It also names
// associated `Tracer` (see `NewStandardTracer`) instance. It also names
// the containing process and provides access to a straightforward tag map.
type Recorder interface {
ProcessIdentifier
Expand Down
2 changes: 1 addition & 1 deletion opentracing/span.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import "golang.org/x/net/context"

// Span represents an active, un-finished span in the opentracing system.
//
// Spans are created by the OpenTracer interface and Span.StartChild.
// Spans are created by the Tracer interface and Span.StartChild.
type Span interface {
// Creates and starts a child span.
StartChild(operationName string) Span
Expand Down
26 changes: 13 additions & 13 deletions opentracing/standardtracer/standardimpl.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,20 @@ import (
"golang.org/x/net/context"
)

// New creates and returns a standard OpenTracer which defers to `rec` and
// New creates and returns a standard Tracer which defers to `recorder` and
// `source` as appropriate.
func New(rec opentracing.Recorder, source opentracing.TraceContextSource) opentracing.OpenTracer {
return &standardOpenTracer{
func New(recorder opentracing.Recorder, source opentracing.TraceContextSource) opentracing.Tracer {
return &standardTracer{
TraceContextSource: source,
recorder: rec,
recorder: recorder,
}
}

// Implements the `Span` interface. Created via standardOpenTracer (see
// Implements the `Span` interface. Created via standardTracer (see
// `NewStandardTracer()`).
type standardSpan struct {
lock sync.Mutex
tracer *standardOpenTracer
tracer *standardTracer
recorder opentracing.Recorder
raw opentracing.RawSpan
}
Expand Down Expand Up @@ -90,14 +90,14 @@ func (s *standardSpan) AddToGoContext(ctx context.Context) (opentracing.Span, co
return s, opentracing.GoContextWithSpan(ctx, s)
}

// Implements the `OpenTracer` interface.
type standardOpenTracer struct {
// Implements the `Tracer` interface.
type standardTracer struct {
opentracing.TraceContextSource

recorder opentracing.Recorder
}

func (s *standardOpenTracer) StartTrace(
func (s *standardTracer) StartTrace(
operationName string,
) opentracing.Span {
return s.startSpanGeneric(
Expand All @@ -107,7 +107,7 @@ func (s *standardOpenTracer) StartTrace(
)
}

func (s *standardOpenTracer) JoinTrace(
func (s *standardTracer) JoinTrace(
operationName string,
parent interface{},
) opentracing.Span {
Expand All @@ -120,7 +120,7 @@ func (s *standardOpenTracer) JoinTrace(
}
}

func (s *standardOpenTracer) startSpanWithGoContextParent(
func (s *standardTracer) startSpanWithGoContextParent(
operationName string,
parent context.Context,
) opentracing.Span {
Expand All @@ -140,7 +140,7 @@ func (s *standardOpenTracer) startSpanWithGoContextParent(
)
}

func (s *standardOpenTracer) startSpanWithTraceContextParent(
func (s *standardTracer) startSpanWithTraceContextParent(
operationName string,
parent opentracing.TraceContext,
) opentracing.Span {
Expand All @@ -153,7 +153,7 @@ func (s *standardOpenTracer) startSpanWithTraceContextParent(
}

// A helper for standardSpan creation.
func (s *standardOpenTracer) startSpanGeneric(
func (s *standardTracer) startSpanGeneric(
operationName string,
childCtx opentracing.TraceContext,
tags opentracing.Tags,
Expand Down
10 changes: 5 additions & 5 deletions opentracing/tracecontext.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ type TraceContextUnmarshaler interface {
// tags (per `SetTraceTag` and `TraceTag`) attached to a TraceContext
// instance.
//
// It's permissable to pass the same map to both parameters (e.g., an HTTP
// It's permissible to pass the same map to both parameters (e.g., an HTTP
// request headers map): the implementation should only unmarshal the
// subset its interested in.
UnmarshalTraceContextStringMap(
Expand All @@ -147,12 +147,12 @@ type TraceContextSource interface {
NewRootTraceContext() TraceContext
}

var kTraceTagRegexp = regexp.MustCompile("^(?i:[a-z0-9][-a-z0-9]*)$")
var regexTraceTag = regexp.MustCompile("^(?i:[a-z0-9][-a-z0-9]*)$")

// Returns the canonicalized version of trace tag key `key`, and true if and
// only if the key was valid.
// CanonicalizeTraceTagKey returns the canonicalized version of trace tag key `key`,
// and true if and only if the key was valid.
func CanonicalizeTraceTagKey(key string) (string, bool) {
if !kTraceTagRegexp.MatchString(key) {
if !regexTraceTag.MatchString(key) {
return "", false
}
return strings.ToLower(key), true
Expand Down
6 changes: 3 additions & 3 deletions opentracing/opentracer.go → opentracing/tracer.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package opentracing

// OpenTracer is a simple, thin interface for Span creation.
// Tracer is a simple, thin interface for Span creation.
//
// A straightforward implementation is available via the
// `opentracing/standardtracer` package's `standardtracer.New()'.
type OpenTracer interface {
type Tracer interface {
TraceContextSource

// Create, start, and return a new Span with the given `operationName`, all
Expand All @@ -13,7 +13,7 @@ type OpenTracer interface {
//
// Examples:
//
// val tracer OpenTracer = ...
// var tracer Tracer = ...
//
// sp := tracer.StartTrace("GetFeed")
//
Expand Down

0 comments on commit d2d4060

Please sign in to comment.