event

package
v0.0.0-...-5a67fa7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 24, 2020 License: BSD-3-Clause Imports: 10 Imported by: 0

Documentation

Overview

Package event provides support for event based telemetry.

Index

Constants

View Source
const (
	LogType       // an event that should be recorded in a log
	StartSpanType // the start of a span of time
	EndSpanType   // the end of a span of time
	LabelType     // some values that should be noted for later events
	DetachType    // an event that causes a context to detach
	RecordType    // a value that should be tracked
)

Variables

View Source
var (
	// Msg is a key used to add message strings to tag lists.
	Msg = NewStringKey("message", "a readable message")
	// Name is used for things like traces that have a name.
	Name = NewStringKey("name", "an entity name")
	// Err is a key used to add error values to tag lists.
	Err = NewErrorKey("error", "an error that occurred")
)

Functions

func Debugf

func Debugf(ctx context.Context, message string, args ...interface{})

Debugf sends a log event with the supplied message to the exporter. This is intended only for temporary debugging lines, and usage should not normally be checked in, preffering structured log events for things that have to be used in production.

func Detach

func Detach(ctx context.Context) 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 Error

func Error(ctx context.Context, message string, err error, tags ...Tag)

Error takes a message and a tag list and combines them into a single event before delivering them to the exporter. It captures the error in the delivered event.

func Label

func Label(ctx context.Context, tags ...Tag) context.Context

Label sends a label event to the exporter with the supplied tags.

func Label1

func Label1(ctx context.Context, t1 Tag) context.Context

Label1 sends a label event to the exporter with the supplied tags.

func Label2

func Label2(ctx context.Context, t1, t2 Tag) context.Context

Label2 sends a label event to the exporter with the supplied tags.

func Label3

func Label3(ctx context.Context, t1, t2, t3 Tag) context.Context

Label3 sends a label event to the exporter with the supplied tags.

func Log

func Log(ctx context.Context, tags ...Tag)

Log sends a log event with the supplied tag list to the exporter.

func Log1

func Log1(ctx context.Context, t1 Tag) context.Context

Log1 sends a label event to the exporter with the supplied tags.

func Log2

func Log2(ctx context.Context, t1, t2 Tag) context.Context

Log2 sends a label event to the exporter with the supplied tags.

func Log3

func Log3(ctx context.Context, t1, t2, t3 Tag) context.Context

Log3 sends a label event to the exporter with the supplied tags.

func Print

func Print(ctx context.Context, message string, tags ...Tag)

Print takes a message and a tag list and combines them into a single event before delivering them to the exporter.

func Print1

func Print1(ctx context.Context, message string, t1 Tag)

Print1 takes a message and one tag delivers a log event to the exporter. It is a customized version of Print that is faster and does no allocation.

func Print2

func Print2(ctx context.Context, message string, t1, t2 Tag)

Print2 takes a message and two tags and delivers a log event to the exporter. It is a customized version of Print that is faster and does no allocation.

func Record

func Record(ctx context.Context, tags ...Tag) context.Context

Record sends a label event to the exporter with the supplied tags.

func Record1

func Record1(ctx context.Context, t1 Tag) context.Context

Record1 sends a label event to the exporter with the supplied tags.

func Record2

func Record2(ctx context.Context, t1, t2 Tag) context.Context

Record2 sends a label event to the exporter with the supplied tags.

func Record3

func Record3(ctx context.Context, t1, t2, t3 Tag) context.Context

Record3 sends a label event to the exporter with the supplied tags.

func SetExporter

func SetExporter(e Exporter)

SetExporter sets the global exporter function that handles all events. The exporter is called synchronously from the event call site, so it should return quickly so as not to hold up user code.

func StartSpan

func StartSpan(ctx context.Context, name string, tags ...Tag) (context.Context, func())

StartSpan sends a span start event with the supplied tag list to the exporter. It also returns a function that will end the span, which should normally be deferred.

func StartSpan1

func StartSpan1(ctx context.Context, name string, t1 Tag) (context.Context, func())

StartSpan1 sends a span start event with the supplied tag list to the exporter. It also returns a function that will end the span, which should normally be deferred.

func StartSpan2

func StartSpan2(ctx context.Context, name string, t1, t2 Tag) (context.Context, func())

StartSpan2 sends a span start event with the supplied tag list to the exporter. It also returns a function that will end the span, which should normally be deferred.

Types

type BooleanKey

type BooleanKey struct {
	// contains filtered or unexported fields
}

BooleanKey represents a key

func NewBooleanKey

func NewBooleanKey(name, description string) *BooleanKey

NewBooleanKey creates a new Key for bool values.

func (*BooleanKey) Description

func (k *BooleanKey) Description() string

func (*BooleanKey) Format

func (k *BooleanKey) Format(w io.Writer, buf []byte, tag Tag)

func (*BooleanKey) From

func (k *BooleanKey) From(t Tag) bool

From can be used to get a value from a Tag.

func (*BooleanKey) Get

func (k *BooleanKey) Get(tags TagMap) bool

Get can be used to get a tag for the key from a TagMap.

func (*BooleanKey) Name

func (k *BooleanKey) Name() string

func (*BooleanKey) Of

func (k *BooleanKey) Of(v bool) Tag

Of creates a new Tag with this key and the supplied value.

type ErrorKey

type ErrorKey struct {
	// contains filtered or unexported fields
}

ErrorKey represents a key

func NewErrorKey

func NewErrorKey(name, description string) *ErrorKey

NewErrorKey creates a new Key for int64 values.

func (*ErrorKey) Description

func (k *ErrorKey) Description() string

func (*ErrorKey) Format

func (k *ErrorKey) Format(w io.Writer, buf []byte, tag Tag)

func (*ErrorKey) From

func (k *ErrorKey) From(t Tag) error

From can be used to get a value from a Tag.

func (*ErrorKey) Get

func (k *ErrorKey) Get(tags TagMap) error

Get can be used to get a tag for the key from a TagMap.

func (*ErrorKey) Name

func (k *ErrorKey) Name() string

func (*ErrorKey) Of

func (k *ErrorKey) Of(v error) Tag

Of creates a new Tag with this key and the supplied value.

type Event

type Event struct {
	At time.Time
	// contains filtered or unexported fields
}

Event holds the information about an event of note that ocurred.

func (Event) Find

func (ev Event) Find(key Key) Tag

func (Event) Format

func (ev Event) Format(f fmt.State, r rune)

func (Event) IsDetach

func (ev Event) IsDetach() bool

func (Event) IsEndSpan

func (ev Event) IsEndSpan() bool

func (Event) IsLabel

func (ev Event) IsLabel() bool

func (Event) IsLog

func (ev Event) IsLog() bool

func (Event) IsRecord

func (ev Event) IsRecord() bool

func (Event) IsStartSpan

func (ev Event) IsStartSpan() bool

func (Event) Tag

func (ev Event) Tag(index int) Tag

func (Event) Valid

func (ev Event) Valid(index int) bool

type Exporter

type Exporter func(context.Context, Event, TagMap) context.Context

Exporter is a function that handles events. It may return a modified context and event.

type Float32Key

type Float32Key struct {
	// contains filtered or unexported fields
}

Float32Key represents a key

func NewFloat32Key

func NewFloat32Key(name, description string) *Float32Key

NewFloat32Key creates a new Key for float32 values.

func (*Float32Key) Description

func (k *Float32Key) Description() string

func (*Float32Key) Format

func (k *Float32Key) Format(w io.Writer, buf []byte, tag Tag)

func (*Float32Key) From

func (k *Float32Key) From(t Tag) float32

From can be used to get a value from a Tag.

func (*Float32Key) Get

func (k *Float32Key) Get(tags TagMap) float32

Get can be used to get a tag for the key from a TagMap.

func (*Float32Key) Name

func (k *Float32Key) Name() string

func (*Float32Key) Of

func (k *Float32Key) Of(v float32) Tag

Of creates a new Tag with this key and the supplied value.

type Float64Key

type Float64Key struct {
	// contains filtered or unexported fields
}

Float64Key represents a key

func NewFloat64Key

func NewFloat64Key(name, description string) *Float64Key

NewFloat64Key creates a new Key for int64 values.

func (*Float64Key) Description

func (k *Float64Key) Description() string

func (*Float64Key) Format

func (k *Float64Key) Format(w io.Writer, buf []byte, tag Tag)

func (*Float64Key) From

func (k *Float64Key) From(t Tag) float64

From can be used to get a value from a Tag.

func (*Float64Key) Get

func (k *Float64Key) Get(tags TagMap) float64

Get can be used to get a tag for the key from a TagMap.

func (*Float64Key) Name

func (k *Float64Key) Name() string

func (*Float64Key) Of

func (k *Float64Key) Of(v float64) Tag

Of creates a new Tag with this key and the supplied value.

type Int16Key

type Int16Key struct {
	// contains filtered or unexported fields
}

Int16Key represents a key

func NewInt16Key

func NewInt16Key(name, description string) *Int16Key

NewInt16Key creates a new Key for int16 values.

func (*Int16Key) Description

func (k *Int16Key) Description() string

func (*Int16Key) Format

func (k *Int16Key) Format(w io.Writer, buf []byte, tag Tag)

func (*Int16Key) From

func (k *Int16Key) From(t Tag) int16

From can be used to get a value from a Tag.

func (*Int16Key) Get

func (k *Int16Key) Get(tags TagMap) int16

Get can be used to get a tag for the key from a TagMap.

func (*Int16Key) Name

func (k *Int16Key) Name() string

func (*Int16Key) Of

func (k *Int16Key) Of(v int16) Tag

Of creates a new Tag with this key and the supplied value.

type Int32Key

type Int32Key struct {
	// contains filtered or unexported fields
}

Int32Key represents a key

func NewInt32Key

func NewInt32Key(name, description string) *Int32Key

NewInt32Key creates a new Key for int32 values.

func (*Int32Key) Description

func (k *Int32Key) Description() string

func (*Int32Key) Format

func (k *Int32Key) Format(w io.Writer, buf []byte, tag Tag)

func (*Int32Key) From

func (k *Int32Key) From(t Tag) int32

From can be used to get a value from a Tag.

func (*Int32Key) Get

func (k *Int32Key) Get(tags TagMap) int32

Get can be used to get a tag for the key from a TagMap.

func (*Int32Key) Name

func (k *Int32Key) Name() string

func (*Int32Key) Of

func (k *Int32Key) Of(v int32) Tag

Of creates a new Tag with this key and the supplied value.

type Int64Key

type Int64Key struct {
	// contains filtered or unexported fields
}

Int64Key represents a key

func NewInt64Key

func NewInt64Key(name, description string) *Int64Key

NewInt64Key creates a new Key for int64 values.

func (*Int64Key) Description

func (k *Int64Key) Description() string

func (*Int64Key) Format

func (k *Int64Key) Format(w io.Writer, buf []byte, tag Tag)

func (*Int64Key) From

func (k *Int64Key) From(t Tag) int64

From can be used to get a value from a Tag.

func (*Int64Key) Get

func (k *Int64Key) Get(tags TagMap) int64

Get can be used to get a tag for the key from a TagMap.

func (*Int64Key) Name

func (k *Int64Key) Name() string

func (*Int64Key) Of

func (k *Int64Key) Of(v int64) Tag

Of creates a new Tag with this key and the supplied value.

type Int8Key

type Int8Key struct {
	// contains filtered or unexported fields
}

Int8Key represents a key

func NewInt8Key

func NewInt8Key(name, description string) *Int8Key

NewInt8Key creates a new Key for int8 values.

func (*Int8Key) Description

func (k *Int8Key) Description() string

func (*Int8Key) Format

func (k *Int8Key) Format(w io.Writer, buf []byte, tag Tag)

func (*Int8Key) From

func (k *Int8Key) From(t Tag) int8

From can be used to get a value from a Tag.

func (*Int8Key) Get

func (k *Int8Key) Get(tags TagMap) int8

Get can be used to get a tag for the key from a TagMap.

func (*Int8Key) Name

func (k *Int8Key) Name() string

func (*Int8Key) Of

func (k *Int8Key) Of(v int8) Tag

Of creates a new Tag with this key and the supplied value.

type IntKey

type IntKey struct {
	// contains filtered or unexported fields
}

IntKey represents a key

func NewIntKey

func NewIntKey(name, description string) *IntKey

NewIntKey creates a new Key for int values.

func (*IntKey) Description

func (k *IntKey) Description() string

func (*IntKey) Format

func (k *IntKey) Format(w io.Writer, buf []byte, tag Tag)

func (*IntKey) From

func (k *IntKey) From(t Tag) int

From can be used to get a value from a Tag.

func (*IntKey) Get

func (k *IntKey) Get(tags TagMap) int

Get can be used to get a tag for the key from a TagMap.

func (*IntKey) Name

func (k *IntKey) Name() string

func (*IntKey) Of

func (k *IntKey) Of(v int) Tag

Of creates a new Tag with this key and the supplied value.

type Key

type Key interface {
	// Name returns the key name.
	Name() string
	// Description returns a string that can be used to describe the value.
	Description() string

	// Format is used in formatting to append the value of the tag to the
	// supplied buffer.
	// The formatter may use the supplied buf as a scratch area to avoid
	// allocations.
	Format(w io.Writer, buf []byte, tag Tag)
}

Key is used as the identity of a Tag. Keys are intended to be compared by pointer only, the name should be unique for communicating with external systems, but it is not required or enforced.

type StringKey

type StringKey struct {
	// contains filtered or unexported fields
}

StringKey represents a key

func NewStringKey

func NewStringKey(name, description string) *StringKey

NewStringKey creates a new Key for int64 values.

func (*StringKey) Description

func (k *StringKey) Description() string

func (*StringKey) Format

func (k *StringKey) Format(w io.Writer, buf []byte, tag Tag)

func (*StringKey) From

func (k *StringKey) From(t Tag) string

From can be used to get a value from a Tag.

func (*StringKey) Get

func (k *StringKey) Get(tags TagMap) string

Get can be used to get a tag for the key from a TagMap.

func (*StringKey) Name

func (k *StringKey) Name() string

func (*StringKey) Of

func (k *StringKey) Of(v string) Tag

Of creates a new Tag with this key and the supplied value.

type Tag

type Tag struct {
	// contains filtered or unexported fields
}

Tag holds a key and value pair. It is normally used when passing around lists of tags.

func TagOf64

func TagOf64(k Key, v uint64) Tag

TagOf64 creates a new tag from a key and a uint64. This is often used for non uint64 values that can be packed into a uint64. This method is for implementing new key types, tag creation should normally be done with the Of method of the key.

func TagOfString

func TagOfString(k Key, v string) Tag

TagOfString creates a new tag from a key and a string. This method is for implementing new key types, tag creation should normally be done with the Of method of the key.

func TagOfValue

func TagOfValue(k Key, value interface{}) Tag

TagOfValue creates a new tag from the key and value. This method is for implementing new key types, tag creation should normally be done with the Of method of the key.

func (Tag) Format

func (t Tag) Format(f fmt.State, r rune)

Format is used for debug printing of tags.

func (Tag) Key

func (t Tag) Key() Key

Key returns the key of this Tag.

func (Tag) Unpack64

func (t Tag) Unpack64() uint64

Unpack64 assumes the tag was built using TagOf64 and returns the value that was passed to that constructor. This method is for implementing new key types, for type safety normal access should be done with the From method of the key.

func (Tag) UnpackString

func (t Tag) UnpackString() string

UnpackString assumes the tag was built using TagOfString and returns the value that was passed to that constructor. This method is for implementing new key types, for type safety normal access should be done with the From method of the key.

func (Tag) UnpackValue

func (t Tag) UnpackValue() interface{}

UnpackValue assumes the tag was built using TagOfValue and returns the value that was passed to that constructor. This method is for implementing new key types, for type safety normal access should be done with the From method of the key.

func (Tag) Valid

func (t Tag) Valid() bool

Valid returns true if the Tag is a valid one (it has a key).

type TagList

type TagList interface {
	// Valid returns true if the index is within range for the list.
	// It does not imply the tag at that index will itself be valid.
	Valid(index int) bool
	// Tag returns the tag at the given index.
	Tag(index int) Tag
}

TagList is the interface to something that provides an iterable list of tags. Iteration should start from 0 and continue until Valid returns false.

func Filter

func Filter(l TagList, keys ...Key) TagList

func NewTagList

func NewTagList(tags ...Tag) TagList

type TagMap

type TagMap interface {
	// Find returns the tag that matches the supplied key.
	Find(key Key) Tag
}

TagMap is the interface to a collection of Tags indexed by key.

func MergeTagMaps

func MergeTagMaps(srcs ...TagMap) TagMap

func NewTagMap

func NewTagMap(tags ...Tag) TagMap

type UInt16Key

type UInt16Key struct {
	// contains filtered or unexported fields
}

UInt16Key represents a key

func NewUInt16Key

func NewUInt16Key(name, description string) *UInt16Key

NewUInt16Key creates a new Key for uint16 values.

func (*UInt16Key) Description

func (k *UInt16Key) Description() string

func (*UInt16Key) Format

func (k *UInt16Key) Format(w io.Writer, buf []byte, tag Tag)

func (*UInt16Key) From

func (k *UInt16Key) From(t Tag) uint16

From can be used to get a value from a Tag.

func (*UInt16Key) Get

func (k *UInt16Key) Get(tags TagMap) uint16

Get can be used to get a tag for the key from a TagMap.

func (*UInt16Key) Name

func (k *UInt16Key) Name() string

func (*UInt16Key) Of

func (k *UInt16Key) Of(v uint16) Tag

Of creates a new Tag with this key and the supplied value.

type UInt32Key

type UInt32Key struct {
	// contains filtered or unexported fields
}

UInt32Key represents a key

func NewUInt32Key

func NewUInt32Key(name, description string) *UInt32Key

NewUInt32Key creates a new Key for uint32 values.

func (*UInt32Key) Description

func (k *UInt32Key) Description() string

func (*UInt32Key) Format

func (k *UInt32Key) Format(w io.Writer, buf []byte, tag Tag)

func (*UInt32Key) From

func (k *UInt32Key) From(t Tag) uint32

From can be used to get a value from a Tag.

func (*UInt32Key) Get

func (k *UInt32Key) Get(tags TagMap) uint32

Get can be used to get a tag for the key from a TagMap.

func (*UInt32Key) Name

func (k *UInt32Key) Name() string

func (*UInt32Key) Of

func (k *UInt32Key) Of(v uint32) Tag

Of creates a new Tag with this key and the supplied value.

type UInt64Key

type UInt64Key struct {
	// contains filtered or unexported fields
}

UInt64Key represents a key

func NewUInt64Key

func NewUInt64Key(name, description string) *UInt64Key

NewUInt64Key creates a new Key for uint64 values.

func (*UInt64Key) Description

func (k *UInt64Key) Description() string

func (*UInt64Key) Format

func (k *UInt64Key) Format(w io.Writer, buf []byte, tag Tag)

func (*UInt64Key) From

func (k *UInt64Key) From(t Tag) uint64

From can be used to get a value from a Tag.

func (*UInt64Key) Get

func (k *UInt64Key) Get(tags TagMap) uint64

Get can be used to get a tag for the key from a TagMap.

func (*UInt64Key) Name

func (k *UInt64Key) Name() string

func (*UInt64Key) Of

func (k *UInt64Key) Of(v uint64) Tag

Of creates a new Tag with this key and the supplied value.

type UInt8Key

type UInt8Key struct {
	// contains filtered or unexported fields
}

UInt8Key represents a key

func NewUInt8Key

func NewUInt8Key(name, description string) *UInt8Key

NewUInt8Key creates a new Key for uint8 values.

func (*UInt8Key) Description

func (k *UInt8Key) Description() string

func (*UInt8Key) Format

func (k *UInt8Key) Format(w io.Writer, buf []byte, tag Tag)

func (*UInt8Key) From

func (k *UInt8Key) From(t Tag) uint8

From can be used to get a value from a Tag.

func (*UInt8Key) Get

func (k *UInt8Key) Get(tags TagMap) uint8

Get can be used to get a tag for the key from a TagMap.

func (*UInt8Key) Name

func (k *UInt8Key) Name() string

func (*UInt8Key) Of

func (k *UInt8Key) Of(v uint8) Tag

Of creates a new Tag with this key and the supplied value.

type UIntKey

type UIntKey struct {
	// contains filtered or unexported fields
}

UIntKey represents a key

func NewUIntKey

func NewUIntKey(name, description string) *UIntKey

NewUIntKey creates a new Key for uint values.

func (*UIntKey) Description

func (k *UIntKey) Description() string

func (*UIntKey) Format

func (k *UIntKey) Format(w io.Writer, buf []byte, tag Tag)

func (*UIntKey) From

func (k *UIntKey) From(t Tag) uint

From can be used to get a value from a Tag.

func (*UIntKey) Get

func (k *UIntKey) Get(tags TagMap) uint

Get can be used to get a tag for the key from a TagMap.

func (*UIntKey) Name

func (k *UIntKey) Name() string

func (*UIntKey) Of

func (k *UIntKey) Of(v uint) Tag

Of creates a new Tag with this key and the supplied value.

type ValueKey

type ValueKey struct {
	// contains filtered or unexported fields
}

ValueKey represents a key for untyped values.

func NewKey

func NewKey(name, description string) *ValueKey

NewKey creates a new Key for untyped values.

func (*ValueKey) Description

func (k *ValueKey) Description() string

func (*ValueKey) Format

func (k *ValueKey) Format(w io.Writer, buf []byte, tag Tag)

func (*ValueKey) From

func (k *ValueKey) From(t Tag) interface{}

From can be used to get a value from a Tag.

func (*ValueKey) Get

func (k *ValueKey) Get(tags TagMap) interface{}

Get can be used to get a tag for the key from a TagMap.

func (*ValueKey) Name

func (k *ValueKey) Name() string

func (*ValueKey) Of

func (k *ValueKey) Of(value interface{}) Tag

Of creates a new Tag with this key and the supplied value.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL