monitoring

package
v0.0.0-...-c5966c3 Latest Latest
Warning

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

Go to latest
Published: Feb 19, 2025 License: Apache-2.0 Imports: 30 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func InjectField

func InjectField[T any](ctx context.Context, key string, value T) context.Context

InjectField injects a field to Logger and trace.Span in context

func InjectFields

func InjectFields(ctx context.Context, fields map[string]string) context.Context

func NewContext

func NewContext(ctx context.Context) context.Context

NewContext copies the logger from old to a new context Use this when you want to use a new context but copy the logger over from the original context

func SetInContext

func SetInContext(ctx context.Context, logger *Logger) context.Context

SetInContext sets the logger in context

func Setup

func Setup(ctx context.Context, cfg MonitorConfig) (context.Context, error)

Setup initializes logging and tracing tools

func StartGRPCUnaryCallSegment

func StartGRPCUnaryCallSegment(ctx context.Context, svcInfo ExternalServiceInfo, fullMethod string) (context.Context, func(error))

func StartVaultSegment

func StartVaultSegment(ctx context.Context, info ExternalServiceInfo, operation string) func(error)

StartVaultSegment starts a trace.Span with vault information

Types

type ExternalServiceInfo

type ExternalServiceInfo struct {
	Hostname string
	Port     string
}

ExternalServiceInfo holds the ext svc info

func NewExternalServiceInfo

func NewExternalServiceInfo(rawURL string) ExternalServiceInfo

NewExternalServiceInfo creates a new ExternalServiceInfo from the given url

type GRPCRequestMetadata

type GRPCRequestMetadata struct {
	ServiceMethod string
	BodyToLog     []byte
	ContextData   []string
}

func StartUnaryIncomingCall

func StartUnaryIncomingCall(ctx context.Context, fullMethod string, req any) (context.Context, GRPCRequestMetadata, func(error))

type LogField

type LogField zap.Field

func Field

func Field[T any](name string, value T) LogField

type Logger

type Logger struct {
	// contains filtered or unexported fields
}

func FromContext

func FromContext(ctx context.Context) *Logger

FromContext gets the logger from context

func NewLogger

func NewLogger(opts ...Option) *Logger

func NewLoggerWithWriter

func NewLoggerWithWriter(w io.Writer, opts ...Option) *Logger

func NewNoopLogger

func NewNoopLogger() *Logger

func (*Logger) Errorf

func (l *Logger) Errorf(err error, msg string, args ...any)

func (*Logger) Infof

func (l *Logger) Infof(msg string, args ...any)

func (*Logger) With

func (l *Logger) With(fields ...LogField) *Logger

func (*Logger) WithLazy

func (l *Logger) WithLazy(fields ...LogField) *Logger

WithLazy adds log fields lazily, where the field values are not computed when added, but are calculated when the log is written to output

type MockOption

type MockOption struct {
	mock.Mock
}

MockOption is an autogenerated mock type for the Option type

func NewMockOption

func NewMockOption(t interface {
	mock.TestingT
	Cleanup(func())
}) *MockOption

NewMockOption creates a new instance of MockOption. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. The first argument is typically a *testing.T value.

func (*MockOption) EXPECT

func (_m *MockOption) EXPECT() *MockOption_Expecter

func (*MockOption) Execute

func (_m *MockOption) Execute(_a0 *Logger)

Execute provides a mock function with given fields: _a0

type MockOption_Execute_Call

type MockOption_Execute_Call struct {
	*mock.Call
}

MockOption_Execute_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Execute'

func (*MockOption_Execute_Call) Return

func (*MockOption_Execute_Call) Run

func (_c *MockOption_Execute_Call) Run(run func(_a0 *Logger)) *MockOption_Execute_Call

func (*MockOption_Execute_Call) RunAndReturn

func (_c *MockOption_Execute_Call) RunAndReturn(run func(*Logger)) *MockOption_Execute_Call

type MockOption_Expecter

type MockOption_Expecter struct {
	// contains filtered or unexported fields
}

func (*MockOption_Expecter) Execute

func (_e *MockOption_Expecter) Execute(_a0 interface{}) *MockOption_Execute_Call

Execute is a helper method to define mock.On call

  • _a0 *Logger

type MonitorConfig

type MonitorConfig struct {
	Tags map[string]string

	ExporterURL string
}

type MonitorTest

type MonitorTest struct {
	// contains filtered or unexported fields
}

func NewMonitorTest

func NewMonitorTest() (MonitorTest, func())

func (MonitorTest) Context

func (m MonitorTest) Context() context.Context

func (MonitorTest) GetLogger

func (m MonitorTest) GetLogger() *Logger

func (MonitorTest) GetLogs

func (m MonitorTest) GetLogs(t *testing.T) []map[string]interface{}

func (MonitorTest) GetPropagator

func (m MonitorTest) GetPropagator() propagation.TextMapPropagator

func (MonitorTest) GetSpans

func (m MonitorTest) GetSpans() tracetest.SpanStubs

func (MonitorTest) GetTracer

func (m MonitorTest) GetTracer() trace.Tracer

type Option

type Option func(*Logger)

func WithFieldFromMap

func WithFieldFromMap(fields map[string]string) Option

func WithFields

func WithFields(fields ...LogField) Option

type RequestMetadata

type RequestMetadata struct {
	Method      string
	Endpoint    string
	BodyToLog   []byte
	ContextData []string
}

func StartIncomingRequest

func StartIncomingRequest(logger *Logger, r *http.Request) (context.Context, RequestMetadata, func(int, error))

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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