From 09ae5378b779f2bc8b1aa401a9e321b1e9aaf6aa Mon Sep 17 00:00:00 2001 From: Cheng-Lung Sung Date: Thu, 19 Dec 2019 02:13:05 +0800 Subject: [PATCH] rename `Message` in Event to `Name` (#389) implements #387 --- api/trace/api.go | 4 ++-- api/trace/current_test.go | 4 ++-- api/trace/noop_span.go | 4 ++-- api/trace/testtrace/event.go | 2 +- api/trace/testtrace/span.go | 8 ++++---- api/trace/testtrace/span_test.go | 12 ++++++------ bridge/opentracing/internal/mock.go | 10 +++++----- exporter/trace/jaeger/jaeger.go | 2 +- exporter/trace/jaeger/jaeger_test.go | 8 ++++---- exporter/trace/stackdriver/trace_proto.go | 2 +- exporter/trace/stdout/stdout_test.go | 8 ++++---- internal/trace/mock_span.go | 4 ++-- sdk/export/trace/trace.go | 4 ++-- sdk/trace/span.go | 12 ++++++------ sdk/trace/trace_test.go | 8 ++++---- 15 files changed, 46 insertions(+), 46 deletions(-) diff --git a/api/trace/api.go b/api/trace/api.go index 9931f7fb7d1..11c7f541427 100644 --- a/api/trace/api.go +++ b/api/trace/api.go @@ -68,10 +68,10 @@ type Span interface { End(options ...EndOption) // AddEvent adds an event to the span. - AddEvent(ctx context.Context, msg string, attrs ...core.KeyValue) + AddEvent(ctx context.Context, name string, attrs ...core.KeyValue) // AddEventWithTimestamp adds an event with a custom timestamp // to the span. - AddEventWithTimestamp(ctx context.Context, timestamp time.Time, msg string, attrs ...core.KeyValue) + AddEventWithTimestamp(ctx context.Context, timestamp time.Time, name string, attrs ...core.KeyValue) // IsRecording returns true if the span is active and recording events is enabled. IsRecording() bool diff --git a/api/trace/current_test.go b/api/trace/current_test.go index 0bf2f7727d0..32e45e80e04 100644 --- a/api/trace/current_test.go +++ b/api/trace/current_test.go @@ -93,9 +93,9 @@ func (mockSpan) Tracer() trace.Tracer { } // Event does nothing. -func (mockSpan) AddEvent(ctx context.Context, msg string, attrs ...core.KeyValue) { +func (mockSpan) AddEvent(ctx context.Context, name string, attrs ...core.KeyValue) { } // AddEventWithTimestamp does nothing. -func (mockSpan) AddEventWithTimestamp(ctx context.Context, timestamp time.Time, msg string, attrs ...core.KeyValue) { +func (mockSpan) AddEventWithTimestamp(ctx context.Context, timestamp time.Time, name string, attrs ...core.KeyValue) { } diff --git a/api/trace/noop_span.go b/api/trace/noop_span.go index 59aa4177f2c..587573784d8 100644 --- a/api/trace/noop_span.go +++ b/api/trace/noop_span.go @@ -60,11 +60,11 @@ func (NoopSpan) Tracer() Tracer { } // AddEvent does nothing. -func (NoopSpan) AddEvent(ctx context.Context, msg string, attrs ...core.KeyValue) { +func (NoopSpan) AddEvent(ctx context.Context, name string, attrs ...core.KeyValue) { } // AddEventWithTimestamp does nothing. -func (NoopSpan) AddEventWithTimestamp(ctx context.Context, timestamp time.Time, msg string, attrs ...core.KeyValue) { +func (NoopSpan) AddEventWithTimestamp(ctx context.Context, timestamp time.Time, name string, attrs ...core.KeyValue) { } // SetName does nothing. diff --git a/api/trace/testtrace/event.go b/api/trace/testtrace/event.go index 06b3cb8861f..70baa21ff58 100644 --- a/api/trace/testtrace/event.go +++ b/api/trace/testtrace/event.go @@ -23,6 +23,6 @@ import ( // Event encapsulates the properties of calls to AddEvent or AddEventWithTimestamp. type Event struct { Timestamp time.Time - Message string + Name string Attributes map[core.Key]core.Value } diff --git a/api/trace/testtrace/span.go b/api/trace/testtrace/span.go index e06038b3554..2b1d0d683e5 100644 --- a/api/trace/testtrace/span.go +++ b/api/trace/testtrace/span.go @@ -69,11 +69,11 @@ func (s *Span) End(opts ...trace.EndOption) { s.ended = true } -func (s *Span) AddEvent(ctx context.Context, msg string, attrs ...core.KeyValue) { - s.AddEventWithTimestamp(ctx, time.Now(), msg, attrs...) +func (s *Span) AddEvent(ctx context.Context, name string, attrs ...core.KeyValue) { + s.AddEventWithTimestamp(ctx, time.Now(), name, attrs...) } -func (s *Span) AddEventWithTimestamp(ctx context.Context, timestamp time.Time, msg string, attrs ...core.KeyValue) { +func (s *Span) AddEventWithTimestamp(ctx context.Context, timestamp time.Time, name string, attrs ...core.KeyValue) { s.lock.Lock() defer s.lock.Unlock() @@ -89,7 +89,7 @@ func (s *Span) AddEventWithTimestamp(ctx context.Context, timestamp time.Time, m s.events = append(s.events, Event{ Timestamp: timestamp, - Message: msg, + Name: name, Attributes: attributes, }) } diff --git a/api/trace/testtrace/span_test.go b/api/trace/testtrace/span_test.go index 08417c481e3..9c311514d9d 100644 --- a/api/trace/testtrace/span_test.go +++ b/api/trace/testtrace/span_test.go @@ -337,23 +337,23 @@ func TestSpan(t *testing.T) { subject, ok := span.(*testtrace.Span) e.Expect(ok).ToBeTrue() - event1Msg := "event1" + event1Name := "event1" event1Attributes := []core.KeyValue{ core.Key("event1Attr1").String("foo"), core.Key("event1Attr2").String("bar"), } event1Start := time.Now() - subject.AddEvent(context.Background(), event1Msg, event1Attributes...) + subject.AddEvent(context.Background(), event1Name, event1Attributes...) event1End := time.Now() event2Timestamp := time.Now().AddDate(5, 0, 0) - event2Msg := "event1" + event2Name := "event1" event2Attributes := []core.KeyValue{ core.Key("event2Attr").String("abc"), } - subject.AddEventWithTimestamp(context.Background(), event2Timestamp, event2Msg, event2Attributes...) + subject.AddEventWithTimestamp(context.Background(), event2Timestamp, event2Name, event2Attributes...) events := subject.Events() @@ -363,7 +363,7 @@ func TestSpan(t *testing.T) { e.Expect(event1.Timestamp).ToBeTemporally(matchers.AfterOrSameTime, event1Start) e.Expect(event1.Timestamp).ToBeTemporally(matchers.BeforeOrSameTime, event1End) - e.Expect(event1.Message).ToEqual(event1Msg) + e.Expect(event1.Name).ToEqual(event1Name) for _, attr := range event1Attributes { e.Expect(event1.Attributes[attr.Key]).ToEqual(attr.Value) @@ -372,7 +372,7 @@ func TestSpan(t *testing.T) { event2 := events[1] e.Expect(event2.Timestamp).ToEqual(event2Timestamp) - e.Expect(event2.Message).ToEqual(event2Msg) + e.Expect(event2.Name).ToEqual(event2Name) for _, attr := range event2Attributes { e.Expect(event2.Attributes[attr.Key]).ToEqual(attr.Value) diff --git a/bridge/opentracing/internal/mock.go b/bridge/opentracing/internal/mock.go index 5392c4c3568..82781a0e19b 100644 --- a/bridge/opentracing/internal/mock.go +++ b/bridge/opentracing/internal/mock.go @@ -195,7 +195,7 @@ func (t *MockTracer) DeferredContextSetupHook(ctx context.Context, span oteltrac type MockEvent struct { CtxAttributes oteldctx.Map Timestamp time.Time - Msg string + Name string Attributes oteldctx.Map } @@ -268,15 +268,15 @@ func (s *MockSpan) Tracer() oteltrace.Tracer { return s.officialTracer } -func (s *MockSpan) AddEvent(ctx context.Context, msg string, attrs ...otelcore.KeyValue) { - s.AddEventWithTimestamp(ctx, time.Now(), msg, attrs...) +func (s *MockSpan) AddEvent(ctx context.Context, name string, attrs ...otelcore.KeyValue) { + s.AddEventWithTimestamp(ctx, time.Now(), name, attrs...) } -func (s *MockSpan) AddEventWithTimestamp(ctx context.Context, timestamp time.Time, msg string, attrs ...otelcore.KeyValue) { +func (s *MockSpan) AddEventWithTimestamp(ctx context.Context, timestamp time.Time, name string, attrs ...otelcore.KeyValue) { s.Events = append(s.Events, MockEvent{ CtxAttributes: oteldctx.FromContext(ctx), Timestamp: timestamp, - Msg: msg, + Name: name, Attributes: oteldctx.NewMap(oteldctx.MapUpdate{ MultiKV: attrs, }), diff --git a/exporter/trace/jaeger/jaeger.go b/exporter/trace/jaeger/jaeger.go index 6a0ee28492d..80cb516b505 100644 --- a/exporter/trace/jaeger/jaeger.go +++ b/exporter/trace/jaeger/jaeger.go @@ -176,7 +176,7 @@ func spanDataToThrift(data *export.SpanData) *gen.Span { fields = append(fields, tag) } } - fields = append(fields, getStringTag("message", a.Message)) + fields = append(fields, getStringTag("name", a.Name)) logs = append(logs, &gen.Log{ Timestamp: a.Time.UnixNano() / 1000, Fields: fields, diff --git a/exporter/trace/jaeger/jaeger_test.go b/exporter/trace/jaeger/jaeger_test.go index c65ba1be20a..e0bbdb763ce 100644 --- a/exporter/trace/jaeger/jaeger_test.go +++ b/exporter/trace/jaeger/jaeger_test.go @@ -152,7 +152,7 @@ func Test_spanDataToThrift(t *testing.T) { linkTraceID, _ := core.TraceIDFromHex("0102030405060709090a0b0c0d0e0f11") linkSpanID, _ := core.SpanIDFromHex("0102030405060709") - messageEventValue := "event-test" + eventNameValue := "event-test" keyValue := "value" statusCodeValue := int64(2) doubleValue := 123.456 @@ -189,7 +189,7 @@ func Test_spanDataToThrift(t *testing.T) { key.Uint64("ignored", 123), }, MessageEvents: []export.Event{ - {Message: messageEventValue, Attributes: []core.KeyValue{key.String("k1", keyValue)}, Time: now}, + {Name: eventNameValue, Attributes: []core.KeyValue{key.String("k1", keyValue)}, Time: now}, }, Status: codes.Unknown, }, @@ -225,8 +225,8 @@ func Test_spanDataToThrift(t *testing.T) { VType: gen.TagType_STRING, }, { - Key: "message", - VStr: &messageEventValue, + Key: "name", + VStr: &eventNameValue, VType: gen.TagType_STRING, }, }, diff --git a/exporter/trace/stackdriver/trace_proto.go b/exporter/trace/stackdriver/trace_proto.go index ff9626af7b4..f8018ecbe17 100644 --- a/exporter/trace/stackdriver/trace_proto.go +++ b/exporter/trace/stackdriver/trace_proto.go @@ -99,7 +99,7 @@ func protoFromSpanData(s *export.SpanData, projectID string) *tracepb.Span { droppedAnnotationsCount = len(es) - i break } - annotation := &tracepb.Span_TimeEvent_Annotation{Description: trunc(e.Message, maxAttributeStringValue)} + annotation := &tracepb.Span_TimeEvent_Annotation{Description: trunc(e.Name, maxAttributeStringValue)} copyAttributes(&annotation.Attributes, e.Attributes) event := &tracepb.Span_TimeEvent{ Time: timestampProto(e.Time), diff --git a/exporter/trace/stdout/stdout_test.go b/exporter/trace/stdout/stdout_test.go index 1f4e0c98a9c..03c7e32244c 100644 --- a/exporter/trace/stdout/stdout_test.go +++ b/exporter/trace/stdout/stdout_test.go @@ -59,8 +59,8 @@ func TestExporter_ExportSpan(t *testing.T) { key.Float64("double", doubleValue), }, MessageEvents: []export.Event{ - {Message: "foo", Attributes: []core.KeyValue{key.String("key", keyValue)}, Time: now}, - {Message: "bar", Attributes: []core.KeyValue{key.Float64("double", doubleValue)}, Time: now}, + {Name: "foo", Attributes: []core.KeyValue{key.String("key", keyValue)}, Time: now}, + {Name: "bar", Attributes: []core.KeyValue{key.Float64("double", doubleValue)}, Time: now}, }, SpanKind: trace.SpanKindInternal, Status: codes.Unknown, @@ -90,7 +90,7 @@ func TestExporter_ExportSpan(t *testing.T) { `],` + `"MessageEvents":[` + `{` + - `"Message":"foo",` + + `"Name":"foo",` + `"Attributes":[` + `{` + `"Key":"key",` + @@ -100,7 +100,7 @@ func TestExporter_ExportSpan(t *testing.T) { `"Time":` + string(expectedSerializedNow) + `},` + `{` + - `"Message":"bar",` + + `"Name":"bar",` + `"Attributes":[` + `{` + `"Key":"double",` + diff --git a/internal/trace/mock_span.go b/internal/trace/mock_span.go index 48a8fc6383d..531847700ac 100644 --- a/internal/trace/mock_span.go +++ b/internal/trace/mock_span.go @@ -72,9 +72,9 @@ func (ms *MockSpan) Tracer() apitrace.Tracer { } // AddEvent does nothing. -func (ms *MockSpan) AddEvent(ctx context.Context, msg string, attrs ...core.KeyValue) { +func (ms *MockSpan) AddEvent(ctx context.Context, name string, attrs ...core.KeyValue) { } // AddEvent does nothing. -func (ms *MockSpan) AddEventWithTimestamp(ctx context.Context, timestamp time.Time, msg string, attrs ...core.KeyValue) { +func (ms *MockSpan) AddEventWithTimestamp(ctx context.Context, timestamp time.Time, name string, attrs ...core.KeyValue) { } diff --git a/sdk/export/trace/trace.go b/sdk/export/trace/trace.go index 01313702ce9..a9cd4e94824 100644 --- a/sdk/export/trace/trace.go +++ b/sdk/export/trace/trace.go @@ -71,8 +71,8 @@ type SpanData struct { // Event is used to describe an Event with a message string and set of // Attributes. type Event struct { - // Message describes the Event. - Message string + // Name is the name of this event + Name string // Attributes contains a list of keyvalue pairs. Attributes []core.KeyValue diff --git a/sdk/trace/span.go b/sdk/trace/span.go index 3b0445981ed..d21ff1f5d39 100644 --- a/sdk/trace/span.go +++ b/sdk/trace/span.go @@ -127,25 +127,25 @@ func (s *span) Tracer() apitrace.Tracer { return s.tracer } -func (s *span) AddEvent(ctx context.Context, msg string, attrs ...core.KeyValue) { +func (s *span) AddEvent(ctx context.Context, name string, attrs ...core.KeyValue) { if !s.IsRecording() { return } - s.addEventWithTimestamp(time.Now(), msg, attrs...) + s.addEventWithTimestamp(time.Now(), name, attrs...) } -func (s *span) AddEventWithTimestamp(ctx context.Context, timestamp time.Time, msg string, attrs ...core.KeyValue) { +func (s *span) AddEventWithTimestamp(ctx context.Context, timestamp time.Time, name string, attrs ...core.KeyValue) { if !s.IsRecording() { return } - s.addEventWithTimestamp(timestamp, msg, attrs...) + s.addEventWithTimestamp(timestamp, name, attrs...) } -func (s *span) addEventWithTimestamp(timestamp time.Time, msg string, attrs ...core.KeyValue) { +func (s *span) addEventWithTimestamp(timestamp time.Time, name string, attrs ...core.KeyValue) { s.mu.Lock() defer s.mu.Unlock() s.messageEvents.add(export.Event{ - Message: msg, + Name: name, Attributes: attrs, Time: timestamp, }) diff --git a/sdk/trace/trace_test.go b/sdk/trace/trace_test.go index 2298132258d..ca566c56c17 100644 --- a/sdk/trace/trace_test.go +++ b/sdk/trace/trace_test.go @@ -423,8 +423,8 @@ func TestEvents(t *testing.T) { Name: "Events/span0", HasRemoteParent: true, MessageEvents: []export.Event{ - {Message: "foo", Attributes: []core.KeyValue{k1v1}}, - {Message: "bar", Attributes: []core.KeyValue{k2v2, k3v3}}, + {Name: "foo", Attributes: []core.KeyValue{k1v1}}, + {Name: "bar", Attributes: []core.KeyValue{k2v2, k3v3}}, }, SpanKind: apitrace.SpanKindInternal, } @@ -472,8 +472,8 @@ func TestEventsOverLimit(t *testing.T) { ParentSpanID: sid, Name: "EventsOverLimit/span0", MessageEvents: []export.Event{ - {Message: "foo", Attributes: []core.KeyValue{k1v1}}, - {Message: "bar", Attributes: []core.KeyValue{k2v2, k3v3}}, + {Name: "foo", Attributes: []core.KeyValue{k1v1}}, + {Name: "bar", Attributes: []core.KeyValue{k2v2, k3v3}}, }, DroppedMessageEventCount: 2, HasRemoteParent: true,