newrelic / go-agent

New Relic Go Agent
Apache License 2.0
773 stars 296 forks source link

nrpgx5 transaction issue during segment close #976

Open akushsky opened 5 days ago

akushsky commented 5 days ago

I'm trying to switch legacy nrpgx-based project to nrpgx5. I have a lot of requests (all my SELECT ones) that are not wrapped to transactions. Previously it was working perfectly, but now it occurs an error log on each segment close. It doesn't affect real NewRelic data, I could see all graphs etc., but it's flooding to my log output.

What I'm doing wrong? It's a must to wrap each request (even if it's a SELECT) to transaction?

Unable to end datastore segment - product: Postgres collection: table_name operation: select reason: transaction has already ended [init]


newrelic.(*DatastoreSegment).End (segments.go:206) github.com/newrelic/go-agent/v3/newrelic
nrpgx5.(*Tracer).TraceQueryEnd (nrpgx5.go:170) github.com/newrelic/go-agent/v3/integrations/nrpgx5
pgx.(*baseRows).Close (rows.go:188) github.com/jackc/pgx/v5
stdlib.(*Rows).Close (sql.go:693) github.com/jackc/pgx/v5/stdlib
sql.(*Rows).close.func1 (sql.go:3450) database/sql
sql.withLock (sql.go:3566) database/sql
sql.(*Rows).close (sql.go:3449) database/sql
sql.(*Rows).Close (sql.go:3433) database/sql
........
runtime.main (proc.go:272) runtime
runtime.goexit (asm_arm64.s:1223) runtime
 - Async Stack Trace
<autogenerated>:2
mirackara commented 3 days ago

Hi @akushsky,

Transactions have to be open to close out datastore segments properly

https://github.com/newrelic/go-agent/blob/73d05e251c7e1d14184a91b69e68a164c25aa46a/v3/integrations/nrpgx5/example/pgx/main.go#L39