You've already forked opentelemetry-go
mirror of
https://github.com/open-telemetry/opentelemetry-go.git
synced 2025-06-14 23:45:20 +02:00
@ -68,10 +68,10 @@ type Span interface {
|
|||||||
End(options ...EndOption)
|
End(options ...EndOption)
|
||||||
|
|
||||||
// AddEvent adds an event to the span.
|
// AddEvent adds an event to the span.
|
||||||
AddEvent(ctx context.Context, msg string, attrs ...core.KeyValue)
|
AddEvent(ctx context.Context, name string, attrs ...core.KeyValue)
|
||||||
// AddEventWithTimestamp adds an event with a custom timestamp
|
// AddEventWithTimestamp adds an event with a custom timestamp
|
||||||
// to the span.
|
// to the span.
|
||||||
AddEventWithTimestamp(ctx context.Context, timestamp time.Time, msg string, attrs ...core.KeyValue)
|
AddEventWithTimestamp(ctx context.Context, timestamp time.Time, name string, attrs ...core.KeyValue)
|
||||||
|
|
||||||
// IsRecording returns true if the span is active and recording events is enabled.
|
// IsRecording returns true if the span is active and recording events is enabled.
|
||||||
IsRecording() bool
|
IsRecording() bool
|
||||||
|
@ -93,9 +93,9 @@ func (mockSpan) Tracer() trace.Tracer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Event does nothing.
|
// Event does nothing.
|
||||||
func (mockSpan) AddEvent(ctx context.Context, msg string, attrs ...core.KeyValue) {
|
func (mockSpan) AddEvent(ctx context.Context, name string, attrs ...core.KeyValue) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// AddEventWithTimestamp does nothing.
|
// AddEventWithTimestamp does nothing.
|
||||||
func (mockSpan) AddEventWithTimestamp(ctx context.Context, timestamp time.Time, msg string, attrs ...core.KeyValue) {
|
func (mockSpan) AddEventWithTimestamp(ctx context.Context, timestamp time.Time, name string, attrs ...core.KeyValue) {
|
||||||
}
|
}
|
||||||
|
@ -60,11 +60,11 @@ func (NoopSpan) Tracer() Tracer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// AddEvent does nothing.
|
// AddEvent does nothing.
|
||||||
func (NoopSpan) AddEvent(ctx context.Context, msg string, attrs ...core.KeyValue) {
|
func (NoopSpan) AddEvent(ctx context.Context, name string, attrs ...core.KeyValue) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// AddEventWithTimestamp does nothing.
|
// AddEventWithTimestamp does nothing.
|
||||||
func (NoopSpan) AddEventWithTimestamp(ctx context.Context, timestamp time.Time, msg string, attrs ...core.KeyValue) {
|
func (NoopSpan) AddEventWithTimestamp(ctx context.Context, timestamp time.Time, name string, attrs ...core.KeyValue) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetName does nothing.
|
// SetName does nothing.
|
||||||
|
@ -23,6 +23,6 @@ import (
|
|||||||
// Event encapsulates the properties of calls to AddEvent or AddEventWithTimestamp.
|
// Event encapsulates the properties of calls to AddEvent or AddEventWithTimestamp.
|
||||||
type Event struct {
|
type Event struct {
|
||||||
Timestamp time.Time
|
Timestamp time.Time
|
||||||
Message string
|
Name string
|
||||||
Attributes map[core.Key]core.Value
|
Attributes map[core.Key]core.Value
|
||||||
}
|
}
|
||||||
|
@ -69,11 +69,11 @@ func (s *Span) End(opts ...trace.EndOption) {
|
|||||||
s.ended = true
|
s.ended = true
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Span) AddEvent(ctx context.Context, msg string, attrs ...core.KeyValue) {
|
func (s *Span) AddEvent(ctx context.Context, name string, attrs ...core.KeyValue) {
|
||||||
s.AddEventWithTimestamp(ctx, time.Now(), msg, attrs...)
|
s.AddEventWithTimestamp(ctx, time.Now(), name, attrs...)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Span) AddEventWithTimestamp(ctx context.Context, timestamp time.Time, msg string, attrs ...core.KeyValue) {
|
func (s *Span) AddEventWithTimestamp(ctx context.Context, timestamp time.Time, name string, attrs ...core.KeyValue) {
|
||||||
s.lock.Lock()
|
s.lock.Lock()
|
||||||
defer s.lock.Unlock()
|
defer s.lock.Unlock()
|
||||||
|
|
||||||
@ -89,7 +89,7 @@ func (s *Span) AddEventWithTimestamp(ctx context.Context, timestamp time.Time, m
|
|||||||
|
|
||||||
s.events = append(s.events, Event{
|
s.events = append(s.events, Event{
|
||||||
Timestamp: timestamp,
|
Timestamp: timestamp,
|
||||||
Message: msg,
|
Name: name,
|
||||||
Attributes: attributes,
|
Attributes: attributes,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -337,23 +337,23 @@ func TestSpan(t *testing.T) {
|
|||||||
subject, ok := span.(*testtrace.Span)
|
subject, ok := span.(*testtrace.Span)
|
||||||
e.Expect(ok).ToBeTrue()
|
e.Expect(ok).ToBeTrue()
|
||||||
|
|
||||||
event1Msg := "event1"
|
event1Name := "event1"
|
||||||
event1Attributes := []core.KeyValue{
|
event1Attributes := []core.KeyValue{
|
||||||
core.Key("event1Attr1").String("foo"),
|
core.Key("event1Attr1").String("foo"),
|
||||||
core.Key("event1Attr2").String("bar"),
|
core.Key("event1Attr2").String("bar"),
|
||||||
}
|
}
|
||||||
|
|
||||||
event1Start := time.Now()
|
event1Start := time.Now()
|
||||||
subject.AddEvent(context.Background(), event1Msg, event1Attributes...)
|
subject.AddEvent(context.Background(), event1Name, event1Attributes...)
|
||||||
event1End := time.Now()
|
event1End := time.Now()
|
||||||
|
|
||||||
event2Timestamp := time.Now().AddDate(5, 0, 0)
|
event2Timestamp := time.Now().AddDate(5, 0, 0)
|
||||||
event2Msg := "event1"
|
event2Name := "event1"
|
||||||
event2Attributes := []core.KeyValue{
|
event2Attributes := []core.KeyValue{
|
||||||
core.Key("event2Attr").String("abc"),
|
core.Key("event2Attr").String("abc"),
|
||||||
}
|
}
|
||||||
|
|
||||||
subject.AddEventWithTimestamp(context.Background(), event2Timestamp, event2Msg, event2Attributes...)
|
subject.AddEventWithTimestamp(context.Background(), event2Timestamp, event2Name, event2Attributes...)
|
||||||
|
|
||||||
events := subject.Events()
|
events := subject.Events()
|
||||||
|
|
||||||
@ -363,7 +363,7 @@ func TestSpan(t *testing.T) {
|
|||||||
|
|
||||||
e.Expect(event1.Timestamp).ToBeTemporally(matchers.AfterOrSameTime, event1Start)
|
e.Expect(event1.Timestamp).ToBeTemporally(matchers.AfterOrSameTime, event1Start)
|
||||||
e.Expect(event1.Timestamp).ToBeTemporally(matchers.BeforeOrSameTime, event1End)
|
e.Expect(event1.Timestamp).ToBeTemporally(matchers.BeforeOrSameTime, event1End)
|
||||||
e.Expect(event1.Message).ToEqual(event1Msg)
|
e.Expect(event1.Name).ToEqual(event1Name)
|
||||||
|
|
||||||
for _, attr := range event1Attributes {
|
for _, attr := range event1Attributes {
|
||||||
e.Expect(event1.Attributes[attr.Key]).ToEqual(attr.Value)
|
e.Expect(event1.Attributes[attr.Key]).ToEqual(attr.Value)
|
||||||
@ -372,7 +372,7 @@ func TestSpan(t *testing.T) {
|
|||||||
event2 := events[1]
|
event2 := events[1]
|
||||||
|
|
||||||
e.Expect(event2.Timestamp).ToEqual(event2Timestamp)
|
e.Expect(event2.Timestamp).ToEqual(event2Timestamp)
|
||||||
e.Expect(event2.Message).ToEqual(event2Msg)
|
e.Expect(event2.Name).ToEqual(event2Name)
|
||||||
|
|
||||||
for _, attr := range event2Attributes {
|
for _, attr := range event2Attributes {
|
||||||
e.Expect(event2.Attributes[attr.Key]).ToEqual(attr.Value)
|
e.Expect(event2.Attributes[attr.Key]).ToEqual(attr.Value)
|
||||||
|
@ -195,7 +195,7 @@ func (t *MockTracer) DeferredContextSetupHook(ctx context.Context, span oteltrac
|
|||||||
type MockEvent struct {
|
type MockEvent struct {
|
||||||
CtxAttributes oteldctx.Map
|
CtxAttributes oteldctx.Map
|
||||||
Timestamp time.Time
|
Timestamp time.Time
|
||||||
Msg string
|
Name string
|
||||||
Attributes oteldctx.Map
|
Attributes oteldctx.Map
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -268,15 +268,15 @@ func (s *MockSpan) Tracer() oteltrace.Tracer {
|
|||||||
return s.officialTracer
|
return s.officialTracer
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *MockSpan) AddEvent(ctx context.Context, msg string, attrs ...otelcore.KeyValue) {
|
func (s *MockSpan) AddEvent(ctx context.Context, name string, attrs ...otelcore.KeyValue) {
|
||||||
s.AddEventWithTimestamp(ctx, time.Now(), msg, attrs...)
|
s.AddEventWithTimestamp(ctx, time.Now(), name, attrs...)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *MockSpan) AddEventWithTimestamp(ctx context.Context, timestamp time.Time, msg string, attrs ...otelcore.KeyValue) {
|
func (s *MockSpan) AddEventWithTimestamp(ctx context.Context, timestamp time.Time, name string, attrs ...otelcore.KeyValue) {
|
||||||
s.Events = append(s.Events, MockEvent{
|
s.Events = append(s.Events, MockEvent{
|
||||||
CtxAttributes: oteldctx.FromContext(ctx),
|
CtxAttributes: oteldctx.FromContext(ctx),
|
||||||
Timestamp: timestamp,
|
Timestamp: timestamp,
|
||||||
Msg: msg,
|
Name: name,
|
||||||
Attributes: oteldctx.NewMap(oteldctx.MapUpdate{
|
Attributes: oteldctx.NewMap(oteldctx.MapUpdate{
|
||||||
MultiKV: attrs,
|
MultiKV: attrs,
|
||||||
}),
|
}),
|
||||||
|
@ -176,7 +176,7 @@ func spanDataToThrift(data *export.SpanData) *gen.Span {
|
|||||||
fields = append(fields, tag)
|
fields = append(fields, tag)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fields = append(fields, getStringTag("message", a.Message))
|
fields = append(fields, getStringTag("name", a.Name))
|
||||||
logs = append(logs, &gen.Log{
|
logs = append(logs, &gen.Log{
|
||||||
Timestamp: a.Time.UnixNano() / 1000,
|
Timestamp: a.Time.UnixNano() / 1000,
|
||||||
Fields: fields,
|
Fields: fields,
|
||||||
|
@ -152,7 +152,7 @@ func Test_spanDataToThrift(t *testing.T) {
|
|||||||
linkTraceID, _ := core.TraceIDFromHex("0102030405060709090a0b0c0d0e0f11")
|
linkTraceID, _ := core.TraceIDFromHex("0102030405060709090a0b0c0d0e0f11")
|
||||||
linkSpanID, _ := core.SpanIDFromHex("0102030405060709")
|
linkSpanID, _ := core.SpanIDFromHex("0102030405060709")
|
||||||
|
|
||||||
messageEventValue := "event-test"
|
eventNameValue := "event-test"
|
||||||
keyValue := "value"
|
keyValue := "value"
|
||||||
statusCodeValue := int64(2)
|
statusCodeValue := int64(2)
|
||||||
doubleValue := 123.456
|
doubleValue := 123.456
|
||||||
@ -189,7 +189,7 @@ func Test_spanDataToThrift(t *testing.T) {
|
|||||||
key.Uint64("ignored", 123),
|
key.Uint64("ignored", 123),
|
||||||
},
|
},
|
||||||
MessageEvents: []export.Event{
|
MessageEvents: []export.Event{
|
||||||
{Message: messageEventValue, Attributes: []core.KeyValue{key.String("k1", keyValue)}, Time: now},
|
{Name: eventNameValue, Attributes: []core.KeyValue{key.String("k1", keyValue)}, Time: now},
|
||||||
},
|
},
|
||||||
Status: codes.Unknown,
|
Status: codes.Unknown,
|
||||||
},
|
},
|
||||||
@ -225,8 +225,8 @@ func Test_spanDataToThrift(t *testing.T) {
|
|||||||
VType: gen.TagType_STRING,
|
VType: gen.TagType_STRING,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Key: "message",
|
Key: "name",
|
||||||
VStr: &messageEventValue,
|
VStr: &eventNameValue,
|
||||||
VType: gen.TagType_STRING,
|
VType: gen.TagType_STRING,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -99,7 +99,7 @@ func protoFromSpanData(s *export.SpanData, projectID string) *tracepb.Span {
|
|||||||
droppedAnnotationsCount = len(es) - i
|
droppedAnnotationsCount = len(es) - i
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
annotation := &tracepb.Span_TimeEvent_Annotation{Description: trunc(e.Message, maxAttributeStringValue)}
|
annotation := &tracepb.Span_TimeEvent_Annotation{Description: trunc(e.Name, maxAttributeStringValue)}
|
||||||
copyAttributes(&annotation.Attributes, e.Attributes)
|
copyAttributes(&annotation.Attributes, e.Attributes)
|
||||||
event := &tracepb.Span_TimeEvent{
|
event := &tracepb.Span_TimeEvent{
|
||||||
Time: timestampProto(e.Time),
|
Time: timestampProto(e.Time),
|
||||||
|
@ -59,8 +59,8 @@ func TestExporter_ExportSpan(t *testing.T) {
|
|||||||
key.Float64("double", doubleValue),
|
key.Float64("double", doubleValue),
|
||||||
},
|
},
|
||||||
MessageEvents: []export.Event{
|
MessageEvents: []export.Event{
|
||||||
{Message: "foo", Attributes: []core.KeyValue{key.String("key", keyValue)}, Time: now},
|
{Name: "foo", Attributes: []core.KeyValue{key.String("key", keyValue)}, Time: now},
|
||||||
{Message: "bar", Attributes: []core.KeyValue{key.Float64("double", doubleValue)}, Time: now},
|
{Name: "bar", Attributes: []core.KeyValue{key.Float64("double", doubleValue)}, Time: now},
|
||||||
},
|
},
|
||||||
SpanKind: trace.SpanKindInternal,
|
SpanKind: trace.SpanKindInternal,
|
||||||
Status: codes.Unknown,
|
Status: codes.Unknown,
|
||||||
@ -90,7 +90,7 @@ func TestExporter_ExportSpan(t *testing.T) {
|
|||||||
`],` +
|
`],` +
|
||||||
`"MessageEvents":[` +
|
`"MessageEvents":[` +
|
||||||
`{` +
|
`{` +
|
||||||
`"Message":"foo",` +
|
`"Name":"foo",` +
|
||||||
`"Attributes":[` +
|
`"Attributes":[` +
|
||||||
`{` +
|
`{` +
|
||||||
`"Key":"key",` +
|
`"Key":"key",` +
|
||||||
@ -100,7 +100,7 @@ func TestExporter_ExportSpan(t *testing.T) {
|
|||||||
`"Time":` + string(expectedSerializedNow) +
|
`"Time":` + string(expectedSerializedNow) +
|
||||||
`},` +
|
`},` +
|
||||||
`{` +
|
`{` +
|
||||||
`"Message":"bar",` +
|
`"Name":"bar",` +
|
||||||
`"Attributes":[` +
|
`"Attributes":[` +
|
||||||
`{` +
|
`{` +
|
||||||
`"Key":"double",` +
|
`"Key":"double",` +
|
||||||
|
@ -72,9 +72,9 @@ func (ms *MockSpan) Tracer() apitrace.Tracer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// AddEvent does nothing.
|
// AddEvent does nothing.
|
||||||
func (ms *MockSpan) AddEvent(ctx context.Context, msg string, attrs ...core.KeyValue) {
|
func (ms *MockSpan) AddEvent(ctx context.Context, name string, attrs ...core.KeyValue) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// AddEvent does nothing.
|
// AddEvent does nothing.
|
||||||
func (ms *MockSpan) AddEventWithTimestamp(ctx context.Context, timestamp time.Time, msg string, attrs ...core.KeyValue) {
|
func (ms *MockSpan) AddEventWithTimestamp(ctx context.Context, timestamp time.Time, name string, attrs ...core.KeyValue) {
|
||||||
}
|
}
|
||||||
|
@ -71,8 +71,8 @@ type SpanData struct {
|
|||||||
// Event is used to describe an Event with a message string and set of
|
// Event is used to describe an Event with a message string and set of
|
||||||
// Attributes.
|
// Attributes.
|
||||||
type Event struct {
|
type Event struct {
|
||||||
// Message describes the Event.
|
// Name is the name of this event
|
||||||
Message string
|
Name string
|
||||||
|
|
||||||
// Attributes contains a list of keyvalue pairs.
|
// Attributes contains a list of keyvalue pairs.
|
||||||
Attributes []core.KeyValue
|
Attributes []core.KeyValue
|
||||||
|
@ -127,25 +127,25 @@ func (s *span) Tracer() apitrace.Tracer {
|
|||||||
return s.tracer
|
return s.tracer
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *span) AddEvent(ctx context.Context, msg string, attrs ...core.KeyValue) {
|
func (s *span) AddEvent(ctx context.Context, name string, attrs ...core.KeyValue) {
|
||||||
if !s.IsRecording() {
|
if !s.IsRecording() {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
s.addEventWithTimestamp(time.Now(), msg, attrs...)
|
s.addEventWithTimestamp(time.Now(), name, attrs...)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *span) AddEventWithTimestamp(ctx context.Context, timestamp time.Time, msg string, attrs ...core.KeyValue) {
|
func (s *span) AddEventWithTimestamp(ctx context.Context, timestamp time.Time, name string, attrs ...core.KeyValue) {
|
||||||
if !s.IsRecording() {
|
if !s.IsRecording() {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
s.addEventWithTimestamp(timestamp, msg, attrs...)
|
s.addEventWithTimestamp(timestamp, name, attrs...)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *span) addEventWithTimestamp(timestamp time.Time, msg string, attrs ...core.KeyValue) {
|
func (s *span) addEventWithTimestamp(timestamp time.Time, name string, attrs ...core.KeyValue) {
|
||||||
s.mu.Lock()
|
s.mu.Lock()
|
||||||
defer s.mu.Unlock()
|
defer s.mu.Unlock()
|
||||||
s.messageEvents.add(export.Event{
|
s.messageEvents.add(export.Event{
|
||||||
Message: msg,
|
Name: name,
|
||||||
Attributes: attrs,
|
Attributes: attrs,
|
||||||
Time: timestamp,
|
Time: timestamp,
|
||||||
})
|
})
|
||||||
|
@ -423,8 +423,8 @@ func TestEvents(t *testing.T) {
|
|||||||
Name: "Events/span0",
|
Name: "Events/span0",
|
||||||
HasRemoteParent: true,
|
HasRemoteParent: true,
|
||||||
MessageEvents: []export.Event{
|
MessageEvents: []export.Event{
|
||||||
{Message: "foo", Attributes: []core.KeyValue{k1v1}},
|
{Name: "foo", Attributes: []core.KeyValue{k1v1}},
|
||||||
{Message: "bar", Attributes: []core.KeyValue{k2v2, k3v3}},
|
{Name: "bar", Attributes: []core.KeyValue{k2v2, k3v3}},
|
||||||
},
|
},
|
||||||
SpanKind: apitrace.SpanKindInternal,
|
SpanKind: apitrace.SpanKindInternal,
|
||||||
}
|
}
|
||||||
@ -472,8 +472,8 @@ func TestEventsOverLimit(t *testing.T) {
|
|||||||
ParentSpanID: sid,
|
ParentSpanID: sid,
|
||||||
Name: "EventsOverLimit/span0",
|
Name: "EventsOverLimit/span0",
|
||||||
MessageEvents: []export.Event{
|
MessageEvents: []export.Event{
|
||||||
{Message: "foo", Attributes: []core.KeyValue{k1v1}},
|
{Name: "foo", Attributes: []core.KeyValue{k1v1}},
|
||||||
{Message: "bar", Attributes: []core.KeyValue{k2v2, k3v3}},
|
{Name: "bar", Attributes: []core.KeyValue{k2v2, k3v3}},
|
||||||
},
|
},
|
||||||
DroppedMessageEventCount: 2,
|
DroppedMessageEventCount: 2,
|
||||||
HasRemoteParent: true,
|
HasRemoteParent: true,
|
||||||
|
Reference in New Issue
Block a user