Apmsql is not tracking my sql queries

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 and this is my current test code


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!

Curious which method / imports did you use...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

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

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