apm-agent-go icon indicating copy to clipboard operation
apm-agent-go copied to clipboard

apmgormv2 postgres is not adding spans to http transactions

Open pkrauss-prot opened this issue 11 months ago • 1 comments

Describe the bug I am using a combination of:

github.com/go-chi/chi/v5 v5.0.12 with go.elastic.co/apm/module/apmchiv5/v2 v2.5.0 gorm.io/gorm v1.25.5 with go.elastic.co/apm/module/apmgormv2/v2 v2.5.0

go.elastic.co/apm/module/apmsql/v2 v2.5.0 // indirect go.elastic.co/apm/v2 v2.5.0 // indirect

When i pass my DB object to my handlers I call .WithContext() using r *http.Request passed from chi to the handler. I am able to see the dependency for postgress and some metrics. However I am unable to see the spans in the http requests.

Screenshot from 2024-03-18 16-45-15

double checked the request object to make sure the transaction information was present and it is

Screenshot from 2024-03-18 16-53-29

To Reproduce Steps to reproduce the behaviour:

var database, _ = gorm.Open(postgres.Open("dsn"), &gorm.Config{})

func handler(w http.ResponseWriter, r *http.Request) error {
	var projects []models.Project
	var responseWrapper models.ResponseWrapper[[]models.Project]
	database.WithContext(r.Context()).Preload(clause.Associations).Order("Name").Find(&projects)

	if len(projects) > 0 {
		responseWrapper.Data = projects
	} else {
		responseWrapper.Data = []models.Project{}
	}

	w.WriteHeader(http.StatusOK)
	w.Write(responseWrapper.Marshal())
	return nil
}

Expected behavior I would expect to see spans in the http transactions for my database queries.

pkrauss-prot avatar Mar 18 '24 20:03 pkrauss-prot

Also digging a little deeper when i use db.WithContext(r.Context()) i do see information populates in the transaction:

Screenshot from 2024-03-19 09-39-22

yet as i said, nothing shows up in apm under the transaction.

pkrauss-prot avatar Mar 19 '24 13:03 pkrauss-prot