monitoring

package
v0.0.0-...-f67da96 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const DefaultFlushWait = 10 * time.Second // 10 sec (this flush) + 10 sec for server shutdown grace = 20 sec which is reasonable considering k8s grace is 30sec

DefaultFlushWait represents the default wait time for flushing

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, tags 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 NotifyErrorToInstrumentation

func NotifyErrorToInstrumentation(ctx context.Context, err error)

func SetInContext

func SetInContext(ctx context.Context, m *Monitor) context.Context

SetInContext sets the logger in context

Types

type Config

type Config struct {
	ServerName      string
	Environment     string
	Version         string
	Writer          io.Writer // Support write log to buffer for testing
	SentryDSN       string    // To capture error, skip init Sentry if it's not provided
	OtelExporterURL string    // To support OpenTelemetry
	ExtraTags       map[string]string
}

Config holds Monitor configuration

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 MockstackTracer

type MockstackTracer struct {
	mock.Mock
}

MockstackTracer is an autogenerated mock type for the stackTracer type

func NewMockstackTracer

func NewMockstackTracer(t interface {
	mock.TestingT
	Cleanup(func())
}) *MockstackTracer

NewMockstackTracer creates a new instance of MockstackTracer. 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 (*MockstackTracer) EXPECT

func (*MockstackTracer) StackTrace

func (_m *MockstackTracer) StackTrace() errors.StackTrace

StackTrace provides a mock function with no fields

type MockstackTracer_Expecter

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

func (*MockstackTracer_Expecter) StackTrace

StackTrace is a helper method to define mock.On call

type MockstackTracer_StackTrace_Call

type MockstackTracer_StackTrace_Call struct {
	*mock.Call
}

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

func (*MockstackTracer_StackTrace_Call) Return

func (*MockstackTracer_StackTrace_Call) Run

func (*MockstackTracer_StackTrace_Call) RunAndReturn

type Monitor

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

Monitor represents instance for logging and capture error

func FromContext

func FromContext(ctx context.Context) *Monitor

FromContext gets the logger from context

func InjectOutgoingTracingInfo

func InjectOutgoingTracingInfo(m *Monitor, spanCtx trace.SpanContext) *Monitor

func InjectTracingInfo

func InjectTracingInfo(m *Monitor, spanCtx trace.SpanContext) *Monitor

func New

func New(cfg Config) (*Monitor, error)

New creates a new Monitor instance

func (*Monitor) Errorf

func (m *Monitor) Errorf(err error, msg string, args ...interface{})

Errorf logs the message using error level and reports the error to sentry

func (*Monitor) Flush

func (m *Monitor) Flush(maxWait time.Duration)

Flush will flush all the monitor data left in the queue to the monitoring service

func (*Monitor) Infof

func (m *Monitor) Infof(format string, args ...interface{})

Infof logs the message using info level

func (*Monitor) ReportError

func (m *Monitor) ReportError(err error, tags map[string]string)

func (*Monitor) With

func (m *Monitor) With(tags map[string]string) *Monitor

With creates a new child Monitor and adds new logTags to it. Parent Monitor remains unchanged.

func (*Monitor) WithTag

func (m *Monitor) WithTag(key string, value string) *Monitor

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

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