Repository: open-telemetry/opentelemetry-go
Pull request #1452 (2021-01-13 20:30:25)

Move Span Event to API
Span events are [an API concern](https://github.com/open-telemetry/opentelemetry-specification/blob/master/specification/trace/api.md#add-events). This moves the `Event` type from the SDK export package to the API.

Related to #1380 

codecov[bot]: # [Codecov](https://codecov.io/gh/open-telemetry/opentelemetry-go/pull/1452?src=pr&el=h1) Report
> Merging [#1452](https://codecov.io/gh/open-telemetry/opentelemetry-go/pull/1452?src=pr&el=desc) (be93869) into [master](https://codecov.io/gh/open-telemetry/opentelemetry-go/commit/74deeddd2608efffe53a2cd9163314af3015eacb?el=desc) (74deedd) will **decrease** coverage by `0.0%`.
> The diff coverage is `80.0%`.

[![Impacted file tree graph](https://codecov.io/gh/open-telemetry/opentelemetry-go/pull/1452/graphs/tree.svg?width=650&height=150&src=pr&token=8efTmh4kvf)](https://codecov.io/gh/open-telemetry/opentelemetry-go/pull/1452?src=pr&el=tree)

```diff
@@           Coverage Diff            @@
##           master   #1452     +/-   ##
========================================
- Coverage    78.8%   78.8%   -0.1%     
========================================
  Files         130     130             
  Lines        6647    6647             
========================================
- Hits         5244    5238      -6     
- Misses       1148    1154      +6     
  Partials      255     255             
```


| [Impacted Files](https://codecov.io/gh/open-telemetry/opentelemetry-go/pull/1452?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [exporters/otlp/internal/transform/span.go](https://codecov.io/gh/open-telemetry/opentelemetry-go/pull/1452/diff?src=pr&el=tree#diff-ZXhwb3J0ZXJzL290bHAvaW50ZXJuYWwvdHJhbnNmb3JtL3NwYW4uZ28=) | `98.0% <ø> (ø)` | |
| [exporters/trace/zipkin/model.go](https://codecov.io/gh/open-telemetry/opentelemetry-go/pull/1452/diff?src=pr&el=tree#diff-ZXhwb3J0ZXJzL3RyYWNlL3ppcGtpbi9tb2RlbC5nbw==) | `98.6% <ø> (ø)` | |
| [trace/trace.go](https://codecov.io/gh/open-telemetry/opentelemetry-go/pull/1452/diff?src=pr&el=tree#diff-dHJhY2UvdHJhY2UuZ28=) | `86.6% <ø> (ø)` | |
| [sdk/trace/span.go](https://codecov.io/gh/open-telemetry/opentelemetry-go/pull/1452/diff?src=pr&el=tree#diff-c2RrL3RyYWNlL3NwYW4uZ28=) | `91.4% <75.0%> (ø)` | |
| [exporters/otlp/internal/otlptest/data.go](https://codecov.io/gh/open-telemetry/opentelemetry-go/pull/1452/diff?src=pr&el=tree#diff-ZXhwb3J0ZXJzL290bHAvaW50ZXJuYWwvb3RscHRlc3QvZGF0YS5nbw==) | `61.7% <100.0%> (ø)` | |
| [sdk/trace/batch\_span\_processor.go](https://codecov.io/gh/open-telemetry/opentelemetry-go/pull/1452/diff?src=pr&el=tree#diff-c2RrL3RyYWNlL2JhdGNoX3NwYW5fcHJvY2Vzc29yLmdv) | `74.5% <0.0%> (-5.9%)` | :arrow_down: |


Patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index aedb792d..50269e3a 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -43,6 +43,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
   - `WithExporter()` and `Start()` to configure Push behavior
   - `Start()` is optional; use `Collect()` and `ForEach()` for Pull behavior
   - `Start()` and `Stop()` accept Context. (#1378)
+- The `Event` type is moved from the `otel/sdk/export/trace` package to the `otel/trace` API package. (#1452)
 
 ### Removed
 
diff --git a/exporters/otlp/internal/transform/span.go b/exporters/otlp/internal/transform/span.go
index a71894c2..33ecbc89 100644
--- a/exporters/otlp/internal/transform/span.go
+++ b/exporters/otlp/internal/transform/span.go
@@ -162,7 +162,7 @@ func links(links []trace.Link) []*tracepb.Span_Link {
 }
 
 // spanEvents transforms span Events to an OTLP span events.
-func spanEvents(es []export.Event) []*tracepb.Span_Event {
+func spanEvents(es []trace.Event) []*tracepb.Span_Event {
 	if len(es) == 0 {
 		return nil
 	}
diff --git a/exporters/trace/zipkin/model.go b/exporters/trace/zipkin/model.go
index fe5454b4..e4ee0098 100644
--- a/exporters/trace/zipkin/model.go
+++ b/exporters/trace/zipkin/model.go
@@ -106,7 +106,7 @@ func toZipkinKind(kind trace.SpanKind) zkmodel.Kind {
 	return zkmodel.Undetermined
 }
 
-func toZipkinAnnotations(events []export.Event) []zkmodel.Annotation {
+func toZipkinAnnotations(events []trace.Event) []zkmodel.Annotation {
 	if len(events) == 0 {
 		return nil
 	}
diff --git a/sdk/export/trace/trace.go b/sdk/export/trace/trace.go
index 96b45b92..2851a0e0 100644
--- a/sdk/export/trace/trace.go
+++ b/sdk/export/trace/trace.go
@@ -63,7 +63,7 @@ type SpanSnapshot struct {
 	// from StartTime by the duration of the span.
 	EndTime                  time.Time
 	Attributes               []label.KeyValue
-	MessageEvents            []Event
+	MessageEvents            []trace.Event
 	Links                    []trace.Link
 	StatusCode               codes.Code
 	StatusMessage            string
@@ -82,15 +82,3 @@ type SpanSnapshot struct {
 	// provide instrumentation.
 	InstrumentationLibrary instrumentation.Library
 }
-
-// Event is thing that happened during a Span's lifetime.
-type Event struct {
-	// Name is the name of this event
-	Name string
-
-	// Attributes describe the aspects of the event.
-	Attributes []label.KeyValue
-
-	// Time is the time at which this event was recorded.
-	Time time.Time
-}
diff --git a/sdk/trace/span.go b/sdk/trace/span.go
index a053f820..b09b4fa2 100644
--- a/sdk/trace/span.go
+++ b/sdk/trace/span.go
@@ -51,7 +51,7 @@ type ReadOnlySpan interface {
 	EndTime() time.Time
 	Attributes() []label.KeyValue
 	Links() []trace.Link
-	Events() []export.Event
+	Events() []trace.Event
 	StatusCode() codes.Code
 	StatusMessage() string
 	Tracer() trace.Tracer
@@ -266,7 +266,7 @@ func (s *span) addEvent(name string, o ...trace.EventOption) {
 
 	s.mu.Lock()
 	defer s.mu.Unlock()
-	s.messageEvents.add(export.Event{
+	s.messageEvents.add(trace.Event{
 		Name:       name,
 		Attributes: c.Attributes,
 		Time:       c.Timestamp,
@@ -355,11 +355,11 @@ func (s *span) Links() []trace.Link {
 	return s.interfaceArrayToLinksArray()
 }
 
-func (s *span) Events() []export.Event {
+func (s *span) Events() []trace.Event {
 	s.mu.Lock()
 	defer s.mu.Unlock()
 	if len(s.messageEvents.queue) == 0 {
-		return []export.Event{}
+		return []trace.Event{}
 	}
 	return s.interfaceArrayToMessageEventArray()
 }
@@ -440,10 +440,10 @@ func (s *span) interfaceArrayToLinksArray() []trace.Link {
 	return linkArr
 }
 
-func (s *span) interfaceArrayToMessageEventArray() []export.Event {
-	messageEventArr := make([]export.Event, 0)
+func (s *span) interfaceArrayToMessageEventArray() []trace.Event {
+	messageEventArr := make([]trace.Event, 0)
 	for _, value := range s.messageEvents.queue {
-		messageEventArr = append(messageEventArr, value.(export.Event))
+		messageEventArr = append(messageEventArr, value.(trace.Event))
 	}
 	return messageEventArr
 }
diff --git a/trace/trace.go b/trace/trace.go
index ced7f10c..1c1e85ad 100644
--- a/trace/trace.go
+++ b/trace/trace.go
@@ -21,6 +21,7 @@ import (
 	"encoding/json"
 	"regexp"
 	"strings"
+	"time"
 
 	"go.opentelemetry.io/otel/codes"
 	"go.opentelemetry.io/otel/label"
@@ -440,6 +441,18 @@ type Span interface {
 	SetAttributes(kv ...label.KeyValue)
 }
 
+// Event is a thing that happened during a Span's lifetime.
+type Event struct {
+	// Name is the name of this event
+	Name string
+
+	// Attributes describe the aspects of the event.
+	Attributes []label.KeyValue
+
+	// Time at which this event was recorded.
+	Time time.Time
+}
+
 // Link is the relationship between two Spans. The relationship can be within
 // the same Trace or across different Traces.
 //


Test patch:
diff --git a/exporters/otlp/internal/otlptest/data.go b/exporters/otlp/internal/otlptest/data.go
index cac514d1..79e001c6 100644
--- a/exporters/otlp/internal/otlptest/data.go
+++ b/exporters/otlp/internal/otlptest/data.go
@@ -93,7 +93,7 @@ func SingleSpanSnapshot() []*exporttrace.SpanSnapshot {
 		StartTime:                time.Date(2020, time.December, 8, 20, 23, 0, 0, time.UTC),
 		EndTime:                  time.Date(2020, time.December, 0, 20, 24, 0, 0, time.UTC),
 		Attributes:               []label.KeyValue{},
-		MessageEvents:            []exporttrace.Event{},
+		MessageEvents:            []trace.Event{},
 		Links:                    []trace.Link{},
 		StatusCode:               codes.Ok,
 		StatusMessage:            "",
diff --git a/exporters/otlp/internal/transform/span_test.go b/exporters/otlp/internal/transform/span_test.go
index e8d863fb..4b8b56c1 100644
--- a/exporters/otlp/internal/transform/span_test.go
+++ b/exporters/otlp/internal/transform/span_test.go
@@ -73,13 +73,13 @@ func TestNilSpanEvent(t *testing.T) {
 }
 
 func TestEmptySpanEvent(t *testing.T) {
-	assert.Nil(t, spanEvents([]export.Event{}))
+	assert.Nil(t, spanEvents([]trace.Event{}))
 }
 
 func TestSpanEvent(t *testing.T) {
 	attrs := []label.KeyValue{label.Int("one", 1), label.Int("two", 2)}
 	eventTime := time.Date(2020, 5, 20, 0, 0, 0, 0, time.UTC)
-	got := spanEvents([]export.Event{
+	got := spanEvents([]trace.Event{
 		{
 			Name:       "test 1",
 			Attributes: []label.KeyValue{},
@@ -101,9 +101,9 @@ func TestSpanEvent(t *testing.T) {
 }
 
 func TestExcessiveSpanEvents(t *testing.T) {
-	e := make([]export.Event, maxMessageEventsPerSpan+1)
+	e := make([]trace.Event, maxMessageEventsPerSpan+1)
 	for i := 0; i < maxMessageEventsPerSpan+1; i++ {
-		e[i] = export.Event{Name: strconv.Itoa(i)}
+		e[i] = trace.Event{Name: strconv.Itoa(i)}
 	}
 	assert.Len(t, e, maxMessageEventsPerSpan+1)
 	got := spanEvents(e)
@@ -211,7 +211,7 @@ func TestSpanData(t *testing.T) {
 		Name:         "span data to span data",
 		StartTime:    startTime,
 		EndTime:      endTime,
-		MessageEvents: []export.Event{
+		MessageEvents: []trace.Event{
 			{Time: startTime,
 				Attributes: []label.KeyValue{
 					label.Uint64("CompressedByteSize", 512),
diff --git a/exporters/stdout/trace_test.go b/exporters/stdout/trace_test.go
index 4a3fabed..59d9cd70 100644
--- a/exporters/stdout/trace_test.go
+++ b/exporters/stdout/trace_test.go
@@ -60,7 +60,7 @@ func TestExporter_ExportSpan(t *testing.T) {
 			label.String("key", keyValue),
 			label.Float64("double", doubleValue),
 		},
-		MessageEvents: []export.Event{
+		MessageEvents: []trace.Event{
 			{Name: "foo", Attributes: []label.KeyValue{label.String("key", keyValue)}, Time: now},
 			{Name: "bar", Attributes: []label.KeyValue{label.Float64("double", doubleValue)}, Time: now},
 		},
diff --git a/exporters/trace/jaeger/jaeger_test.go b/exporters/trace/jaeger/jaeger_test.go
index 6cfe858a..e882bc6a 100644
--- a/exporters/trace/jaeger/jaeger_test.go
+++ b/exporters/trace/jaeger/jaeger_test.go
@@ -403,7 +403,7 @@ func Test_spanSnapshotToThrift(t *testing.T) {
 					label.Uint64("uint", uint64(uintValue)),
 					label.Uint64("overflows", math.MaxUint64),
 				},
-				MessageEvents: []export.Event{
+				MessageEvents: []trace.Event{
 					{Name: eventNameValue, Attributes: []label.KeyValue{label.String("k1", keyValue)}, Time: now},
 				},
 				StatusCode:    codes.Error,
diff --git a/exporters/trace/zipkin/model_test.go b/exporters/trace/zipkin/model_test.go
index 51ec1021..b0ec9598 100644
--- a/exporters/trace/zipkin/model_test.go
+++ b/exporters/trace/zipkin/model_test.go
@@ -48,7 +48,7 @@ func TestModelConversion(t *testing.T) {
 				label.Uint64("attr1", 42),
 				label.String("attr2", "bar"),
 			},
-			MessageEvents: []export.Event{
+			MessageEvents: []trace.Event{
 				{
 					Time: time.Date(2020, time.March, 11, 19, 24, 30, 0, time.UTC),
 					Name: "ev1",
@@ -81,7 +81,7 @@ func TestModelConversion(t *testing.T) {
 				label.Uint64("attr1", 42),
 				label.String("attr2", "bar"),
 			},
-			MessageEvents: []export.Event{
+			MessageEvents: []trace.Event{
 				{
 					Time: time.Date(2020, time.March, 11, 19, 24, 30, 0, time.UTC),
 					Name: "ev1",
@@ -113,7 +113,7 @@ func TestModelConversion(t *testing.T) {
 				label.Uint64("attr1", 42),
 				label.String("attr2", "bar"),
 			},
-			MessageEvents: []export.Event{
+			MessageEvents: []trace.Event{
 				{
 					Time: time.Date(2020, time.March, 11, 19, 24, 30, 0, time.UTC),
 					Name: "ev1",
@@ -145,7 +145,7 @@ func TestModelConversion(t *testing.T) {
 				label.Uint64("attr1", 42),
 				label.String("attr2", "bar"),
 			},
-			MessageEvents: []export.Event{
+			MessageEvents: []trace.Event{
 				{
 					Time: time.Date(2020, time.March, 11, 19, 24, 30, 0, time.UTC),
 					Name: "ev1",
@@ -177,7 +177,7 @@ func TestModelConversion(t *testing.T) {
 				label.Uint64("attr1", 42),
 				label.String("attr2", "bar"),
 			},
-			MessageEvents: []export.Event{
+			MessageEvents: []trace.Event{
 				{
 					Time: time.Date(2020, time.March, 11, 19, 24, 30, 0, time.UTC),
 					Name: "ev1",
@@ -209,7 +209,7 @@ func TestModelConversion(t *testing.T) {
 				label.Uint64("attr1", 42),
 				label.String("attr2", "bar"),
 			},
-			MessageEvents: []export.Event{
+			MessageEvents: []trace.Event{
 				{
 					Time: time.Date(2020, time.March, 11, 19, 24, 30, 0, time.UTC),
 					Name: "ev1",
@@ -241,7 +241,7 @@ func TestModelConversion(t *testing.T) {
 				label.Uint64("attr1", 42),
 				label.String("attr2", "bar"),
 			},
-			MessageEvents: []export.Event{
+			MessageEvents: []trace.Event{
 				{
 					Time: time.Date(2020, time.March, 11, 19, 24, 30, 0, time.UTC),
 					Name: "ev1",
@@ -291,7 +291,7 @@ func TestModelConversion(t *testing.T) {
 			Attributes: []label.KeyValue{
 				label.String("error", "false"),
 			},
-			MessageEvents: []export.Event{
+			MessageEvents: []trace.Event{
 				{
 					Time: time.Date(2020, time.March, 11, 19, 24, 30, 0, time.UTC),
 					Name: "ev1",
diff --git a/sdk/trace/trace_test.go b/sdk/trace/trace_test.go
index dfaf186b..fb73b2ef 100644
--- a/sdk/trace/trace_test.go
+++ b/sdk/trace/trace_test.go
@@ -551,7 +551,7 @@ func TestEvents(t *testing.T) {
 		ParentSpanID:    sid,
 		Name:            "span0",
 		HasRemoteParent: true,
-		MessageEvents: []export.Event{
+		MessageEvents: []trace.Event{
 			{Name: "foo", Attributes: []label.KeyValue{k1v1}},
 			{Name: "bar", Attributes: []label.KeyValue{k2v2, k3v3}},
 		},
@@ -601,7 +601,7 @@ func TestEventsOverLimit(t *testing.T) {
 		},
 		ParentSpanID: sid,
 		Name:         "span0",
-		MessageEvents: []export.Event{
+		MessageEvents: []trace.Event{
 			{Name: "foo", Attributes: []label.KeyValue{k1v1}},
 			{Name: "bar", Attributes: []label.KeyValue{k2v2, k3v3}},
 		},
@@ -755,7 +755,7 @@ func TestSetSpanStatus(t *testing.T) {
 func cmpDiff(x, y interface{}) string {
 	return cmp.Diff(x, y,
 		cmp.AllowUnexported(label.Value{}),
-		cmp.AllowUnexported(export.Event{}),
+		cmp.AllowUnexported(trace.Event{}),
 		cmp.AllowUnexported(trace.TraceState{}))
 }
 
@@ -1104,7 +1104,7 @@ func TestRecordError(t *testing.T) {
 			StatusCode:      codes.Error,
 			SpanKind:        trace.SpanKindInternal,
 			HasRemoteParent: true,
-			MessageEvents: []export.Event{
+			MessageEvents: []trace.Event{
 				{
 					Name: errorEventName,
 					Time: errTime,