1
0
mirror of https://github.com/golang/go synced 2024-11-06 01:46:12 -07:00
go/internal/telemetry/event/key.go
Ian Cottrell d780ff7bdd internal/telemetry: unify the event handling to an event package
This is now the only package that is exposed to normal use, and should
be the only thing to appear in libraries.

Change-Id: I90ee47c6519f30db16ff5d5d2910be86e91e5df2
Reviewed-on: https://go-review.googlesource.com/c/tools/+/222557
Run-TryBot: Ian Cottrell <iancottrell@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
2020-03-12 03:58:56 +00:00

40 lines
1.3 KiB
Go

// Copyright 2019 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package event
import (
"context"
)
// 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.
type Key string
// TagOf returns a Tag for a key and value.
// This is a trivial helper that makes common logging easier to read.
func TagOf(key interface{}, value interface{}) Tag {
return Tag{Key: key, Value: value}
}
// Of creates a new Tag with this key and the supplied value.
// You can use this when building a tag list.
func (k Key) Of(v interface{}) Tag {
return Tag{Key: k, Value: v}
}
// From can be used to get a tag for the key from a context.
func (k Key) From(ctx context.Context) Tag {
return Tag{Key: k, Value: ctx.Value(k)}
}
// With is a wrapper over the Label package level function for just this key.
func (k Key) With(ctx context.Context, v interface{}) context.Context {
return Label(ctx, Tag{Key: k, Value: v})
}