1
0
mirror of https://github.com/open-telemetry/opentelemetry-go.git synced 2025-01-03 22:52:30 +02:00

rename Message in Event to Name (#389)

implements #387
This commit is contained in:
Cheng-Lung Sung 2019-12-19 02:13:05 +08:00 committed by rghetia
parent b863b8f6ab
commit 09ae5378b7
15 changed files with 46 additions and 46 deletions

View File

@ -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

View File

@ -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) {
}

View File

@ -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.

View File

@ -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
}

View File

@ -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,
})
}

View File

@ -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)

View File

@ -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,
}),

View File

@ -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,

View File

@ -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,
},
},

View File

@ -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),

View File

@ -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",` +

View File

@ -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) {
}

View File

@ -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

View File

@ -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,
})

View File

@ -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,