Documentation ¶
Overview ¶
Package event provides the core functionality for observability that allows libraries using it to interact well. It enforces the middle layer interchange format, but allows both frontend wrappers and back end exporters to customize the usage.
Index ¶
- Constants
- func Annotate(ctx context.Context, labels ...Label)
- func End(ctx context.Context, labels ...Label)
- func Error(ctx context.Context, msg string, err error, labels ...Label)
- func Log(ctx context.Context, msg string, labels ...Label)
- func Logf(ctx context.Context, msg string, args ...interface{})
- func RegisterHelper(v interface{})
- func SetDefaultExporter(e *Exporter)
- func Start(ctx context.Context, name string, labels ...Label) context.Context
- func WithExporter(ctx context.Context, e *Exporter) context.Context
- type Counter
- type DurationDistribution
- type Event
- type Exporter
- type ExporterOptions
- type FloatGauge
- type Handler
- type IntDistribution
- type Kind
- type Label
- func Bool(name string, b bool) Label
- func Bytes(name string, data []byte) Label
- func Duration(name string, d time.Duration) Label
- func Float64(name string, f float64) Label
- func Int64(name string, u int64) Label
- func String(name string, s string) Label
- func Uint64(name string, u uint64) Label
- func Value(name string, value interface{}) Label
- func (v Label) Bool() bool
- func (v Label) Bytes() []byte
- func (v Label) Duration() time.Duration
- func (l Label) Equal(l2 Label) bool
- func (v Label) Float64() float64
- func (l Label) HasValue() bool
- func (v Label) Int64() int64
- func (v Label) Interface() interface{}
- func (v Label) IsBool() bool
- func (v Label) IsBytes() bool
- func (v Label) IsDuration() bool
- func (v Label) IsFloat64() bool
- func (v Label) IsInt64() bool
- func (v Label) IsString() bool
- func (v Label) IsUint64() bool
- func (v Label) String() string
- func (v Label) Uint64() uint64
- type Metric
- type MetricDescriptor
- type Source
Constants ¶
const ( MetricKey = "metric" MetricVal = "metricValue" DurationMetric = interfaceKey("durationMetric") )
const ( LogKind MetricKind StartKind EndKind )
Variables ¶
This section is empty.
Functions ¶
func RegisterHelper ¶
func RegisterHelper(v interface{})
RegisterHelper records a function as being an event helper that should not be used when capturing the source infomation on events. v should be either a string or a function pointer. If v is a string it is of the form
Space.Owner.Name
where Owner and Name cannot contain '/' and Name also cannot contain '.'
func SetDefaultExporter ¶
func SetDefaultExporter(e *Exporter)
SetDefaultExporter sets an exporter that is used if no exporter can be found on the context.
Types ¶
type Counter ¶
type Counter struct {
*MetricDescriptor
}
A Counter is a metric that counts something cumulatively.
func NewCounter ¶
NewCounter creates a counter with the given name.
func (*Counter) Descriptor ¶
func (c *Counter) Descriptor() *MetricDescriptor
Descriptor returns the receiver's MetricDescriptor.
type DurationDistribution ¶
type DurationDistribution struct {
*MetricDescriptor
}
A DurationDistribution records a distribution of durations. TODO(generics): Distribution[T]
func NewDuration ¶
func NewDuration(name, description string) *DurationDistribution
NewDuration creates a new Duration with the given name.
func (*DurationDistribution) Descriptor ¶
func (d *DurationDistribution) Descriptor() *MetricDescriptor
Descriptor returns the receiver's MetricDescriptor.
type Event ¶
type Event struct { ID uint64 Parent uint64 // id of the parent event for this event Source Source // source of event; if empty, set by exporter to import path At time.Time // time at which the event is delivered to the exporter. Kind Kind Labels []Label // contains filtered or unexported fields }
Event holds the information about an event that occurred. It combines the event metadata with the user supplied labels.
func New ¶
New prepares a new event. This is intended to avoid allocations in the steady state case, to do this it uses a pool of events. Events are returned to the pool when Deliver is called. Failure to call Deliver will exhaust the pool and cause allocations. It returns nil if there is no active exporter for this kind of event.
func (*Event) Clone ¶
Clone makes a deep copy of the Event. Deliver can be called on both Events independently.
type Exporter ¶
type Exporter struct {
// contains filtered or unexported fields
}
Exporter synchronizes the delivery of events to handlers.
func NewExporter ¶
func NewExporter(handler Handler, opts *ExporterOptions) *Exporter
NewExporter creates an Exporter using the supplied handler and options. Event delivery is serialized to enable safe atomic handling.
type ExporterOptions ¶
type ExporterOptions struct { // If non-nil, sets zero Event.At on delivery. Now func() time.Time // Disable some event types, for better performance. DisableLogging bool DisableTracing bool DisableAnnotations bool DisableMetrics bool // Enable automatically setting the event Namespace to the calling package's // import path. EnableNamespaces bool }
type FloatGauge ¶
type FloatGauge struct {
*MetricDescriptor
}
A FloatGauge records a single floating-point value that may go up or down. TODO(generics): Gauge[T]
func NewFloatGauge ¶
func NewFloatGauge(name, description string) *FloatGauge
NewFloatGauge creates a new FloatGauge with the given name.
func (*FloatGauge) Descriptor ¶
func (g *FloatGauge) Descriptor() *MetricDescriptor
Descriptor returns the receiver's MetricDescriptor.
type Handler ¶
type Handler interface { // Event is called with each event. Event(context.Context, *Event) context.Context }
Handler is a the type for something that handles events as they occur.
type IntDistribution ¶
type IntDistribution struct {
*MetricDescriptor
}
An IntDistribution records a distribution of int64s.
func NewIntDistribution ¶
func NewIntDistribution(name, description string) *IntDistribution
NewIntDistribution creates a new IntDistribution with the given name.
func (*IntDistribution) Descriptor ¶
func (d *IntDistribution) Descriptor() *MetricDescriptor
Descriptor returns the receiver's MetricDescriptor.
type Label ¶
type Label struct { Name string // contains filtered or unexported fields }
Label is a named value.
func (Label) Bool ¶
Bool returns the bool from a value that was set with SetBool. It will panic for any value for which IsBool is not true.
func (Label) Float64 ¶
Float64 returns the float64 from a value that was set with SetFloat64. It will panic for any value for which IsFloat64 is not true.
func (Label) Int64 ¶
Int64 returns the int64 from a value that was set with SetInt64. It will panic for any value for which IsInt64 is not true.
func (Label) Interface ¶
func (v Label) Interface() interface{}
Interface returns the value. This will never panic, things that were not set using SetInterface will be unpacked and returned anyway.
func (Label) IsDuration ¶
type Metric ¶
type Metric interface {
Descriptor() *MetricDescriptor
}
A Metric represents a kind of recorded measurement.
type MetricDescriptor ¶
type MetricDescriptor struct {
// contains filtered or unexported fields
}
A MetricDescriptor describes a metric.
func NewMetricDescriptor ¶
func NewMetricDescriptor(name, description string) *MetricDescriptor
NewMetricDescriptor creates a MetricDescriptor with the given name. The namespace defaults to the import path of the caller of NewMetricDescriptor. Use SetNamespace to provide a different one. Neither the name nor the namespace can be empty.
func (*MetricDescriptor) Description ¶
func (m *MetricDescriptor) Description() string
func (*MetricDescriptor) Name ¶
func (m *MetricDescriptor) Name() string
func (*MetricDescriptor) Namespace ¶
func (m *MetricDescriptor) Namespace() string
func (*MetricDescriptor) SetNamespace ¶
func (m *MetricDescriptor) SetNamespace(ns string)
SetNamespace sets the namespace of m to a non-empty string.
func (*MetricDescriptor) String ¶
func (m *MetricDescriptor) String() string