Skip to content

Commit b763217

Browse files
Add logs when tracing information is not propagated (#765)
1 parent 1d8a79b commit b763217

File tree

4 files changed

+19
-11
lines changed

4 files changed

+19
-11
lines changed

internal/client.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import (
3131
s "go.uber.org/cadence/.gen/go/shared"
3232
"go.uber.org/cadence/encoded"
3333
"go.uber.org/cadence/internal/common/metrics"
34+
"go.uber.org/zap"
3435
)
3536

3637
const (
@@ -477,7 +478,7 @@ func NewClient(service workflowserviceclient.Interface, domain string, options *
477478
var tracer opentracing.Tracer
478479
if options != nil && options.Tracer != nil {
479480
tracer = options.Tracer
480-
contextPropagators = append(contextPropagators, NewTracingContextPropagator(tracer))
481+
contextPropagators = append(contextPropagators, NewTracingContextPropagator(zap.NewNop(), tracer))
481482
} else {
482483
tracer = opentracing.NoopTracer{}
483484
}

internal/internal_worker.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1399,7 +1399,7 @@ func augmentWorkerOptions(options WorkerOptions) WorkerOptions {
13991399

14001400
// if the user passes in a tracer then add a tracing context propagator
14011401
if options.Tracer != nil {
1402-
options.ContextPropagators = append(options.ContextPropagators, NewTracingContextPropagator(options.Tracer))
1402+
options.ContextPropagators = append(options.ContextPropagators, NewTracingContextPropagator(options.Logger, options.Tracer))
14031403
} else {
14041404
options.Tracer = opentracing.NoopTracer{}
14051405
}

internal/tracer.go

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,9 @@ import (
2424
"context"
2525

2626
"github.com/opentracing/opentracing-go"
27+
"go.uber.org/zap"
2728
)
2829

29-
// NewTracingContextPropagator returns new tracing context propagator object
30-
func NewTracingContextPropagator(tracer opentracing.Tracer) ContextPropagator {
31-
return &tracingContextPropagator{tracer}
32-
}
33-
3430
type tracingReader struct {
3531
reader HeaderReader
3632
}
@@ -62,16 +58,23 @@ func (t tracingWriter) Set(key, val string) {
6258
// the header and puts it in the Context object. Does not start a new span
6359
// as that is started outside when the workflow is actually executed
6460
type tracingContextPropagator struct {
61+
logger *zap.Logger
6562
tracer opentracing.Tracer
6663
}
6764

65+
// NewTracingContextPropagator returns new tracing context propagator object
66+
func NewTracingContextPropagator(logger *zap.Logger, tracer opentracing.Tracer) ContextPropagator {
67+
return &tracingContextPropagator{logger, tracer}
68+
}
69+
6870
func (t *tracingContextPropagator) Inject(
6971
ctx context.Context,
7072
hw HeaderWriter,
7173
) error {
7274
// retrieve span from context object
7375
span := opentracing.SpanFromContext(ctx)
7476
if span == nil {
77+
t.logger.Info("could not retrieve span from context")
7578
return nil
7679
}
7780
return t.tracer.Inject(span.Context(), opentracing.TextMap, tracingWriter{hw})
@@ -84,6 +87,7 @@ func (t *tracingContextPropagator) Extract(
8487
spanContext, err := t.tracer.Extract(opentracing.TextMap, tracingReader{hr})
8588
if err != nil {
8689
// did not find a tracing span, just return the current context
90+
t.logger.Info("could not extract span information", zap.Error(err))
8791
return ctx, nil
8892
}
8993
return context.WithValue(ctx, activeSpanContextKey, spanContext), nil
@@ -96,6 +100,7 @@ func (t *tracingContextPropagator) InjectFromWorkflow(
96100
// retrieve span from context object
97101
spanContext := spanFromContext(ctx)
98102
if spanContext == nil {
103+
t.logger.Info("could not retrieve span from context")
99104
return nil
100105
}
101106
return t.tracer.Inject(spanContext, opentracing.HTTPHeaders, tracingWriter{hw})
@@ -108,6 +113,7 @@ func (t *tracingContextPropagator) ExtractToWorkflow(
108113
spanContext, err := t.tracer.Extract(opentracing.TextMap, tracingReader{hr})
109114
if err != nil {
110115
// did not find a tracing span, just return the current context
116+
t.logger.Info("could not extract span information", zap.Error(err))
111117
return ctx, nil
112118
}
113119
return contextWithSpan(ctx, spanContext), nil

internal/tracer_test.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import (
2828
"github.com/stretchr/testify/assert"
2929
jaeger_config "github.com/uber/jaeger-client-go/config"
3030
"go.uber.org/cadence/.gen/go/shared"
31+
"go.uber.org/zap"
3132
)
3233

3334
func TestTracingContextPropagator(t *testing.T) {
@@ -36,7 +37,7 @@ func TestTracingContextPropagator(t *testing.T) {
3637
assert.NoError(t, err)
3738
defer closer.Close()
3839
tracer := opentracing.GlobalTracer()
39-
ctxProp := NewTracingContextPropagator(tracer)
40+
ctxProp := NewTracingContextPropagator(zap.NewNop(), tracer)
4041

4142
span := tracer.StartSpan("test-operation")
4243
ctx := context.Background()
@@ -57,7 +58,7 @@ func TestTracingContextPropagator(t *testing.T) {
5758
}
5859

5960
func TestTracingContextPropagatorNoSpan(t *testing.T) {
60-
ctxProp := NewTracingContextPropagator(opentracing.NoopTracer{})
61+
ctxProp := NewTracingContextPropagator(zap.NewNop(), opentracing.NoopTracer{})
6162

6263
header := &shared.Header{
6364
Fields: map[string][]byte{},
@@ -76,7 +77,7 @@ func TestTracingContextPropagatorWorkflowContext(t *testing.T) {
7677
assert.NoError(t, err)
7778
defer closer.Close()
7879
tracer := opentracing.GlobalTracer()
79-
ctxProp := NewTracingContextPropagator(tracer)
80+
ctxProp := NewTracingContextPropagator(zap.NewNop(), tracer)
8081

8182
span := tracer.StartSpan("test-operation")
8283
ctx := contextWithSpan(Background(), span.Context())
@@ -97,7 +98,7 @@ func TestTracingContextPropagatorWorkflowContext(t *testing.T) {
9798
}
9899

99100
func TestTracingContextPropagatorWorkflowContextNoSpan(t *testing.T) {
100-
ctxProp := NewTracingContextPropagator(opentracing.NoopTracer{})
101+
ctxProp := NewTracingContextPropagator(zap.NewNop(), opentracing.NoopTracer{})
101102

102103
header := &shared.Header{
103104
Fields: map[string][]byte{},

0 commit comments

Comments
 (0)