1
0
mirror of https://github.com/golang/go synced 2024-11-18 12:54:44 -07:00

internal/telemetry: remove the ProcessEvent function

There is no reason for it to be public now, it is no longer possible to build an
event
without using the helpers.
This also allows us to delay setting the time until after the nil exporter
check, for
a significant time saving in the no exporter case.

name                old time/op    new time/op    delta
/Baseline-8            588ns ± 4%     575ns ± 4%   -2.24%  (p=0.000 n=18+18)
/StdLog-8             9.61µs ± 3%    9.58µs ± 3%     ~     (p=0.384 n=18+18)
/LogNoExporter-8      3.94µs ± 2%    2.26µs ± 2%  -42.50%  (p=0.000 n=17+18)
/TraceNoExporter-8    2.77µs ± 4%    1.11µs ± 2%  -59.82%  (p=0.000 n=18+18)
/StatsNoExporter-8    3.83µs ± 5%    2.15µs ± 3%  -43.70%  (p=0.000 n=18+17)
/Log-8                23.3µs ± 6%    23.0µs ± 1%     ~     (p=0.245 n=18+17)
/Trace-8              26.4µs ± 3%    26.5µs ± 4%     ~     (p=0.269 n=18+17)
/Stats-8              5.36µs ± 2%    5.45µs ± 3%   +1.68%  (p=0.000 n=17+18)

Change-Id: Ibde0e20eaf99d03f786cd1436f05eab7b2a17b20
Reviewed-on: https://go-review.googlesource.com/c/tools/+/224657
Run-TryBot: Ian Cottrell <iancottrell@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Emmanuel Odeke <emm.odeke@gmail.com>
This commit is contained in:
Ian Cottrell 2020-03-20 17:18:18 -04:00
parent 224c947ce5
commit f207553f3c
5 changed files with 16 additions and 25 deletions

View File

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

View File

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

View File

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

View File

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

View File

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