tags

package
v0.3.2 Latest Latest
Warning

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

Go to latest
Published: Apr 3, 2023 License: BSD-3-Clause Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (

	// NoopTags is a trivial, minimum overhead implementation of Tags for which all operations are no-ops.
	NoopTags = &noopTags{}
)

Functions

func CodeGenRequestFieldExtractor

func CodeGenRequestFieldExtractor(_ string, req interface{}) map[string]string

CodeGenRequestFieldExtractor is a function that relies on code-generated functions that export log fields from requests. These are usually coming from a protoc-plugin that generates additional information based on custom field options.

func SetInContext

func SetInContext(ctx context.Context, tags Tags) context.Context

func StreamServerInterceptor

func StreamServerInterceptor(opts ...Option) grpc.StreamServerInterceptor

StreamServerInterceptor returns a new streaming server interceptor that sets the values for request tags.

func UnaryServerInterceptor

func UnaryServerInterceptor(opts ...Option) grpc.UnaryServerInterceptor

UnaryServerInterceptor returns a new unary server interceptors that sets the values for request tags.

Types

type Option

type Option func(*options)

func WithFieldExtractor

func WithFieldExtractor(f RequestFieldExtractorFunc) Option

WithFieldExtractor customizes the function for extracting log fields from protobuf messages, for unary and server-streamed methods only.

type RequestFieldExtractorFunc

type RequestFieldExtractorFunc func(fullMethod string, req interface{}) map[string]string

RequestFieldExtractorFunc is a user-provided function that extracts field information from a gRPC request. It is called from tags middleware on arrival of unary request or a server-stream request. Keys and values will be added to the context tags of the request. If there are no fields, you should return a nil.

func TagBasedRequestFieldExtractor

func TagBasedRequestFieldExtractor(tagName string) RequestFieldExtractorFunc

TagBasedRequestFieldExtractor is a function that relies on Go struct tags to export log fields from requests. TODO(bwplotka): Add tests/examples https://github.com/grpc-ecosystem/go-grpc-middleware/issues/382 The tagName is configurable using the tagName variable. Here it would be "log_field".

type Tags

type Tags interface {
	// Set sets the given key in the metadata tags.
	Set(key string, value string) Tags
	// Has checks if the given key exists.
	Has(key string) bool
	// Values returns a map of key to values.
	// Do not modify the underlying map, use Set instead.
	Values() map[string]string
}

Tags is the interface used for storing request tags between Context calls. The default implementation is *not* thread safe, and should be handled only in the context of the request.

func Extract

func Extract(ctx context.Context) Tags

Extracts returns a pre-existing Tags object in the Context. If the context wasn't set in a tag interceptor, a no-op Tag storage is returned that will *not* be propagated in context.

func NewTags

func NewTags() Tags

Jump to

Keyboard shortcuts

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