Skip to content

Commit

Permalink
Added new constructor for tracer that propagates error. (#228)
Browse files Browse the repository at this point in the history
Signed-off-by: Bartek Plotka <bwplotka@gmail.com>
  • Loading branch information
bwplotka authored and codeboten committed Oct 28, 2019
1 parent 6dba53b commit 0532feb
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions tracer.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,22 @@ type tracerImpl struct {
}

// NewTracer creates and starts a new Lightstep Tracer.
// In case of error, we emit event and return nil.
func NewTracer(opts Options) Tracer {
err := opts.Initialize()
if err != nil {
tr, err := CreateTracer(opts)
if err != nil {
emitEvent(newEventStartError(err))
return nil
}
return tr
}

// CreateTracer creates and starts a new Lightstep Tracer.
// It is meant to replace NewTracer which does not propagate the error.
func CreateTracer(opts Options) (Tracer, error) {
if err := opts.Initialize(); err != nil {
return nil, fmt.Errorf("init; err: %v", err)
}

attributes := map[string]string{}
for k, v := range opts.Tags {
Expand All @@ -121,16 +131,15 @@ func NewTracer(opts Options) Tracer {

impl.buffer.setCurrent(now)

var err error
impl.client, err = newCollectorClient(opts)
if err != nil {
fmt.Println("Failed to create to Collector client!", err)
return nil
return nil, fmt.Errorf("create collector client; err: %v", err)
}

conn, err := impl.client.ConnectClient()
if err != nil {
emitEvent(newEventStartError(err))
return nil
return nil, err
}
impl.connection = conn

Expand All @@ -151,7 +160,7 @@ func NewTracer(opts Options) Tracer {
impl.propagators[opentracing.HTTPHeaders] = theB3Propagator
}

return impl
return impl, nil
}

func (tracer *tracerImpl) Options() Options {
Expand Down

0 comments on commit 0532feb

Please sign in to comment.