Config

The following are the fields of the ApitallyConfig struct.

ParameterDescriptionType
ClientIdClient ID for your application. Find it on the Setup instructions page for your app.string
EnvName of the environment, e.g. prod or dev. The environment will be automatically created in Apitally if it doesn’t exist.string
RequestLoggingConfigConfiguration for request logging. See table below.*RequestLoggingConfig
AppVersionThe current version of your application, e.g. 1.0.0.string

Request logging config

The following are the fields of the RequestLoggingConfig struct.

ParameterDescriptionTypeDefault
EnabledWhether request logging is enabled.boolfalse
LogQueryParamsWhether to include query parameters in the logs. If disabled these will be stripped from the request URLs logged.booltrue
LogRequestHeadersWhether to include request headers in the logs. Default masking for common sensitive headers (e.g. Authorization) applies.boolfalse
LogRequestBodyWhether to include the request body in the logs. Only JSON and text are supported, up to 50 KB.boolfalse
LogResponseHeadersWhether to include response headers in the logs.booltrue
LogResponseBodyWhether to include the response body in the logs. Only JSON and text are supported, up to 50 KB.boolfalse
LogPanicWhether to log information when a panic occurs during request handling.boolfalse
MaskQueryParamsList of regular expressions for matching query parameter names that should be masked.[]*regexp.Regexpnil
MaskHeadersList of regular expressions for matching header names that should be masked.[]*regexp.Regexpnil
MaskRequestBodyCallbackCallback function for masking the request body. Takes one parameter request and returns the request body as []byte or nil.func(request *Request) []bytenil
MaskResponseBodyCallbackCallback function for masking the response body. Takes two parameters request and response and returns the response body as []byte or nil.func(request *Request, response *Response) []bytenil
ExcludePathsList of regular expressions for matching paths to exclude from logging.[]*regexp.Regexpnil
ExcludeCallbackCallback function for excluding requests from logging. Takes two parameters request and response and returns a true, if the request should be excluded, or false otherwise.func(request *Request, response *Response) boolnil

Request struct

Below are the fields of the Request struct.

FieldDescriptionType
TimestampUnix timestamp of the request.float64
MethodHTTP method of the request.string
PathPath of the request.string
URLFull URL of the request.string
HeadersArray of key-value pairs representing the request headers.[][2]string
SizeSize of the request body in bytes.int64
ConsumerIdentifier of the consumer making the request.string
BodyRaw request body.[]byte

Response struct

Below are the fields of the Response struct.

FieldDescriptionType
StatusCodeHTTP status code of the response.int
ResponseTimeTime taken to respond to the request in seconds.float64
HeadersArray of key-value pairs representing the response headers.[][2]string
SizeSize of the response body in bytes.int64
BodyRaw response body.[]byte

Default masking

The below regular expressions are used to mask sensitive query parameters and headers.

// Query parameters
var DefaultMaskQueryParamPatterns = []*regexp.Regexp{
	regexp.MustCompile(`(?i)auth`),
	regexp.MustCompile(`(?i)api-?key`),
	regexp.MustCompile(`(?i)secret`),
	regexp.MustCompile(`(?i)token`),
	regexp.MustCompile(`(?i)password`),
	regexp.MustCompile(`(?i)pwd`),
}
// Headers
var DefaultMaskHeaderPatterns = []*regexp.Regexp{
	regexp.MustCompile(`(?i)auth`),
	regexp.MustCompile(`(?i)api-?key`),
	regexp.MustCompile(`(?i)secret`),
	regexp.MustCompile(`(?i)token`),
	regexp.MustCompile(`(?i)cookie`),
}

Default exclusions

The below regular expressions are used to exclude common health check endpoints from logging. They are applied to the request path.

// Common paths of health check endpoints
var DefaultExcludePathPatterns = []*regexp.Regexp{
	regexp.MustCompile(`/_?healthz?$`),
	regexp.MustCompile(`/_?health[_-]?checks?$`),
	regexp.MustCompile(`/_?heart[_-]?beats?$`),
	regexp.MustCompile(`/ping$`),
	regexp.MustCompile(`/ready$`),
	regexp.MustCompile(`/live$`),
}