Installation steps
Install Atatus Go Agent and logging module
copygo get go.atatus.com/agent go get go.atatus.com/agent/module/atzerolog
Set up tracer and configure log exporter
copyimport ( "net/http" "github.com/rs/zerolog" "go.atatus.com/agent" "go.atatus.com/agent/module/atzerolog" ) // Global logger setup (optional): Use if you need to log messages outside HTTP handlers or during application startup. // atzerolog.Writer will send log records with the level error or greater to Atatus at. var baseLogger = zerolog.New(zerolog.MultiLevelWriter(os.Stdout, &atzerolog.Writer{})) func main() { // Initialize Atatus tracer using environment variables tracer := atatus.DefaultTracer tracer.Service.LicenseKey = os.Getenv("ATATUS_LICENSE_KEY") tracer.Service.AppName = os.Getenv("ATATUS_APP_NAME") tracer.Service.Tracing = os.Getenv("ATATUS_TRACING") tracer.Service.Analytics = os.Getenv("ATATUS_ANALYTICS") // atzerolog.MarshalErrorStack will extract stack traces from // errors produced by github.com/pkg/errors. The main difference // with github.com/rs/zerolog/pkgerrors.MarshalStack is that // the atzerolog implementation records fully-qualified function // names, enabling errors reported to Atatus at to be attributed // to the correct package. zerolog.ErrorStackMarshaler = atzerolog.MarshalErrorStack } func traceLoggingMiddleware(h http.Handler) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) { ctx := req.Context() logger := zerolog.Ctx(ctx).Hook(atzerolog.TraceContextHook(ctx)) req = req.WithContext(logger.WithContext(ctx)) h.ServeHTTP(w, req) }) }
Clean Up Dependencies
copygo mod tidy
Run the Application
copygo run main.go