# How to capture and send error with Go APM?

**URL:** <https://discuss.elastic.co/t/how-to-capture-and-send-error-with-go-apm/316715>\
**Category:** APM\
**Tags:** go\
**Created:** [October 16, 2022, 10:23pm UTC](https://discuss.elastic.co/t/how-to-capture-and-send-error-with-go-apm/316715 "2022-10-16T22:23:09Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![learningelastic](https://avatars.discourse-cdn.com/v4/letter/l/958977/32.png) [@learningelastic](https://discuss.elastic.co/u/learningelastic)\
**Post date:** [October 16, 2022, 10:23pm UTC](https://discuss.elastic.co/t/how-to-capture-and-send-error-with-go-apm/316715/1 "2022-10-16T22:23:09Z")

</div>

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:

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/0/b/0bc99305cab8a6fa1caee03d2329459f78a24008.png)

The Overview page properly shows things though like this:

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/a/8/a897f88355d2a2411ca4fde8a7e2a8c2c9a29893.png)

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

```auto
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:

```auto

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.

---

<div class="post-metadata">

**Author:** ![rachel\_gomez](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rachel_gomez/32/108615_2.png) [@rachel\_gomez](https://discuss.elastic.co/u/rachel_gomez)\
**Post date:** [November 10, 2022, 7:44am UTC](https://discuss.elastic.co/t/how-to-capture-and-send-error-with-go-apm/316715/2 "2022-11-10T07:44:20Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![axw](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/axw/32/28197_2.png) [@axw](https://discuss.elastic.co/u/axw)\
**Post date:** [November 14, 2022, 5:09am UTC](https://discuss.elastic.co/t/how-to-capture-and-send-error-with-go-apm/316715/3 "2022-11-14T05:09:13Z")

</div>

> [@learningelastic](#):
>
> ```auto
> "go.elastic.co/apm"
> "go.elastic.co/apm/module/apmhttp/v2"
> 
> ```

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

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [December 12, 2022, 2:15pm UTC](https://discuss.elastic.co/t/how-to-capture-and-send-error-with-go-apm/316715/5 "2022-12-12T14:15:09Z")

</div>

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