Golang APM
Get the most out of Middleware OpsAI for your Go applications by using the Middleware Golang SDK (version 1.7.0
or newer) and Gin Middleware (version 1.0.0
or newer).
🚀 Key Features
- Captures exception and error details automatically
- Works with popular Go frameworks like Gin
- Function code recording for all files
- Library file detection for better error tracking
🛠️ APM Setup
Install the Middleware packages:
go get github.com/middleware-labs/[email protected] go get github.com/middleware-labs/[email protected]
Initialize the tracker at the top of your main file:
import ( tracker "github.com/middleware-labs/golang-apm/tracker" mwgin "github.com/middleware-labs/golang-apm-gin/gin" ) func main() { config := track.Track( track.WithConfigTag(track.Service, "your service name"), track.WithConfigTag(track.Token, "your access token"), }
⚡ Exception Code Capturing
The SDK automatically captures:
- Exception types and messages
- Stack traces with line numbers
- Function names and bodies
- File paths and line ranges
- Library file detection (for files in /go/src, /go/pkg/mod, vendor, and third_party directories)
⚙️ VCS Metadata Configuration (Recommended)
To help Middleware suggest fixes and even open GitHub pull requests for you, it's important to send version control (VCS) information along with your error data.
Set these environment variables before starting your app:
MW_VCS_COMMIT_SHA=$(git rev-parse HEAD) MW_VCS_REPOSITORY_URL=$(git config --get remote.origin.url)
- This lets Middleware know exactly which version of your code is running, so it can suggest the right fix and even create a solution PR for you.
📚 Resources
- Middleware Golang APM on pkg.go.dev — Package and usage info
- Middleware Golang Gin Middleware — Gin framework integration
- Official Middleware Golang APM Docs — Full documentation and advanced usage