1
0
mirror of https://github.com/open-telemetry/opentelemetry-go.git synced 2025-12-01 23:12:29 +02:00

Consolidate AddEvent and Event methods, add FinishOptions (#99)

* Merge two event methods in span API

There was an agreement to get rid of the Event interface and
consolidate the two methods for adding events into one. See #57.

* Eliminate the use of the Event interface

There is no need for the SDK to provide the implementation of the
Event interface - it is used nowhere.

* Drop the Event interface

It's dead code now.

* Make it possible to override a finish timestamp through options

Opentracing to opentelemetry bridge will certainly use this feature.

* Obey the start time option

* Add tests for events and custom start/end times
This commit is contained in:
Krzesimir Nowak
2019-09-03 20:03:51 +02:00
committed by rghetia
parent 3fc6025071
commit a776e95c61
15 changed files with 297 additions and 98 deletions

View File

@@ -234,8 +234,8 @@ func TestEvents(t *testing.T) {
k2v2 := key.New("key2").String("value2")
k3v3 := key.New("key3").String("value3")
span.Event(context.Background(), "foo", key.New("key1").String("value1"))
span.Event(context.Background(), "bar",
span.AddEvent(context.Background(), "foo", key.New("key1").String("value1"))
span.AddEvent(context.Background(), "bar",
key.New("key2").String("value2"),
key.New("key3").String("value3"),
)
@@ -276,13 +276,13 @@ func TestEventsOverLimit(t *testing.T) {
k2v2 := key.New("key2").String("value2")
k3v3 := key.New("key3").String("value3")
span.Event(context.Background(), "fooDrop", key.New("key1").String("value1"))
span.Event(context.Background(), "barDrop",
span.AddEvent(context.Background(), "fooDrop", key.New("key1").String("value1"))
span.AddEvent(context.Background(), "barDrop",
key.New("key2").String("value2"),
key.New("key3").String("value3"),
)
span.Event(context.Background(), "foo", key.New("key1").String("value1"))
span.Event(context.Background(), "bar",
span.AddEvent(context.Background(), "foo", key.New("key1").String("value1"))
span.AddEvent(context.Background(), "bar",
key.New("key2").String("value2"),
key.New("key3").String("value3"),
)
@@ -596,3 +596,27 @@ func TestExecutionTracerTaskEnd(t *testing.T) {
t.Fatalf("Execution tracer task ended for %v spans; want %v", got, want)
}
}
func TestCustomStartEndTime(t *testing.T) {
startTime := time.Date(2019, time.August, 27, 14, 42, 0, 0, time.UTC)
endTime := startTime.Add(time.Second * 20)
_, span := apitrace.Start(
context.Background(),
"testspan",
apitrace.WithStartTime(startTime),
)
var te testExporter
RegisterExporter(&te)
span.Finish(apitrace.WithFinishTime(endTime))
UnregisterExporter(&te)
if len(te.spans) != 1 {
t.Fatalf("got exported spans %#v, want one span", te.spans)
}
got := te.spans[0]
if got.StartTime != startTime {
t.Errorf("expected start time to be %s, got %s", startTime, got.StartTime)
}
if got.EndTime != endTime {
t.Errorf("expected end time to be %s, got %s", endTime, got.EndTime)
}
}