events

package
v1.90.1 Latest Latest
Warning

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

Go to latest
Published: May 17, 2024 License: Apache-2.0 Imports: 10 Imported by: 5

Documentation

Overview

Package events defines the standard logging event structures

This is based on https://docs.google.com/document/d/1V1py1iXX9B9NAb30veHYNGOuymZ9o_C2pYSU9E6qmsg/edit# and https://outreach-io.atlassian.net/wiki/spaces/EN/pages/691405109/Logging+Standards

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Durations

type Durations struct {
	ServiceSeconds float64 `log:"timing.service_time"`
	WaitSeconds    float64 `log:"timing.wait_time"`
	TotalSeconds   float64 `log:"timing.total_time"`
}

Durations holds the various times in seconds

func (*Durations) MarshalLog

func (s *Durations) MarshalLog(addField func(key string, value interface{}))

type ErrorInfo

type ErrorInfo struct {
	RawError error
	Kind     string
	Error    string
	Message  string
	Stack    []string
	Cause    log.Marshaler
	Custom   log.Marshaler
}

ErrorInfo tracks the error info for logging purposes. Log tags are omitted to do custom MarshalLog handling on Stack.

func NewErrorInfo

func NewErrorInfo(err error) *ErrorInfo

NewErrorInfo converts an error into ErrorInfo meant for logging.

In the case of errors wrapped with github.com/pkg/errors.Wrap, NewErrorInfo will attempt to collapse (message, stack) pairs within the error stack into A single level of the error.

func NewErrorInfoFromPanic

func NewErrorInfoFromPanic(r interface{}) *ErrorInfo

NewErrorInfoFromPanic converts the panic result into an appropriate error info for logging

func (*ErrorInfo) MarshalLog

func (e *ErrorInfo) MarshalLog(addField func(key string, value interface{}))

type HTTPRequest

type HTTPRequest struct {
	// embed the network requests
	NetworkRequest `log:"."`

	// embed times
	Times `log:"."`

	// embed timing
	Durations `log:"."`

	// Duration is same as Durations.ServiceTime
	Duration float64 `log:"duration"`

	Method     string `log:"http.method"`
	Referer    string `log:"http.referer"`
	RequestID  string `log:"http.request_id"`
	StatusCode int    `log:"http.status_code"`
	Path       string `log:"http.url_details.path"`
	URI        string `log:"http.url_details.uri"`
	Endpoint   string `log:"http.url_details.endpoint"`
}

HTTPRequest tracks HTTP request related information

func (*HTTPRequest) FillFieldsFromRequest

func (h *HTTPRequest) FillFieldsFromRequest(r *http.Request)

FillFieldsFromRequest fills in the standard request fields

Call FillResponseInfo() before logging this.

func (*HTTPRequest) FillResponseInfo

func (h *HTTPRequest) FillResponseInfo(bytesWritten, statusCode int)

FillResponseInfo fills in the response data as well as ends the timing information.

Only the first call of this function has any effect. After the Finished time has been updated, further calls will be ignored

func (*HTTPRequest) MarshalLog

func (s *HTTPRequest) MarshalLog(addField func(key string, value interface{}))

type LazyErrInfo

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

LazyErrInfo holds an unserialized error and marshals it on-demand.

func Err

func Err(err error) *LazyErrInfo

Err is a convenience method for logging. It lazily yields the result of NewErrorInfo when logged, and caches it for future use.

func (*LazyErrInfo) ErrorInfo

func (l *LazyErrInfo) ErrorInfo() *ErrorInfo

func (*LazyErrInfo) MarshalLog

func (l *LazyErrInfo) MarshalLog(addField func(field string, value interface{}))

type NetworkRequest

type NetworkRequest struct {
	BytesRead    int    `log:"network.bytes_read"`
	BytesWritten int    `log:"network.bytes_written"`
	RemoteAddr   string `log:"network.client.ip"`
	DestAddr     string `log:"network.destination.ip"`
}

NetworkRequest tracks network request related information

func (*NetworkRequest) MarshalLog

func (s *NetworkRequest) MarshalLog(addField func(key string, value interface{}))

type Times

type Times struct {
	Scheduled time.Time `log:"timing.scheduled_at"`
	Started   time.Time `log:"timing.dequeued_at"`
	Finished  time.Time `log:"timing.finished_at"`
}

Times holds the actual times and also provides a convenient way to calculate the associated durations

func (*Times) Durations

func (t *Times) Durations() *Durations

Durations returns the durations associated with the times

func (*Times) MarshalLog

func (s *Times) MarshalLog(addField func(key string, value interface{}))

Jump to

Keyboard shortcuts

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