sloggrpc

package module
v0.0.0-...-dbb0582 Latest Latest
Warning

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

Go to latest
Published: Dec 19, 2024 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DefaultClientErrorToLevel

func DefaultClientErrorToLevel(err error) slog.Level

DefaultClientErrorToLevel is the helper mapper that maps gRPC return errors/codes to log levels for client side.

func DefaultServerErrorToLevel

func DefaultServerErrorToLevel(err error) slog.Level

DefaultServerErrorToLevel is the helper mapper that maps gRPC return errors/codes to log levels for server side.

func FullMethod

func FullMethod(ii *otelgrpc.InterceptorInfo) string

FullMethod returns the full grpc method name, when given an *otelgrpc.InterceptorInfo

func InterceptorFilterIgnoreReflection

func InterceptorFilterIgnoreReflection(ii *otelgrpc.InterceptorInfo) bool

InterceptorFilterIgnoreReflection returns an InterceptorFilter that will ignore all grpc Reflection calls.

func JsonPB

func JsonPB(m proto.Message) any

JsonPB turns a protobuf message into json, and should be used when logging a protobuf message, instead of the "encoding/json" package. It will marshal the protobuf using jsonpb (the official Proto<->JSON spec), instead of a json package that doesn't know how to handle well known types.

func ReplaceAttrJsonPB

func ReplaceAttrJsonPB(group []string, a slog.Attr) slog.Attr

func SlogStreamClientInterceptor

func SlogStreamClientInterceptor(opts ...Option) grpc.StreamClientInterceptor

SlogStreamClientInterceptor returns a grpc.StreamClientInterceptor suitable for use in a grpc.NewClient or grpc.WithChainStreamInterceptor call. This interceptor will log stream start, sends and receives.

func SlogStreamServerInterceptor

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

SlogStreamServerInterceptor returns a grpc.StreamServerInterceptor suitable for use in a grpc.NewServer call. This interceptor will log stream start, sends and receives.

func SlogUnaryClientInterceptor

func SlogUnaryClientInterceptor(opts ...Option) grpc.UnaryClientInterceptor

SlogUnaryClientInterceptor returns a grpc.UnaryClientInterceptor suitable for use in a grpc.NewClient or grpc.WithChainUnaryInterceptor call. This interceptor will log requests and responses.

func SlogUnaryServerInterceptor

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

SlogUnaryServerInterceptor returns a grpc.UnaryServerInterceptor suitable for use in a grpc.NewServer or grpc.ChainUnaryInterceptor call. This interceptor will log requests and responses.

Types

type AppendToAttributes

type AppendToAttributes func(attrs []slog.Attr, attr slog.Attr) []slog.Attr

AppendToAttributes allows customizing the attributes, including disabling some

type Call

type Call struct {
	System  string `json:"system,omitempty"`
	Package string `json:"package,omitempty"`
	Service string `json:"service,omitempty"`
	Method  string `json:"method,omitempty"`
}

Call contains information about the grpc call being made

type ErrorToLevel

type ErrorToLevel func(err error) slog.Level

ErrorToLevel defines the mapping between the gRPC return error/code to a log level

type InterceptorFilter

type InterceptorFilter func(*otelgrpc.InterceptorInfo) bool

InterceptorFilter is a predicate used to determine whether a given request in interceptor info should be instrumented. A InterceptorFilter must return true if the request should be traced.

type Option

type Option interface {
	// contains filtered or unexported methods
}

Option applies an option value for a config.

func WithAppendToAttributes

func WithAppendToAttributes(f AppendToAttributes) Option

WithAppendToAttributes returns an Option to use the appending function

func WithErrorToLevel

func WithErrorToLevel(f ErrorToLevel) Option

WithErrorToLevel returns an Option to use the error to level function

func WithInterceptorFilter

func WithInterceptorFilter(f InterceptorFilter) Option

WithInterceptorFilter returns an Option to use the request filter.

type Payload

type Payload struct {
	Payload any `json:"payload,omitempty"`
}

Payload contains the protobuf message and metadata about it

type Peer

type Peer struct {
	Host string `json:"host,omitempty"`
	Port int    `json:"port,omitempty"`
}

Peer contains information about the other party

type Result

type Result struct {
	Error   error         `json:"error,omitempty"` // Call status.FromError() to get the status code, message, and details
	Elapsed time.Duration `json:"elapsed,omitempty"`
}

Result contains information about the end result of the grpc call

type Role

type Role struct {
	Role         string `json:"role,omitempty"`
	ClientStream bool   `json:"client_stream,omitempty"`
	ServerStream bool   `json:"server_stream,omitempty"`
}

Role contains information about the server and client

type StreamInfo

type StreamInfo struct {
	MsgID int64 `json:"msg_id,omitempty"` // Incrementing ID
}

StreamInfo contains information specific to streaming Sends and Receives

Directories

Path Synopsis
test
gen

Jump to

Keyboard shortcuts

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