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

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

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)

Thanks!

This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.