# Apmsql is not tracking my sql queries

**URL:** <https://discuss.elastic.co/t/apmsql-is-not-tracking-my-sql-queries/316158>\
**Category:** APM\
**Created:** [October 9, 2022, 7:42pm UTC](https://discuss.elastic.co/t/apmsql-is-not-tracking-my-sql-queries/316158 "2022-10-09T19:42:05Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Leonardo\_Henrique](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/leonardo_henrique/32/79658_2.png) [@Leonardo\_Henrique](https://discuss.elastic.co/u/Leonardo_Henrique)\
**Post date:** [October 9, 2022, 7:42pm UTC](https://discuss.elastic.co/t/apmsql-is-not-tracking-my-sql-queries/316158/1 "2022-10-09T19:42:05Z")

</div>

Hello Everyone.

I am trying to configure the APM to track as well the SQL transactions. I am looking to [Built-in instrumentation modules | APM Go Agent Reference [2.x] | Elastic](https://www.elastic.co/guide/en/apm/agent/go/current/builtin-modules.html#builtin-modules-apmgorm) and this is my current test code

```auto

dsn := "user@pass(localhost:3306)/db?charset=utf8&parseTime=True&loc=Local"
	db, err := apmsql.Open("mysql", dsn)
	if err != nil {
		returns.Error(w, http.StatusInternalServerError, err)
		return
	}
	defer db.Close()

	stmt, _ := db.Prepare("INSERT INTO user (name) values (value))
	defer stmt.Close()

	if _, err := stmt.Exec(); err != nil {
		returns.Error(w, http.StatusInternalServerError, err)
		return
	}

```

The transaction is executed and a new row is created but I can not see the tracing of the queries in the APM UI in Kibana. Just for you know, I can see the HTTP transactions tracked.

Thank you!

---

<div class="post-metadata">

**Author:** ![stephenb](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/stephenb/32/40856_2.png) [@stephenb](https://discuss.elastic.co/u/stephenb)\
**Post date:** [October 9, 2022, 9:25pm UTC](https://discuss.elastic.co/t/apmsql-is-not-tracking-my-sql-queries/316158/2 "2022-10-09T21:25:57Z")

</div>

Curious which method / imports did you use...[apmsql](https://www.elastic.co/guide/en/apm/agent/go/current/builtin-modules.html#builtin-modules-apmsql) ?

I just went through something similar with another user... perhaps this will help

> It was a config issue indeed, simply doing `apmsql.Register(mysqlDriverName, mysql.MySQLDriver{})` is not enough, I needed to specify another option, but it’s easier to use one of the convenient packages provided by elastic to register the driver

> importing `_ "` `go.elastic.co/apm/module/apmsql/v2/mysql` `"` and commenting out `apmsql.Register(mysqlDriverName, mysql.MySQLDriver{})` fixed the issue

---

<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:** [October 10, 2022, 2:03am UTC](https://discuss.elastic.co/t/apmsql-is-not-tracking-my-sql-queries/316158/3 "2022-10-10T02:03:15Z")

</div>

You must use the context methods: `PrepareContext`, `ExecContext`, etc. If you pass in the HTTP request context, you should then see database spans.

---

<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:** [November 7, 2022, 2:03am UTC](https://discuss.elastic.co/t/apmsql-is-not-tracking-my-sql-queries/316158/4 "2022-11-07T02:03:22Z")

</div>

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