APM Go Agent doesn't sends any requests to APM-server


(Arsalan Rabdanov) #1

Trying to configure APM Go Agent with a simple example:

main.go

package main

import (
	"errors"
	"log"

	"github.com/joho/godotenv"
	"go.elastic.co/apm"
)

func main() {
	err := godotenv.Load()
	if err != nil {
		log.Println("Error loading .env file")
	}
	tx := apm.DefaultTracer.StartTransaction("GET /api/v1", "request")
	tx.Result = "HTTP 2xx"
	tx.Context.SetTag("region", "us-east-1")
	defer tx.End()

	e := apm.DefaultTracer.NewError(errors.New("error"))
	e.Send()
}

.dotenv

ELASTIC_APM_SERVER_URL=http://192.168.1.52:8200
ELASTIC_APM_SERVICE_NAME=go-apm-test

No requests, no logs. I have looked net packets with Wireshark. No packets with dst port 8200 on client machine


(Andrew Wilkins) #2

Hi Arsalan, thanks for trying out the Elastic APM Go agent!

The Go agent starts a background goroutine to send events to the APM Server. What's happening here is that your process is exiting before the goroutine has a chance to send them.

For testing purposes, Tracer has a method called Flush, which you can call to force any enqueued events to be flushed to the server. Tracer.Flush takes a single argument, a channel which will abort the flush (you can pass nil to wait until the flush completes, successfully or not.)

So just add this to the end of your main function:

apm.DefaultTracer.Flush(nil)

(Arsalan Rabdanov) #3

Thanks!