Golang APM Setup
Traces | Metrics | App Logs | Custom Logs | Profiling |
---|---|---|---|---|
- |
Prerequisites
- To monitor APM data on dashboard, Middleware Host agent needs to be installed.
- You can refer this demo project to refer use cases of APM.
Step 1 : Install Golang package
Run this in your terminal
Step 2 : Import Tracker
Add these line at the very start of your project
Collect Golang specific metrics
Call track method in your main function
Running this method with go routine is important ! This will start collecting the application traces & profiling data.
Add custom logs
Distributed Tracing
You may need to add a framework specific middleware, to watch traces.
Framework | Reference |
---|---|
gin/gonic | GIN Demo |
gorilla/mux | MUX Demo |
go-chi | go-chi Demo |
go-chi/v5 | go-chi/v5 Demo |
astaxie-beego | astaxie-beego Demo |
beego/v2 | beego/v2 Demo |
database/sql | SQL Demo |
go-pg/pg | PG Demo |
GORM 1 | GORM 1 Demo |
GORM 2 | GORM 2 Demo |
go-pg/mongo | Mongo Demo |
gRPC | gRPC Demo |
go-redis/redis/v9 | go-redis/redis/v9 Demo |
go-redis/redis/v8 | go-redis/redis/v8 Demo |
Note for APM inside Kubernetes
If you are using APM in a Kubernetes cluster make sure to follow these 2 steps:
Step 1 : Find your Middleware Service namespace
For older setup, your “mw-service” can be inside mw-agent-ns-{FIRST-5-LETTERS-OF-API-KEY}
namespace
For newer setup, we simplified the namespace name to mw-agent-ns
Step 2 : Set this ENV variable in your application deployment YAML
Please replace “NAMESPACE” with the correct value that you found from Step 1.
Error Handling :
If you want to record exception in traces then you can use track.RecordError(ctx,error) method.