Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move the Event type from the API to the SDK #1846

Merged
merged 6 commits into from
Apr 29, 2021
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm

- Make `NewSplitDriver` from `go.opentelemetry.io/otel/exporters/otlp` take variadic arguments instead of a `SplitConfig` item.
`NewSplitDriver` now automatically implements an internal `noopDriver` for `SplitConfig` fields that are not initialized. (#1798)
- Move the `Event` type from the `go.opentelemetry.io/otel` package to the `go.opentelemetry.io/otel/sdk/trace` package. (TBD)
MrAlias marked this conversation as resolved.
Show resolved Hide resolved

### Deprecated

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 @@ -97,7 +97,7 @@ func SingleSpanSnapshot() []*tracesdk.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: []attribute.KeyValue{},
MessageEvents: []trace.Event{},
MessageEvents: []tracesdk.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 @@ -168,7 +168,7 @@ func links(links []trace.Link) []*tracepb.Span_Link {
}

// spanEvents transforms span Events to an OTLP span events.
func spanEvents(es []trace.Event) []*tracepb.Span_Event {
func spanEvents(es []tracesdk.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([]trace.Event{}))
assert.Nil(t, spanEvents([]tracesdk.Event{}))
}

func TestSpanEvent(t *testing.T) {
attrs := []attribute.KeyValue{attribute.Int("one", 1), attribute.Int("two", 2)}
eventTime := time.Date(2020, 5, 20, 0, 0, 0, 0, time.UTC)
got := spanEvents([]trace.Event{
got := spanEvents([]tracesdk.Event{
{
Name: "test 1",
Attributes: []attribute.KeyValue{},
Expand All @@ -101,9 +101,9 @@ func TestSpanEvent(t *testing.T) {
}

func TestExcessiveSpanEvents(t *testing.T) {
e := make([]trace.Event, maxMessageEventsPerSpan+1)
e := make([]tracesdk.Event, maxMessageEventsPerSpan+1)
for i := 0; i < maxMessageEventsPerSpan+1; i++ {
e[i] = trace.Event{Name: strconv.Itoa(i)}
e[i] = tracesdk.Event{Name: strconv.Itoa(i)}
}
assert.Len(t, e, maxMessageEventsPerSpan+1)
got := spanEvents(e)
Expand Down Expand Up @@ -215,7 +215,7 @@ func TestSpanData(t *testing.T) {
Name: "span data to span data",
StartTime: startTime,
EndTime: endTime,
MessageEvents: []trace.Event{
MessageEvents: []tracesdk.Event{
{Time: startTime,
Attributes: []attribute.KeyValue{
attribute.Int64("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) {
attribute.String("key", keyValue),
attribute.Float64("double", doubleValue),
},
MessageEvents: []trace.Event{
MessageEvents: []tracesdk.Event{
{Name: "foo", Attributes: []attribute.KeyValue{attribute.String("key", keyValue)}, Time: now},
{Name: "bar", Attributes: []attribute.KeyValue{attribute.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 @@ -279,7 +279,7 @@ func Test_spanSnapshotToThrift(t *testing.T) {
attribute.Float64("double", doubleValue),
attribute.Int64("int", intValue),
},
MessageEvents: []trace.Event{
MessageEvents: []sdktrace.Event{
{
Name: eventNameValue,
Attributes: []attribute.KeyValue{attribute.String("k1", keyValue)},
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 @@ -136,7 +136,7 @@ func toZipkinKind(kind trace.SpanKind) zkmodel.Kind {
return zkmodel.Undetermined
}

func toZipkinAnnotations(events []trace.Event) []zkmodel.Annotation {
func toZipkinAnnotations(events []tracesdk.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 @@ -60,7 +60,7 @@ func TestModelConversion(t *testing.T) {
attribute.String("attr2", "bar"),
attribute.Array("attr3", []int{0, 1, 2}),
},
MessageEvents: []trace.Event{
MessageEvents: []tracesdk.Event{
{
Time: time.Date(2020, time.March, 11, 19, 24, 30, 0, time.UTC),
Name: "ev1",
Expand Down Expand Up @@ -93,7 +93,7 @@ func TestModelConversion(t *testing.T) {
attribute.Int64("attr1", 42),
attribute.String("attr2", "bar"),
},
MessageEvents: []trace.Event{
MessageEvents: []tracesdk.Event{
{
Time: time.Date(2020, time.March, 11, 19, 24, 30, 0, time.UTC),
Name: "ev1",
Expand Down Expand Up @@ -129,7 +129,7 @@ func TestModelConversion(t *testing.T) {
attribute.Int64("attr1", 42),
attribute.String("attr2", "bar"),
},
MessageEvents: []trace.Event{
MessageEvents: []tracesdk.Event{
{
Time: time.Date(2020, time.March, 11, 19, 24, 30, 0, time.UTC),
Name: "ev1",
Expand Down Expand Up @@ -165,7 +165,7 @@ func TestModelConversion(t *testing.T) {
attribute.Int64("attr1", 42),
attribute.String("attr2", "bar"),
},
MessageEvents: []trace.Event{
MessageEvents: []tracesdk.Event{
{
Time: time.Date(2020, time.March, 11, 19, 24, 30, 0, time.UTC),
Name: "ev1",
Expand Down Expand Up @@ -204,7 +204,7 @@ func TestModelConversion(t *testing.T) {
attribute.String("net.peer.ip", "1.2.3.4"),
attribute.Int64("net.peer.port", 9876),
},
MessageEvents: []trace.Event{
MessageEvents: []tracesdk.Event{
{
Time: time.Date(2020, time.March, 11, 19, 24, 30, 0, time.UTC),
Name: "ev1",
Expand Down Expand Up @@ -240,7 +240,7 @@ func TestModelConversion(t *testing.T) {
attribute.Int64("attr1", 42),
attribute.String("attr2", "bar"),
},
MessageEvents: []trace.Event{
MessageEvents: []tracesdk.Event{
{
Time: time.Date(2020, time.March, 11, 19, 24, 30, 0, time.UTC),
Name: "ev1",
Expand Down Expand Up @@ -276,7 +276,7 @@ func TestModelConversion(t *testing.T) {
attribute.Int64("attr1", 42),
attribute.String("attr2", "bar"),
},
MessageEvents: []trace.Event{
MessageEvents: []tracesdk.Event{
{
Time: time.Date(2020, time.March, 11, 19, 24, 30, 0, time.UTC),
Name: "ev1",
Expand Down Expand Up @@ -334,7 +334,7 @@ func TestModelConversion(t *testing.T) {
Attributes: []attribute.KeyValue{
attribute.String("error", "false"),
},
MessageEvents: []trace.Event{
MessageEvents: []tracesdk.Event{
{
Time: time.Date(2020, time.March, 11, 19, 24, 30, 0, time.UTC),
Name: "ev1",
Expand Down
37 changes: 37 additions & 0 deletions sdk/trace/event.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// Copyright The OpenTelemetry Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package trace

import (
"time"

"go.opentelemetry.io/otel/attribute"
)

// 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 []attribute.KeyValue

// DroppedAttributeCount is the number of attributes that were not
// recorded due to configured limits being reached.
DroppedAttributeCount int

// Time at which this event was recorded.
Time time.Time
}
16 changes: 8 additions & 8 deletions sdk/trace/span.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ type ReadOnlySpan interface {
EndTime() time.Time
Attributes() []attribute.KeyValue
Links() []trace.Link
Events() []trace.Event
Events() []Event
StatusCode() codes.Code
StatusMessage() string
Tracer() trace.Tracer
Expand Down Expand Up @@ -295,7 +295,7 @@ func (s *span) addEvent(name string, o ...trace.EventOption) {

s.mu.Lock()
defer s.mu.Unlock()
s.messageEvents.add(trace.Event{
s.messageEvents.add(Event{
Name: name,
Attributes: c.Attributes,
DroppedAttributeCount: discarded,
Expand Down Expand Up @@ -372,11 +372,11 @@ func (s *span) Links() []trace.Link {
}

// Events returns the events of this span.
func (s *span) Events() []trace.Event {
func (s *span) Events() []Event {
s.mu.Lock()
defer s.mu.Unlock()
if len(s.messageEvents.queue) == 0 {
return []trace.Event{}
return []Event{}
}
return s.interfaceArrayToMessageEventArray()
}
Expand Down Expand Up @@ -469,10 +469,10 @@ func (s *span) interfaceArrayToLinksArray() []trace.Link {
return linkArr
}

func (s *span) interfaceArrayToMessageEventArray() []trace.Event {
messageEventArr := make([]trace.Event, 0)
func (s *span) interfaceArrayToMessageEventArray() []Event {
messageEventArr := make([]Event, 0)
for _, value := range s.messageEvents.queue {
messageEventArr = append(messageEventArr, value.(trace.Event))
messageEventArr = append(messageEventArr, value.(Event))
}
return messageEventArr
}
Expand Down Expand Up @@ -595,7 +595,7 @@ type SpanSnapshot struct {
// from StartTime by the duration of the span.
EndTime time.Time
Attributes []attribute.KeyValue
MessageEvents []trace.Event
MessageEvents []Event
Links []trace.Link
StatusCode codes.Code
StatusMessage string
Expand Down
10 changes: 5 additions & 5 deletions sdk/trace/trace_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -559,7 +559,7 @@ func TestEvents(t *testing.T) {
}),
Parent: sc.WithRemote(true),
Name: "span0",
MessageEvents: []trace.Event{
MessageEvents: []Event{
{Name: "foo", Attributes: []attribute.KeyValue{k1v1}},
{Name: "bar", Attributes: []attribute.KeyValue{k2v2, k3v3}},
},
Expand Down Expand Up @@ -608,7 +608,7 @@ func TestEventsOverLimit(t *testing.T) {
}),
Parent: sc.WithRemote(true),
Name: "span0",
MessageEvents: []trace.Event{
MessageEvents: []Event{
{Name: "foo", Attributes: []attribute.KeyValue{k1v1}},
{Name: "bar", Attributes: []attribute.KeyValue{k2v2, k3v3}},
},
Expand Down Expand Up @@ -781,7 +781,7 @@ func TestSetSpanStatusWithoutMessageWhenStatusIsNotError(t *testing.T) {
func cmpDiff(x, y interface{}) string {
return cmp.Diff(x, y,
cmp.AllowUnexported(attribute.Value{}),
cmp.AllowUnexported(trace.Event{}),
cmp.AllowUnexported(Event{}),
cmp.AllowUnexported(trace.TraceState{}))
}

Expand Down Expand Up @@ -1119,7 +1119,7 @@ func TestRecordError(t *testing.T) {
Name: "span0",
StatusCode: codes.Unset,
SpanKind: trace.SpanKindInternal,
MessageEvents: []trace.Event{
MessageEvents: []Event{
{
Name: semconv.ExceptionEventName,
Time: errTime,
Expand Down Expand Up @@ -1489,7 +1489,7 @@ func TestAddEventsWithMoreAttributesThanLimit(t *testing.T) {
Parent: sc.WithRemote(true),
Name: "span0",
Attributes: nil,
MessageEvents: []trace.Event{
MessageEvents: []Event{
{
Name: "test1",
Attributes: []attribute.KeyValue{
Expand Down
17 changes: 0 additions & 17 deletions trace/trace.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
"encoding/json"
"regexp"
"strings"
"time"

"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/codes"
Expand Down Expand Up @@ -539,22 +538,6 @@ type Span interface {
SetAttributes(kv ...attribute.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 []attribute.KeyValue

// DroppedAttributeCount is the number of attributes that were not
// recorded due to configured limits being reached.
DroppedAttributeCount int

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