Mx.Load document
Toggle Dark/Light/Auto mode Toggle Dark/Light/Auto mode Toggle Dark/Light/Auto mode Back to homepage

2.3.2.2 Go

Installation

Add mxload_go to the application from which you want to retrieve logs.

go get github.com/mxload/mxload_go
go get github.com/gwatts/gin-adapter

Configuration

Add the following content to the entry point of your application (usually main.go). Currently supports three frameworks: Gin, go-chi, and echo.

Gin

import (
    ...
+	mxload "github.com/mxload/mxload_go"
)

func main() {
  r := gin.Default()

+  r.Use(adapter.Wrap(mxload.MiddlewareFunc(
+	&mxload.MxloadConfig{
+		Enabled:      true,
+		CollectorURL: "https://lambda-public.mxload.mx/put-request-log",
+		ProjectID:    YOUR_PROJECT_ID,
+		ServiceKey:   "YOUR_SERVICE_KEY",
+		CustomHeaders: []string{
+			"Authorization",
+		},
+		IgnorePaths: []string{
+			"/ignored",
+		},
+	},
+  )))
    ...
}

go-chi

import (
    ...

+	mxload "github.com/mxload/mxload_go"
)

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

+	r.Use(mxload.MiddlewareFunc(
+		&mxload.MxloadConfig{
+			Enabled:      true,
+			CollectorURL: "https://lambda-public.mxload.mx/put-request-log",
+			ProjectID:    YOUR_PROJECT_ID,
+			ServiceKey:   "YOUR_SERVICE_KEY",
+			CustomHeaders: []string{
+				"Authorization",
+			},
+			IgnorePaths: []string{
+				"/ignored",
+			},
+		},
+	))

    ....
}

echo

import (
    ...

+	mxload "github.com/mxload/mxload_go"
)

func main() {
	e := echo.New()

+	e.Use(echo.WrapMiddleware(mxload.MiddlewareFunc(
+		&mxload.MxloadConfig{
+			Enabled:      true,
+			CollectorURL: "https://lambda-public.mxload.mx/put-request-log",
+			ProjectID:    YOUR_PROJECT_ID,
+			ServiceKey:   "YOUR_SERVICE_KEY",
+			CustomHeaders: []string{
+				"Authorization",
+			},
+			IgnorePaths: []string{
+				"/ignored",
+			},
+		},
+	)))
    ...
}

Configuration Parameters

The main configuration parameters are as follows:

  • Enabled
    • Enables/disables logging. Default is false.
  • collector_url
    • URL of mxload to receive logs. Specify https://lambda-public.mxload.mx/put-request-log.
  • ProjectID
    • Set the id of the created project. project_id can be confirmed from the home or project details.
  • ServiceKey
  • CustomHeaders (optional)
    • Required for recording header contents.
    • For example, if you want to include "Content-Type": "application/json", add Content-Type to the CustomHeaders value.
  • IgnorePaths (optional)
    • If the request path is within IgnorePaths, the sending of request logs is ignored.
    • Set this when you want to disable paths such as /health for health checks.

The log parameters sent to Mx.Load are as follows:

  • Method
  • Request path
  • Request body
  • Query parameters
  • Request header
  • Cookies