package tag
import "go.opencensus.io/tag"
Package tag contains OpenCensus tags.
Tags are key-value pairs. Tags provide additional cardinality to the OpenCensus instrumentation data.
Tags can be propagated on the wire and in the same process via context.Context. Encode and Decode should be used to represent tags into their binary propagation form.
Index ¶
- func Encode(m *Map) []byte
- func NewContext(ctx context.Context, m *Map) context.Context
- type Key
- type Map
- func Decode(bytes []byte) (*Map, error)
- func FromContext(ctx context.Context) *Map
- func NewMap(ctx context.Context, mutator ...Mutator) (*Map, error)
- func (m *Map) String() string
- func (m *Map) Value(k Key) (string, bool)
- type Mutator
- func Delete(k Key) Mutator
- func Insert(k Key, v string) Mutator
- func Update(k Key, v string) Mutator
- func Upsert(k Key, v string) Mutator
- type Tag
Examples ¶
Functions ¶
func Encode ¶
Encode encodes the tag map into a []byte. It is useful to propagate the tag maps on wire in binary format.
func NewContext ¶
NewContext creates a new context with the given tag map. To propagate a tag map to downstream methods and downstream RPCs, add a tag map to the current context. NewContext will return a copy of the current context, and put the tag map into the returned one. If there is already a tag map in the current context, it will be replaced with m.
Types ¶
type Key ¶
type Key struct {
// contains filtered or unexported fields
}
Key represents a tag key.
func NewKey ¶
NewKey creates or retrieves a string key identified by name. Calling NewKey consequently with the same name returns the same key.
func (Key) Name ¶
Name returns the name of the key.
type Map ¶
type Map struct {
// contains filtered or unexported fields
}
Map is a map of tags. Use NewMap to build tag maps.
func Decode ¶
Decode decodes the given []byte into a tag map.
func FromContext ¶
FromContext returns the tag map stored in the context.
func NewMap ¶
NewMap returns a new tag map originated from the incoming context
and modified with the provided mutators.
Code:play
Code:play
Example¶
package main
import (
"context"
"log"
"go.opencensus.io/tag"
)
var ctx context.Context
func main() {
osKey, err := tag.NewKey("my.org/keys/user-os")
if err != nil {
log.Fatal(err)
}
userIDKey, err := tag.NewKey("my.org/keys/user-id")
if err != nil {
log.Fatal(err)
}
tagMap, err := tag.NewMap(ctx,
tag.Insert(osKey, "macOS-10.12.5"),
tag.Upsert(userIDKey, "cde36753ed"),
)
if err != nil {
log.Fatal(err)
}
_ = tagMap // use the tag map
}
Example (Replace)¶
package main
import (
"context"
"log"
"go.opencensus.io/tag"
)
var (
ctx context.Context
key tag.Key
)
func main() {
tagMap, err := tag.NewMap(ctx,
tag.Insert(key, "macOS-10.12.5"),
tag.Upsert(key, "macOS-10.12.7"),
)
if err != nil {
log.Fatal(err)
}
ctx = tag.NewContext(ctx, tagMap)
_ = ctx // use context
}
func (*Map) String ¶
func (*Map) Value ¶
Value returns the value for the key if a value for the key exists.
type Mutator ¶
Mutator modifies a tag map.
func Delete ¶
Delete returns a mutator that deletes the value associated with k.
func Insert ¶
Insert returns a mutator that inserts a value associated with k. If k already exists in the tag map, mutator doesn't update the value.
func Update ¶
Update returns a mutator that updates the value of the tag associated with k with v. If k doesn't exists in the tag map, the mutator doesn't insert the value.
func Upsert ¶
Upsert returns a mutator that upserts the value of the tag associated with k with v. It inserts the value if k doesn't exist already. It mutates the value if k already exists.
type Tag ¶
Tag is a key value pair that can be propagated on wire.
Source Files ¶
context.go doc.go key.go keys_manager.go map.go map_codec.go validate.go
- Version
- v0.1.0
- Published
- Dec 15, 2017
- Platform
- js/wasm
- Imports
- 7 packages
- Last checked
- 1 hour ago –
Tools for package owners.