Skip to content

Commit

Permalink
Move Span Event to API (#1452)
Browse files Browse the repository at this point in the history
* Move Span Event to API

* Add changes to CHANGELOG
  • Loading branch information
MrAlias authored Jan 14, 2021
1 parent 4392224 commit fe363be
Show file tree
Hide file tree
Showing 12 changed files with 44 additions and 42 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion exporters/otlp/internal/otlptest/data.go
Original file line number Diff line number Diff line change
Expand Up @@ -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: "",
Expand Down
2 changes: 1 addition & 1 deletion exporters/otlp/internal/transform/span.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
10 changes: 5 additions & 5 deletions exporters/otlp/internal/transform/span_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{},
Expand All @@ -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)
Expand Down Expand Up @@ -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),
Expand Down
2 changes: 1 addition & 1 deletion exporters/stdout/trace_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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},
},
Expand Down
2 changes: 1 addition & 1 deletion exporters/trace/jaeger/jaeger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion exporters/trace/zipkin/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
16 changes: 8 additions & 8 deletions exporters/trace/zipkin/model_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
14 changes: 1 addition & 13 deletions sdk/export/trace/trace.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
}
14 changes: 7 additions & 7 deletions sdk/trace/span.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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()
}
Expand Down Expand Up @@ -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
}
Expand Down
8 changes: 4 additions & 4 deletions sdk/trace/trace_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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}},
},
Expand Down Expand Up @@ -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}},
},
Expand Down Expand Up @@ -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{}))
}

Expand Down Expand Up @@ -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,
Expand Down
13 changes: 13 additions & 0 deletions trace/trace.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"encoding/json"
"regexp"
"strings"
"time"

"go.opentelemetry.io/otel/codes"
"go.opentelemetry.io/otel/label"
Expand Down Expand Up @@ -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.
//
Expand Down

0 comments on commit fe363be

Please sign in to comment.