How to capture and send error with Go APM?

I got the basics of Elastic and Kibana (version 8.4) APM for a simple go app, but I can't seem to populate the errors page when I go to Kibana>Observability>APM>Services>MyGoApp>Errors. It always looks empty like this:

The Overview page properly shows things though like this:

This is my golang code, any idea what I'm doing wrong?

package main

import (
        "errors"
        "fmt"
        "net/http"
        "github.com/gorilla/mux"
        "github.com/joho/godotenv"
        "go.elastic.co/apm"
        "go.elastic.co/apm/module/apmhttp/v2"
)

func main() {
        godotenv.Load()
        router := mux.NewRouter()
        router.HandleFunc("/", homePage)
        router.HandleFunc("/error", errorPage)
        http.ListenAndServe(":8080", apmhttp.Wrap(router))

}
func homePage(w http.ResponseWriter, r *http.Request) {
        fmt.Fprintf(w, "Welcome to the HomePage!")
        fmt.Println("Endpoint Hit: homePage")
}
func errorPage(w http.ResponseWriter, r *http.Request) {
        fmt.Fprintf(w, "Sending Error!")
        apm.CaptureError(r.Context(), errors.New("test error")).Send()
}


As experiment, I tried using CaptureError() method in nodejs. And it actually populated the errors. This was my code:


var apm = require('elastic-apm-node').start({

  // Allowed characters: a-z, A-Z, 0-9, -, _, and space
  serviceName: 'app2',

  // Use if APM Server requires a secret token
  secretToken: 'testtoken',
  serverUrl: 'http url',
  verifyServerCert: false,
  environment: 'production'
})

const express = require('express')
const app = express()
const port = 3030

app.get('/', (req, res) => {
  res.send('Hello World!')
})

app.get('/error', (req, res) => {
  res.send('Send Err!')
  const err = new Error('Trigger Error!')

  apm.setTransactionName('/error')
  apm.captureError(err)
})

app.listen(port, () => {
  console.log(`Example app listening on port ${port}`)
})

So it seems that CaptureError() works for nodejs package, but not for golang package.

Is something not working as expected? Don’t worry if you can’t figure out what the problem is; we’re here to help! First, ensure your app is compatible with the agent’s supported technologies.

If you’re an existing Elastic customer with a support contract, please create a ticket in the Elastic Support portal.

Regards,
Rachel Gomez

You need to use go.elastic.co/apm/v2 instead of go.elastic.co/apm.

1 Like

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