Skip to main content
You can configure Apitally using the Config struct passed to the Middleware function.
package main

import (
    apitally "github.com/apitally/apitally-go/chi"
    "github.com/go-chi/chi/v5"
)

func main() {
    r := chi.NewRouter()

    config := apitally.NewConfig("your-client-id")
    config.Env = "dev"
    config.RequestLogging.Enabled = true
    // other parameters ...

    r.Use(apitally.Middleware(r, config))
}
See the setup guides for more examples.

Parameters

The following are the fields of the Config 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 if it doesn’t exist.string
RequestLoggingConfiguration options for request logging. See table below.*RequestLoggingConfig
AppVersionThe current version of your application, e.g. 1.0.0.string
The RequestLogging field is a pointer to a RequestLoggingConfig struct with the following fields:
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
CaptureLogsWhether to capture application logs emitted during request handling.boolfalse
CaptureTracesWhether to enable tracing with OpenTelemetry.boolfalse
MaskQueryParamsList of regular expressions for matching query parameters to mask. These are in addition to the default masking patterns.[]*regexp.Regexpnil
MaskHeadersList of regular expressions for matching headers to mask. These are in addition to the default masking patterns.[]*regexp.Regexpnil
MaskBodyFieldsList of regular expressions for matching request/response body fields to mask. These are in addition to the default masking patterns.[]*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 true, if the request should be excluded, or false otherwise.func(request *Request, response *Response) boolnil