Ops AI Golang APM

Instrument your Go service with the Middleware Golang SDK (≥ 1.7.0) and (if you use Gin) the Gin middleware (≥ 1.0.0) so Ops AI can analyze runtime issues with full code context.

What you’ll Set Up

  • SDK install (Go modules)
  • Tracker initialization at app start (top of main)
  • (If using Gin) Add the Gin middleware to trace requests
  • Exception code capture (function names/bodies, stacks, file ranges)
  • VCS metadata (auto or env vars) so Ops AI can map incidents to the right commit and suggest fixes/PRs

APM Setup

1. Install the Middleware Packages (Shell)

Install the core Go APM SDK and (optionally) the Gin integration. Using @latest satisfies the minimum versions.

1go get github.com/middleware-labs/golang-apm@latest
2go get github.com/middleware-labs/golang-apm-gin@latest

2. Initialize the tracker (Go)

Add the tracker import near the top of your entry file, then initialize before wiring framework middleware. (Your access token is the Middleware account key.)

1import (
2    track "github.com/middleware-labs/golang-apm/tracker"
3)
4
5Initialize in main (base pattern):
6config, _ := track.Track(
7    track.WithConfigTag("service", "<apm-service-name>"),
8    track.WithConfigTag("accessToken", "<MW_API_KEY>"),
9)

3. Gin framework wiring (Go)

If you use Gin, install its package, import it, and attach the Middleware APM Gin middleware using the config returned by track.Track(...).

1import (
2    "github.com/gin-gonic/gin"
3    track "github.com/middleware-labs/golang-apm/tracker"
4    mwgin "github.com/middleware-labs/golang-apm-gin/gin"
5)
6
7func main() {
8    r := gin.Default()
9
10    config, _ := track.Track(
11        track.WithConfigTag("service", "<apm-service-name>"),
12        track.WithConfigTag("accessToken", "<MW_API_KEY>"),
13    )
14
15    r.Use(mwgin.Middleware(config))
16    // ... your routes ...
17    r.Run(":8090")
18}

Exception Code Capturing (what gets recorded)

The Go SDK automatically captures:

  • Exception types & messages
  • Stack traces with line numbers
  • Function names and bodies
  • File paths and line ranges
  • Library file detection (files under /go/src, /go/pkg/mod, vendor, third_party)

This is what enables Ops AI to show precise code context alongside an incident. No extra config required.

VCS Metadata

If you need to override the automatic detection or if your project is not a git repository, you can set these environment variables:

1MW_VCS_COMMIT_SHA=$(git rev-parse HEAD)
2MW_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 correct fix and even create a solution PR for you.

Need assistance or want to learn more about Middleware? Contact our support team at [email protected] or join our Slack channel.