diff --git a/internal/telemetry/event/export.go b/internal/telemetry/event/export.go index 82afb8917b..fd470278c7 100644 --- a/internal/telemetry/event/export.go +++ b/internal/telemetry/event/export.go @@ -7,6 +7,7 @@ package event import ( "context" "sync/atomic" + "time" "unsafe" ) @@ -33,12 +34,16 @@ func SetExporter(e Exporter) { atomic.StorePointer(&exporter, p) } -// ProcessEvent is called to deliver an event to the global exporter. -func ProcessEvent(ctx context.Context, ev Event) context.Context { +// dispatch is called to deliver an event to the supplied exporter. +// it will fill in the time and generate the basic tag source. +func dispatch(ctx context.Context, ev Event) context.Context { + // get the global exporter and abort early if there is not one exporterPtr := (*Exporter)(atomic.LoadPointer(&exporter)) if exporterPtr == nil { return ctx } - // and now also hand the event of to the current exporter + // add the current time to the event + ev.At = time.Now() + // hand the event off to the current exporter return (*exporterPtr)(ctx, ev, ev.Map()) } diff --git a/internal/telemetry/event/label.go b/internal/telemetry/event/label.go index 7faec1ef88..5892e7f842 100644 --- a/internal/telemetry/event/label.go +++ b/internal/telemetry/event/label.go @@ -6,14 +6,12 @@ package event import ( "context" - "time" ) // Label sends a label event to the exporter with the supplied tags. func Label(ctx context.Context, tags ...Tag) context.Context { - return ProcessEvent(ctx, Event{ + return dispatch(ctx, Event{ Type: LabelType, - At: time.Now(), tags: tags, }) } diff --git a/internal/telemetry/event/log.go b/internal/telemetry/event/log.go index 6029585809..abbe2206b9 100644 --- a/internal/telemetry/event/log.go +++ b/internal/telemetry/event/log.go @@ -7,14 +7,12 @@ package event import ( "context" "errors" - "time" ) // Log sends a log event with the supplied tag list to the exporter. func Log(ctx context.Context, tags ...Tag) { - ProcessEvent(ctx, Event{ + dispatch(ctx, Event{ Type: LogType, - At: time.Now(), tags: tags, }) } @@ -22,9 +20,8 @@ func Log(ctx context.Context, tags ...Tag) { // Print takes a message and a tag list and combines them into a single event // before delivering them to the exporter. func Print(ctx context.Context, message string, tags ...Tag) { - ProcessEvent(ctx, Event{ + dispatch(ctx, Event{ Type: LogType, - At: time.Now(), Message: message, tags: tags, }) @@ -38,9 +35,8 @@ func Error(ctx context.Context, message string, err error, tags ...Tag) { err = errors.New(message) message = "" } - ProcessEvent(ctx, Event{ + dispatch(ctx, Event{ Type: LogType, - At: time.Now(), Message: message, Error: err, tags: tags, diff --git a/internal/telemetry/event/metric.go b/internal/telemetry/event/metric.go index 7d4aaa5903..23af8d5e53 100644 --- a/internal/telemetry/event/metric.go +++ b/internal/telemetry/event/metric.go @@ -6,13 +6,11 @@ package event import ( "context" - "time" ) func Record(ctx context.Context, tags ...Tag) { - ProcessEvent(ctx, Event{ + dispatch(ctx, Event{ Type: RecordType, - At: time.Now(), tags: tags, }) } diff --git a/internal/telemetry/event/trace.go b/internal/telemetry/event/trace.go index 878ca4a859..57095ab702 100644 --- a/internal/telemetry/event/trace.go +++ b/internal/telemetry/event/trace.go @@ -6,20 +6,17 @@ package event import ( "context" - "time" ) func StartSpan(ctx context.Context, name string, tags ...Tag) (context.Context, func()) { - ctx = ProcessEvent(ctx, Event{ + ctx = dispatch(ctx, Event{ Type: StartSpanType, Message: name, - At: time.Now(), tags: tags, }) return ctx, func() { - ProcessEvent(ctx, Event{ + dispatch(ctx, Event{ Type: EndSpanType, - At: time.Now(), }) } } @@ -27,8 +24,5 @@ func StartSpan(ctx context.Context, name string, tags ...Tag) (context.Context, // Detach returns a context without an associated span. // This allows the creation of spans that are not children of the current span. func Detach(ctx context.Context) context.Context { - return ProcessEvent(ctx, Event{ - Type: DetachType, - At: time.Now(), - }) + return dispatch(ctx, Event{Type: DetachType}) }