mirror of
https://github.com/golang/go
synced 2024-11-05 11:36:10 -07:00
c81623a0cb
Also moves core.Key to label.Key, but leaves the implementations behind for now. After using for a while, the word Tag conveys slightly the wrong concept, tagging implies the entire set of information, label maps better to a single named piece of information. A label is just a named key/value pair, it is not really tied to the event package, separating it makes it much easier to understand the public symbols of the event and core packages, and allows us to also move the key implementations somewhere else, which otherwise dominate the API. Change-Id: I46275d531cec91e28af6ab1e74a2713505d52533 Reviewed-on: https://go-review.googlesource.com/c/tools/+/229239 Run-TryBot: Ian Cottrell <iancottrell@google.com> Reviewed-by: Robert Findley <rfindley@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org>
57 lines
2.3 KiB
Go
57 lines
2.3 KiB
Go
// Copyright 2019 The Go Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style
|
|
// license that can be found in the LICENSE file.
|
|
|
|
package core
|
|
|
|
import (
|
|
"context"
|
|
|
|
"golang.org/x/tools/internal/event/label"
|
|
)
|
|
|
|
// Log1 takes a message and one label delivers a log event to the exporter.
|
|
// It is a customized version of Print that is faster and does no allocation.
|
|
func Log1(ctx context.Context, message string, t1 label.Label) {
|
|
Export(ctx, MakeEvent(LogType, [3]label.Label{Msg.Of(message), t1}, nil))
|
|
}
|
|
|
|
// Log2 takes a message and two labels and delivers a log event to the exporter.
|
|
// It is a customized version of Print that is faster and does no allocation.
|
|
func Log2(ctx context.Context, message string, t1 label.Label, t2 label.Label) {
|
|
Export(ctx, MakeEvent(LogType, [3]label.Label{Msg.Of(message), t1, t2}, nil))
|
|
}
|
|
|
|
// Metric1 sends a label event to the exporter with the supplied labels.
|
|
func Metric1(ctx context.Context, t1 label.Label) context.Context {
|
|
return Export(ctx, MakeEvent(RecordType, [3]label.Label{t1}, nil))
|
|
}
|
|
|
|
// Metric2 sends a label event to the exporter with the supplied labels.
|
|
func Metric2(ctx context.Context, t1, t2 label.Label) context.Context {
|
|
return Export(ctx, MakeEvent(RecordType, [3]label.Label{t1, t2}, nil))
|
|
}
|
|
|
|
// Metric3 sends a label event to the exporter with the supplied labels.
|
|
func Metric3(ctx context.Context, t1, t2, t3 label.Label) context.Context {
|
|
return Export(ctx, MakeEvent(RecordType, [3]label.Label{t1, t2, t3}, nil))
|
|
}
|
|
|
|
// Start1 sends a span start event with the supplied label list to the exporter.
|
|
// It also returns a function that will end the span, which should normally be
|
|
// deferred.
|
|
func Start1(ctx context.Context, name string, t1 label.Label) (context.Context, func()) {
|
|
return ExportPair(ctx,
|
|
MakeEvent(StartSpanType, [3]label.Label{Name.Of(name), t1}, nil),
|
|
MakeEvent(EndSpanType, [3]label.Label{}, nil))
|
|
}
|
|
|
|
// Start2 sends a span start event with the supplied label list to the exporter.
|
|
// It also returns a function that will end the span, which should normally be
|
|
// deferred.
|
|
func Start2(ctx context.Context, name string, t1, t2 label.Label) (context.Context, func()) {
|
|
return ExportPair(ctx,
|
|
MakeEvent(StartSpanType, [3]label.Label{Name.Of(name), t1, t2}, nil),
|
|
MakeEvent(EndSpanType, [3]label.Label{}, nil))
|
|
}
|