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
Middleware can automatically detect VCS (Version Control System) metadata from your .git directory, similar to Node.js and Python implementations. This helps Middleware suggest fixes and even open GitHub pull requests for you.
Automatic Detection
The SDK will automatically detect:
- Git commit SHA
- Repository URL from your project's .git directory. No additional configuration is needed if your project is a git repository.
Manual Configuration
If you need to override the automatic detection or if your project is not a git repository, you can set these environment variables:
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