[#2] tagging: Add grpc and context methods

Signed-off-by: Dmitrii Stepanov <d.stepanov@yadro.com>
This commit is contained in:
Dmitrii Stepanov 2025-01-21 09:56:13 +03:00
parent f4d8ebf13d
commit 1fb8b137c5
Signed by: dstepanov-yadro
GPG key ID: 237AF1A763293BC0
5 changed files with 190 additions and 1 deletions

21
tagging/context.go Normal file
View file

@ -0,0 +1,21 @@
package tagging
import "context"
type tagContextKeyType struct{}
var currentTagKey = tagContextKeyType{}
func ContextWithIOTag(parent context.Context, ioTag string) context.Context {
return context.WithValue(parent, currentTagKey, ioTag)
}
func IOTagFromContext(ctx context.Context) (string, bool) {
if ctx == nil {
panic("context must be non nil")
}
if tag, ok := ctx.Value(currentTagKey).(string); ok {
return tag, true
}
return "", false
}