1
0
mirror of https://github.com/open-telemetry/opentelemetry-go.git synced 2025-01-30 04:40:41 +02:00

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

* Move the Event type from the API to the SDK

This type is not used in the API. It is used in the SDK and then through
the processing pipelines. Move it to the package that originates its use.

* Add changes to changelog

* Update CHANGELOG.md

Co-authored-by: Gustavo Silva Paiva <guustavo.paiva@gmail.com>

Co-authored-by: Gustavo Silva Paiva <guustavo.paiva@gmail.com>
This commit is contained in:
Tyler Yahn 2021-04-29 17:29:48 +00:00 committed by GitHub
parent e399d355cb
commit 8e55f10ad5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 69 additions and 48 deletions

View File

@ -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. - 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) `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. (#1846)
- BatchSpanProcessor now report export failures when calling `ForceFlush()` method. (#1860) - BatchSpanProcessor now report export failures when calling `ForceFlush()` method. (#1860)
### Deprecated ### Deprecated

View File

@ -97,7 +97,7 @@ func SingleSpanSnapshot() []*tracesdk.SpanSnapshot {
StartTime: time.Date(2020, time.December, 8, 20, 23, 0, 0, time.UTC), 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), EndTime: time.Date(2020, time.December, 0, 20, 24, 0, 0, time.UTC),
Attributes: []attribute.KeyValue{}, Attributes: []attribute.KeyValue{},
MessageEvents: []trace.Event{}, MessageEvents: []tracesdk.Event{},
Links: []trace.Link{}, Links: []trace.Link{},
StatusCode: codes.Ok, StatusCode: codes.Ok,
StatusMessage: "", StatusMessage: "",

View File

@ -168,7 +168,7 @@ func links(links []trace.Link) []*tracepb.Span_Link {
} }
// spanEvents transforms span Events to an OTLP span events. // 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 { if len(es) == 0 {
return nil return nil
} }

View File

@ -73,13 +73,13 @@ func TestNilSpanEvent(t *testing.T) {
} }
func TestEmptySpanEvent(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) { func TestSpanEvent(t *testing.T) {
attrs := []attribute.KeyValue{attribute.Int("one", 1), attribute.Int("two", 2)} attrs := []attribute.KeyValue{attribute.Int("one", 1), attribute.Int("two", 2)}
eventTime := time.Date(2020, 5, 20, 0, 0, 0, 0, time.UTC) eventTime := time.Date(2020, 5, 20, 0, 0, 0, 0, time.UTC)
got := spanEvents([]trace.Event{ got := spanEvents([]tracesdk.Event{
{ {
Name: "test 1", Name: "test 1",
Attributes: []attribute.KeyValue{}, Attributes: []attribute.KeyValue{},
@ -101,9 +101,9 @@ func TestSpanEvent(t *testing.T) {
} }
func TestExcessiveSpanEvents(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++ { 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) assert.Len(t, e, maxMessageEventsPerSpan+1)
got := spanEvents(e) got := spanEvents(e)
@ -215,7 +215,7 @@ func TestSpanData(t *testing.T) {
Name: "span data to span data", Name: "span data to span data",
StartTime: startTime, StartTime: startTime,
EndTime: endTime, EndTime: endTime,
MessageEvents: []trace.Event{ MessageEvents: []tracesdk.Event{
{Time: startTime, {Time: startTime,
Attributes: []attribute.KeyValue{ Attributes: []attribute.KeyValue{
attribute.Int64("CompressedByteSize", 512), attribute.Int64("CompressedByteSize", 512),

View File

@ -60,7 +60,7 @@ func TestExporter_ExportSpan(t *testing.T) {
attribute.String("key", keyValue), attribute.String("key", keyValue),
attribute.Float64("double", doubleValue), attribute.Float64("double", doubleValue),
}, },
MessageEvents: []trace.Event{ MessageEvents: []tracesdk.Event{
{Name: "foo", Attributes: []attribute.KeyValue{attribute.String("key", keyValue)}, Time: now}, {Name: "foo", Attributes: []attribute.KeyValue{attribute.String("key", keyValue)}, Time: now},
{Name: "bar", Attributes: []attribute.KeyValue{attribute.Float64("double", doubleValue)}, Time: now}, {Name: "bar", Attributes: []attribute.KeyValue{attribute.Float64("double", doubleValue)}, Time: now},
}, },

View File

@ -279,7 +279,7 @@ func Test_spanSnapshotToThrift(t *testing.T) {
attribute.Float64("double", doubleValue), attribute.Float64("double", doubleValue),
attribute.Int64("int", intValue), attribute.Int64("int", intValue),
}, },
MessageEvents: []trace.Event{ MessageEvents: []sdktrace.Event{
{ {
Name: eventNameValue, Name: eventNameValue,
Attributes: []attribute.KeyValue{attribute.String("k1", keyValue)}, Attributes: []attribute.KeyValue{attribute.String("k1", keyValue)},

View File

@ -136,7 +136,7 @@ func toZipkinKind(kind trace.SpanKind) zkmodel.Kind {
return zkmodel.Undetermined return zkmodel.Undetermined
} }
func toZipkinAnnotations(events []trace.Event) []zkmodel.Annotation { func toZipkinAnnotations(events []tracesdk.Event) []zkmodel.Annotation {
if len(events) == 0 { if len(events) == 0 {
return nil return nil
} }

View File

@ -60,7 +60,7 @@ func TestModelConversion(t *testing.T) {
attribute.String("attr2", "bar"), attribute.String("attr2", "bar"),
attribute.Array("attr3", []int{0, 1, 2}), 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), Time: time.Date(2020, time.March, 11, 19, 24, 30, 0, time.UTC),
Name: "ev1", Name: "ev1",
@ -93,7 +93,7 @@ func TestModelConversion(t *testing.T) {
attribute.Int64("attr1", 42), attribute.Int64("attr1", 42),
attribute.String("attr2", "bar"), attribute.String("attr2", "bar"),
}, },
MessageEvents: []trace.Event{ MessageEvents: []tracesdk.Event{
{ {
Time: time.Date(2020, time.March, 11, 19, 24, 30, 0, time.UTC), Time: time.Date(2020, time.March, 11, 19, 24, 30, 0, time.UTC),
Name: "ev1", Name: "ev1",
@ -129,7 +129,7 @@ func TestModelConversion(t *testing.T) {
attribute.Int64("attr1", 42), attribute.Int64("attr1", 42),
attribute.String("attr2", "bar"), attribute.String("attr2", "bar"),
}, },
MessageEvents: []trace.Event{ MessageEvents: []tracesdk.Event{
{ {
Time: time.Date(2020, time.March, 11, 19, 24, 30, 0, time.UTC), Time: time.Date(2020, time.March, 11, 19, 24, 30, 0, time.UTC),
Name: "ev1", Name: "ev1",
@ -165,7 +165,7 @@ func TestModelConversion(t *testing.T) {
attribute.Int64("attr1", 42), attribute.Int64("attr1", 42),
attribute.String("attr2", "bar"), attribute.String("attr2", "bar"),
}, },
MessageEvents: []trace.Event{ MessageEvents: []tracesdk.Event{
{ {
Time: time.Date(2020, time.March, 11, 19, 24, 30, 0, time.UTC), Time: time.Date(2020, time.March, 11, 19, 24, 30, 0, time.UTC),
Name: "ev1", Name: "ev1",
@ -204,7 +204,7 @@ func TestModelConversion(t *testing.T) {
attribute.String("net.peer.ip", "1.2.3.4"), attribute.String("net.peer.ip", "1.2.3.4"),
attribute.Int64("net.peer.port", 9876), 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), Time: time.Date(2020, time.March, 11, 19, 24, 30, 0, time.UTC),
Name: "ev1", Name: "ev1",
@ -240,7 +240,7 @@ func TestModelConversion(t *testing.T) {
attribute.Int64("attr1", 42), attribute.Int64("attr1", 42),
attribute.String("attr2", "bar"), attribute.String("attr2", "bar"),
}, },
MessageEvents: []trace.Event{ MessageEvents: []tracesdk.Event{
{ {
Time: time.Date(2020, time.March, 11, 19, 24, 30, 0, time.UTC), Time: time.Date(2020, time.March, 11, 19, 24, 30, 0, time.UTC),
Name: "ev1", Name: "ev1",
@ -276,7 +276,7 @@ func TestModelConversion(t *testing.T) {
attribute.Int64("attr1", 42), attribute.Int64("attr1", 42),
attribute.String("attr2", "bar"), attribute.String("attr2", "bar"),
}, },
MessageEvents: []trace.Event{ MessageEvents: []tracesdk.Event{
{ {
Time: time.Date(2020, time.March, 11, 19, 24, 30, 0, time.UTC), Time: time.Date(2020, time.March, 11, 19, 24, 30, 0, time.UTC),
Name: "ev1", Name: "ev1",
@ -334,7 +334,7 @@ func TestModelConversion(t *testing.T) {
Attributes: []attribute.KeyValue{ Attributes: []attribute.KeyValue{
attribute.String("error", "false"), attribute.String("error", "false"),
}, },
MessageEvents: []trace.Event{ MessageEvents: []tracesdk.Event{
{ {
Time: time.Date(2020, time.March, 11, 19, 24, 30, 0, time.UTC), Time: time.Date(2020, time.March, 11, 19, 24, 30, 0, time.UTC),
Name: "ev1", Name: "ev1",

37
sdk/trace/event.go Normal file
View File

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

View File

@ -45,7 +45,7 @@ type ReadOnlySpan interface {
EndTime() time.Time EndTime() time.Time
Attributes() []attribute.KeyValue Attributes() []attribute.KeyValue
Links() []trace.Link Links() []trace.Link
Events() []trace.Event Events() []Event
StatusCode() codes.Code StatusCode() codes.Code
StatusMessage() string StatusMessage() string
Tracer() trace.Tracer Tracer() trace.Tracer
@ -295,7 +295,7 @@ func (s *span) addEvent(name string, o ...trace.EventOption) {
s.mu.Lock() s.mu.Lock()
defer s.mu.Unlock() defer s.mu.Unlock()
s.messageEvents.add(trace.Event{ s.messageEvents.add(Event{
Name: name, Name: name,
Attributes: c.Attributes, Attributes: c.Attributes,
DroppedAttributeCount: discarded, DroppedAttributeCount: discarded,
@ -372,11 +372,11 @@ func (s *span) Links() []trace.Link {
} }
// Events returns the events of this span. // Events returns the events of this span.
func (s *span) Events() []trace.Event { func (s *span) Events() []Event {
s.mu.Lock() s.mu.Lock()
defer s.mu.Unlock() defer s.mu.Unlock()
if len(s.messageEvents.queue) == 0 { if len(s.messageEvents.queue) == 0 {
return []trace.Event{} return []Event{}
} }
return s.interfaceArrayToMessageEventArray() return s.interfaceArrayToMessageEventArray()
} }
@ -469,10 +469,10 @@ func (s *span) interfaceArrayToLinksArray() []trace.Link {
return linkArr return linkArr
} }
func (s *span) interfaceArrayToMessageEventArray() []trace.Event { func (s *span) interfaceArrayToMessageEventArray() []Event {
messageEventArr := make([]trace.Event, 0) messageEventArr := make([]Event, 0)
for _, value := range s.messageEvents.queue { for _, value := range s.messageEvents.queue {
messageEventArr = append(messageEventArr, value.(trace.Event)) messageEventArr = append(messageEventArr, value.(Event))
} }
return messageEventArr return messageEventArr
} }
@ -595,7 +595,7 @@ type SpanSnapshot struct {
// from StartTime by the duration of the span. // from StartTime by the duration of the span.
EndTime time.Time EndTime time.Time
Attributes []attribute.KeyValue Attributes []attribute.KeyValue
MessageEvents []trace.Event MessageEvents []Event
Links []trace.Link Links []trace.Link
StatusCode codes.Code StatusCode codes.Code
StatusMessage string StatusMessage string

View File

@ -559,7 +559,7 @@ func TestEvents(t *testing.T) {
}), }),
Parent: sc.WithRemote(true), Parent: sc.WithRemote(true),
Name: "span0", Name: "span0",
MessageEvents: []trace.Event{ MessageEvents: []Event{
{Name: "foo", Attributes: []attribute.KeyValue{k1v1}}, {Name: "foo", Attributes: []attribute.KeyValue{k1v1}},
{Name: "bar", Attributes: []attribute.KeyValue{k2v2, k3v3}}, {Name: "bar", Attributes: []attribute.KeyValue{k2v2, k3v3}},
}, },
@ -608,7 +608,7 @@ func TestEventsOverLimit(t *testing.T) {
}), }),
Parent: sc.WithRemote(true), Parent: sc.WithRemote(true),
Name: "span0", Name: "span0",
MessageEvents: []trace.Event{ MessageEvents: []Event{
{Name: "foo", Attributes: []attribute.KeyValue{k1v1}}, {Name: "foo", Attributes: []attribute.KeyValue{k1v1}},
{Name: "bar", Attributes: []attribute.KeyValue{k2v2, k3v3}}, {Name: "bar", Attributes: []attribute.KeyValue{k2v2, k3v3}},
}, },
@ -781,7 +781,7 @@ func TestSetSpanStatusWithoutMessageWhenStatusIsNotError(t *testing.T) {
func cmpDiff(x, y interface{}) string { func cmpDiff(x, y interface{}) string {
return cmp.Diff(x, y, return cmp.Diff(x, y,
cmp.AllowUnexported(attribute.Value{}), cmp.AllowUnexported(attribute.Value{}),
cmp.AllowUnexported(trace.Event{}), cmp.AllowUnexported(Event{}),
cmp.AllowUnexported(trace.TraceState{})) cmp.AllowUnexported(trace.TraceState{}))
} }
@ -1119,7 +1119,7 @@ func TestRecordError(t *testing.T) {
Name: "span0", Name: "span0",
StatusCode: codes.Unset, StatusCode: codes.Unset,
SpanKind: trace.SpanKindInternal, SpanKind: trace.SpanKindInternal,
MessageEvents: []trace.Event{ MessageEvents: []Event{
{ {
Name: semconv.ExceptionEventName, Name: semconv.ExceptionEventName,
Time: errTime, Time: errTime,
@ -1489,7 +1489,7 @@ func TestAddEventsWithMoreAttributesThanLimit(t *testing.T) {
Parent: sc.WithRemote(true), Parent: sc.WithRemote(true),
Name: "span0", Name: "span0",
Attributes: nil, Attributes: nil,
MessageEvents: []trace.Event{ MessageEvents: []Event{
{ {
Name: "test1", Name: "test1",
Attributes: []attribute.KeyValue{ Attributes: []attribute.KeyValue{

View File

@ -21,7 +21,6 @@ import (
"encoding/json" "encoding/json"
"regexp" "regexp"
"strings" "strings"
"time"
"go.opentelemetry.io/otel/attribute" "go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/codes" "go.opentelemetry.io/otel/codes"
@ -539,22 +538,6 @@ type Span interface {
SetAttributes(kv ...attribute.KeyValue) 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 // Link is the relationship between two Spans. The relationship can be within
// the same Trace or across different Traces. // the same Trace or across different Traces.
// //