contextmd

package
v0.0.0-...-faba519 Latest Latest
Warning

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

Go to latest
Published: May 1, 2024 License: Apache-2.0 Imports: 9 Imported by: 4

Documentation

Overview

Package contextmd allows attaching metadata to the context of RPC calls.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FromContexts

func FromContexts(ctx context.Context, ctxs ...context.Context) (context.Context, error)

FromContexts returns a context derived from the first one with metadata merged from all of ctxs.

If len(ctxs) == 0, ctx is returned as is. Returns the first error or nil.

func Infof

func Infof(ctx context.Context, v log.Level, format string, args ...any)

Infof is equivalent to log.V(x).Infof(...) except it also logs context metadata, if available.

func WithMetadata

func WithMetadata(ctx context.Context, ms ...*Metadata) (context.Context, error)

WithMetadata attaches metadata to the passed-in context, returning a new context. This function should be called in every test method after a context is created. It uses the already created context to generate a new one containing the metadata header.

Types

type Metadata

type Metadata struct {
	// ActionID is an optional id to use to identify an action.
	ActionID string
	// InvocationID is an optional id to use to identify an invocation spanning multiple commands.
	InvocationID string
	// CorrelatedInvocationID is an optional id to use to identify a build spanning multiple invocations.
	CorrelatedInvocationID string
	// ToolName is an optional tool name to pass to the remote server for logging.
	ToolName string
	// ToolVersion is an optional tool version to pass to the remote server for logging.
	ToolVersion string
}

Metadata is optionally attached to RPC requests.

func ExtractMetadata

func ExtractMetadata(ctx context.Context) (m *Metadata, err error)

ExtractMetadata parses the metadata from the given context, if it exists. If metadata does not exist, empty values are returned.

func MergeMetadata

func MergeMetadata(metas ...*Metadata) *Metadata

MergeMetadata returns a new instance that has the tool name, tool version and correlated action id from the first argument, and joins a sorted and unique set of action IDs and invocation IDs from all arguments. Nil is never returned.

Jump to

Keyboard shortcuts

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