package tag

Import Path
	go.opencensus.io/tag (on go.dev)

Dependency Relation
	imports 7 packages, and imported by 14 packages

Involved Source Files context.go 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. key.go map.go map_codec.go metadata.go profile_19.go validate.go
Code Examples package main import ( "context" "go.opencensus.io/tag" "log" ) var ( tagMap *tag.Map ctx context.Context key tag.Key ) func main() { ctx, err := tag.New(ctx, tag.Insert(key, "macOS-10.12.5"), tag.Upsert(key, "macOS-10.12.7"), ) if err != nil { log.Fatal(err) } tag.Do(ctx, func(ctx context.Context) { _ = ctx // use context }) } package main import ( "context" "go.opencensus.io/tag" ) var ( tagMap *tag.Map ctx context.Context key tag.Key ) func main() { tagMap := tag.FromContext(ctx) _ = tagMap // use the tag map } package main import ( "go.opencensus.io/tag" ) func main() { key := tag.MustNewKey("example.com/keys/user-os") _ = key // use key } package main import ( "context" "go.opencensus.io/tag" "log" ) var ( tagMap *tag.Map ctx context.Context key tag.Key ) func main() { osKey := tag.MustNewKey("example.com/keys/user-os") userIDKey := tag.MustNewKey("example.com/keys/user-id") ctx, err := tag.New(ctx, tag.Insert(osKey, "macOS-10.12.5"), tag.Upsert(userIDKey, "cde36753ed"), ) if err != nil { log.Fatal(err) } _ = ctx // use context } package main import ( "context" "go.opencensus.io/tag" ) var ( tagMap *tag.Map ctx context.Context key tag.Key ) func main() { // Propagate the tag map in the current context. ctx := tag.NewContext(context.Background(), tagMap) _ = ctx // use context } package main import ( "go.opencensus.io/tag" "log" ) func main() { // Get a key to represent user OS. key, err := tag.NewKey("example.com/keys/user-os") if err != nil { log.Fatal(err) } _ = key // use key } package main import ( "context" "go.opencensus.io/tag" "log" ) var ( tagMap *tag.Map ctx context.Context key tag.Key ) func main() { ctx, err := tag.New(ctx, tag.Insert(key, "macOS-10.12.5"), tag.Upsert(key, "macOS-10.12.7"), ) if err != nil { log.Fatal(err) } _ = ctx // use context }
Package-Level Type Names (total 12, in which 6 are exported)
/* sort exporteds by: | */
Key represents a tag key. Name returns the name of the key. func MustNewKey(name string) Key func NewKey(name string) (Key, error) func Delete(k Key) Mutator func Insert(k Key, v string, mds ...Metadata) Mutator func Update(k Key, v string, mds ...Metadata) Mutator func Upsert(k Key, v string, mds ...Metadata) Mutator func (*Map).Value(k Key) (string, bool) func golang.org/x/pkgsite/internal/dcensus.RecordWithTag(ctx context.Context, key Key, val string, m stats.Measurement) var go.opencensus.io/plugin/ocgrpc.KeyClientMethod var go.opencensus.io/plugin/ocgrpc.KeyClientStatus var go.opencensus.io/plugin/ocgrpc.KeyServerMethod var go.opencensus.io/plugin/ocgrpc.KeyServerStatus var go.opencensus.io/plugin/ochttp.Host var go.opencensus.io/plugin/ochttp.KeyClientHost var go.opencensus.io/plugin/ochttp.KeyClientMethod var go.opencensus.io/plugin/ochttp.KeyClientPath var go.opencensus.io/plugin/ochttp.KeyClientStatus var go.opencensus.io/plugin/ochttp.KeyServerRoute var go.opencensus.io/plugin/ochttp.Method var go.opencensus.io/plugin/ochttp.Path var go.opencensus.io/plugin/ochttp.StatusCode var contrib.go.opencensus.io/integrations/ocsql.GoSQLError var contrib.go.opencensus.io/integrations/ocsql.GoSQLMethod var contrib.go.opencensus.io/integrations/ocsql.GoSQLStatus var golang.org/x/pkgsite/internal/dcensus.KeyStatus
Map is a map of tags. Use New to create a context containing a new Map. (*T) String() string Value returns the value for the key if a value for the key exists. *T : expvar.Var *T : fmt.Stringer func Decode(bytes []byte) (*Map, error) func FromContext(ctx context.Context) *Map func Mutator.Mutate(t *Map) (*Map, error) func Encode(m *Map) []byte func NewContext(ctx context.Context, m *Map) context.Context func Mutator.Mutate(t *Map) (*Map, error) func go.opencensus.io/stats.Recorder.Record(*Map, interface{}, map[string]interface{}) func go.opencensus.io/stats/view.Meter.Record(*Map, interface{}, map[string]interface{})
Metadata applies metadatas specified by the function. func WithTTL(ttl TTL) Metadata func Insert(k Key, v string, mds ...Metadata) Mutator func Update(k Key, v string, mds ...Metadata) Mutator func Upsert(k Key, v string, mds ...Metadata) Mutator
Mutator modifies a tag map. ( T) Mutate(t *Map) (*Map, error) func Delete(k Key) Mutator func Insert(k Key, v string, mds ...Metadata) Mutator func Update(k Key, v string, mds ...Metadata) Mutator func Upsert(k Key, v string, mds ...Metadata) Mutator func New(ctx context.Context, mutator ...Mutator) (context.Context, error) func go.opencensus.io/stats.RecordWithTags(ctx context.Context, mutators []Mutator, ms ...stats.Measurement) error func go.opencensus.io/stats.WithTags(mutators ...Mutator) stats.Options
Tag is a key value pair that can be propagated on wire. Key Key Value string
TTL is metadata that specifies number of hops a tag can propagate. Details about TTL metadata is specified at https://github.com/census-instrumentation/opencensus-specs/blob/master/tags/TagMap.md#tagmetadata func WithTTL(ttl TTL) Metadata var TTLNoPropagation var TTLUnlimitedPropagation
Package-Level Functions (total 20, in which 14 are exported)
Decode decodes the given []byte into a tag map.
DecodeEach decodes the given serialized tag map, calling handler for each tag key and value decoded.
Delete returns a mutator that deletes the value associated with k.
Do is similar to pprof.Do: a convenience for installing the tags from the context as Go profiler labels. This allows you to correlated runtime profiling with stats. It converts the key/values from the given map to Go profiler labels and calls pprof.Do. Do is going to do nothing if your Go version is below 1.9.
Encode encodes the tag map into a []byte. It is useful to propagate the tag maps on wire in binary format.
FromContext returns the tag map stored in the context.
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. Metadata applies metadata to the tag. It is optional. Metadatas are applied in the order in which it is provided. If more than one metadata updates the same attribute then the update from the last metadata prevails.
MustNewKey returns a key with the given name, and panics if name is an invalid key name.
New returns a new context that contains a tag map originated from the incoming context and modified with the provided mutators.
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.
NewKey creates or retrieves a string key identified by name. Calling NewKey more than once with the same name returns the same key.
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. Metadata applies metadata to the tag. It is optional. Metadatas are applied in the order in which it is provided. If more than one metadata updates the same attribute then the update from the last metadata prevails.
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. Metadata applies metadata to the tag. It is optional. Metadatas are applied in the order in which it is provided. If more than one metadata updates the same attribute then the update from the last metadata prevails.
WithTTL applies metadata with provided ttl.
Package-Level Variables (total 5, in which 2 are exported)
TTLNoPropagation is TTL metadata that prevents tag from propagating.
TTLUnlimitedPropagation is TTL metadata that allows tag to propagate without any limits on number of hops.
Package-Level Constants (total 10, none are exported)