diff --git a/log.go b/log.go index 52cbc38bf297..7732d7db8f29 100644 --- a/log.go +++ b/log.go @@ -223,8 +223,8 @@ func (el *eventLogger) SetTags(ctx context.Context, tags map[string]interface{}) log.Errorf("SetTags with no Span in context called on %s:%d", path.Base(file), line) return } - for k := range tags { - span.SetTag(k, tags[k]) + for k, v := range tags { + span.SetTag(k, v) } } diff --git a/log_test.go b/log_test.go index 2fd15e2c5378..46ac7372592d 100644 --- a/log_test.go +++ b/log_test.go @@ -53,6 +53,8 @@ func TestSingleEvent(t *testing.T) { // greater than zero should work for now assertNotZero(t, ls.Duration) assertNotZero(t, ls.Start) + assertNotZero(t, ls.TraceID) + assertNotZero(t, ls.SpanID) } func TestSingleEventWithErr(t *testing.T) { @@ -88,6 +90,8 @@ func TestSingleEventWithErr(t *testing.T) { // greater than zero should work for now assertNotZero(t, ls.Duration) assertNotZero(t, ls.Start) + assertNotZero(t, ls.TraceID) + assertNotZero(t, ls.SpanID) } func TestEventWithTag(t *testing.T) { @@ -122,6 +126,8 @@ func TestEventWithTag(t *testing.T) { // greater than zero should work for now assertNotZero(t, ls.Duration) assertNotZero(t, ls.Start) + assertNotZero(t, ls.TraceID) + assertNotZero(t, ls.SpanID) } func TestEventWithTags(t *testing.T) { @@ -160,6 +166,8 @@ func TestEventWithTags(t *testing.T) { // greater than zero should work for now assertNotZero(t, ls.Duration) assertNotZero(t, ls.Start) + assertNotZero(t, ls.TraceID) + assertNotZero(t, ls.SpanID) } func TestEventWithLogs(t *testing.T) { @@ -204,6 +212,8 @@ func TestEventWithLogs(t *testing.T) { // greater than zero should work for now assertNotZero(t, ls.Duration) assertNotZero(t, ls.Start) + assertNotZero(t, ls.TraceID) + assertNotZero(t, ls.SpanID) } func TestMultiEvent(t *testing.T) { @@ -238,11 +248,14 @@ func TestMultiEvent(t *testing.T) { assertEqual(t, "e2", e2.Operation) assertEqual(t, "test", e2.Tags["system"]) assertNotZero(t, e2.Duration) + assertEqual(t, e1.TraceID, e2.TraceID) er := getEvent(evtDecoder) assertEqual(t, "root", er.Operation) assertEqual(t, "test", er.Tags["system"]) assertNotZero(t, er.Start) + assertNotZero(t, er.TraceID) + assertNotZero(t, er.SpanID) } @@ -288,7 +301,9 @@ func TestEventSerialization(t *testing.T) { assertEqual(t, "recv", e.Operation) assertEqual(t, "test", e.Tags["system"]) assertNotZero(t, e.Start) - assertNotZero(t, e.Start) + assertNotZero(t, e.Duration) + assertNotZero(t, e.TraceID) + assertNotZero(t, e.SpanID) } @@ -347,6 +362,8 @@ func TestEventBegin(t *testing.T) { // greater than zero should work for now assertNotZero(t, ls.Duration) assertNotZero(t, ls.Start) + assertNotZero(t, ls.SpanID) + assertNotZero(t, ls.TraceID) } func TestEventBeginWithErr(t *testing.T) { @@ -385,4 +402,6 @@ func TestEventBeginWithErr(t *testing.T) { // greater than zero should work for now assertNotZero(t, ls.Duration) assertNotZero(t, ls.Start) + assertNotZero(t, ls.SpanID) + assertNotZero(t, ls.TraceID) } diff --git a/tracer/recorder.go b/tracer/recorder.go index 12121f29594b..60ed1f8cb27f 100644 --- a/tracer/recorder.go +++ b/tracer/recorder.go @@ -27,11 +27,14 @@ func NewLoggableRecorder() *LoggableSpanRecorder { // Loggable Representation of a span, treated as an event log type LoggableSpan struct { - Operation string `json:"Operation"` - Start time.Time `json:"Start"` - Duration time.Duration `json:"Duration"` - Tags opentrace.Tags `json:"Tags"` - Logs []SpanLog `json:"Logs"` + TraceID uint64 `json:"TraceID"` + SpanID uint64 `json:"SpanID"` + ParentSpanID uint64 `json:"ParentSpanID"` + Operation string `json:"Operation"` + Start time.Time `json:"Start"` + Duration time.Duration `json:"Duration"` + Tags opentrace.Tags `json:"Tags"` + Logs []SpanLog `json:"Logs"` } type SpanLog struct { @@ -63,11 +66,14 @@ func (r *LoggableSpanRecorder) RecordSpan(span RawSpan) { } spanlog := &LoggableSpan{ - Operation: span.Operation, - Start: span.Start, - Duration: span.Duration, - Tags: span.Tags, - Logs: sl, + TraceID: span.Context.TraceID, + SpanID: span.Context.SpanID, + ParentSpanID: span.ParentSpanID, + Operation: span.Operation, + Start: span.Start, + Duration: span.Duration, + Tags: span.Tags, + Logs: sl, } out, err := json.Marshal(spanlog)