Installation steps
Install Atatus Go Agent and Required Modules
copygo get go.atatus.com/agent go get go.atatus.com/agent/module/atmongo
Configure Atatus and Set Up Database Connection
copyimport ( "go.mongodb.org/mongo-driver/bson" "go.mongodb.org/mongo-driver/mongo" "go.mongodb.org/mongo-driver/mongo/options" "go.atatus.com/agent" "go.atatus.com/agent/module/atmongo" ) func main() { // Initialize Atatus tracer with values from environment tracer := atatus.DefaultTracer tracer.Service.LicenseKey = os.Getenv("ATATUS_LICENSE_KEY") tracer.Service.AppName = os.Getenv("ATATUS_APP_NAME") tracer.Service.Tracing = os.Getenv("ATATUS_TRACING") tracer.Service.Analytics = os.Getenv("ATATUS_ANALYTICS") } var client, _ = mongo.Connect( context.Background(), options.Client().SetMonitor(atmongo.CommandMonitor()), ) func handleRequest(w http.ResponseWriter, req *http.Request) { //req.Context() should be propagated to downstream operations such as database queries , http external API calls collection := client.Database("db").Collection("mongo") cur, err := collection.Find(req.Context(), bson.D{}) if err != nil { http.Error(w, "MongoDB query failed", http.StatusInternalServerError) } ... }
Clean Up Dependencies
copygo mod tidy
Run the Application
copygo run main.go