Version: v1.60.0 Latest Latest

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

Go to latest
Published: Feb 3, 2022 License: MIT Imports: 12 Imported by: 0



Package observability provides logging and metrics collection middleware for YARPC.



This section is empty.


This section is empty.


This section is empty.


type Config added in v1.36.0

type Config struct {
	// Logger to which messages will be logged.
	Logger *zap.Logger

	// Scope to which metrics are emitted.
	Scope *metrics.Scope

	// MetricTagsBlocklist of metric tags being suppressed from being tagged on
	// metrics emitted by the middleware.
	MetricTagsBlocklist []string

	// ContextExtractor Extracts request-scoped information from the context for logging.
	ContextExtractor ContextExtractor

	// Levels specify log levels for various classes of requests.
	Levels LevelsConfig

Config configures the observability middleware.

type ContextExtractor

type ContextExtractor func(context.Context) zapcore.Field

A ContextExtractor pulls any relevant request-scoped data (e.g., tracing spans) from the request's Context.

func NewNopContextExtractor

func NewNopContextExtractor() ContextExtractor

NewNopContextExtractor returns a no-op ContextExtractor.

type DirectionalLevelsConfig added in v1.40.0

type DirectionalLevelsConfig struct {
	// Log level used to log successful calls.
	// Defaults to DebugLevel.
	Success *zapcore.Level

	// Log level used to log failed calls.
	// This includes low-level network errors, TChannel error frames, etc.
	// Defaults to ErrorLevel.
	// Deprecated in favor of ServerError and ClientError.
	Failure *zapcore.Level

	// Log level used to log calls that failed with an application error.
	// All Thrift exceptions are considered application errors.
	// Defaults to ErrorLevel.
	// Deprecated in favor of ServerError and ClientError.
	ApplicationError *zapcore.Level

	// Log level used to log calls that failed with an server error.
	// Defaults to ErrorLevel.
	ServerError *zapcore.Level

	// Log level used to log calls that failed with an client error.
	// All Thrift exceptions are considered application errors if
	// there are not annotated with the option rpc.code.
	// Defaults to ErrorLevel.
	ClientError *zapcore.Level

DirectionalLevelsConfig may override the log levels for any combination of successes, failures, and application errors.

type LevelsConfig added in v1.40.0

type LevelsConfig struct {
	Default  DirectionalLevelsConfig
	Inbound  DirectionalLevelsConfig
	Outbound DirectionalLevelsConfig

LevelsConfig specifies log level overrides for inbound traffic, outbound traffic, or the defaults for either.

type Middleware

type Middleware struct {
	// contains filtered or unexported fields

Middleware is logging and metrics middleware for all RPC types.

func NewMiddleware

func NewMiddleware(cfg Config) *Middleware

NewMiddleware constructs an observability middleware with the provided configuration.

func (*Middleware) Call

Call implements middleware.UnaryOutbound.

func (*Middleware) CallOneway

CallOneway implements middleware.OnewayOutbound.

func (*Middleware) CallStream added in v1.27.0

CallStream implements middleware.StreamOutbound.

func (*Middleware) Handle

Handle implements middleware.UnaryInbound.

func (*Middleware) HandleOneway

func (m *Middleware) HandleOneway(ctx context.Context, req *transport.Request, h transport.OnewayHandler) error

HandleOneway implements middleware.OnewayInbound.

func (*Middleware) HandleStream added in v1.27.0

func (m *Middleware) HandleStream(serverStream *transport.ServerStream, h transport.StreamHandler) error

HandleStream implements middleware.StreamInbound.

Jump to

Keyboard shortcuts

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