Skip to content

Commit f207553

Browse files
committed
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 <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Emmanuel Odeke <[email protected]>
1 parent 224c947 commit f207553

File tree

5 files changed

+16
-25
lines changed

5 files changed

+16
-25
lines changed

internal/telemetry/event/export.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ package event
77
import (
88
"context"
99
"sync/atomic"
10+
"time"
1011
"unsafe"
1112
)
1213

@@ -33,12 +34,16 @@ func SetExporter(e Exporter) {
3334
atomic.StorePointer(&exporter, p)
3435
}
3536

36-
// ProcessEvent is called to deliver an event to the global exporter.
37-
func ProcessEvent(ctx context.Context, ev Event) context.Context {
37+
// dispatch is called to deliver an event to the supplied exporter.
38+
// it will fill in the time and generate the basic tag source.
39+
func dispatch(ctx context.Context, ev Event) context.Context {
40+
// get the global exporter and abort early if there is not one
3841
exporterPtr := (*Exporter)(atomic.LoadPointer(&exporter))
3942
if exporterPtr == nil {
4043
return ctx
4144
}
42-
// and now also hand the event of to the current exporter
45+
// add the current time to the event
46+
ev.At = time.Now()
47+
// hand the event off to the current exporter
4348
return (*exporterPtr)(ctx, ev, ev.Map())
4449
}

internal/telemetry/event/label.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,12 @@ package event
66

77
import (
88
"context"
9-
"time"
109
)
1110

1211
// Label sends a label event to the exporter with the supplied tags.
1312
func Label(ctx context.Context, tags ...Tag) context.Context {
14-
return ProcessEvent(ctx, Event{
13+
return dispatch(ctx, Event{
1514
Type: LabelType,
16-
At: time.Now(),
1715
tags: tags,
1816
})
1917
}

internal/telemetry/event/log.go

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,24 +7,21 @@ package event
77
import (
88
"context"
99
"errors"
10-
"time"
1110
)
1211

1312
// Log sends a log event with the supplied tag list to the exporter.
1413
func Log(ctx context.Context, tags ...Tag) {
15-
ProcessEvent(ctx, Event{
14+
dispatch(ctx, Event{
1615
Type: LogType,
17-
At: time.Now(),
1816
tags: tags,
1917
})
2018
}
2119

2220
// Print takes a message and a tag list and combines them into a single event
2321
// before delivering them to the exporter.
2422
func Print(ctx context.Context, message string, tags ...Tag) {
25-
ProcessEvent(ctx, Event{
23+
dispatch(ctx, Event{
2624
Type: LogType,
27-
At: time.Now(),
2825
Message: message,
2926
tags: tags,
3027
})
@@ -38,9 +35,8 @@ func Error(ctx context.Context, message string, err error, tags ...Tag) {
3835
err = errors.New(message)
3936
message = ""
4037
}
41-
ProcessEvent(ctx, Event{
38+
dispatch(ctx, Event{
4239
Type: LogType,
43-
At: time.Now(),
4440
Message: message,
4541
Error: err,
4642
tags: tags,

internal/telemetry/event/metric.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,11 @@ package event
66

77
import (
88
"context"
9-
"time"
109
)
1110

1211
func Record(ctx context.Context, tags ...Tag) {
13-
ProcessEvent(ctx, Event{
12+
dispatch(ctx, Event{
1413
Type: RecordType,
15-
At: time.Now(),
1614
tags: tags,
1715
})
1816
}

internal/telemetry/event/trace.go

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,29 +6,23 @@ package event
66

77
import (
88
"context"
9-
"time"
109
)
1110

1211
func StartSpan(ctx context.Context, name string, tags ...Tag) (context.Context, func()) {
13-
ctx = ProcessEvent(ctx, Event{
12+
ctx = dispatch(ctx, Event{
1413
Type: StartSpanType,
1514
Message: name,
16-
At: time.Now(),
1715
tags: tags,
1816
})
1917
return ctx, func() {
20-
ProcessEvent(ctx, Event{
18+
dispatch(ctx, Event{
2119
Type: EndSpanType,
22-
At: time.Now(),
2320
})
2421
}
2522
}
2623

2724
// Detach returns a context without an associated span.
2825
// This allows the creation of spans that are not children of the current span.
2926
func Detach(ctx context.Context) context.Context {
30-
return ProcessEvent(ctx, Event{
31-
Type: DetachType,
32-
At: time.Now(),
33-
})
27+
return dispatch(ctx, Event{Type: DetachType})
3428
}

0 commit comments

Comments
 (0)