tag

package
v0.0.22 Latest Latest
Warning

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

Go to latest
Published: Jul 20, 2019 License: BSD-3-Clause, BSD-3-Clause Imports: 4 Imported by: 0

Documentation

Overview

Package tag provides support for telemetry tagging.

Package tag provides support for telemetry tagging. This package is a thin shim over contexts with the main addition being the the ability to observe when contexts get tagged with new values.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Observe added in v0.0.22

func Observe(observer Observer)

Observe adds a new tag observer to the registered set. There is no way to ever unregister a observer. Observers are free to use context information to control their behavior.

func With added in v0.0.22

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

With is roughly equivalent to context.WithValue except that it also notifies registered observers. Unlike WithValue, it takes a list of tags so that you can set many values at once if needed. Each call to With results in one invocation of each observer.

Types

type Key

type Key string

Key represents the key for a context tag. It is a helper to make use of context tagging slightly easier to read, it is not strictly needed to use it at all. It is intended that your common tagging keys are declared as constants of this type, and then you can use the methods of this type to apply and find those values in the context.

func (Key) Of added in v0.0.22

func (k Key) Of(v interface{}) Tag

Of creates a new Tag with this key and the supplied value. You can use this when building a tag list.

func (Key) With added in v0.0.22

func (k Key) With(ctx context.Context, v interface{}) context.Context

With applies sets this key to the supplied value on the context and returns the new context generated. It uses the With package level function so that observers are also notified.

type List added in v0.0.22

type List []Tag

List is a way of passing around a collection of key value pairs. It is an alternative to the less efficient and unordered method of using maps.

func Get added in v0.0.22

func Get(ctx context.Context, keys ...interface{}) List

Get collects a set of values from the context and returns them as a tag list.

func (List) Equal added in v0.0.22

func (l List) Equal(other List) bool

Equal returns true if two lists are identical.

func (List) Format added in v0.0.22

func (l List) Format(f fmt.State, r rune)

Format pretty prints a list. It is intended only for debugging.

func (List) Get added in v0.0.22

func (l List) Get(k interface{}) interface{}

Get will get a single key's value from the list.

func (List) Less added in v0.0.22

func (l List) Less(other List) bool

Less is intended only for using tag lists as a sorting key.

type Observer added in v0.0.22

type Observer func(ctx context.Context, at time.Time, tags List)

Observer is the type for a function that wants to be notified when new tags are set on a context. If you use context.WithValue (or equivalent) it will bypass the observers, you must use the setters in this package for tags that should be observed. Register new observers with the Observe function.

type Tag added in v0.0.22

type Tag struct {
	Key   interface{}
	Value interface{}
}

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

func (Tag) Format added in v0.0.22

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

Format is used for debug printing of tags.

Jump to

Keyboard shortcuts

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